Applied rector with PHP8.1 migration rules

This commit is contained in:
Jan Böhmer 2023-06-11 14:15:46 +02:00
parent dc6a67c2f0
commit 7ee01d9a05
303 changed files with 1228 additions and 3465 deletions

View file

@ -44,24 +44,15 @@ use Twig\TwigTest;
final class EntityExtension extends AbstractExtension
{
protected EntityURLGenerator $entityURLGenerator;
protected TreeViewGenerator $treeBuilder;
private ElementTypeNameGenerator $nameGenerator;
public function __construct(EntityURLGenerator $entityURLGenerator, TreeViewGenerator $treeBuilder, ElementTypeNameGenerator $elementTypeNameGenerator)
public function __construct(protected EntityURLGenerator $entityURLGenerator, protected TreeViewGenerator $treeBuilder, private readonly ElementTypeNameGenerator $nameGenerator)
{
$this->entityURLGenerator = $entityURLGenerator;
$this->treeBuilder = $treeBuilder;
$this->nameGenerator = $elementTypeNameGenerator;
}
public function getTests(): array
{
return [
/* Checks if the given variable is an entitity (instance of AbstractDBElement) */
new TwigTest('entity', static function ($var) {
return $var instanceof AbstractDBElement;
}),
new TwigTest('entity', static fn($var) => $var instanceof AbstractDBElement),
];
}
@ -69,16 +60,16 @@ final class EntityExtension extends AbstractExtension
{
return [
/* Returns a string representation of the given entity */
new TwigFunction('entity_type', [$this, 'getEntityType']),
new TwigFunction('entity_type', fn(object $entity): ?string => $this->getEntityType($entity)),
/* Returns the URL to the given entity */
new TwigFunction('entity_url', [$this, 'generateEntityURL']),
new TwigFunction('entity_url', fn(\App\Entity\Base\AbstractDBElement $entity, string $method = 'info'): string => $this->generateEntityURL($entity, $method)),
/* Returns the URL to the given entity in timetravel mode */
new TwigFunction('timetravel_url', [$this, 'timeTravelURL']),
new TwigFunction('timetravel_url', fn(\App\Entity\Base\AbstractDBElement $element, \DateTimeInterface $dateTime): ?string => $this->timeTravelURL($element, $dateTime)),
/* Generates a JSON array of the given tree */
new TwigFunction('tree_data', [$this, 'treeData']),
new TwigFunction('tree_data', fn(\App\Entity\Base\AbstractDBElement $element, string $type = 'newEdit'): string => $this->treeData($element, $type)),
/* Gets a human readable label for the type of the given entity */
new TwigFunction('entity_type_label', [$this->nameGenerator, 'getLocalizedTypeLabel']),
new TwigFunction('entity_type_label', fn(object|string $entity): string => $this->nameGenerator->getLocalizedTypeLabel($entity)),
];
}
@ -86,14 +77,14 @@ final class EntityExtension extends AbstractExtension
{
try {
return $this->entityURLGenerator->timeTravelURL($element, $dateTime);
} catch (EntityNotSupportedException $e) {
} catch (EntityNotSupportedException) {
return null;
}
}
public function treeData(AbstractDBElement $element, string $type = 'newEdit'): string
{
$tree = $this->treeBuilder->getTreeView(get_class($element), null, $type, $element);
$tree = $this->treeBuilder->getTreeView($element::class, null, $type, $element);
return json_encode($tree, JSON_THROW_ON_ERROR);
}