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

@@ -7,4 +7,4 @@ use App\Domain\Scraping\Domain\Model\Manga;
interface MangaRepositoryInterface
{
public function getById(string $id): ?Manga;
}
}

View File

@@ -9,4 +9,4 @@ interface ScraperInterface
public function createScrapingJob(string $mangaId, string $chapterId, string $sourceId): ScrapingJob;
public function scrape(ScrapingJob $job): void;
public function supports(string $sourceType): bool;
}
}

View File

@@ -7,7 +7,8 @@ class ChapterScrapingCompleted
public function __construct(
private readonly string $jobId,
private readonly array $scrapedPages
) {}
) {
}
public function getJobId(): string
{
@@ -18,4 +19,4 @@ class ChapterScrapingCompleted
{
return $this->scrapedPages;
}
}
}

View File

@@ -7,7 +7,8 @@ class ChapterScrapingFailed
public function __construct(
private readonly string $chapterId,
private readonly string $reason
) {}
) {
}
public function getChapterId(): string
{
@@ -18,4 +19,4 @@ class ChapterScrapingFailed
{
return $this->reason;
}
}
}

View File

@@ -6,7 +6,8 @@ class ChapterScrapingStarted
{
public function __construct(
private readonly string $jobId
) {}
) {
}
public function getJobId(): string
{

View File

@@ -9,7 +9,8 @@ class PageScrapingProgressed
public function __construct(
private readonly string $jobId,
private readonly ScrapingProgress $progress
) {}
) {
}
public function getJobId(): string
{
@@ -20,4 +21,4 @@ class PageScrapingProgressed
{
return $this->progress;
}
}
}

View File

@@ -10,7 +10,8 @@ class Manga
private readonly string $slug,
private readonly string $description,
private readonly string $author,
) {}
) {
}
public function getId(): string
{
@@ -36,4 +37,4 @@ class Manga
{
return $this->author;
}
}
}

View File

@@ -87,4 +87,4 @@ class ScrapingJob
{
return $this->completedAt;
}
}
}

View File

@@ -7,7 +7,8 @@ class ScrapingProgress
public function __construct(
private readonly int $pagesScraped,
private readonly int $totalPages
) {}
) {
}
public function getPercentage(): float
{
@@ -16,4 +17,4 @@ class ScrapingProgress
}
return ($this->pagesScraped / $this->totalPages) * 100;
}
}
}

View File

@@ -8,4 +8,4 @@ enum ScrapingStatus: string
case IN_PROGRESS = 'in_progress';
case COMPLETED = 'completed';
case FAILED = 'failed';
}
}

View File

@@ -15,7 +15,8 @@ class Source
private readonly bool $isActive,
private readonly DateTimeImmutable $createdAt,
private readonly DateTimeImmutable $updatedAt
) {}
) {
}
public function getId(): string
{
@@ -56,4 +57,4 @@ class Source
{
return $this->updatedAt;
}
}
}

View File

@@ -15,4 +15,4 @@ class ChapterId
{
return $this->value;
}
}
}

View File

@@ -21,4 +21,4 @@ class ImageUrl
{
return pathinfo(parse_url($this->url, PHP_URL_PATH), PATHINFO_EXTENSION);
}
}
}

View File

@@ -21,4 +21,4 @@ class PageNumber
{
return sprintf('%03d', $this->number);
}
}
}

View File

@@ -2,7 +2,7 @@
namespace App\Domain\Scraping\Domain\Model\ValueObject;
class SourceId
class SourceId
{
public function __construct(private readonly string $value)
{
@@ -15,4 +15,4 @@ class SourceId
{
return $this->value;
}
}
}

View File

@@ -15,4 +15,4 @@ class TempDirectory
{
return $this->path;
}
}
}

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;
}
}
}