Skip to content

Commit

Permalink
Merge pull request #134 from alexislefebvre/use-stricter-rules-for-ph…
Browse files Browse the repository at this point in the history
…p-cs-fixer

Use stricter rules for PHP-CS-Fixer
  • Loading branch information
alexislefebvre authored Jun 21, 2021
2 parents 160f4a2 + e2b7bef commit da7a451
Show file tree
Hide file tree
Showing 24 changed files with 91 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: PHP-CS-Fixer
uses: docker://jakzal/phpqa:1.58.7-php7.4-alpine
with:
args: php-cs-fixer --dry-run --diff --no-interaction --ansi --rules=@PhpCsFixer fix
args: php-cs-fixer --dry-run --diff --no-interaction --ansi fix

tests:
name: Symfony ${{ matrix.symfony-version }} on PHP ${{ matrix.php-version }} flags ${{ matrix.composer-flags }}
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/LiipTestFixturesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function load(array $configs, ContainerBuilder $container): void
// "liip_test_fixtures.cache_db.mysql"
// instead of an array "liip_test_fixtures.cache_db"
// with a "mysql" key.
if (is_array($value)) {
if (\is_array($value)) {
foreach ($value as $key2 => $value2) {
$container->setParameter($this->getAlias().'.'.$key.
'.'.$key2, $value2);
Expand Down
10 changes: 5 additions & 5 deletions src/LiipTestFixturesEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
final class LiipTestFixturesEvents
{
/** @see PreFixtureBackupRestoreEvent */
const PRE_FIXTURE_BACKUP_RESTORE = 'liip_test_fixtures.pre_fixture_backup_restore';
public const PRE_FIXTURE_BACKUP_RESTORE = 'liip_test_fixtures.pre_fixture_backup_restore';

/** @see FixtureEvent */
const POST_FIXTURE_SETUP = 'liip_test_fixtures.post_fixture_setup';
public const POST_FIXTURE_SETUP = 'liip_test_fixtures.post_fixture_setup';

/** @see PostFixtureBackupRestoreEvent */
const POST_FIXTURE_BACKUP_RESTORE = 'liip_test_fixtures.post_fixture_backup_restore';
public const POST_FIXTURE_BACKUP_RESTORE = 'liip_test_fixtures.post_fixture_backup_restore';

/** @see ReferenceSaveEvent */
const PRE_REFERENCE_SAVE = 'liip_test_fixtures.pre_reference_save';
public const PRE_REFERENCE_SAVE = 'liip_test_fixtures.pre_reference_save';

/** @see ReferenceSaveEvent */
const POST_REFERENCE_SAVE = 'liip_test_fixtures.post_reference_save';
public const POST_REFERENCE_SAVE = 'liip_test_fixtures.post_reference_save';
}
4 changes: 3 additions & 1 deletion src/Services/DatabaseBackup/AbstractDatabaseBackup.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
Expand Down Expand Up @@ -65,7 +67,7 @@ public function init(array $metadatas, array $classNames, bool $append = false):
*/
protected function isBackupUpToDate(string $backup): bool
{
$backupLastModifiedDateTime = DateTime::createFromFormat('U', filemtime($backup));
$backupLastModifiedDateTime = DateTime::createFromFormat('U', (string) filemtime($backup));

$loader = $this->fixturesLoaderFactory->getFixtureLoader($this->classNames);

Expand Down
2 changes: 2 additions & 0 deletions src/Services/DatabaseBackup/DatabaseBackupInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
Expand Down
2 changes: 2 additions & 0 deletions src/Services/DatabaseBackup/MongodbDatabaseBackup.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
Expand Down
12 changes: 7 additions & 5 deletions src/Services/DatabaseBackup/MysqlDatabaseBackup.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
Expand Down Expand Up @@ -53,14 +55,14 @@ public function backup(AbstractExecutor $executor): void
$params = $params['master'];
}

$dbName = isset($params['dbname']) ? $params['dbname'] : '';
$dbHost = isset($params['host']) ? $params['host'] : '';
$dbName = $params['dbname'] ?? '';
$dbHost = $params['host'] ?? '';

// Define parameter only if there's a value, to avoid warning from mysqldump:
// mysqldump: [Warning] mysqldump: Empty value for 'port' specified. Will throw an error in future versions
$port = isset($params['port']) && $params['port'] ? '--port='.$params['port'] : '';

$dbUser = isset($params['user']) ? $params['user'] : '';
$dbUser = $params['user'] ?? '';
// Set password through environment variable to remove warning
$dbPass = isset($params['password']) && $params['password'] ? 'MYSQL_PWD='.$params['password'].' ' : '';

Expand All @@ -82,7 +84,7 @@ public function restore(AbstractExecutor $executor, array $excludedTables = []):
foreach ($this->metadatas as $classMetadata) {
$tableName = $classMetadata->table['name'];

if (!in_array($tableName, $excludedTables)) {
if (!\in_array($tableName, $excludedTables, true)) {
$truncateSql[] = 'DELETE FROM '.$tableName; // in small tables it's really faster than truncate
}
}
Expand Down Expand Up @@ -121,7 +123,7 @@ protected function getReferenceBackup(): string
return file_get_contents($this->getReferenceBackupFilePath());
}

protected function updateSchemaIfNeed(EntityManager $em)
protected function updateSchemaIfNeed(EntityManager $em): void
{
if (!self::$schemaUpdatedFlag) {
$schemaTool = new SchemaTool($em);
Expand Down
2 changes: 2 additions & 0 deletions src/Services/DatabaseBackup/SqliteDatabaseBackup.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
Expand Down
2 changes: 2 additions & 0 deletions src/Services/DatabaseToolCollection.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
Expand Down
18 changes: 10 additions & 8 deletions src/Services/DatabaseTools/AbstractDatabaseTool.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
Expand Down Expand Up @@ -28,8 +30,8 @@
*/
abstract class AbstractDatabaseTool
{
const KEEP_DATABASE_AND_SCHEMA_PARAMETER_NAME = 'liip_test_fixtures.keep_database_and_schema';
const CACHE_METADATA_PARAMETER_NAME = 'liip_test_fixtures.cache_metadata';
public const KEEP_DATABASE_AND_SCHEMA_PARAMETER_NAME = 'liip_test_fixtures.keep_database_and_schema';
public const CACHE_METADATA_PARAMETER_NAME = 'liip_test_fixtures.cache_metadata';

protected $container;

Expand All @@ -44,7 +46,7 @@ abstract class AbstractDatabaseTool
protected $registry;

/**
* @var null|string
* @var string|null
*/
protected $omName;

Expand All @@ -64,7 +66,7 @@ abstract class AbstractDatabaseTool
protected $connection;

/**
* @var null|int
* @var int|null
*/
protected $purgeMode;

Expand Down Expand Up @@ -126,15 +128,15 @@ public function getDriverName(): string
return 'default';
}

public function withPurgeMode(int $purgeMode): AbstractDatabaseTool
public function withPurgeMode(int $purgeMode): self
{
$newTool = clone $this;
$newTool->setPurgeMode($purgeMode);

return $newTool;
}

public function withDatabaseCacheEnabled(bool $databaseCacheEnabled): AbstractDatabaseTool
public function withDatabaseCacheEnabled(bool $databaseCacheEnabled): self
{
$newTool = clone $this;
$newTool->setDatabaseCacheEnabled($databaseCacheEnabled);
Expand All @@ -158,7 +160,7 @@ public function loadAllFixtures(array $groups = []): ?AbstractExecutor
$loader = $this->container->get('test.service_container')->get('doctrine.fixtures.loader');
$fixtures = $loader->getFixtures($groups);
foreach ($fixtures as $fixture) {
$fixtureClasses[] = get_class($fixture);
$fixtureClasses[] = \get_class($fixture);
}
}

Expand Down Expand Up @@ -199,7 +201,7 @@ protected function getBackupService(): ?DatabaseBackupInterface

if ($this->container->hasParameter($backupServiceParamName)) {
$backupServiceName = $this->container->getParameter($backupServiceParamName);
if (is_string($backupServiceName) && $this->container->has($backupServiceName)) {
if (\is_string($backupServiceName) && $this->container->has($backupServiceName)) {
$backupService = $this->container->get($backupServiceName);
} else {
@trigger_error("Could not find {$backupServiceName} in container. Possible misconfiguration.");
Expand Down
2 changes: 2 additions & 0 deletions src/Services/DatabaseTools/MongoDBDatabaseTool.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
Expand Down
8 changes: 5 additions & 3 deletions src/Services/DatabaseTools/ORMDatabaseTool.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
Expand Down Expand Up @@ -88,7 +90,7 @@ public function loadFixtures(array $classNames = [], bool $append = false): Abst
// TODO: handle case when using persistent connections. Fail loudly?
if (false === $this->getKeepDatabaseAndSchemaParameter()) {
$schemaTool = new SchemaTool($this->om);
if (count($this->excludedDoctrineTables) > 0 || true === $append) {
if (\count($this->excludedDoctrineTables) > 0 || true === $append) {
if (!empty($this->getMetadatas())) {
$schemaTool->updateSchema($this->getMetadatas());
}
Expand Down Expand Up @@ -148,7 +150,7 @@ protected function createDatabaseIfNotExists(): void
if (isset($params['master'])) {
$params = $params['master'];
}
$dbName = isset($params['dbname']) ? $params['dbname'] : '';
$dbName = $params['dbname'] ?? '';

unset($params['dbname'], $params['url']);

Expand All @@ -158,7 +160,7 @@ protected function createDatabaseIfNotExists(): void
$tmpConnection = DriverManager::getConnection($params);
$tmpConnection->connect();

if (!in_array($dbName, $tmpConnection->getSchemaManager()->listDatabases())) {
if (!\in_array($dbName, $tmpConnection->getSchemaManager()->listDatabases(), true)) {
$tmpConnection->getSchemaManager()->createDatabase($dbName);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Services/DatabaseTools/ORMSqliteDatabaseTool.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
Expand Down
2 changes: 2 additions & 0 deletions src/Services/DatabaseTools/PHPCRDatabaseTool.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
Expand Down
2 changes: 2 additions & 0 deletions src/Services/FixturesLoaderFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
Expand Down
13 changes: 12 additions & 1 deletion src/Services/SymfonyFixturesLoaderWrapper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
* (c) Lukas Kahwe Smith <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Liip\TestFixturesBundle\Services;

use Doctrine\Bundle\FixturesBundle\Loader\SymfonyFixturesLoader;
Expand All @@ -14,7 +25,7 @@ public function __construct(SymfonyFixturesLoader $symfonyFixturesLoader)
$this->symfonyFixturesLoader = $symfonyFixturesLoader;
}

public function loadFixturesClass($className)
public function loadFixturesClass($className): void
{
$this->addFixture($this->symfonyFixturesLoader->getFixture($className));
}
Expand Down
9 changes: 9 additions & 0 deletions tests/AppConfigEvents/EventListener/FixturesSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
* (c) Lukas Kahwe Smith <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Liip\Acme\Tests\AppConfigEvents\EventListener;

use Liip\TestFixturesBundle\Event\FixtureEvent;
Expand Down
2 changes: 1 addition & 1 deletion tests/AppConfigPhpcr/DataFixtures/PHPCR/LoadTaskData.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LoadTaskData implements FixtureInterface
public function load(ObjectManager $manager): void
{
if (!$manager instanceof DocumentManager) {
$class = get_class($manager);
$class = \get_class($manager);

throw new RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '{$class}' given.");
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Test/ConfigEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
class ConfigEventsTest extends KernelTestCase
{
public function setUp(): void
protected function setUp(): void
{
parent::setUp();

Expand Down
12 changes: 6 additions & 6 deletions tests/Test/ConfigMysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ConfigMysqlTest extends KernelTestCase
/** @var AbstractDatabaseTool */
protected $databaseTool;

public function setUp(): void
protected function setUp(): void
{
parent::setUp();

Expand All @@ -71,7 +71,7 @@ public function setUp(): void
$this->databaseTool = self::$container->get(DatabaseToolCollection::class)->get();
}

public function testToolType()
public function testToolType(): void
{
$this->assertInstanceOf(ORMDatabaseTool::class, $this->databaseTool);
}
Expand Down Expand Up @@ -219,7 +219,7 @@ public function testLoadFixturesAndExcludeFromPurge(): void
// Check that there are 2 users.
$this->assertSame(
2,
count($this->userRepository->findAll())
\count($this->userRepository->findAll())
);

$this->databaseTool->setExcludedDoctrineTables(['liip_user']);
Expand All @@ -231,7 +231,7 @@ public function testLoadFixturesAndExcludeFromPurge(): void
// The exclusion from purge worked, the user table is still alive and well.
$this->assertSame(
2,
count($this->userRepository->findAll())
\count($this->userRepository->findAll())
);
}

Expand Down Expand Up @@ -296,7 +296,7 @@ public function testLoadFixturesAndPurge(): void
// The purge worked: there is no user.
$this->assertSame(
0,
count($this->userRepository->findAll())
\count($this->userRepository->findAll())
);
}

Expand All @@ -323,7 +323,7 @@ public function testLoadFixturesFiles(): void

$this->assertSame(
10,
count($users)
\count($users)
);

/** @var User $user */
Expand Down
2 changes: 1 addition & 1 deletion tests/Test/ConfigPgsqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*/
class ConfigPgsqlTest extends ConfigMysqlTest
{
public function testToolType()
public function testToolType(): void
{
$this->assertInstanceOf(ORMDatabaseTool::class, $this->databaseTool);
}
Expand Down
Loading

0 comments on commit da7a451

Please sign in to comment.