Skip to content

Commit cbd3fe0

Browse files
author
Pierre Tondereau
committed
Fix PHPStan errors.
1 parent 7d14c15 commit cbd3fe0

18 files changed

+51
-30
lines changed

.travis.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ matrix:
2424
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" EXECUTE_CS_CHECK=true COVERAGE=true
2525
- php: 7.2
2626
- php: 7.3
27-
env: SYMFONY_REQUIRE="4.4.*"
27+
env: SYMFONY_REQUIRE="4.3.*"
2828
- php: 7.4
29-
env: SYMFONY_REQUIRE="4.4.*"
29+
env: SYMFONY_REQUIRE="4.3.*"
3030
- php: 7.4
3131
env: SYMFONY_REQUIRE="5.0.*"
3232
- php: 7.4
3333
env: SYMFONY_REQUIRE="5.1.*@dev"
3434
- php: nightly
35-
env: SYMFONY_REQUIRE="4.4.*"
35+
env: SYMFONY_REQUIRE="4.3.*"
3636
allow_failures:
3737
# Allow failures on next Symfony minor, should always be tested on newest stable PHP branch
3838
- php: 7.4
3939
env: SYMFONY_REQUIRE="5.1.*@dev"
4040
- php: nightly
41-
env: SYMFONY_REQUIRE="4.4.*"
41+
env: SYMFONY_REQUIRE="4.3.*"
4242

4343
before_install:
4444
- phpenv config-rm xdebug.ini || return 0

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
"prooph/php-cs-fixer-config": "^0.2.1",
7373
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
7474
"phpstan/phpstan": "^0.12",
75-
"symfony/messenger": "^4.3 || ^5.0"
75+
"symfony/messenger": "^4.3 || ^5.0",
76+
"phpstan/phpstan-symfony": "^0.12.1"
7677
},
7778
"suggest": {
7879
"prooph/event-store-bus-bridge": "To Marry CQRS (ProophSerivceBus) with Event Sourcing"

phpstan.neon

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
parameters:
22
reportUnmatchedIgnoredErrors: false
3+
checkMissingIterableValueType: false
4+
checkGenericClassInNonGenericObjectType: false
35
ignoreErrors:
46
# Only available in ArrayNodeDefinition which is given
57
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::children\(\)\.#'
@@ -9,6 +11,7 @@ parameters:
911
# TreeBuilder in Symfony 4.2 and up has a constructor and a getRootNode() method
1012
- '#Class Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder does not have a constructor and must be instantiated without any parameters\.#'
1113
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::getRootNode\(\)#'
14+
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::root\(\)#'
1215
# More Symfony 4.2 compatibility errors
1316
- '#Parameter \#2 \$deleteEmittedEvents of method Prooph\\EventStore\\Projection\\ProjectionManager::deleteProjection\(\) expects bool, array<string>\|bool\|string\|null given\.#'
1417
- '#Property Prooph\\Bundle\\EventStore\\Command\\AbstractProjectionCommand::\$projectionName \(string\) does not accept array<string>\|string\|null\.#'
@@ -18,4 +21,5 @@ parameters:
1821
# MariaDbEventStore is available since pdo-event-store v1.3
1922
- '#Class Prooph\\EventStore\\Pdo\\MariaDbEventStore not found\.#'
2023
- '#Method Prooph\\Bundle\\EventStore\\ProjectionManagerFactory::createProjectionManager\(\) should return Prooph\\EventStore\\Projection\\ProjectionManager but returns Prooph\\EventStore\\Pdo\\Projection\\MariaDbProjectionManager\.#'
21-
- '#Instantiated class Prooph\\EventStore\\Pdo\\Projection\\MariaDbProjectionManager not found\.#'
24+
- '#Instantiated class Prooph\\EventStore\\Pdo\\Projection\\MariaDbProjectionManager not found\.#'
25+
- '#Parameter \#1 $argument of class ReflectionClass constructor expects class-string<T of object>\|T of object, string\|null given.#'

src/Command/AbstractProjectionCommand.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ public function __construct(
7575
parent::__construct();
7676
}
7777

78-
protected function configure()
78+
protected function configure(): void
7979
{
8080
$this->addArgument(static::ARGUMENT_PROJECTION_NAME, InputArgument::REQUIRED, 'The name of the Projection');
8181
}
8282

83-
protected function initialize(InputInterface $input, OutputInterface $output)
83+
protected function initialize(InputInterface $input, OutputInterface $output): void
8484
{
8585
$input->validate();
8686

@@ -89,18 +89,18 @@ protected function initialize(InputInterface $input, OutputInterface $output)
8989
$this->projectionName = $input->getArgument(static::ARGUMENT_PROJECTION_NAME);
9090

9191
if (! $this->projectionManagerForProjectionsLocator->has($this->projectionName)) {
92-
throw new RuntimeException(\sprintf('ProjectionManager for "%s" not found', $this->projectionName));
92+
throw new RuntimeException(\vsprintf('ProjectionManager for "%s" not found', is_array($this->projectionName) ? $this->projectionName : [$this->projectionName]));
9393
}
9494
$this->projectionManager = $this->projectionManagerForProjectionsLocator->get($this->projectionName);
9595

9696
if (! $this->projectionsLocator->has($this->projectionName)) {
97-
throw new RuntimeException(\sprintf('Projection "%s" not found', $this->projectionName));
97+
throw new RuntimeException(\vsprintf('Projection "%s" not found', is_array($this->projectionName) ? $this->projectionName : [$this->projectionName]));
9898
}
9999
$this->projection = $this->projectionsLocator->get($this->projectionName);
100100

101101
if ($this->projection instanceof ReadModelProjection) {
102102
if (! $this->projectionReadModelLocator->has($this->projectionName)) {
103-
throw new RuntimeException(\sprintf('ReadModel for "%s" not found', $this->projectionName));
103+
throw new RuntimeException(\vsprintf('ReadModel for "%s" not found', is_array($this->projectionName) ? $this->projectionName : [$this->projectionName]));
104104
}
105105
$this->readModel = $this->projectionReadModelLocator->get($this->projectionName);
106106

@@ -114,7 +114,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
114114
if (null === $this->projector) {
115115
throw new RuntimeException('Projection was not created');
116116
}
117-
$output->writeln(\sprintf('<header>Initialized projection "%s"</header>', $this->projectionName));
117+
$output->writeln(\vsprintf('<header>Initialized projection "%s"</header>', is_array($this->projectionName) ? $this->projectionName : [$this->projectionName]));
118118
try {
119119
$state = $this->projectionManager->fetchProjectionStatus($this->projectionName)->getValue();
120120
} catch (\Prooph\EventStore\Exception\RuntimeException $e) {

src/Command/FormatsOutput.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
trait FormatsOutput
1111
{
12-
protected function formatOutput(OutputInterface $output)
12+
protected function formatOutput(OutputInterface $output): void
1313
{
1414
$outputFormatter = $output->getFormatter();
1515
$outputFormatter->setStyle('header', new OutputFormatterStyle('green', null));

src/Command/ProjectionDeleteCommand.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ProjectionDeleteCommand extends AbstractProjectionCommand
1212
{
1313
protected const OPTION_WITH_EVENTS = 'with-emitted-events';
1414

15-
protected function configure()
15+
protected function configure(): void
1616
{
1717
parent::configure();
1818
$this
@@ -21,7 +21,7 @@ protected function configure()
2121
->addOption(static::OPTION_WITH_EVENTS, 'w', InputOption::VALUE_NONE, 'Delete with emitted events');
2222
}
2323

24-
protected function execute(InputInterface $input, OutputInterface $output)
24+
protected function execute(InputInterface $input, OutputInterface $output): int
2525
{
2626
$withEvents = $input->getOption(self::OPTION_WITH_EVENTS);
2727
if ($withEvents) {
@@ -30,5 +30,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
3030
$output->writeln(\sprintf('<action>Deleting projection </action><highlight>%s</highlight>', $this->projectionName));
3131
}
3232
$this->projectionManager->deleteProjection($this->projectionName, $withEvents);
33+
34+
return 0;
3335
}
3436
}

src/Command/ProjectionNamesCommand.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(ContainerInterface $projectionManagersLocator, array
4040
parent::__construct();
4141
}
4242

43-
protected function configure()
43+
protected function configure(): void
4444
{
4545
$this
4646
->setName('event-store:projection:names')
@@ -64,6 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6464
});
6565
}
6666

67+
/** @var string|null $filter */
6768
$filter = $input->getArgument(self::ARGUMENT_FILTER);
6869
$regex = $input->getOption(static::OPTION_REGEX);
6970

@@ -80,8 +81,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
8081
$output->writeln('</action>');
8182

8283
$names = [];
83-
$offset = (int) $input->getOption(self::OPTION_OFFSET);
84-
$limit = (int) $input->getOption(self::OPTION_LIMIT);
84+
/** @var int $offset */
85+
$offset = $input->getOption(self::OPTION_OFFSET);
86+
/** @var int $limit */
87+
$limit = $input->getOption(self::OPTION_LIMIT);
8588
$maxNeeded = $offset + $limit;
8689

8790
foreach ($managerNames as $managerName) {

src/Command/ProjectionResetCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class ProjectionResetCommand extends AbstractProjectionCommand
1111
{
12-
protected function configure()
12+
protected function configure(): void
1313
{
1414
parent::configure();
1515
$this

src/Command/ProjectionStateCommand.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class ProjectionStateCommand extends AbstractProjectionCommand
1111
{
12-
protected function configure()
12+
protected function configure(): void
1313
{
1414
parent::configure();
1515
$this
@@ -20,7 +20,10 @@ protected function configure()
2020
protected function execute(InputInterface $input, OutputInterface $output)
2121
{
2222
$output->writeln('<action>Current state:</action>');
23-
$output->writeln(\json_encode($this->projectionManager->fetchProjectionState($this->projectionName)));
23+
24+
/** @var string $state */
25+
$state = \json_encode($this->projectionManager->fetchProjectionState($this->projectionName));
26+
$output->writeln($state);
2427

2528
return 0;
2629
}

src/Command/ProjectionStopCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class ProjectionStopCommand extends AbstractProjectionCommand
1111
{
12-
protected function configure()
12+
protected function configure(): void
1313
{
1414
parent::configure();
1515
$this

src/Command/ProjectionStreamPositionsCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class ProjectionStreamPositionsCommand extends AbstractProjectionCommand
1212
{
13-
protected function configure()
13+
protected function configure(): void
1414
{
1515
parent::configure();
1616
$this

src/DependencyInjection/Compiler/MetadataEnricherPass.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
class MetadataEnricherPass implements CompilerPassInterface
2020
{
21-
public function process(ContainerBuilder $container)
21+
public function process(ContainerBuilder $container): void
2222
{
2323
if (! $container->hasParameter('prooph_event_store.stores')) {
2424
return;
@@ -30,6 +30,8 @@ public function process(ContainerBuilder $container)
3030

3131
foreach ($stores as $name => $store) {
3232
$storeEnricherPlugins = $container->findTaggedServiceIds(\sprintf('prooph_event_store.%s.metadata_enricher', $name));
33+
34+
/** @var array<string, string> $plugins */
3335
$plugins = \array_merge($globalPlugins, $storeEnricherPlugins);
3436
$enrichers = [];
3537

src/DependencyInjection/Compiler/PluginLocatorPass.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
final class PluginLocatorPass implements CompilerPassInterface
1515
{
16-
public function process(ContainerBuilder $container)
16+
public function process(ContainerBuilder $container): void
1717
{
1818
if (! $container->hasParameter('prooph_event_store.stores')) {
1919
return;
@@ -28,6 +28,7 @@ public function process(ContainerBuilder $container)
2828
$storePlugins[] = $container->findTaggedServiceIds(\sprintf('prooph_event_store.%s.plugin', $name));
2929
}
3030

31+
/** @var array<string, string> $plugins */
3132
$plugins = \array_merge($globalPlugins, ...$storePlugins);
3233

3334
$locatorPlugins = [];

src/DependencyInjection/Compiler/PluginsPass.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class PluginsPass implements CompilerPassInterface
1818
{
19-
public function process(ContainerBuilder $container)
19+
public function process(ContainerBuilder $container): void
2020
{
2121
if (! $container->hasParameter('prooph_event_store.stores')) {
2222
return;

src/DependencyInjection/Compiler/RegisterProjectionsPass.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public function process(ContainerBuilder $container): void
3939

4040
foreach ($projectionIds as $id) {
4141
$projectorDefinition = $container->getDefinition($id);
42-
$projectionClass = new ReflectionClass($projectorDefinition->getClass());
42+
/** @var object $projectorDefinitionClass */
43+
$projectorDefinitionClass = $projectorDefinition->getClass();
44+
$projectionClass = new ReflectionClass($projectorDefinitionClass);
4345

4446
self::assertProjectionHasAValidClass($id, $projectionClass);
4547

src/DependencyInjection/ProophEventStoreExtension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private static function collectProjectionsForLocators(
134134
* @param array $config
135135
* @param ContainerBuilder $container
136136
*/
137-
private function loadEventStores(string $class, array $config, ContainerBuilder $container)
137+
private function loadEventStores(string $class, array $config, ContainerBuilder $container): void
138138
{
139139
$eventStores = [];
140140

@@ -163,7 +163,7 @@ private function loadEventStores(string $class, array $config, ContainerBuilder
163163
* @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
164164
* @throws \Prooph\Bundle\EventStore\Exception\RuntimeException
165165
*/
166-
private function loadEventStore(string $name, array $options, ContainerBuilder $container)
166+
private function loadEventStore(string $name, array $options, ContainerBuilder $container): void
167167
{
168168
$eventStoreId = 'prooph_event_store.'.$name;
169169
$eventStoreDefinition = $container

src/ProophEventStoreBundle.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
final class ProophEventStoreBundle extends Bundle
2323
{
24-
public function build(ContainerBuilder $container)
24+
public function build(ContainerBuilder $container): void
2525
{
2626
parent::build($container);
2727

src/RepositoryFactory.php

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
class RepositoryFactory
2121
{
22+
/**
23+
* @return mixed
24+
*/
2225
public function create(
2326
string $repositoryClass,
2427
EventStore $eventStore,

0 commit comments

Comments
 (0)