Skip to content

Commit 8ff48f2

Browse files
authored
Merge pull request #666 from franmomu/upgrade_cs_8
Update coding standards to 8.2
2 parents a2bf17f + b7b1942 commit 8ff48f2

File tree

70 files changed

+445
-211
lines changed

Some content is hidden

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

70 files changed

+445
-211
lines changed

.github/workflows/coding-standards.yml

+3-7
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,11 @@ jobs:
3131
php-version: "${{ matrix.php-version }}"
3232
tools: "cs2pr"
3333

34-
- name: "Cache dependencies installed with Composer"
35-
uses: "actions/cache@v2"
36-
with:
37-
path: "~/.composer/cache"
38-
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
39-
restore-keys: "php-${{ matrix.php-version }}-composer-locked-"
34+
- name: "Set minimum-stability to stable in Composer"
35+
run: "composer config minimum-stability stable"
4036

4137
- name: "Install dependencies with Composer"
42-
run: "composer install --no-interaction --no-progress --no-suggest"
38+
uses: "ramsey/composer-install@v1"
4339

4440
# https://github.com/doctrine/.github/issues/3
4541
- name: "Run PHP_CodeSniffer"

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ composer.phar
33
composer.lock
44
phpunit.xml
55
.phpcs-cache
6+
.phpunit.result.cache

APM/CommandLoggerRegistry.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\Bundle\MongoDBBundle\APM;
66

77
use Doctrine\ODM\MongoDB\APM\CommandLoggerInterface;
8+
89
use function array_map;
910

1011
final class CommandLoggerRegistry
@@ -19,21 +20,21 @@ public function __construct(iterable $commandLoggers)
1920
}
2021
}
2122

22-
public function register() : void
23+
public function register(): void
2324
{
2425
array_map(static function (CommandLoggerInterface $commandLogger) {
2526
$commandLogger->register();
2627
}, $this->commandLoggers);
2728
}
2829

29-
public function unregister() : void
30+
public function unregister(): void
3031
{
3132
array_map(static function (CommandLoggerInterface $commandLogger) {
3233
$commandLogger->unregister();
3334
}, $this->commandLoggers);
3435
}
3536

36-
private function addLogger(CommandLoggerInterface $logger) : void
37+
private function addLogger(CommandLoggerInterface $logger): void
3738
{
3839
$this->commandLoggers[] = $logger;
3940
}

APM/PSRCommandLogger.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use MongoDB\Driver\Monitoring\CommandStartedEvent;
1010
use MongoDB\Driver\Monitoring\CommandSucceededEvent;
1111
use Psr\Log\LoggerInterface;
12+
1213
use function json_encode;
1314
use function MongoDB\Driver\Monitoring\addSubscriber;
1415
use function MongoDB\Driver\Monitoring\removeSubscriber;
@@ -30,7 +31,7 @@ public function __construct(?LoggerInterface $logger, string $prefix = 'MongoDB
3031
$this->prefix = $prefix;
3132
}
3233

33-
public function register() : void
34+
public function register(): void
3435
{
3536
if ($this->logger === null || $this->registered) {
3637
return;
@@ -40,7 +41,7 @@ public function register() : void
4041
addSubscriber($this);
4142
}
4243

43-
public function unregister() : void
44+
public function unregister(): void
4445
{
4546
if (! $this->registered) {
4647
return;

CacheWarmer/HydratorCacheWarmer.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use RuntimeException;
1111
use Symfony\Component\DependencyInjection\ContainerInterface;
1212
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
13+
14+
use function assert;
1315
use function dirname;
1416
use function file_exists;
1517
use function is_writable;
@@ -42,6 +44,9 @@ public function isOptional()
4244
return false;
4345
}
4446

47+
/**
48+
* {@inheritDoc}
49+
*/
4550
public function warmUp($cacheDir)
4651
{
4752
// we need the directory no matter the hydrator cache generation strategy.
@@ -58,8 +63,8 @@ public function warmUp($cacheDir)
5863
return;
5964
}
6065

61-
/** @var ManagerRegistry $registry */
6266
$registry = $this->container->get('doctrine_mongodb');
67+
assert($registry instanceof ManagerRegistry);
6368
foreach ($registry->getManagers() as $dm) {
6469
/** @var DocumentManager $dm */
6570
$classes = $dm->getMetadataFactory()->getAllMetadata();

CacheWarmer/PersistentCollectionCacheWarmer.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use RuntimeException;
1111
use Symfony\Component\DependencyInjection\ContainerInterface;
1212
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
13+
14+
use function assert;
1315
use function dirname;
1416
use function file_exists;
1517
use function in_array;
@@ -43,6 +45,9 @@ public function isOptional()
4345
return false;
4446
}
4547

48+
/**
49+
* {@inheritDoc}
50+
*/
4651
public function warmUp($cacheDir)
4752
{
4853
// we need the directory no matter the hydrator cache generation strategy.
@@ -61,8 +66,8 @@ public function warmUp($cacheDir)
6166
}
6267

6368
$generated = [];
64-
/** @var ManagerRegistry $registry */
65-
$registry = $this->container->get('doctrine_mongodb');
69+
$registry = $this->container->get('doctrine_mongodb');
70+
assert($registry instanceof ManagerRegistry);
6671
foreach ($registry->getManagers() as $dm) {
6772
/** @var DocumentManager $dm */
6873
$collectionGenerator = $dm->getConfiguration()->getPersistentCollectionGenerator();
@@ -73,6 +78,7 @@ public function warmUp($cacheDir)
7378
if (empty($mapping['collectionClass']) || in_array($mapping['collectionClass'], $generated)) {
7479
continue;
7580
}
81+
7682
$generated[] = $mapping['collectionClass'];
7783
$collectionGenerator->generateClass($mapping['collectionClass'], $collCacheDir);
7884
}

CacheWarmer/ProxyCacheWarmer.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
use RuntimeException;
1212
use Symfony\Component\DependencyInjection\ContainerInterface;
1313
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
14+
1415
use function array_filter;
16+
use function assert;
1517
use function dirname;
1618
use function file_exists;
1719
use function is_writable;
@@ -44,6 +46,9 @@ public function isOptional()
4446
return false;
4547
}
4648

49+
/**
50+
* {@inheritDoc}
51+
*/
4752
public function warmUp($cacheDir)
4853
{
4954
// we need the directory no matter the proxy cache generation strategy.
@@ -60,8 +65,8 @@ public function warmUp($cacheDir)
6065
return;
6166
}
6267

63-
/** @var ManagerRegistry $registry */
6468
$registry = $this->container->get('doctrine_mongodb');
69+
assert($registry instanceof ManagerRegistry);
6570
foreach ($registry->getManagers() as $dm) {
6671
/** @var DocumentManager $dm */
6772
$classes = $this->getClassesForProxyGeneration($dm);

Command/ClearMetadataCacheDoctrineODMCommand.php

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ protected function configure()
3636
);
3737
}
3838

39+
/**
40+
* @return int
41+
*/
3942
protected function execute(InputInterface $input, OutputInterface $output)
4043
{
4144
DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));

Command/CreateSchemaDoctrineODMCommand.php

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ protected function configure()
3636
);
3737
}
3838

39+
/**
40+
* @return int
41+
*/
3942
protected function execute(InputInterface $input, OutputInterface $output)
4043
{
4144
DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));

Command/DoctrineODMCommand.php

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

77
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
88
use Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper;
9+
use Doctrine\Persistence\ObjectManager;
910
use InvalidArgumentException;
1011
use RuntimeException;
1112
use Symfony\Bundle\FrameworkBundle\Console\Application;
@@ -14,11 +15,14 @@
1415
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
1516
use Symfony\Component\DependencyInjection\ContainerInterface;
1617
use Symfony\Component\HttpKernel\Bundle\Bundle;
17-
use const DIRECTORY_SEPARATOR;
18+
19+
use function assert;
1820
use function sprintf;
1921
use function str_replace;
2022
use function strtolower;
2123

24+
use const DIRECTORY_SEPARATOR;
25+
2226
/**
2327
* Base class for Doctrine ODM console commands to extend.
2428
*/
@@ -44,20 +48,28 @@ protected function getContainer()
4448
return $this->container;
4549
}
4650

51+
/**
52+
* @param string $dmName
53+
*/
4754
public static function setApplicationDocumentManager(Application $application, $dmName)
4855
{
4956
$dm = $application->getKernel()->getContainer()->get('doctrine_mongodb')->getManager($dmName);
5057
$helperSet = $application->getHelperSet();
5158
$helperSet->set(new DocumentManagerHelper($dm), 'dm');
5259
}
5360

61+
/**
62+
* @return ObjectManager[]
63+
*/
5464
protected function getDoctrineDocumentManagers()
5565
{
5666
return $this->getManagerRegistry()->getManagers();
5767
}
5868

5969
/**
6070
* @internal
71+
*
72+
* @return ManagerRegistry
6173
*/
6274
protected function getManagerRegistry()
6375
{
@@ -68,11 +80,16 @@ protected function getManagerRegistry()
6880
return $this->managerRegistry;
6981
}
7082

83+
/**
84+
* @param string $bundleName
85+
*
86+
* @return Bundle
87+
*/
7188
protected function findBundle($bundleName)
7289
{
7390
$foundBundle = false;
7491
foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
75-
/** @var $bundle Bundle */
92+
assert($bundle instanceof Bundle);
7693
if (strtolower($bundleName) === strtolower($bundle->getName())) {
7794
$foundBundle = $bundle;
7895
break;

Command/DropSchemaDoctrineODMCommand.php

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ protected function configure()
3636
);
3737
}
3838

39+
/**
40+
* @return int
41+
*/
3942
protected function execute(InputInterface $input, OutputInterface $output)
4043
{
4144
DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));

Command/GenerateHydratorsDoctrineODMCommand.php

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ protected function configure()
3535
);
3636
}
3737

38+
/**
39+
* @return int
40+
*/
3841
protected function execute(InputInterface $input, OutputInterface $output)
3942
{
4043
DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));

Command/GenerateProxiesDoctrineODMCommand.php

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ protected function configure()
3535
);
3636
}
3737

38+
/**
39+
* @return int
40+
*/
3841
protected function execute(InputInterface $input, OutputInterface $output)
3942
{
4043
DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));

Command/InfoDoctrineODMCommand.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Symfony\Component\Console\Input\InputOption;
1111
use Symfony\Component\Console\Output\OutputInterface;
1212
use Throwable;
13+
14+
use function assert;
1315
use function count;
1416
use function sprintf;
1517

@@ -39,14 +41,17 @@ protected function configure()
3941
);
4042
}
4143

44+
/**
45+
* @return int
46+
*/
4247
protected function execute(InputInterface $input, OutputInterface $output)
4348
{
4449
$documentManagerName = $input->getOption('dm') ?
4550
$input->getOption('dm') :
4651
$this->getManagerRegistry()->getDefaultManagerName();
4752

48-
/** @var DocumentManager $documentManager */
4953
$documentManager = $this->getManagerRegistry()->getManager($documentManagerName);
54+
assert($documentManager instanceof DocumentManager);
5055

5156
$documentClassNames = $documentManager->getConfiguration()
5257
->getMetadataDriverImpl()

Command/LoadDataFixturesDoctrineODMCommand.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
use Symfony\Component\Console\Question\ConfirmationQuestion;
1717
use Symfony\Component\Console\Style\SymfonyStyle;
1818
use Symfony\Component\HttpKernel\KernelInterface;
19-
use const E_USER_DEPRECATED;
19+
2020
use function class_exists;
2121
use function implode;
2222
use function sprintf;
2323
use function trigger_error;
2424

25+
use const E_USER_DEPRECATED;
26+
2527
/**
2628
* Load data fixtures from bundles.
2729
*/
@@ -53,7 +55,7 @@ protected function configure()
5355
$this
5456
->setDescription('Load data fixtures to your database.')
5557
->addOption('services', null, InputOption::VALUE_NONE, 'Use services as fixtures')
56-
->addOption('group', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_REQUIRED, 'Only load fixtures that belong to this group (use with --services)')
58+
->addOption('group', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Only load fixtures that belong to this group (use with --services)')
5759
->addOption('append', null, InputOption::VALUE_NONE, 'Append the data fixtures instead of flushing the database first.')
5860
->addOption('dm', null, InputOption::VALUE_REQUIRED, 'The document manager to use for this command.')
5961
->setHelp(<<<EOT
@@ -77,6 +79,9 @@ protected function configure()
7779
);
7880
}
7981

82+
/**
83+
* @return int
84+
*/
8085
protected function execute(InputInterface $input, OutputInterface $output)
8186
{
8287
$dm = $this->getManagerRegistry()->getManager($input->getOption('dm'));

Command/QueryDoctrineODMCommand.php

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ protected function configure()
2525
->addOption('dm', null, InputOption::VALUE_OPTIONAL, 'The document manager to use for this command.');
2626
}
2727

28+
/**
29+
* @return int
30+
*/
2831
protected function execute(InputInterface $input, OutputInterface $output)
2932
{
3033
DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));

Command/ShardDoctrineODMCommand.php

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ protected function configure()
3636
);
3737
}
3838

39+
/**
40+
* @return int
41+
*/
3942
protected function execute(InputInterface $input, OutputInterface $output)
4043
{
4144
DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm'));

0 commit comments

Comments
 (0)