Skip to content

Commit 383bf5e

Browse files
Merge branch '1.x' into 2.x
2 parents d032b53 + c33888f commit 383bf5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+63
-61
lines changed

rector.php

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use Rector\Config\RectorConfig;
2121
use Rector\Php70\Rector\FunctionLike\ExceptionHandlerTypehintRector;
22+
use Rector\PHPUnit\CodeQuality\Rector\Class_\NarrowUnusedSetUpDefinedPropertyRector;
2223
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
2324
use Rector\PHPUnit\Set\PHPUnitSetList;
2425
use Rector\Set\ValueObject\LevelSetList;
@@ -40,5 +41,6 @@
4041
$rectorConfig->skip([
4142
ExceptionHandlerTypehintRector::class,
4243
PreferPHPUnitThisCallRector::class,
44+
NarrowUnusedSetUpDefinedPropertyRector::class,
4345
]);
4446
};

src/Action/CompareAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class CompareAction
2222
{
2323
public function __construct(
2424
private Environment $twig,
25-
private AuditReader $auditReader
25+
private AuditReader $auditReader,
2626
) {
2727
}
2828

src/Action/IndexAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class IndexAction
2121
{
2222
public function __construct(
2323
private Environment $twig,
24-
private AuditReader $auditReader
24+
private AuditReader $auditReader,
2525
) {
2626
}
2727

src/Action/ViewDetailAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class ViewDetailAction
2222
{
2323
public function __construct(
2424
private Environment $twig,
25-
private AuditReader $auditReader
25+
private AuditReader $auditReader,
2626
) {
2727
}
2828

src/Action/ViewEntityAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class ViewEntityAction
2121
{
2222
public function __construct(
2323
private Environment $twig,
24-
private AuditReader $auditReader
24+
private AuditReader $auditReader,
2525
) {
2626
}
2727

src/Action/ViewRevisionAction.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class ViewRevisionAction
2323
{
2424
public function __construct(
2525
private Environment $twig,
26-
private AuditReader $auditReader
26+
private AuditReader $auditReader,
2727
) {
2828
}
2929

@@ -35,7 +35,7 @@ public function __invoke(int $rev): Response
3535
try {
3636
$revision = $this->auditReader->findRevision($rev);
3737
} catch (InvalidRevisionException $ex) {
38-
throw new NotFoundHttpException(sprintf('Revision %d not found', $rev), $ex);
38+
throw new NotFoundHttpException(\sprintf('Revision %d not found', $rev), $ex);
3939
}
4040

4141
$changedEntities = $this->auditReader->findEntitiesChangedAtRevision($rev);

src/AuditManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AuditManager
3030

3131
public function __construct(
3232
private AuditConfiguration $config,
33-
private ?ClockInterface $clock = null
33+
private ?ClockInterface $clock = null,
3434
) {
3535
$this->metadataFactory = $config->createMetadataFactory();
3636
}

src/AuditReader.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class AuditReader
7575
public function __construct(
7676
private EntityManagerInterface $em,
7777
private AuditConfiguration $config,
78-
private MetadataFactory $metadataFactory
78+
private MetadataFactory $metadataFactory,
7979
) {
8080
$this->platform = $this->em->getConnection()->getDatabasePlatform();
8181
$this->quoteStrategy = $this->em->getConfiguration()->getQuoteStrategy();
@@ -237,7 +237,7 @@ public function find($className, int|string|array $id, int|string $revision, arr
237237
: 'e';
238238

239239
$type = Type::getType(self::getMappingValue($classMetadata->fieldMappings[$field], 'type'));
240-
$columnList[] = sprintf(
240+
$columnList[] = \sprintf(
241241
'%s AS %s',
242242
$type->convertToPHPValueSQL(
243243
$tableAlias.'.'.$this->quoteStrategy->getColumnName($field, $classMetadata, $this->platform),
@@ -292,15 +292,15 @@ public function find($className, int|string|array $id, int|string $revision, arr
292292
$queriedDiscrValues[] = $this->em->getConnection()->quote($allDiscrValues[$subclassName]);
293293
}
294294

295-
$whereSQL .= sprintf(
295+
$whereSQL .= \sprintf(
296296
' AND %s IN (%s)',
297297
self::getMappingNameValue($classMetadata->discriminatorColumn),
298298
implode(', ', $queriedDiscrValues)
299299
);
300300
}
301301
}
302302

303-
$query = sprintf(
303+
$query = \sprintf(
304304
'SELECT %s FROM %s e %s WHERE %s ORDER BY e.%s DESC',
305305
implode(', ', $columnList),
306306
$tableName,
@@ -537,7 +537,7 @@ public function findRevisions($className, int|string|array $id)
537537
}
538538
}
539539

540-
$query = sprintf(
540+
$query = \sprintf(
541541
'SELECT r.* FROM %s r INNER JOIN %s e ON r.id = e.%s WHERE %s ORDER BY r.id DESC',
542542
$this->config->getRevisionTableName(),
543543
$tableName,
@@ -1025,7 +1025,7 @@ private function createEntity($className, array $columnMap, array $data, int|str
10251025
$columnList[] = $targetKeyJoinColumn;
10261026
}
10271027

1028-
$query = sprintf(
1028+
$query = \sprintf(
10291029
'SELECT %s FROM %s e WHERE %s ORDER BY e.%s DESC',
10301030
implode(', ', $columnList),
10311031
$tableName,
@@ -1112,7 +1112,7 @@ private function createEntity($className, array $columnMap, array $data, int|str
11121112
foreach ($targetAssoc['relationToSourceKeyColumns'] as $sourceKeyJoinColumn => $sourceKeyColumn) {
11131113
$columnList[] = $sourceKeyJoinColumn;
11141114
}
1115-
$query = sprintf(
1115+
$query = \sprintf(
11161116
'SELECT %s FROM %s e WHERE %s ORDER BY e.%s DESC',
11171117
implode(', ', $columnList),
11181118
$tableName,

src/ChangedEntity.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(
2828
private string $className,
2929
private array $id,
3030
private string $revType,
31-
private object $entity
31+
private object $entity,
3232
) {
3333
}
3434

src/Collection/AuditedCollection.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct(
7373
protected ClassMetadata $metadata,
7474
protected array|AssociationMapping $associationDefinition,
7575
protected array $foreignKeys,
76-
protected $revision
76+
protected $revision,
7777
) {
7878
$this->configuration = $auditReader->getConfiguration();
7979
$this->entities = new ArrayCollection();
@@ -414,7 +414,7 @@ public function offsetGet(mixed $offset)
414414
$this->initialize();
415415

416416
if (!$this->entities->offsetExists($offset)) {
417-
throw new AuditedCollectionException(sprintf('Offset "%s" is not defined', $offset));
417+
throw new AuditedCollectionException(\sprintf('Offset "%s" is not defined', $offset));
418418
}
419419

420420
$entity = $this->entities->offsetGet($offset);

src/DeferredChangedManyToManyEntityRevisionToPersist.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(
3333
private array $entityData,
3434
private array|ManyToManyOwningSideMapping $assoc,
3535
private ClassMetadata $class,
36-
private ClassMetadata $targetClass
36+
private ClassMetadata $targetClass,
3737
) {
3838
}
3939

src/DependencyInjection/Configuration.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function getConfigTreeBuilder(): TreeBuilder
5959
->beforeNormalization()
6060
->always(static function (?string $value): ?string {
6161
if (null !== $value && !\in_array($value, self::ALLOWED_REVISION_ID_FIELD_TYPES, true)) {
62-
@trigger_error(sprintf(
62+
@trigger_error(\sprintf(
6363
'The value "%s" for the "revision_id_field_type" is deprecated'
6464
.' since sonata-project/entity-audit-bundle 1.3 and will throw an error in version 2.0.'
6565
.' You must pass one of the following values: "%s".',

src/EventListener/CreateSchemaListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function postGenerateSchemaTable(GenerateSchemaTableEventArgs $eventArgs)
102102
$revisionTable->addColumn($this->config->getRevisionFieldName(), $this->config->getRevisionIdFieldType());
103103
$revisionTable->addColumn($this->config->getRevisionTypeFieldName(), Types::STRING, ['length' => 4]);
104104
if (!\in_array($cm->inheritanceType, [ClassMetadata::INHERITANCE_TYPE_NONE, ClassMetadata::INHERITANCE_TYPE_JOINED, ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE], true)) {
105-
throw new \Exception(sprintf('Inheritance type "%s" is not yet supported', $cm->inheritanceType));
105+
throw new \Exception(\sprintf('Inheritance type "%s" is not yet supported', $cm->inheritanceType));
106106
}
107107

108108
$primaryKey = $entityTable->getPrimaryKey();

src/EventListener/LogRevisionsListener.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class LogRevisionsListener implements EventSubscriber
7878

7979
public function __construct(
8080
AuditManager $auditManager,
81-
private ?ClockInterface $clock = null
81+
private ?ClockInterface $clock = null,
8282
) {
8383
$this->config = $auditManager->getConfiguration();
8484
$this->metadataFactory = $auditManager->getMetadataFactory();
@@ -166,7 +166,7 @@ public function postFlush(PostFlushEventArgs $eventArgs): void
166166
}
167167

168168
if (null === $type) {
169-
throw new \Exception(sprintf('Could not resolve database type for column "%s" during extra updates', $column));
169+
throw new \Exception(\sprintf('Could not resolve database type for column "%s" during extra updates', $column));
170170
}
171171

172172
$types[] = $type;
@@ -473,7 +473,7 @@ private function getInsertRevisionSQL(EntityManagerInterface $em, ClassMetadata
473473
private function getInsertJoinTableRevisionSQL(
474474
ClassMetadata $class,
475475
ClassMetadata $targetClass,
476-
array|ManyToManyOwningSideMapping $assoc
476+
array|ManyToManyOwningSideMapping $assoc,
477477
): string {
478478
$joinTableName = self::getMappingJoinTableNameValue($assoc);
479479
$cacheKey = $class->name.'.'.$targetClass->name.'.'.$joinTableName;
@@ -632,7 +632,7 @@ private function recordRevisionForManyToManyEntity(
632632
array $entityData,
633633
array|ManyToManyOwningSideMapping $assoc,
634634
ClassMetadata $class,
635-
ClassMetadata $targetClass
635+
ClassMetadata $targetClass,
636636
): void {
637637
$conn = $em->getConnection();
638638
$joinTableParams = [$this->getRevisionId($conn), $revType];

src/Exception/AuditException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(
3333
?string $className,
3434
?array $id,
3535
protected $revision,
36-
string $message = ''
36+
string $message = '',
3737
) {
3838
parent::__construct($message);
3939

src/Exception/DeletedException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class DeletedException extends AuditException
2121
*/
2222
public function __construct(string $className, array $id, $revision)
2323
{
24-
parent::__construct($className, $id, $revision, sprintf(
24+
parent::__construct($className, $id, $revision, \sprintf(
2525
'Class "%s" entity id "%s" has been removed at revision %s',
2626
$className,
2727
implode(', ', $id),

src/Exception/InvalidRevisionException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ class InvalidRevisionException extends AuditException
2020
*/
2121
public function __construct($revision)
2222
{
23-
parent::__construct(null, null, $revision, sprintf('No revision "%s" exists.', $revision));
23+
parent::__construct(null, null, $revision, \sprintf('No revision "%s" exists.', $revision));
2424
}
2525
}

src/Exception/NoRevisionFoundException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class NoRevisionFoundException extends AuditException
2121
*/
2222
public function __construct(string $className, array $id, $revision)
2323
{
24-
parent::__construct($className, $id, $revision, sprintf(
24+
parent::__construct($className, $id, $revision, \sprintf(
2525
'No revision of class "%s" (%s) was found at revision %s or before. The entity did not exist at the specified revision yet.',
2626
$className,
2727
implode(', ', $id),

src/Exception/NotAuditedException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ class NotAuditedException extends AuditException
1717
{
1818
public function __construct(string $className)
1919
{
20-
parent::__construct($className, null, null, sprintf('Class "%s" is not audited.', $className));
20+
parent::__construct($className, null, null, \sprintf('Class "%s" is not audited.', $className));
2121
}
2222
}

src/Revision.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Revision
2424
public function __construct(
2525
private $rev,
2626
private \DateTime $timestamp,
27-
private ?string $username
27+
private ?string $username,
2828
) {
2929
}
3030

src/User/TokenStorageUsernameCallable.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(object $tokenStorageOrContainer)
3030
if ($tokenStorageOrContainer instanceof TokenStorageInterface) {
3131
$this->tokenStorage = $tokenStorageOrContainer;
3232
} elseif ($tokenStorageOrContainer instanceof Container) {
33-
@trigger_error(sprintf(
33+
@trigger_error(\sprintf(
3434
'Passing as argument 1 an instance of "%s" to "%s" is deprecated since'
3535
.' sonata-project/entity-audit-bundle 1.x and will throw an "%s" in version 2.0.'
3636
.' You must pass an instance of "%s" instead.',
@@ -44,7 +44,7 @@ public function __construct(object $tokenStorageOrContainer)
4444
\assert($tokenStorage instanceof TokenStorageInterface);
4545
$this->tokenStorage = $tokenStorage;
4646
} else {
47-
throw new \TypeError(sprintf(
47+
throw new \TypeError(\sprintf(
4848
'Argument 1 passed to "%s()" must be an instance of "%s" or %s, instance of "%s" given.',
4949
__METHOD__,
5050
TokenStorageInterface::class,

tests/App/AppKernel.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ public function registerBundles(): iterable
4444

4545
public function getCacheDir(): string
4646
{
47-
return sprintf('%scache', $this->getBaseDir());
47+
return \sprintf('%scache', $this->getBaseDir());
4848
}
4949

5050
public function getLogDir(): string
5151
{
52-
return sprintf('%slog', $this->getBaseDir());
52+
return \sprintf('%slog', $this->getBaseDir());
5353
}
5454

5555
public function getProjectDir(): string
@@ -59,7 +59,7 @@ public function getProjectDir(): string
5959

6060
protected function configureRoutes(RoutingConfigurator $routes): void
6161
{
62-
$routes->import(sprintf('%s/config/routes.yml', $this->getProjectDir()));
62+
$routes->import(\sprintf('%s/config/routes.yml', $this->getProjectDir()));
6363
}
6464

6565
protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader): void
@@ -77,6 +77,6 @@ protected function configureContainer(ContainerBuilder $containerBuilder, Loader
7777

7878
private function getBaseDir(): string
7979
{
80-
return sprintf('%s/entity-audit-bundle/var/', sys_get_temp_dir());
80+
return \sprintf('%s/entity-audit-bundle/var/', sys_get_temp_dir());
8181
}
8282
}

tests/App/Entity/User.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class User
3030

3131
public function __construct(
3232
#[ORM\Column(type: Types::STRING)]
33-
private string $name
33+
private string $name,
3434
) {
3535
}
3636

tests/CoreTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function testFindNoRevisionFound(): void
159159
$reader = $this->getAuditManager()->createAuditReader($this->getEntityManager());
160160

161161
$this->expectException(NoRevisionFoundException::class);
162-
$this->expectExceptionMessage(sprintf(
162+
$this->expectExceptionMessage(\sprintf(
163163
'No revision of class "%s" (1) was found at revision 1 or before. The entity did not exist at the specified revision yet.',
164164
UserAudit::class
165165
));

tests/Fixtures/Core/AnimalAudit.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ abstract class AnimalAudit
3232

3333
public function __construct(
3434
#[ORM\Column(type: Types::STRING)]
35-
private string $name
35+
private string $name,
3636
) {
3737
}
3838

tests/Fixtures/Core/ArticleAudit.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(
3535
#[ORM\ManyToOne(targetEntity: UserAudit::class)]
3636
private ?UserAudit $author,
3737
#[ORM\Column(type: Types::TEXT)]
38-
protected string $ignoreme
38+
protected string $ignoreme,
3939
) {
4040
}
4141

tests/Fixtures/Core/Cat.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Cat extends PetAudit
2222
public function __construct(
2323
string $name,
2424
#[ORM\Column(type: Types::STRING, name: 'cute_cat_color')]
25-
private string $color
25+
private string $color,
2626
) {
2727
parent::__construct($name);
2828
}

tests/Fixtures/Core/Dog.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Dog extends PetAudit
2222
public function __construct(
2323
string $name,
2424
#[ORM\Column(type: Types::INTEGER, name: 'dog_tail_length')]
25-
private int $tailLength
25+
private int $tailLength,
2626
) {
2727
parent::__construct($name);
2828
}

tests/Fixtures/Core/Fox.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Fox extends AnimalAudit
2222
public function __construct(
2323
string $name,
2424
#[ORM\Column(type: Types::INTEGER, name: 'fox_tail_length')]
25-
private int $tailLength
25+
private int $tailLength,
2626
) {
2727
parent::__construct($name);
2828
}

0 commit comments

Comments
 (0)