fix: phpcs-fixer

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-02-05 21:32:04 +01:00
parent ba874480ee
commit c55cd62ec7
65 changed files with 346 additions and 355 deletions

View File

@@ -24,11 +24,9 @@ readonly class ScrapeChapterRequest
#[ApiProperty(description: 'ID du chapitre à scraper')]
#[Assert\NotBlank]
public string $chapterId,
#[ApiProperty(description: 'ID de la source à utiliser')]
#[Assert\NotBlank]
public string $sourceId,
#[ApiProperty(description: 'ID du manga')]
#[Assert\NotBlank]
public string $mangaId,

View File

@@ -31,13 +31,10 @@ readonly class ScrapingStatusResponse
public function __construct(
#[ApiProperty(identifier: true)]
public string $jobId,
#[ApiProperty]
public string $status,
#[ApiProperty]
public ?float $progress = null,
#[ApiProperty]
public ?string $error = null
) {

View File

@@ -12,7 +12,8 @@ final class ScrapeChapterStateProcessor implements ProcessorInterface
{
public function __construct(
private readonly MessageBusInterface $commandBus
) {}
) {
}
/**
* @param ScrapeChapterRequest $data

View File

@@ -11,7 +11,8 @@ class DoctrineMangaRepository implements MangaRepositoryInterface
{
public function __construct(
private readonly EntityManagerInterface $entityManager
) {}
) {
}
public function getById(string $id): ?Manga
{
@@ -19,4 +20,4 @@ class DoctrineMangaRepository implements MangaRepositoryInterface
return $manga ? $manga->toDomain() : null;
}
}
}

View File

@@ -11,16 +11,17 @@ class DoctrineSourceRepository implements SourceRepositoryInterface
{
public function __construct(
private readonly EntityManagerInterface $entityManager
) {}
) {
}
public function getById(string $id): ?Source
{
$sourceEntity = $this->entityManager->getRepository(SourceEntityEntity::class)->find($id);
if (!$sourceEntity) {
return null;
}
return $sourceEntity->toDomain();
}
}
}

View File

@@ -56,7 +56,7 @@ class MangaEntity
$entity->description = $manga->getDescription();
$entity->author = $manga->getAuthor();
return $entity;
}

View File

@@ -45,7 +45,7 @@ class ScrapingJobEntity
$entity->status = $job->getStatus()->value;
$entity->createdAt = $job->getCreatedAt();
$entity->completedAt = $job->getCompletedAt();
return $entity;
}
@@ -60,4 +60,4 @@ class ScrapingJobEntity
return $job;
}
}
}

View File

@@ -45,7 +45,7 @@ class SourceEntity
$entity->isActive = $source->isActive();
$entity->createdAt = $source->getCreatedAt();
$entity->updatedAt = $source->getUpdatedAt();
return $entity;
}
@@ -62,4 +62,4 @@ class SourceEntity
$this->updatedAt
);
}
}
}

View File

@@ -4,20 +4,21 @@ namespace App\Domain\Scraping\Infrastructure\Service;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class ImageDownloader
class ImageDownloader
{
public function __construct(
private readonly HttpClientInterface $httpClient
) {}
) {
}
public function download(string $url, string $destination): void
{
$response = $this->httpClient->request('GET', $url);
if (!str_starts_with($response->getHeaders()['content-type'][0], 'image/')) {
throw new \RuntimeException('Invalid content type');
}
file_put_contents($destination, $response->getContent());
}
}
}

View File

@@ -19,7 +19,8 @@ abstract class AbstractScraper implements ScraperInterface
public function __construct(
protected readonly ImageDownloader $imageDownloader,
protected readonly MessageBusInterface $eventBus
) {}
) {
}
public function createScrapingJob(string $mangaId, string $chapterId, string $sourceId): ScrapingJob
{
@@ -32,7 +33,7 @@ abstract class AbstractScraper implements ScraperInterface
}
abstract public function scrape(ScrapingJob $job): void;
abstract protected function scrapePages(ScrapingJob $job, Source $source): array;
protected function cleanupTempDirectory(string $tempDir): void
@@ -82,4 +83,4 @@ abstract class AbstractScraper implements ScraperInterface
}
abstract public function supports(string $sourceType): bool;
}
}

View File

@@ -30,7 +30,7 @@ class HtmlScraper extends AbstractScraper
try {
$pages = $this->scrapePages($job, $sourceConfig);
foreach ($pages as $index => $imageUrl) {
$pageNumber = new PageNumber($index + 1);
$extension = pathinfo(parse_url($imageUrl, PHP_URL_PATH), PATHINFO_EXTENSION);
@@ -43,7 +43,7 @@ class HtmlScraper extends AbstractScraper
$this->downloadImage($imageUrl, $destination);
$job->addPage($pageNumber, new ImageUrl($imageUrl));
$this->dispatchProgressEvent($job, $index + 1, count($pages));
}
@@ -61,7 +61,7 @@ class HtmlScraper extends AbstractScraper
if (!$sourceConfig['next_page_selector']) {
return $this->scrapeVerticalReader($job, $sourceConfig);
}
return $this->scrapeHorizontalReader($job, $sourceConfig);
}
@@ -69,7 +69,7 @@ class HtmlScraper extends AbstractScraper
{
$html = $this->fetchHtml($this->buildChapterUrl($job, $sourceConfig));
$crawler = new Crawler($html);
return $crawler->filter($sourceConfig['image_selector'])
->each(function ($node) {
return $this->cleanImageUrl(
@@ -86,11 +86,11 @@ class HtmlScraper extends AbstractScraper
while ($currentUrl) {
$html = $this->fetchHtml($currentUrl);
$crawler = new Crawler($html);
$imageUrl = $crawler->filter($sourceConfig['image_selector'])
->attr('src') ?: $crawler->filter($sourceConfig['image_selector'])
->attr('data-src');
$pages[] = $this->cleanImageUrl($imageUrl);
$nextLink = $crawler->filter($sourceConfig['next_page_selector']);
@@ -103,11 +103,11 @@ class HtmlScraper extends AbstractScraper
private function fetchHtml(string $url): string
{
$response = $this->httpClient->request('GET', $url);
if ($response->getStatusCode() >= 400) {
throw new \RuntimeException('Failed to fetch page: ' . $url);
}
return $response->getContent();
}
@@ -130,4 +130,4 @@ class HtmlScraper extends AbstractScraper
{
return 'html' === $sourceType;
}
}
}