Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevKit updates for 1.x branch #633

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use Rector\Config\RectorConfig;
use Rector\Php70\Rector\FunctionLike\ExceptionHandlerTypehintRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\NarrowUnusedSetUpDefinedPropertyRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
Expand All @@ -40,5 +41,6 @@
$rectorConfig->skip([
ExceptionHandlerTypehintRector::class,
PreferPHPUnitThisCallRector::class,
NarrowUnusedSetUpDefinedPropertyRector::class,
]);
};
2 changes: 1 addition & 1 deletion src/Action/CompareAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class CompareAction
{
public function __construct(
private Environment $twig,
private AuditReader $auditReader
private AuditReader $auditReader,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Action/IndexAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class IndexAction
{
public function __construct(
private Environment $twig,
private AuditReader $auditReader
private AuditReader $auditReader,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Action/ViewDetailAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class ViewDetailAction
{
public function __construct(
private Environment $twig,
private AuditReader $auditReader
private AuditReader $auditReader,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Action/ViewEntityAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class ViewEntityAction
{
public function __construct(
private Environment $twig,
private AuditReader $auditReader
private AuditReader $auditReader,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Action/ViewRevisionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class ViewRevisionAction
{
public function __construct(
private Environment $twig,
private AuditReader $auditReader
private AuditReader $auditReader,
) {
}

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

$changedEntities = $this->auditReader->findEntitiesChangedAtRevision($rev);
Expand Down
2 changes: 1 addition & 1 deletion src/AuditConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public function setUsernameCallable($usernameCallable): void
{
// php 5.3 compat
if (null !== $usernameCallable && !\is_callable($usernameCallable)) {
throw new \InvalidArgumentException(sprintf('Username Callable must be callable. Got: %s', get_debug_type($usernameCallable)));
throw new \InvalidArgumentException(\sprintf('Username Callable must be callable. Got: %s', get_debug_type($usernameCallable)));
}

$this->usernameCallable = $usernameCallable;
Expand Down
2 changes: 1 addition & 1 deletion src/AuditManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AuditManager

public function __construct(
private AuditConfiguration $config,
private ?ClockInterface $clock = null
private ?ClockInterface $clock = null,
) {
$this->metadataFactory = $config->createMetadataFactory();
}
Expand Down
14 changes: 7 additions & 7 deletions src/AuditReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class AuditReader
public function __construct(
private EntityManagerInterface $em,
private AuditConfiguration $config,
private MetadataFactory $metadataFactory
private MetadataFactory $metadataFactory,
) {
$this->platform = $this->em->getConnection()->getDatabasePlatform();
$this->quoteStrategy = $this->em->getConfiguration()->getQuoteStrategy();
Expand Down Expand Up @@ -240,7 +240,7 @@ public function find($className, $id, $revision, array $options = [])
: 'e';

$type = Type::getType(self::getMappingValue($classMetadata->fieldMappings[$field], 'type'));
$columnList[] = sprintf(
$columnList[] = \sprintf(
'%s AS %s',
$type->convertToPHPValueSQL(
$tableAlias.'.'.$this->quoteStrategy->getColumnName($field, $classMetadata, $this->platform),
Expand Down Expand Up @@ -295,15 +295,15 @@ public function find($className, $id, $revision, array $options = [])
$queriedDiscrValues[] = $this->em->getConnection()->quote($allDiscrValues[$subclassName]);
}

$whereSQL .= sprintf(
$whereSQL .= \sprintf(
' AND %s IN (%s)',
self::getMappingNameValue($classMetadata->discriminatorColumn),
implode(', ', $queriedDiscrValues)
);
}
}

$query = sprintf(
$query = \sprintf(
'SELECT %s FROM %s e %s WHERE %s ORDER BY e.%s DESC',
implode(', ', $columnList),
$tableName,
Expand Down Expand Up @@ -547,7 +547,7 @@ public function findRevisions($className, $id)
}
}

$query = sprintf(
$query = \sprintf(
'SELECT r.* FROM %s r INNER JOIN %s e ON r.id = e.%s WHERE %s ORDER BY r.id DESC',
$this->config->getRevisionTableName(),
$tableName,
Expand Down Expand Up @@ -1041,7 +1041,7 @@ private function createEntity($className, array $columnMap, array $data, $revisi
$columnList[] = $targetKeyJoinColumn;
}

$query = sprintf(
$query = \sprintf(
'SELECT %s FROM %s e WHERE %s ORDER BY e.%s DESC',
implode(', ', $columnList),
$tableName,
Expand Down Expand Up @@ -1128,7 +1128,7 @@ private function createEntity($className, array $columnMap, array $data, $revisi
foreach ($targetAssoc['relationToSourceKeyColumns'] as $sourceKeyJoinColumn => $sourceKeyColumn) {
$columnList[] = $sourceKeyJoinColumn;
}
$query = sprintf(
$query = \sprintf(
'SELECT %s FROM %s e WHERE %s ORDER BY e.%s DESC',
implode(', ', $columnList),
$tableName,
Expand Down
2 changes: 1 addition & 1 deletion src/ChangedEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(
private string $className,
private array $id,
private string $revType,
private object $entity
private object $entity,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Collection/AuditedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __construct(
protected ClassMetadata $metadata,
protected array|AssociationMapping $associationDefinition,
protected array $foreignKeys,
protected $revision
protected $revision,
) {
$this->configuration = $auditReader->getConfiguration();
$this->entities = new ArrayCollection();
Expand Down Expand Up @@ -414,7 +414,7 @@ public function offsetGet(mixed $offset)
$this->initialize();

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

$entity = $this->entities->offsetGet($offset);
Expand Down
2 changes: 1 addition & 1 deletion src/DeferredChangedManyToManyEntityRevisionToPersist.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
private array $entityData,
private array|ManyToManyOwningSideMapping $assoc,
private ClassMetadata $class,
private ClassMetadata $targetClass
private ClassMetadata $targetClass,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->beforeNormalization()
->always(static function (?string $value): ?string {
if (null !== $value && !\in_array($value, self::ALLOWED_REVISION_ID_FIELD_TYPES, true)) {
@trigger_error(sprintf(
@trigger_error(\sprintf(
'The value "%s" for the "revision_id_field_type" is deprecated'
.' since sonata-project/entity-audit-bundle 1.3 and will throw an error in version 2.0.'
.' You must pass one of the following values: "%s".',
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/CreateSchemaListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function postGenerateSchemaTable(GenerateSchemaTableEventArgs $eventArgs)
$revisionTable->addColumn($this->config->getRevisionFieldName(), $this->config->getRevisionIdFieldType());
$revisionTable->addColumn($this->config->getRevisionTypeFieldName(), Types::STRING, ['length' => 4]);
if (!\in_array($cm->inheritanceType, [ClassMetadata::INHERITANCE_TYPE_NONE, ClassMetadata::INHERITANCE_TYPE_JOINED, ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE], true)) {
throw new \Exception(sprintf('Inheritance type "%s" is not yet supported', $cm->inheritanceType));
throw new \Exception(\sprintf('Inheritance type "%s" is not yet supported', $cm->inheritanceType));
}

$primaryKey = $entityTable->getPrimaryKey();
Expand Down
8 changes: 4 additions & 4 deletions src/EventListener/LogRevisionsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class LogRevisionsListener implements EventSubscriber

public function __construct(
AuditManager $auditManager,
private ?ClockInterface $clock = null
private ?ClockInterface $clock = null,
) {
$this->config = $auditManager->getConfiguration();
$this->metadataFactory = $auditManager->getMetadataFactory();
Expand Down Expand Up @@ -166,7 +166,7 @@ public function postFlush(PostFlushEventArgs $eventArgs): void
}

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

$types[] = $type;
Expand Down Expand Up @@ -476,7 +476,7 @@ private function getInsertRevisionSQL(EntityManagerInterface $em, ClassMetadata
private function getInsertJoinTableRevisionSQL(
ClassMetadata $class,
ClassMetadata $targetClass,
array|ManyToManyOwningSideMapping $assoc
array|ManyToManyOwningSideMapping $assoc,
): string {
$joinTableName = self::getMappingJoinTableNameValue($assoc);
$cacheKey = $class->name.'.'.$targetClass->name.'.'.$joinTableName;
Expand Down Expand Up @@ -635,7 +635,7 @@ private function recordRevisionForManyToManyEntity(
array $entityData,
array|ManyToManyOwningSideMapping $assoc,
ClassMetadata $class,
ClassMetadata $targetClass
ClassMetadata $targetClass,
): void {
$conn = $em->getConnection();
$joinTableParams = [$this->getRevisionId($conn), $revType];
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/AuditException.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
?string $className,
?array $id,
protected $revision,
string $message = ''
string $message = '',
) {
parent::__construct($message);

Expand Down
2 changes: 1 addition & 1 deletion src/Exception/DeletedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DeletedException extends AuditException
*/
public function __construct(string $className, array $id, $revision)
{
parent::__construct($className, $id, $revision, sprintf(
parent::__construct($className, $id, $revision, \sprintf(
'Class "%s" entity id "%s" has been removed at revision %s',
$className,
implode(', ', $id),
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/InvalidRevisionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class InvalidRevisionException extends AuditException
*/
public function __construct($revision)
{
parent::__construct(null, null, $revision, sprintf('No revision "%s" exists.', $revision));
parent::__construct(null, null, $revision, \sprintf('No revision "%s" exists.', $revision));
}
}
2 changes: 1 addition & 1 deletion src/Exception/NoRevisionFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NoRevisionFoundException extends AuditException
*/
public function __construct(string $className, array $id, $revision)
{
parent::__construct($className, $id, $revision, sprintf(
parent::__construct($className, $id, $revision, \sprintf(
'No revision of class "%s" (%s) was found at revision %s or before. The entity did not exist at the specified revision yet.',
$className,
implode(', ', $id),
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/NotAuditedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class NotAuditedException extends AuditException
{
public function __construct(string $className)
{
parent::__construct($className, null, null, sprintf('Class "%s" is not audited.', $className));
parent::__construct($className, null, null, \sprintf('Class "%s" is not audited.', $className));
}
}
2 changes: 1 addition & 1 deletion src/Revision.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Revision
public function __construct(
private $rev,
private \DateTime $timestamp,
private ?string $username
private ?string $username,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/User/TokenStorageUsernameCallable.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(object $tokenStorageOrContainer)
if ($tokenStorageOrContainer instanceof TokenStorageInterface) {
$this->tokenStorage = $tokenStorageOrContainer;
} elseif ($tokenStorageOrContainer instanceof Container) {
@trigger_error(sprintf(
@trigger_error(\sprintf(
'Passing as argument 1 an instance of "%s" to "%s" is deprecated since'
.' sonata-project/entity-audit-bundle 1.x and will throw an "%s" in version 2.0.'
.' You must pass an instance of "%s" instead.',
Expand All @@ -44,7 +44,7 @@ public function __construct(object $tokenStorageOrContainer)
\assert($tokenStorage instanceof TokenStorageInterface);
$this->tokenStorage = $tokenStorage;
} else {
throw new \TypeError(sprintf(
throw new \TypeError(\sprintf(
'Argument 1 passed to "%s()" must be an instance of "%s" or %s, instance of "%s" given.',
__METHOD__,
TokenStorageInterface::class,
Expand Down
8 changes: 4 additions & 4 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public function registerBundles(): iterable

public function getCacheDir(): string
{
return sprintf('%scache', $this->getBaseDir());
return \sprintf('%scache', $this->getBaseDir());
}

public function getLogDir(): string
{
return sprintf('%slog', $this->getBaseDir());
return \sprintf('%slog', $this->getBaseDir());
}

public function getProjectDir(): string
Expand All @@ -59,7 +59,7 @@ public function getProjectDir(): string

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

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

private function getBaseDir(): string
{
return sprintf('%s/entity-audit-bundle/var/', sys_get_temp_dir());
return \sprintf('%s/entity-audit-bundle/var/', sys_get_temp_dir());
}
}
2 changes: 1 addition & 1 deletion tests/App/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class User

public function __construct(
#[ORM\Column(type: Types::STRING)]
private string $name
private string $name,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion tests/CoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function testFindNoRevisionFound(): void
$reader = $this->getAuditManager()->createAuditReader($this->getEntityManager());

$this->expectException(NoRevisionFoundException::class);
$this->expectExceptionMessage(sprintf(
$this->expectExceptionMessage(\sprintf(
'No revision of class "%s" (1) was found at revision 1 or before. The entity did not exist at the specified revision yet.',
UserAudit::class
));
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Core/AnimalAudit.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class AnimalAudit

public function __construct(
#[ORM\Column(type: Types::STRING)]
private string $name
private string $name,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Core/ArticleAudit.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(
#[ORM\ManyToOne(targetEntity: UserAudit::class)]
private ?UserAudit $author,
#[ORM\Column(type: Types::TEXT)]
protected string $ignoreme
protected string $ignoreme,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Core/Cat.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Cat extends PetAudit
public function __construct(
string $name,
#[ORM\Column(type: Types::STRING, name: 'cute_cat_color')]
private string $color
private string $color,
) {
parent::__construct($name);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Core/Dog.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Dog extends PetAudit
public function __construct(
string $name,
#[ORM\Column(type: Types::INTEGER, name: 'dog_tail_length')]
private int $tailLength
private int $tailLength,
) {
parent::__construct($name);
}
Expand Down
Loading
Loading