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 3908db0 commit 15be017
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 45 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ci-2.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ jobs:
run: composer install --no-progress --ansi --working-dir=tools/php-cs-fixer

- name: Run PHP-CS-Fixer
run: |
sed -i "s/'phpdoc_to_return_type' => true/'phpdoc_to_return_type' => false/g" .php-cs-fixer.php
sed -i "s/'phpdoc_to_param_type' => true/'phpdoc_to_param_type' => false/g" .php-cs-fixer.php
sed -i "s/'phpdoc_to_property_type' => true/'phpdoc_to_property_type' => false/g" .php-cs-fixer.php
composer cs-check
run: composer cs-check

- name: Validate composer
run: composer validate --strict --no-check-lock
Expand Down
7 changes: 4 additions & 3 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
'php_unit_size_class' => true,
'php_unit_test_class_requires_covers' => false,
'phpdoc_types' => true,
'phpdoc_to_param_type' => true,
'phpdoc_to_property_type' => true,
'phpdoc_to_return_type' => true,
'phpdoc_to_param_type' => false,
'phpdoc_to_property_type' => false,
'phpdoc_to_return_type' => false,
'new_with_parentheses' => false,
'regular_callable_call' => true,
'self_static_accessor' => true,
'simplified_if_return' => true,
Expand Down
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.', \get_class($provider)));
throw new ProviderException(\sprintf('Provider "%s" does not support storage and auditing.', \get_class($provider)));
}

$this->providers[\get_class($provider)] = $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.', \get_class($provider)));
throw new ProviderException(\sprintf('Provider "%s" does not support storage.', \get_class($provider)));
}

$this->storageProviders[\get_class($provider)] = $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.', \get_class($provider)));
throw new ProviderException(\sprintf('Provider "%s" does not support storage.', \get_class($provider)));
}

if (1 === \count($this->storageProviders)) {
Expand All @@ -144,7 +144,7 @@ public function isStorageEnabled(ProviderInterface $provider): bool
{
$key = \get_class($provider);
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.', \get_class($provider)));
throw new ProviderException(\sprintf('Provider "%s" does not support audit hooks.', \get_class($provider)));
}

$this->auditProviders[\get_class($provider)] = $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.', \get_class($provider)));
throw new ProviderException(\sprintf('Provider "%s" does not support audit hooks.', \get_class($provider)));
}

if (1 === \count($this->auditProviders)) {
Expand All @@ -189,7 +189,7 @@ public function isAuditingEnabled(ProviderInterface $provider): bool
{
$key = \get_class($provider);
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->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 @@ -80,7 +80,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 @@ -33,7 +33,7 @@ private function id(EntityManagerInterface $entityManager, object $entity)
try {
$pk = $meta->getSingleIdentifierFieldName();
} catch (ORMMappingException $e) {
throw new MappingException(sprintf('Composite primary keys are not supported (%s).', \get_class($entity)));
throw new MappingException(\sprintf('Composite primary keys are not supported (%s).', \get_class($entity)));
}

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 @@ -75,7 +75,7 @@ public function getAuditingServiceForEntity(string $entity): AuditingServiceInte
}
}

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): StorageServiceInterface
Expand Down Expand Up @@ -120,7 +120,7 @@ public function persist(LifecycleEvent $event): void
'created_at' => ':created_at',
];

$query = sprintf(
$query = \sprintf(
'INSERT INTO %s (%s) VALUES (%s)',
$auditTable,
implode(', ', array_keys($fields)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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 @@ -173,7 +173,7 @@ private function validateKeepArgument(string $keep, SymfonyStyle $io): ?DateTime
try {
$dateInterval = new DateInterval($keep);
} catch (Exception $e) {
$io->error(sprintf("'keep' argument must be a valid ISO 8601 date interval, '%s' given.", (string) $keep));
$io->error(\sprintf("'keep' argument must be a valid ISO 8601 date interval, '%s' given.", (string) $keep));
$this->release();

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

foreach ($sqls as $name => $queries) {
foreach ($queries as $index => $sql) {
$io->text(sprintf(' %s;', $sql));
$io->text(\sprintf(' %s;', $sql));
}
}
}
Expand All @@ -108,7 +108,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 @@ -121,12 +121,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 @@ -37,7 +37,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 @@ -65,7 +65,7 @@ public static function getRealClassName($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 @@ -42,12 +42,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->format('Y-m-d H:i:s');
}

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->format('Y-m-d H:i:s');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,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 @@ -39,12 +39,12 @@ public function getSQL(): array
{
if (\is_array($this->value) && 1 < \count($this->value)) {
$data = [
'sql' => sprintf('%s IN (:%s)', $this->name, $this->name),
'sql' => \sprintf('%s IN (:%s)', $this->name, $this->name),
'params' => [$this->name => $this->value],
];
} else {
$data = [
'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 @@ -286,7 +286,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 @@ -183,7 +183,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 @@ -264,8 +264,8 @@ public function resolveAuditTableName(string $entity, Configuration $configurati
public function computeAuditTablename(string $entityTableName, Configuration $configuration): ?string
{
return preg_replace(
sprintf('#^([^\.]+\.)?(%s)$#', preg_quote($entityTableName, '#')),
sprintf(
\sprintf('#^([^\.]+\.)?(%s)$#', preg_quote($entityTableName, '#')),
\sprintf(
'$1%s$2%s',
preg_quote($configuration->getTablePrefix(), '#'),
preg_quote($configuration->getTableSuffix(), '#')
Expand Down
4 changes: 0 additions & 4 deletions tests/Provider/Doctrine/Fixtures/Issue37/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ public function getLocaleId(): ?string

/**
* Set Locale entity (many to one).
*
* @param ?Locale $locale
*/
public function setLocale(?Locale $locale): self
{
Expand All @@ -115,8 +113,6 @@ public function setLocale(?Locale $locale): self

/**
* Get Locale entity (many to one).
*
* @return ?Locale
*/
public function getLocale(): ?Locale
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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.", $keep), $output);
self::assertStringContainsString(\sprintf("[ERROR] 'keep' argument must be a valid ISO 8601 date interval, '%s' given.", $keep), $output);
}

public function testDumpSQL(): void
Expand Down

0 comments on commit 15be017

Please sign in to comment.