Skip to content

Commit

Permalink
style #12 Add PHPStan to the build (pamil)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.3 branch.

Discussion
----------

Fixes #5.

Commits
-------

9c7b535 Set up PHPStan
4aa535d Improve code to match PHPStan's level 4
ca99d98 Improve code to match PHPStan's level 5
5a3cce9 Improve code to match PHPStan's level 6
8ea9cbe Improve code to match PHPStan's level "max"
  • Loading branch information
bartoszpietrzak1994 authored Feb 20, 2019
2 parents 0547431 + 8ea9cbe commit 6dbdfea
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ install:
script:
- composer validate --strict

- composer analyse

- vendor/bin/phpspec run
- vendor/bin/phpunit
18 changes: 13 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,39 @@
"zendframework/zend-stdlib": "^3.0"
},
"require-dev": {
"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^1.3",
"doctrine/orm": "^2.5",
"matthiasnoback/symfony-config-test": "^4.0",
"matthiasnoback/symfony-dependency-injection-test": "^3.0",
"phpspec/phpspec": "^5.0",
"phpstan/phpstan-shim": "^0.10",
"phpunit/phpunit": "^7.0",
"twig/twig": "^2.0",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"symfony/browser-kit": "^3.4|^4.1.1",
"symfony/dependency-injection": "^3.4|^4.1.1",
"symfony/security-csrf": "^3.4|^4.1.1",
"symfony/templating": "^3.4|^4.1.1",
"symfony/translation": "^3.4|^4.1.1",
"symfony/twig-bundle": "^3.4|^4.1.1",
"symfony/security-csrf": "^3.4|^4.1.1",
"polishsymfonycommunity/symfony-mocker-container": "^1.0"
"twig/twig": "^2.0",
"proget-hq/phpstan-phpspec": "^0.1.1",
"phpstan/phpstan-phpunit": "^0.10"
},
"autoload": {
"psr-4": { "Sylius\\Bundle\\FixturesBundle\\": "src/" }
},
"autoload-dev": {
"psr-4": {
"Sylius\\Bundle\\FixturesBundle\\spec\\": "spec/",
"spec\\Sylius\\Bundle\\FixturesBundle\\": "spec/",
"Sylius\\Bundle\\FixturesBundle\\Tests\\": "tests/"
},
"classmap": ["test/app/AppKernel.php"]
},
"scripts": {
"analyse": [
"@php vendor/bin/phpstan analyse --ansi -c phpstan.neon -l max spec src tests"
]
},
"extra": {
"branch-alias": {
"dev-master": "1.3-dev"
Expand Down
15 changes: 15 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
includes:
- vendor/proget-hq/phpstan-phpspec/extension.neon
- vendor/phpstan/phpstan-phpunit/extension.neon

- vendor/phpstan/phpstan-phpunit/rules.neon

parameters:
reportUnmatchedIgnoredErrors: false
specDir: 'spec/'
ignoreErrors:
# PHPStan extension bug
- '/proget-hq\/phpstan-phpspec\/src\/NodeVisitor\/CollaboratorResolver\.php/'

# Replaced `'` with `.`, could not figure out how to escape single quotes
- '/^Call to function method_exists\(\) with .Symfony\\\\Component…. and .getRootNode. will always evaluate to false\.$/'
12 changes: 10 additions & 2 deletions src/Command/FixturesListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,19 @@ private function listFixtures(OutputInterface $output): void

private function getSuiteRegistry(): SuiteRegistryInterface
{
return $this->getContainer()->get('sylius_fixtures.suite_registry');
$suiteRegistry = $this->getContainer()->get('sylius_fixtures.suite_registry');

assert($suiteRegistry instanceof SuiteRegistryInterface);

return $suiteRegistry;
}

private function getFixtureRegistry(): FixtureRegistryInterface
{
return $this->getContainer()->get('sylius_fixtures.fixture_registry');
$fixtureRegistry = $this->getContainer()->get('sylius_fixtures.fixture_registry');

assert($fixtureRegistry instanceof FixtureRegistryInterface);

return $fixtureRegistry;
}
}
22 changes: 19 additions & 3 deletions src/Command/FixturesLoadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output): void

$output->writeln(sprintf(
"\n<error>Warning! Loading fixtures will purge your database for the %s environment.</error>\n",
$input->getOption('env')
$this->getEnvironment()
));

if (!$questionHelper->ask($input, $output, new ConfirmationQuestion('Continue? (y/N) ', false))) {
Expand All @@ -61,18 +61,34 @@ protected function execute(InputInterface $input, OutputInterface $output): void
private function loadSuites(InputInterface $input): void
{
$suiteName = $input->getArgument('suite');

assert(is_string($suiteName));

$suite = $this->getSuiteRegistry()->getSuite($suiteName);

$this->getSuiteLoader()->load($suite);
}

private function getSuiteRegistry(): SuiteRegistryInterface
{
return $this->getContainer()->get('sylius_fixtures.suite_registry');
$suiteRegistry = $this->getContainer()->get('sylius_fixtures.suite_registry');

assert($suiteRegistry instanceof SuiteRegistryInterface);

return $suiteRegistry;
}

private function getSuiteLoader(): SuiteLoaderInterface
{
return $this->getContainer()->get('sylius_fixtures.suite_loader');
$suiteLoader = $this->getContainer()->get('sylius_fixtures.suite_loader');

assert($suiteLoader instanceof SuiteLoaderInterface);

return $suiteLoader;
}

private function getEnvironment(): string
{
return $this->getContainer()->getParameter('kernel.environment');
}
}
4 changes: 4 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ public function getConfigTreeBuilder(): TreeBuilder
{
if (method_exists(TreeBuilder::class, 'getRootNode')) {
$treeBuilder = new TreeBuilder('sylius_fixtures');

/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$treeBuilder = new TreeBuilder();

/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->root('sylius_fixtures');
}

Expand Down
9 changes: 9 additions & 0 deletions src/DependencyInjection/SyliusFixturesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sylius\Bundle\FixturesBundle\DependencyInjection;

use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
Expand All @@ -21,6 +22,14 @@

final class SyliusFixturesExtension extends Extension implements PrependExtensionInterface
{
/**
* {@inheritdoc}
*/
public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface
{
return new Configuration();
}

/**
* {@inheritdoc}
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Fixture/AbstractFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ final public function getConfigTreeBuilder(): TreeBuilder
{
if (method_exists(TreeBuilder::class, 'getRootNode')) {
$treeBuilder = new TreeBuilder($this->getName());

/** @var ArrayNodeDefinition $optionsNode */
$optionsNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$treeBuilder = new TreeBuilder();

/** @var ArrayNodeDefinition $optionsNode */
$optionsNode = $treeBuilder->root($this->getName());
}

Expand Down
4 changes: 4 additions & 0 deletions src/Listener/AbstractListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ final public function getConfigTreeBuilder(): TreeBuilder
{
if (method_exists(TreeBuilder::class, 'getRootNode')) {
$treeBuilder = new TreeBuilder($this->getName());

/** @var ArrayNodeDefinition $optionsNode */
$optionsNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$treeBuilder = new TreeBuilder();

/** @var ArrayNodeDefinition $optionsNode */
$optionsNode = $treeBuilder->root($this->getName());
}

Expand Down
4 changes: 2 additions & 2 deletions src/Suite/SuiteInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ interface SuiteInterface
public function getName(): string;

/**
* @return iterable|FixtureInterface[] Fixtures as keys, options as values
* @return iterable<FixtureInterface, array> Fixtures as keys, options as values
*/
public function getFixtures(): iterable;

/**
* @see \Sylius\Bundle\FixturesBundle\Listener\ListenerInterface
*
* @return iterable|ListenerInterface[] Listeners as keys, options as values
* @return iterable<ListenerInterface, array> Listeners as keys, options as values
*/
public function getListeners(): iterable;
}

0 comments on commit 6dbdfea

Please sign in to comment.