Skip to content
This repository has been archived by the owner on Feb 6, 2020. It is now read-only.

phpstan fixes #272

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
/phpcs.xml export-ignore
/phpunit.xml.dist export-ignore
/test/ export-ignore
/phpstan.neon.dist export-ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/vendor/
/zf-mkdoc-theme.tgz
/zf-mkdoc-theme/
/phpstan.neon
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ env:
global:
- COMPOSER_ARGS="--no-interaction"
- COVERAGE_DEPS="php-coveralls/php-coveralls"
- STATIC_ANALYSIS_DEPS="phpstan/phpstan"

matrix:
include:
Expand All @@ -22,6 +23,7 @@ matrix:
- CS_CHECK=true
- BENCHMARKS=true
- TEST_COVERAGE=true
- STATIC_ANALYSIS=true
- php: 7.1
env:
- DEPS=latest
Expand All @@ -43,12 +45,14 @@ install:
- if [[ $DEPS == 'latest' ]]; then travis_retry composer update $COMPOSER_ARGS ; fi
- if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi
- if [[ $STATIC_ANALYSIS == 'true' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $STATIC_ANALYSIS_DEPS ; fi
- stty cols 120 && composer show

script:
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi
- if [[ $BENCHMARKS == 'true' ]]; then vendor/bin/phpbench run --revs=2 --iterations=2 --report=aggregate ; fi
- if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi
- if [[ $STATIC_ANALYSIS == 'true' ]]; then ./vendor/bin/phpstan analyse --no-progress . ; fi

after_script:
- if [[ $TEST_COVERAGE == 'true' ]]; then vendor/bin/php-coveralls -v ; fi
Expand Down
101 changes: 51 additions & 50 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
parameters:
level: max

fileExtensions:
- php

excludes_analyse:
- %currentWorkingDirectory%/benchmarks/*
- %currentWorkingDirectory%/bin/*
- %currentWorkingDirectory%/docs/*
- %currentWorkingDirectory%/test/*
- %currentWorkingDirectory%/vendor/*

ignoreErrors:
- '#PHPDoc tag @throws with type Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#'
# AbstractPluginManager::__construct() accepts more types:
-
message: '#Result of && is always false#'
path: %currentWorkingDirectory%/src/AbstractPluginManager.php
-
message: '#Else branch is unreachable because ternary operator condition is always true#'
path: %currentWorkingDirectory%/src/AbstractPluginManager.php
-
message: '#Default value of the parameter \#1 \$resource \(mixed\) of method Zend\\ServiceManager\\Tool\\FactoryCreatorCommand::help\(\) is incompatible with type resource#'
path: %currentWorkingDirectory%/src/Tool/FactoryCreatorCommand.php
-
message: '#Default value of the parameter \#1 \$resource \(mixed\) of method Zend\\ServiceManager\\Tool\\ConfigDumperCommand::help\(\) is incompatible with type resource#'
path: %currentWorkingDirectory%/src/Tool/ConfigDumperCommand.php
10 changes: 8 additions & 2 deletions src/AbstractFactory/ConfigAbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ final class ConfigAbstractFactory implements AbstractFactoryInterface
*/
public function canCreate(\Psr\Container\ContainerInterface $container, $requestedName)
{
if (! $container->has('config') || ! array_key_exists(self::class, $container->get('config'))) {
if (! $container->has('config')) {
return false;
}

$config = $container->get('config');

if (! isset($config[self::class])) {
return false;
}

$dependencies = $config[self::class];

return is_array($dependencies) && array_key_exists($requestedName, $dependencies);
Expand All @@ -50,7 +56,7 @@ public function __invoke(\Psr\Container\ContainerInterface $container, $requeste
throw new ServiceNotCreatedException('Config must be an array or an instance of ArrayObject');
}

if (! array_key_exists(self::class, $config)) {
if (! isset($config[self::class])) {
throw new ServiceNotCreatedException('Cannot find a `' . self::class . '` key in the config array');
}

Expand Down
Loading