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

@ -51,7 +51,6 @@ abstract class AbstractPartsContainingRepository extends StructuralDBElementRepo
/**
* Returns the count of the parts associated with this element and all its children.
* Please be aware that this function is pretty slow on large trees!
* @param AbstractPartsContainingDBElement $element
* @return int
*/
public function getPartsCountRecursive(AbstractPartsContainingDBElement $element): int
@ -64,8 +63,6 @@ abstract class AbstractPartsContainingRepository extends StructuralDBElementRepo
* This function is used to limit the recursion depth (remaining_depth is decreased on each call).
* If the recursion limit is reached (remaining_depth <= 0), a RuntimeException is thrown.
* @internal This function is not intended to be called directly, use getPartsCountRecursive() instead.
* @param AbstractPartsContainingDBElement $element
* @param int $remaining_depth
* @return int
*/
protected function getPartsCountRecursiveWithDepthN(AbstractPartsContainingDBElement $element, int $remaining_depth): int

View file

@ -57,7 +57,7 @@ class DBElementRepository extends EntityRepository
public function changeID(AbstractDBElement $element, int $new_id): void
{
$qb = $this->createQueryBuilder('element');
$q = $qb->update(get_class($element), 'element')
$q = $qb->update($element::class, 'element')
->set('element.id', $new_id)
->where('element.id = ?1')
->setParameter(1, $element->getID())
@ -87,7 +87,7 @@ class DBElementRepository extends EntityRepository
protected function setField(AbstractDBElement $element, string $field, int $new_value): void
{
$reflection = new ReflectionClass(get_class($element));
$reflection = new ReflectionClass($element::class);
$property = $reflection->getProperty($field);
$property->setAccessible(true);
$property->setValue($element, $new_value);

View file

@ -84,7 +84,7 @@ class LabelProfileRepository extends NamedDBElementRepository
$type_children[] = $node;
}
if (!empty($type_children)) {
if ($type_children !== []) {
//Use default label e.g. 'part_label'. $$ marks that it will be translated in TreeViewGenerator
$tmp = new TreeViewNode('$$'.$type.'.label', null, $type_children);
@ -112,7 +112,6 @@ class LabelProfileRepository extends NamedDBElementRepository
/**
* Returns all LabelProfiles that can be used for parts
* @return array
*/
public function getPartLabelProfiles(): array
{
@ -121,7 +120,6 @@ class LabelProfileRepository extends NamedDBElementRepository
/**
* Returns all LabelProfiles that can be used for part lots
* @return array
*/
public function getPartLotsLabelProfiles(): array
{
@ -130,7 +128,6 @@ class LabelProfileRepository extends NamedDBElementRepository
/**
* Returns all LabelProfiles that can be used for storelocations
* @return array
*/
public function getStorelocationsLabelProfiles(): array
{

View file

@ -41,7 +41,7 @@ class LogEntryRepository extends DBElementRepository
/** @var AbstractDBElement $element */
$element = $criteria['target'];
$criteria['target_id'] = $element->getID();
$criteria['target_type'] = AbstractLogEntry::targetTypeClassToID(get_class($element));
$criteria['target_type'] = AbstractLogEntry::targetTypeClassToID($element::class);
unset($criteria['target']);
}
@ -117,7 +117,7 @@ class LogEntryRepository extends DBElementRepository
->orderBy('log.timestamp', 'DESC');
$qb->setParameters([
'target_type' => AbstractLogEntry::targetTypeClassToID(get_class($element)),
'target_type' => AbstractLogEntry::targetTypeClassToID($element::class),
'target_id' => $element->getID(),
'until' => $until,
]);
@ -143,7 +143,7 @@ class LogEntryRepository extends DBElementRepository
->orderBy('log.timestamp', 'DESC');
$qb->setParameters([
'target_type' => AbstractLogEntry::targetTypeClassToID(get_class($element)),
'target_type' => AbstractLogEntry::targetTypeClassToID($element::class),
'target_id' => $element->getID(),
'until' => $timestamp,
]);
@ -151,13 +151,12 @@ class LogEntryRepository extends DBElementRepository
$query = $qb->getQuery();
$count = $query->getSingleScalarResult();
return !($count > 0);
return $count <= 0;
}
/**
* Gets the last log entries ordered by timestamp.
*
* @param string $order
* @param null $limit
* @param null $offset
*/
@ -216,7 +215,7 @@ class LogEntryRepository extends DBElementRepository
->orderBy('log.timestamp', 'DESC');
$qb->setParameters([
'target_type' => AbstractLogEntry::targetTypeClassToID(get_class($element)),
'target_type' => AbstractLogEntry::targetTypeClassToID($element::class),
'target_id' => $element->getID(),
]);

View file

@ -26,8 +26,6 @@ class ParameterRepository extends DBElementRepository
* Find parameters using a parameter name
* @param string $name The name to search for
* @param bool $exact True, if only exact names should match. False, if the name just needs to be contained in the parameter name
* @param int $max_results
* @return array
*/
public function autocompleteParamName(string $name, bool $exact = false, int $max_results = 50): array
{

View file

@ -100,8 +100,6 @@ class StructuralDBElementRepository extends NamedDBElementRepository
* Creates a structure of AbstractStructuralDBElements from a path separated by $separator, which splits the various levels.
* This function will try to use existing elements, if they are already in the database. If not, they will be created.
* An array of the created elements will be returned, with the last element being the deepest element.
* @param string $path
* @param string $separator
* @return AbstractStructuralDBElement[]
*/
public function getNewEntityFromPath(string $path, string $separator = '->'): array
@ -118,7 +116,7 @@ class StructuralDBElementRepository extends NamedDBElementRepository
$entity = $this->getNewEntityFromCache($name, $parent);
//See if we already have an element with this name and parent in the database
if (!$entity) {
if (!$entity instanceof \App\Entity\Base\AbstractStructuralDBElement) {
$entity = $this->findOneBy(['name' => $name, 'parent' => $parent]);
}
if (null === $entity) {
@ -140,7 +138,7 @@ class StructuralDBElementRepository extends NamedDBElementRepository
private function getNewEntityFromCache(string $name, ?AbstractStructuralDBElement $parent): ?AbstractStructuralDBElement
{
$key = $parent ? $parent->getFullPath('%->%').'%->%'.$name : $name;
$key = $parent instanceof \App\Entity\Base\AbstractStructuralDBElement ? $parent->getFullPath('%->%').'%->%'.$name : $name;
if (isset($this->new_entity_cache[$key])) {
return $this->new_entity_cache[$key];
}
@ -157,8 +155,6 @@ class StructuralDBElementRepository extends NamedDBElementRepository
* Returns an element of AbstractStructuralDBElements queried from a path separated by $separator, which splits the various levels.
* An array of the created elements will be returned, with the last element being the deepest element.
* If no element was found, an empty array will be returned.
* @param string $path
* @param string $separator
* @return AbstractStructuralDBElement[]
*/
public function getEntityByPath(string $path, string $separator = '->'): array

View file

@ -44,7 +44,7 @@ final class UserRepository extends NamedDBElementRepository implements PasswordU
*/
public function getAnonymousUser(): ?User
{
if (null === $this->anonymous_user) {
if (!$this->anonymous_user instanceof \App\Entity\UserSystem\User) {
$this->anonymous_user = $this->findOneBy([
'id' => User::ID_ANONYMOUS,
]);
@ -78,7 +78,7 @@ final class UserRepository extends NamedDBElementRepository implements PasswordU
try {
return $qb->getQuery()->getOneOrNullResult();
} catch (NonUniqueResultException $nonUniqueResultException) {
} catch (NonUniqueResultException) {
return null;
}
}