Skip to content

Commit

Permalink
Run rector
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored and jordisala1991 committed Mar 6, 2023
1 parent da446fc commit 7baf4e4
Show file tree
Hide file tree
Showing 39 changed files with 233 additions and 402 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
],
"homepage": "https://docs.sonata-project.org/projects/SonataDoctrineORMAdminBundle",
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.0",
"doctrine/dbal": "^3.4",
"doctrine/doctrine-bundle": "^2.7",
"doctrine/orm": "^2.14",
Expand Down
10 changes: 4 additions & 6 deletions src/Block/AuditBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
*/
final class AuditBlockService extends AbstractBlockService
{
private AuditReader $auditReader;

public function __construct(Environment $twig, AuditReader $auditReader)
{
public function __construct(
Environment $twig,
private AuditReader $auditReader
) {
parent::__construct($twig);

$this->auditReader = $auditReader;
}

public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response
Expand Down
20 changes: 4 additions & 16 deletions src/Builder/DatagridBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,12 @@
*/
final class DatagridBuilder implements DatagridBuilderInterface
{
private FilterFactoryInterface $filterFactory;

private FormFactoryInterface $formFactory;

private TypeGuesserInterface $guesser;

private bool $csrfTokenEnabled;

public function __construct(
FormFactoryInterface $formFactory,
FilterFactoryInterface $filterFactory,
TypeGuesserInterface $guesser,
bool $csrfTokenEnabled = true
private FormFactoryInterface $formFactory,
private FilterFactoryInterface $filterFactory,
private TypeGuesserInterface $guesser,
private bool $csrfTokenEnabled = true
) {
$this->formFactory = $formFactory;
$this->filterFactory = $filterFactory;
$this->guesser = $guesser;
$this->csrfTokenEnabled = $csrfTokenEnabled;
}

public function fixFieldDescription(FieldDescriptionInterface $fieldDescription): void
Expand Down
17 changes: 5 additions & 12 deletions src/Builder/ListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,13 @@
*/
final class ListBuilder implements ListBuilderInterface
{
private TypeGuesserInterface $guesser;

/**
* @var string[]
*/
private array $templates = [];

/**
* @param string[] $templates
*/
public function __construct(TypeGuesserInterface $guesser, array $templates = [])
{
$this->guesser = $guesser;
$this->templates = $templates;
public function __construct(
private TypeGuesserInterface $guesser,
private array $templates = []
) {
}

public function getBaseList(array $options = []): FieldDescriptionCollection
Expand Down Expand Up @@ -82,7 +75,7 @@ public function fixFieldDescription(FieldDescriptionInterface $fieldDescription)
throw new \RuntimeException(sprintf(
'Please define a type for field `%s` in `%s`',
$fieldDescription->getName(),
\get_class($fieldDescription->getAdmin())
$fieldDescription->getAdmin()::class
));
}

Expand Down
17 changes: 5 additions & 12 deletions src/Builder/ShowBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,13 @@
*/
final class ShowBuilder implements ShowBuilderInterface
{
private TypeGuesserInterface $guesser;

/**
* @var string[]
*/
private array $templates;

/**
* @param string[] $templates
*/
public function __construct(TypeGuesserInterface $guesser, array $templates)
{
$this->guesser = $guesser;
$this->templates = $templates;
public function __construct(
private TypeGuesserInterface $guesser,
private array $templates
) {
}

public function getBaseList(array $options = []): FieldDescriptionCollection
Expand Down Expand Up @@ -75,7 +68,7 @@ public function fixFieldDescription(FieldDescriptionInterface $fieldDescription)
throw new \RuntimeException(sprintf(
'Please define a type for field `%s` in `%s`',
$fieldDescription->getName(),
\get_class($fieldDescription->getAdmin())
$fieldDescription->getAdmin()::class
));
}

Expand Down
9 changes: 3 additions & 6 deletions src/Datagrid/ProxyQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@
*/
final class ProxyQuery implements ProxyQueryInterface
{
private QueryBuilder $queryBuilder;

private ?string $sortBy = null;

private ?string $sortOrder = null;
Expand All @@ -100,9 +98,8 @@ final class ProxyQuery implements ProxyQueryInterface
*/
private array $hints = [];

public function __construct(QueryBuilder $queryBuilder)
public function __construct(private QueryBuilder $queryBuilder)
{
$this->queryBuilder = $queryBuilder;
$this->uniqueParameterId = 0;
$this->entityJoinAliases = [];
}
Expand Down Expand Up @@ -158,7 +155,7 @@ public function getDoctrineQuery(): Query
$orderByDQLPart = $queryBuilder->getDQLPart('orderBy');
$queryBuilder->resetDQLPart('orderBy');

if (false === strpos($sortBy, '.')) {
if (!str_contains($sortBy, '.')) {
$sortBy = $rootAlias.'.'.$sortBy;
}

Expand Down Expand Up @@ -318,7 +315,7 @@ public function entityJoin(array $associationMappings): string
*
* @return $this
*/
public function setHint(string $name, $value): ProxyQueryInterface
public function setHint(string $name, mixed $value): ProxyQueryInterface
{
$this->hints[$name] = $value;

Expand Down
5 changes: 1 addition & 4 deletions src/FieldDescription/FieldDescriptionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@

final class FieldDescriptionFactory implements FieldDescriptionFactoryInterface
{
private ManagerRegistry $registry;

public function __construct(ManagerRegistry $registry)
public function __construct(private ManagerRegistry $registry)
{
$this->registry = $registry;
}

public function create(string $class, string $name, array $options = []): FieldDescriptionInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Filter/CallbackFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function filter(ProxyQueryInterface $query, string $alias, string $field,
if (!\is_bool($isActive)) {
throw new \UnexpectedValueException(sprintf(
'The callback should return a boolean, %s returned',
\is_object($isActive) ? 'instance of "'.\get_class($isActive).'"' : '"'.\gettype($isActive).'"'
\is_object($isActive) ? 'instance of "'.$isActive::class.'"' : '"'.\gettype($isActive).'"'
));
}

Expand Down
9 changes: 3 additions & 6 deletions src/Filter/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ protected function association(ProxyQueryInterface $query, FilterData $data): ar

/**
* @param ProxyQueryInterface<object> $query
* @param mixed $parameter
*/
final protected function applyWhere(ProxyQueryInterface $query, $parameter): void
final protected function applyWhere(ProxyQueryInterface $query, mixed $parameter): void
{
if (self::CONDITION_OR === $this->getCondition()) {
$this->addOrParameter($query, $parameter);
Expand All @@ -99,9 +98,8 @@ final protected function applyWhere(ProxyQueryInterface $query, $parameter): voi

/**
* @param ProxyQueryInterface<object> $query
* @param mixed $parameter
*/
final protected function applyHaving(ProxyQueryInterface $query, $parameter): void
final protected function applyHaving(ProxyQueryInterface $query, mixed $parameter): void
{
if (self::CONDITION_OR === $this->getCondition()) {
$query->getQueryBuilder()->orHaving($parameter);
Expand Down Expand Up @@ -132,9 +130,8 @@ final protected function getNewParameterName(ProxyQueryInterface $query): string
* which will produce undesired results.
*
* @param ProxyQueryInterface<object> $query
* @param mixed $parameter
*/
private function addOrParameter(ProxyQueryInterface $query, $parameter): void
private function addOrParameter(ProxyQueryInterface $query, mixed $parameter): void
{
if ($this->hasPreviousFilter()) {
$previousFilter = $this->getPreviousFilter();
Expand Down
20 changes: 6 additions & 14 deletions src/Filter/StringFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,12 @@ public function filter(ProxyQueryInterface $query, string $alias, string $field,

$this->applyWhere($query, $or);

switch ($type) {
case StringOperatorType::TYPE_EQUAL:
case StringOperatorType::TYPE_NOT_EQUAL:
$format = '%s';
break;
case StringOperatorType::TYPE_STARTS_WITH:
$format = '%s%%';
break;
case StringOperatorType::TYPE_ENDS_WITH:
$format = '%%%s';
break;
default:
$format = '%%%s%%';
}
$format = match ($type) {
StringOperatorType::TYPE_EQUAL, StringOperatorType::TYPE_NOT_EQUAL => '%s',
StringOperatorType::TYPE_STARTS_WITH => '%s%%',
StringOperatorType::TYPE_ENDS_WITH => '%%%s',
default => '%%%s%%',
};

$query->getQueryBuilder()->setParameter(
$parameterName,
Expand Down
13 changes: 5 additions & 8 deletions src/Model/AuditReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@
*/
final class AuditReader implements AuditReaderInterface
{
private SimpleThingsAuditReader $auditReader;

public function __construct(SimpleThingsAuditReader $auditReader)
public function __construct(private SimpleThingsAuditReader $auditReader)
{
$this->auditReader = $auditReader;
}

/**
Expand All @@ -42,7 +39,7 @@ public function find(string $className, $id, $revisionId): ?object
{
try {
return $this->auditReader->find($className, $id, $revisionId);
} catch (\Throwable $exception) {
} catch (\Throwable) {
return null;
}
}
Expand Down Expand Up @@ -72,7 +69,7 @@ public function findRevision(string $className, $revisionId): ?Revision
{
try {
return $this->createRevisionFromEntityAuditRevision($this->auditReader->findRevision($revisionId));
} catch (\Throwable $exception) {
} catch (\Throwable) {
return null;
}
}
Expand All @@ -84,7 +81,7 @@ public function findRevisions(string $className, $id): array
[$this, 'createRevisionFromEntityAuditRevision'],
$this->auditReader->findRevisions($className, $id)
);
} catch (\Throwable $exception) {
} catch (\Throwable) {
return [];
}
}
Expand All @@ -93,7 +90,7 @@ public function diff(string $className, $id, $oldRevisionId, $newRevisionId): ar
{
try {
return $this->auditReader->diff($className, $id, $oldRevisionId, $newRevisionId);
} catch (\Throwable $exception) {
} catch (\Throwable) {
return [];
}
}
Expand Down
16 changes: 6 additions & 10 deletions src/Model/ModelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,15 @@ final class ModelManager implements ModelManagerInterface, LockInterface, ProxyR
{
public const ID_SEPARATOR = '~';

private ManagerRegistry $registry;

private PropertyAccessorInterface $propertyAccessor;

/**
* @var EntityManagerInterface[]
*/
private array $cache = [];

public function __construct(ManagerRegistry $registry, PropertyAccessorInterface $propertyAccessor)
{
$this->registry = $registry;
$this->propertyAccessor = $propertyAccessor;
public function __construct(
private ManagerRegistry $registry,
private PropertyAccessorInterface $propertyAccessor
) {
}

public function getRealClass(object $object): string
Expand Down Expand Up @@ -182,7 +178,7 @@ public function findOneBy(string $class, array $criteria = []): ?object
public function getEntityManager($class): EntityManagerInterface
{
if (\is_object($class)) {
$class = \get_class($class);
$class = $class::class;
}

if (!isset($this->cache[$class])) {
Expand Down Expand Up @@ -385,7 +381,7 @@ public function getExportFields(string $class): array

public function reverseTransform(object $object, array $array = []): void
{
$metadata = $this->getMetadata(\get_class($object));
$metadata = $this->getMetadata($object::class);

foreach ($array as $name => $value) {
$property = $this->getFieldName($metadata, $name);
Expand Down
5 changes: 1 addition & 4 deletions src/Util/ObjectAclManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@

final class ObjectAclManipulator extends BaseObjectAclManipulator
{
private ManagerRegistry $registry;

public function __construct(ManagerRegistry $registry)
public function __construct(private ManagerRegistry $registry)
{
$this->registry = $registry;
}

public function batchConfigureAcls(OutputInterface $output, AdminInterface $admin, ?UserSecurityIdentity $securityIdentity = null): void
Expand Down
4 changes: 2 additions & 2 deletions src/Util/SmartPaginatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private static function hasOrderByWithToManyAssociation(ProxyQueryInterface $pro

if (null !== $sortBy) {
foreach ($joinAliases as $joinAlias) {
if (0 === strpos($sortBy, $joinAlias.'.')) {
if (str_starts_with($sortBy, $joinAlias.'.')) {
return true;
}
}
Expand All @@ -158,7 +158,7 @@ private static function hasOrderByWithToManyAssociation(ProxyQueryInterface $pro
foreach ($orderByParts as $orderByPart) {
foreach ($orderByPart->getParts() as $part) {
foreach ($joinAliases as $joinAlias) {
if (0 === strpos($part, $joinAlias.'.')) {
if (str_starts_with($part, $joinAlias.'.')) {
return true;
}
}
Expand Down
18 changes: 8 additions & 10 deletions tests/App/Entity/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@

/** @ORM\Embeddable() */
#[ORM\Embeddable]
class Address
class Address implements \Stringable
{
/**
* @ORM\Column(type="string")
*/
#[ORM\Column(type: Types::STRING)]
private string $street;

public function __construct(string $street = '')
{
$this->street = $street;
public function __construct(
/**
* @ORM\Column(type="string")
*/
#[ORM\Column(type: Types::STRING)]
private string $street = ''
) {
}

public function __toString(): string
Expand Down
Loading

0 comments on commit 7baf4e4

Please sign in to comment.