Skip to content

Commit

Permalink
Coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienHarper committed Aug 13, 2024
1 parent aa0f9ee commit ec4fb4e
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 39 deletions.
16 changes: 8 additions & 8 deletions src/Auditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getProviders(): array
public function getProvider(string $name): ProviderInterface
{
if (!$this->hasProvider($name)) {
throw new InvalidArgumentException(sprintf('Unknown provider "%s"', $name));
throw new InvalidArgumentException(\sprintf('Unknown provider "%s"', $name));
}

return $this->providers[$name];
Expand All @@ -88,7 +88,7 @@ public function hasProvider(string $name): bool
public function registerProvider(ProviderInterface $provider): self
{
if (!$provider->supportsStorage() && !$provider->supportsAuditing()) {
throw new ProviderException(sprintf('Provider "%s" does not support storage and auditing.', $provider::class));
throw new ProviderException(\sprintf('Provider "%s" does not support storage and auditing.', $provider::class));
}

$this->providers[$provider::class] = $provider;
Expand All @@ -111,7 +111,7 @@ public function registerProvider(ProviderInterface $provider): self
public function enableStorage(ProviderInterface $provider): self
{
if (!$provider->supportsStorage()) {
throw new ProviderException(sprintf('Provider "%s" does not support storage.', $provider::class));
throw new ProviderException(\sprintf('Provider "%s" does not support storage.', $provider::class));
}

$this->storageProviders[$provider::class] = $provider;
Expand All @@ -125,7 +125,7 @@ public function enableStorage(ProviderInterface $provider): self
public function disableStorage(ProviderInterface $provider): self
{
if (!$provider->supportsStorage()) {
throw new ProviderException(sprintf('Provider "%s" does not support storage.', $provider::class));
throw new ProviderException(\sprintf('Provider "%s" does not support storage.', $provider::class));
}

if (1 === \count($this->storageProviders)) {
Expand All @@ -144,7 +144,7 @@ public function isStorageEnabled(ProviderInterface $provider): bool
{
$key = $provider::class;
if (!$this->hasProvider($key)) {
throw new InvalidArgumentException(sprintf('Unknown provider "%s"', $key));
throw new InvalidArgumentException(\sprintf('Unknown provider "%s"', $key));
}

return \array_key_exists($key, $this->storageProviders);
Expand All @@ -156,7 +156,7 @@ public function isStorageEnabled(ProviderInterface $provider): bool
public function enableAuditing(ProviderInterface $provider): self
{
if (!$provider->supportsAuditing()) {
throw new ProviderException(sprintf('Provider "%s" does not support audit hooks.', $provider::class));
throw new ProviderException(\sprintf('Provider "%s" does not support audit hooks.', $provider::class));
}

$this->auditProviders[$provider::class] = $provider;
Expand All @@ -170,7 +170,7 @@ public function enableAuditing(ProviderInterface $provider): self
public function disableAuditing(ProviderInterface $provider): self
{
if (!$provider->supportsAuditing()) {
throw new ProviderException(sprintf('Provider "%s" does not support audit hooks.', $provider::class));
throw new ProviderException(\sprintf('Provider "%s" does not support audit hooks.', $provider::class));
}

if (1 === \count($this->auditProviders)) {
Expand All @@ -188,7 +188,7 @@ public function disableAuditing(ProviderInterface $provider): self
public function isAuditingEnabled(ProviderInterface $provider): bool
{
if (!$this->hasProvider($provider::class)) {
throw new InvalidArgumentException(sprintf('Unknown provider "%s"', $provider::class));
throw new InvalidArgumentException(\sprintf('Unknown provider "%s"', $provider::class));
}

return \array_key_exists($provider::class, $this->auditProviders);
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function registerStorageService(StorageServiceInterface $service): Provid
}

if (\array_key_exists($service->getName(), $this->storageServices)) {
throw new ProviderException(sprintf('A storage service named "%s" is already registered.', $service->getName()));
throw new ProviderException(\sprintf('A storage service named "%s" is already registered.', $service->getName()));
}

$this->storageServices[$service->getName()] = $service;
Expand All @@ -81,7 +81,7 @@ public function registerAuditingService(AuditingServiceInterface $service): Prov
}

if (\array_key_exists($service->getName(), $this->auditingServices)) {
throw new ProviderException(sprintf('An auditing service named "%s" is already registered.', $service->getName()));
throw new ProviderException(\sprintf('An auditing service named "%s" is already registered.', $service->getName()));
}

$this->auditingServices[$service->getName()] = $service;
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/Doctrine/Auditing/Transaction/AuditTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private function id(EntityManagerInterface $entityManager, object $entity): mixe
try {
$pk = $meta->getSingleIdentifierFieldName();
} catch (ORMMappingException) {
throw new MappingException(sprintf('Composite primary keys are not supported (%s).', $entity::class));
throw new MappingException(\sprintf('Composite primary keys are not supported (%s).', $entity::class));
}

if (isset($meta->fieldMappings[$pk])) {
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/Doctrine/DoctrineProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function getAuditingServiceForEntity(string $entity): AuditingService
}
}

throw new InvalidArgumentException(sprintf('Auditing service not found for "%s".', $entity));
throw new InvalidArgumentException(\sprintf('Auditing service not found for "%s".', $entity));
}

public function getStorageServiceForEntity(string $entity): StorageService
Expand Down Expand Up @@ -130,7 +130,7 @@ public function persist(LifecycleEvent $event): void
unset($payload['table'], $payload['entity']);

$keys = array_keys(self::FIELDS);
$query = sprintf(
$query = \sprintf(
'INSERT INTO %s (%s) VALUES (%s)',
$auditTable,
implode(', ', $keys),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
try {
$until = new DateTimeImmutable($date);
} catch (Exception) {
$io->error(sprintf('Invalid date format provided: %s', $date));
$io->error(\sprintf('Invalid date format provided: %s', $date));
}
} else {
// Fall back to default retention period
Expand Down Expand Up @@ -129,7 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$count += \count($entities);
}

$message = sprintf(
$message = \sprintf(
"You are about to clean audits created before <comment>%s</comment>: %d classes involved.\n Do you want to proceed?",
$until->format(self::UNTIL_DATE_FORMAT),
$count
Expand Down Expand Up @@ -176,7 +176,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$queryBuilder->executeStatement();
}

$progressBar->setMessage(sprintf('Cleaning audit tables... (<info>%s</info>)', $auditTable));
$progressBar->setMessage(\sprintf('Cleaning audit tables... (<info>%s</info>)', $auditTable));
$progressBar->advance();
}
}
Expand Down Expand Up @@ -211,7 +211,7 @@ private function validateKeepArgument(string $keep, SymfonyStyle $io): ?DateTime
try {
$dateInterval = new DateInterval($keep);
} catch (Exception) {
$io->error(sprintf("'keep' argument must be a valid ISO 8601 date interval, '%s' given.", $keep));
$io->error(\sprintf("'keep' argument must be a valid ISO 8601 date interval, '%s' given.", $keep));
$this->release();

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

foreach ($sqls as $queries) {
foreach ($queries as $sql) {
$io->text(sprintf(' %s;', $sql));
$io->text(\sprintf(' %s;', $sql));
}
}
}
Expand All @@ -104,7 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$pluralization = (1 === $count) ? 'query was' : 'queries were';

$io->text(sprintf(' <info>%s</info> %s executed', $count, $pluralization));
$io->text(\sprintf(' <info>%s</info> %s executed', $count, $pluralization));
$io->success('Database schema updated successfully!');
}

Expand All @@ -117,12 +117,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io->caution('This operation should not be executed in a production environment!');
$io->text(
[
sprintf('The Schema-Tool would execute <info>"%s"</info> queries to update the database.', $count),
\sprintf('The Schema-Tool would execute <info>"%s"</info> queries to update the database.', $count),
'',
'Please run the operation by passing one - or both - of the following options:',
'',
sprintf(' <info>%s --force</info> to execute the command', $this->getName()),
sprintf(' <info>%s --dump-sql</info> to dump the SQL statements to the screen', $this->getName()),
\sprintf(' <info>%s --force</info> to execute the command', $this->getName()),
\sprintf(' <info>%s --dump-sql</info> to dump the SQL statements to the screen', $this->getName()),
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function postGenerateSchemaTable(GenerateSchemaTableEventArgs $eventArgs)
ClassMetadataInfo::INHERITANCE_TYPE_JOINED,
ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE,
], true)) {
throw new Exception(sprintf('Inheritance type "%s" is not yet supported', $metadata->inheritanceType));
throw new Exception(\sprintf('Inheritance type "%s" is not yet supported', $metadata->inheritanceType));
}

$targetEntity = $metadata->name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function getRealClassName(object|string $subject): string
public static function getDoctrineType(string $type): string
{
if (!\defined(Types::class.'::'.$type)) {
throw new InvalidArgumentException(sprintf('Undefined Doctrine type "%s"', $type));
throw new InvalidArgumentException(\sprintf('Undefined Doctrine type "%s"', $type));
}

\assert(\is_string(\constant(Types::class.'::'.$type)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public function getSQL(): array
$params = [];

if ($this->minValue instanceof DateTimeInterface) {
$sqls[] = sprintf('%s >= :min_%s', $this->name, $this->name);
$sqls[] = \sprintf('%s >= :min_%s', $this->name, $this->name);
$params['min_'.$this->name] = $this->minValue->format('Y-m-d H:i:s');
}

if ($this->maxValue instanceof DateTimeInterface) {
$sqls[] = sprintf('%s <= :max_%s', $this->name, $this->name);
$sqls[] = \sprintf('%s <= :max_%s', $this->name, $this->name);
$params['max_'.$this->name] = $this->maxValue->format('Y-m-d H:i:s');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public function getSQL(): array
$params = [];

if (null !== $this->minValue) {
$sqls[] = sprintf('%s >= :min_%s', $this->name, $this->name);
$sqls[] = \sprintf('%s >= :min_%s', $this->name, $this->name);
$params['min_'.$this->name] = $this->minValue;
}

if (null !== $this->maxValue) {
$sqls[] = sprintf('%s <= :max_%s', $this->name, $this->name);
$sqls[] = \sprintf('%s <= :max_%s', $this->name, $this->name);
$params['max_'.$this->name] = $this->maxValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public function getSQL(): array
{
if (\is_array($this->value) && 1 < \count($this->value)) {
return [
'sql' => sprintf('%s IN (:%s)', $this->name, $this->name),
'sql' => \sprintf('%s IN (:%s)', $this->name, $this->name),
'params' => [$this->name => $this->value],
];
}

return [
'sql' => sprintf('%s = :%s', $this->name, $this->name),
'sql' => \sprintf('%s = :%s', $this->name, $this->name),
'params' => [$this->name => (\is_array($this->value) ? $this->value[0] : $this->value)],
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/Doctrine/Persistence/Reader/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ private function buildLimit(QueryBuilder $queryBuilder): QueryBuilder
private function checkFilter(string $filter): void
{
if (!\in_array($filter, $this->getSupportedFilters(), true)) {
throw new InvalidArgumentException(sprintf('Unsupported "%s" filter, allowed filters: %s.', $filter, implode(', ', $this->getSupportedFilters())));
throw new InvalidArgumentException(\sprintf('Unsupported "%s" filter, allowed filters: %s.', $filter, implode(', ', $this->getSupportedFilters())));
}
}
}
2 changes: 1 addition & 1 deletion src/Provider/Doctrine/Persistence/Reader/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function getEntityAuditTableName(string $entity): string
$schema = $entityManager->getClassMetadata($entity)->getSchemaName().'.';
}

return sprintf(
return \sprintf(
'%s%s%s%s',
$schema,
$configuration->getTablePrefix(),
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/Doctrine/Persistence/Schema/SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function createAuditTable(string $entity, ?Schema $schema = null): Schema
PlatformHelper::isIndexLengthLimited($columnName, $connection) ? ['lengths' => [191]] : []
);
} else {
throw new InvalidArgumentException(sprintf("Missing key 'name' for column '%s'", $columnName));
throw new InvalidArgumentException(\sprintf("Missing key 'name' for column '%s'", $columnName));
}
}
}
Expand Down Expand Up @@ -274,7 +274,7 @@ public function computeAuditTablename(string $entityTableName, Configuration $co
{
return preg_replace(
'#^([^.]+\.)?(.+)$#',
sprintf(
\sprintf(
'$1%s$2%s',
preg_quote($configuration->getTablePrefix(), '#'),
preg_quote($configuration->getTableSuffix(), '#')
Expand Down
8 changes: 4 additions & 4 deletions tests/Provider/Doctrine/Event/DoctrineSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class DoctrineSubscriberTest extends TestCase
{
public function testIssue184IfAbstractDriverMiddleware(): void
{
$transactionManager = new class() implements TransactionManagerInterface {
$transactionManager = new class implements TransactionManagerInterface {
public function populate($transaction): void {}

public function process($transaction): void
Expand Down Expand Up @@ -70,7 +70,7 @@ public function process($transaction): void

public function testIssue184IfNotAbstractDriverMiddleware(): void
{
$transactionManager = new class() implements TransactionManagerInterface {
$transactionManager = new class implements TransactionManagerInterface {
public function populate($transaction): void {}

public function process($transaction): void
Expand Down Expand Up @@ -133,7 +133,7 @@ public function createDatabasePlatformForVersion($version): void {}

public function testIssue184Unexpected(): void
{
$transactionManager = new class() implements TransactionManagerInterface {
$transactionManager = new class implements TransactionManagerInterface {
public function populate($transaction): void {}

public function process($transaction): void
Expand All @@ -145,7 +145,7 @@ public function process($transaction): void

$args = new OnFlushEventArgs($objectManager);

$driver = new class() implements VersionAwarePlatformDriver {
$driver = new class implements VersionAwarePlatformDriver {
public function connect(array $params): void {}

public function getDatabasePlatform(): void {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testExecuteFailsWithKeepWrongFormat(): void

// the output of the command in the console
$output = $commandTester->getDisplay();
self::assertStringContainsString(sprintf("[ERROR] 'keep' argument must be a valid ISO 8601 date interval, '%s' given.", self::KEEP), $output);
self::assertStringContainsString(\sprintf("[ERROR] 'keep' argument must be a valid ISO 8601 date interval, '%s' given.", self::KEEP), $output);
}

public function testDumpSQL(): void
Expand Down

0 comments on commit ec4fb4e

Please sign in to comment.