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

@ -34,15 +34,8 @@ use Symfony\Contracts\Cache\TagAwareCacheInterface;
*/
class NodesListBuilder
{
protected EntityManagerInterface $em;
protected TagAwareCacheInterface $cache;
protected UserCacheKeyGenerator $keyGenerator;
public function __construct(EntityManagerInterface $em, TagAwareCacheInterface $treeCache, UserCacheKeyGenerator $keyGenerator)
public function __construct(protected EntityManagerInterface $em, protected TagAwareCacheInterface $cache, protected UserCacheKeyGenerator $keyGenerator)
{
$this->em = $em;
$this->keyGenerator = $keyGenerator;
$this->cache = $treeCache;
}
/**
@ -56,7 +49,7 @@ class NodesListBuilder
*/
public function typeToNodesList(string $class_name, ?AbstractStructuralDBElement $parent = null): array
{
$parent_id = null !== $parent ? $parent->getID() : '0';
$parent_id = $parent instanceof \App\Entity\Base\AbstractStructuralDBElement ? $parent->getID() : '0';
// Backslashes are not allowed in cache keys
$secure_class_name = str_replace('\\', '_', $class_name);
$key = 'list_'.$this->keyGenerator->generateKey().'_'.$secure_class_name.$parent_id;
@ -81,6 +74,6 @@ class NodesListBuilder
*/
public function getChildrenFlatList(AbstractStructuralDBElement $element): array
{
return $this->typeToNodesList(get_class($element), $element);
return $this->typeToNodesList($element::class, $element);
}
}

View file

@ -27,19 +27,18 @@ use Symfony\Contracts\Cache\TagAwareCacheInterface;
final class SidebarTreeUpdater
{
private const CACHE_KEY = 'sidebar_tree_updated';
private const TTL = 60 * 60 * 24; // 24 hours
private const TTL = 60 * 60 * 24;
private CacheInterface $cache;
public function __construct(TagAwareCacheInterface $treeCache)
public function __construct(
// 24 hours
private readonly TagAwareCacheInterface $cache
)
{
$this->cache = $treeCache;
}
/**
* Returns the time when the sidebar tree was updated the last time.
* The frontend uses this information to reload the sidebar tree.
* @return \DateTimeInterface
*/
public function getLastTreeUpdate(): \DateTimeInterface
{

View file

@ -27,11 +27,8 @@ use Doctrine\ORM\EntityManagerInterface;
class StructuralElementRecursionHelper
{
protected EntityManagerInterface $em;
public function __construct(EntityManagerInterface $em)
public function __construct(protected EntityManagerInterface $em)
{
$this->em = $em;
}
/**

View file

@ -49,24 +49,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
*/
class ToolsTreeBuilder
{
protected TranslatorInterface $translator;
protected UrlGeneratorInterface $urlGenerator;
protected UserCacheKeyGenerator $keyGenerator;
protected TagAwareCacheInterface $cache;
protected \Symfony\Bundle\SecurityBundle\Security $security;
public function __construct(TranslatorInterface $translator, UrlGeneratorInterface $urlGenerator,
TagAwareCacheInterface $treeCache, UserCacheKeyGenerator $keyGenerator,
\Symfony\Bundle\SecurityBundle\Security $security)
public function __construct(protected TranslatorInterface $translator, protected UrlGeneratorInterface $urlGenerator, protected TagAwareCacheInterface $cache, protected UserCacheKeyGenerator $keyGenerator, protected \Symfony\Bundle\SecurityBundle\Security $security)
{
$this->translator = $translator;
$this->urlGenerator = $urlGenerator;
$this->cache = $treeCache;
$this->keyGenerator = $keyGenerator;
$this->security = $security;
}
/**

View file

@ -47,26 +47,8 @@ use function count;
class TreeViewGenerator
{
protected EntityURLGenerator $urlGenerator;
protected EntityManagerInterface $em;
protected TagAwareCacheInterface $cache;
protected UserCacheKeyGenerator $keyGenerator;
protected TranslatorInterface $translator;
protected bool $rootNodeExpandedByDefault;
protected bool $rootNodeEnabled;
public function __construct(EntityURLGenerator $URLGenerator, EntityManagerInterface $em,
TagAwareCacheInterface $treeCache, UserCacheKeyGenerator $keyGenerator, TranslatorInterface $translator, bool $rootNodeExpandedByDefault, bool $rootNodeEnabled)
public function __construct(protected EntityURLGenerator $urlGenerator, protected EntityManagerInterface $em, protected TagAwareCacheInterface $cache, protected UserCacheKeyGenerator $keyGenerator, protected TranslatorInterface $translator, protected bool $rootNodeExpandedByDefault, protected bool $rootNodeEnabled)
{
$this->urlGenerator = $URLGenerator;
$this->em = $em;
$this->cache = $treeCache;
$this->keyGenerator = $keyGenerator;
$this->translator = $translator;
$this->rootNodeExpandedByDefault = $rootNodeExpandedByDefault;
$this->rootNodeEnabled = $rootNodeEnabled;
}
/**
@ -92,7 +74,7 @@ class TreeViewGenerator
$href = $this->urlGenerator->createURL(new $class());
$new_node = new TreeViewNode($this->translator->trans('entity.tree.new'), $href);
//When the id of the selected element is null, then we have a new element, and we need to select "new" node
if (null === $selectedElement || null === $selectedElement->getID()) {
if (!$selectedElement instanceof \App\Entity\Base\AbstractDBElement || null === $selectedElement->getID()) {
$new_node->setSelected(true);
}
$head[] = $new_node;
@ -116,7 +98,7 @@ class TreeViewGenerator
$recursiveIterator = new RecursiveIteratorIterator($treeIterator, RecursiveIteratorIterator::SELF_FIRST);
foreach ($recursiveIterator as $item) {
/** @var TreeViewNode $item */
if (null !== $selectedElement && $item->getId() === $selectedElement->getID()) {
if ($selectedElement instanceof \App\Entity\Base\AbstractDBElement && $item->getId() === $selectedElement->getID()) {
$item->setSelected(true);
}
@ -202,7 +184,7 @@ class TreeViewGenerator
if (!is_a($class, AbstractNamedDBElement::class, true)) {
throw new InvalidArgumentException('$class must be a class string that implements StructuralDBElement or NamedDBElement!');
}
if (null !== $parent && !is_a($parent, $class)) {
if ($parent instanceof \App\Entity\Base\AbstractStructuralDBElement && !$parent instanceof $class) {
throw new InvalidArgumentException('$parent must be of the type $class!');
}
@ -210,7 +192,7 @@ class TreeViewGenerator
$repo = $this->em->getRepository($class);
//If we just want a part of a tree, don't cache it
if (null !== $parent) {
if ($parent instanceof \App\Entity\Base\AbstractStructuralDBElement) {
return $repo->getGenericNodeTree($parent);
}