refactor: inject AgeConstraintParserRegistry into TravelParser

This commit is contained in:
Björn Fromme
2026-06-26 17:20:42 +02:00
parent a8d2852313
commit a6ed60462d
3 changed files with 14 additions and 25 deletions
-18
View File
@@ -1,18 +0,0 @@
<?php
namespace App\BusProNet\Traits;
use Symfony\Component\DomCrawler\Crawler;
trait XmlParserTrait
{
protected function getStringOrNullValue(Crawler $node): ?string
{
return 0 < $node->count() ? $node->text() : null;
}
protected function getIntOrNullValue(Crawler $node): ?int
{
return 0 < $node->count() ? (int) $node->text() : null;
}
}
+11 -2
View File
@@ -3,18 +3,27 @@
namespace App\BusProNet\XmlLoader;
use App\BusProNet\Traits\TypeConversionTrait;
use App\BusProNet\Traits\XmlParserTrait;
use League\Flysystem\FilesystemOperator;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Contracts\Cache\CacheInterface;
abstract class AbstractLoader
{
use TypeConversionTrait;
use XmlParserTrait;
public function __construct(
protected readonly CacheInterface $cache,
protected readonly FilesystemOperator $xmlExport,
) {
}
protected function getStringOrNullValue(Crawler $node): ?string
{
return 0 < $node->count() ? $node->text() : null;
}
protected function getIntOrNullValue(Crawler $node): ?int
{
return 0 < $node->count() ? (int) $node->text() : null;
}
}
+3 -5
View File
@@ -22,8 +22,6 @@ use Symfony\Component\DomCrawler\Crawler;
*/
class TravelParser extends AbstractParser
{
private AgeConstraintParserRegistry $ageConstraintRegistry;
/**
* @var array<string>
*/
@@ -31,9 +29,9 @@ class TravelParser extends AbstractParser
Constants::PSEUDO_PRICE_ROOM_CODE,
];
public function __construct()
{
$this->ageConstraintRegistry = new AgeConstraintParserRegistry();
public function __construct(
private readonly AgeConstraintParserRegistry $ageConstraintRegistry = new AgeConstraintParserRegistry(),
) {
}
/**