Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce PHPStan (retry) #48

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -6,3 +6,4 @@
/laminas-mkdoc-theme/
/phpunit.xml
/vendor/
/phpstan.neon
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ env:
global:
- COMPOSER_ARGS="--no-interaction"
- COVERAGE_DEPS="php-coveralls/php-coveralls"
- STATIC_ANALYSIS_DEPS="phpstan/phpstan"

matrix:
fast_finish: true
Expand All @@ -21,6 +22,7 @@ matrix:
- CS_CHECK=true
- BENCHMARKS=true
- TEST_COVERAGE=true
- STATIC_ANALYSIS=true
- php: 7.4
env:
- DEPS=lowest
Expand All @@ -36,12 +38,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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"mikey179/vfsstream": "^1.6.8",
"ocramius/proxy-manager": "^2.1.1",
"phpbench/phpbench": "^0.13.0",
"phpstan/phpstan": "^0.12.28",
"phpunit/phpunit": "^7.5.20"
},
"provide": {
Expand Down
42 changes: 42 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
parameters:
ignoreErrors:
-
message: "#^Result of && is always false\\.$#"
count: 1
path: src/AbstractPluginManager.php

-
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
count: 2
path: src/AbstractPluginManager.php

-
message: "#^Parameter \\#1 \\$detectedCycles of static method Laminas\\\\ServiceManager\\\\Exception\\\\CyclicAliasException\\:\\:printCycles\\(\\) expects array\\<array\\<string\\>\\>, array\\<array\\<bool\\>\\> given\\.$#"
count: 1
path: src/Exception/CyclicAliasException.php

-
message: "#^If condition is always false\\.$#"
count: 1
path: src/ServiceManager.php

-
message: "#^Parameter \\#1 \\$autoload_function of function spl_autoload_register expects callable\\(string\\)\\: void, ProxyManager\\\\Autoloader\\\\AutoloaderInterface given\\.$#"
count: 1
path: src/ServiceManager.php

-
message: "#^Negated boolean expression is always true\\.$#"
count: 7
path: src/ServiceManager.php

-
message: "#^Left side of && is always true\\.$#"
count: 1
path: src/Tool/ConfigDumper.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
path: src/Tool/FactoryCreator.php

7 changes: 7 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
includes:
- phpstan-baseline.neon

parameters:
level: 5
paths:
- src
1 change: 1 addition & 0 deletions src/AbstractFactory/ReflectionBasedAbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use Laminas\ServiceManager\Factory\AbstractFactoryInterface;
use Laminas\Stdlib\DispatchableInterface;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a mistake for

    /**
     * {@inheritDoc}
     *
     * @return DispatchableInterface
     */
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)

Not returned DispatchableInterface, just returned object - requestedName instance

use Psr\Container\ContainerInterface;
use ReflectionClass;
use ReflectionParameter;
Expand Down
8 changes: 4 additions & 4 deletions src/AbstractFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ interface AbstractFactoryInterface extends Factory\AbstractFactoryInterface
* Determine if we can create a service with name
*
* @param ServiceLocatorInterface $serviceLocator
* @param $name
* @param $requestedName
* @param string $name
* @param string $requestedName
* @return bool
*/
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName);
Expand All @@ -51,8 +51,8 @@ public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator
* Create service with name
*
* @param ServiceLocatorInterface $serviceLocator
* @param $name
* @param $requestedName
* @param string $name
* @param string $requestedName
* @return mixed
*/
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName);
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
/**
* Base exception for all Laminas\ServiceManager exceptions.
*/
interface ExceptionInterface extends ContainerExceptionInterface
interface ExceptionInterface extends ContainerExceptionInterface, \Throwable
{
}
3 changes: 2 additions & 1 deletion src/Factory/DelegatorFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use Psr\Container\ContainerInterface;
use Psr\Container\ContainerExceptionInterface;

/**
* Delegator factory interface.
Expand All @@ -33,7 +34,7 @@ interface DelegatorFactoryInterface
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException if any other error occurs
* @throws ContainerExceptionInterface&\Throwable if any other error occurs
*/
public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null);
}
3 changes: 2 additions & 1 deletion src/Factory/FactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;

/**
Expand All @@ -32,7 +33,7 @@ interface FactoryInterface
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException if any other error occurs
* @throws ContainerExceptionInterface&\Throwable if any other error occurs
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null);
}
2 changes: 1 addition & 1 deletion src/InitializerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface InitializerInterface extends Initializer\InitializerInterface
/**
* Initialize
*
* @param $instance
* @param object $instance
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
Expand Down
3 changes: 2 additions & 1 deletion src/PluginManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Laminas\ServiceManager;

use Laminas\ServiceManager\Exception\InvalidServiceException;
use Psr\Container\ContainerExceptionInterface;

/**
* Interface for a plugin manager
Expand All @@ -24,7 +25,7 @@ interface PluginManagerInterface extends ServiceLocatorInterface
* @return void
* @throws InvalidServiceException If created instance does not respect the
* constraint on type imposed by the plugin manager
* @throws ContainerException if any other error occurs
* @throws ContainerExceptionInterface&\Throwable if any other error occurs
*/
public function validate($instance);
}
2 changes: 1 addition & 1 deletion src/ServiceLocatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface ServiceLocatorInterface extends ContainerInterface
* factory could be found to create the instance.
* @throws Exception\ServiceNotCreatedException If factory/delegator fails
* to create the instance.
* @throws ContainerExceptionInterface if any other error occurs
* @throws ContainerExceptionInterface&\Throwable if any other error occurs
*/
public function build($name, array $options = null);
}
6 changes: 3 additions & 3 deletions src/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ServiceManager implements ServiceLocatorInterface
/**
* Whether or not changes may be made to this instance.
*
* @param bool
* @var bool
*/
protected $allowOverride = false;

Expand Down Expand Up @@ -646,7 +646,7 @@ private function createDelegatorFromName($name, array $options = null)
};
}

return $creationCallback($this->creationContext, $name, $creationCallback, $options);
return $creationCallback();
}

/**
Expand Down Expand Up @@ -953,7 +953,7 @@ private function mapAliasesToTargets()
/**
* Instantiate abstract factories in order to avoid checks during service construction.
*
* @param string|Factory\AbstractFactoryInterface $abstractFactories
* @param string|Factory\AbstractFactoryInterface $abstractFactory
* @return void
*/
private function resolveAbstractFactoryInstance($abstractFactory)
Expand Down
3 changes: 2 additions & 1 deletion src/Tool/ConfigDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ function (ReflectionParameter $argument) {
}

/**
* @param $className
* @param string $className
* @psalm-param class-string $className
* @throws InvalidArgumentException if class name is not a string or does
* not exist.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/Tool/FactoryCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public function createFactory($className)
}

/**
* @param $className
* @param string $className
* @psalm-param class-string $className
* @return string
*/
private function getClassName($className)
Expand Down