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

Add PHPStan (config) and some fixes #2505

Merged
merged 2 commits into from Nov 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -13,12 +13,14 @@ php:

before_script:
- if [[ "$TRAVIS_PHP_VERSION" == '5.6' ]]; then composer require satooshi/php-coveralls:1.* squizlabs/php_codesniffer:2.* -n ; fi
- if [[ "$TRAVIS_PHP_VERSION" == '7.1' ]]; then composer require phpstan/phpstan:^0.10.3 -n ; fi
- if [[ "$TRAVIS_PHP_VERSION" != '5.6' ]]; then composer install -n ; fi

script:
- if [[ "$TRAVIS_PHP_VERSION" == '5.6' ]]; then vendor/bin/phpunit --coverage-clover clover.xml ; fi
- if [[ "$TRAVIS_PHP_VERSION" != '5.6' ]]; then vendor/bin/phpunit ; fi
- if [[ "$TRAVIS_PHP_VERSION" == '5.6' ]]; then vendor/bin/phpcs ; fi
- if [[ "$TRAVIS_PHP_VERSION" == '7.1' ]]; then vendor/bin/phpstan analyse Slim -l 1 || true ; fi
Copy link
Author

Choose a reason for hiding this comment

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

Allow failure

Copy link
Author

Choose a reason for hiding this comment

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

It's only at level 1 now, this can be increased over the time


after_script:
- if [[ "$TRAVIS_PHP_VERSION" == '5.6' ]]; then php vendor/bin/coveralls --coverage_clover=clover.xml -v ; fi
Expand Down
20 changes: 10 additions & 10 deletions Slim/Container.php
Expand Up @@ -31,16 +31,16 @@
* - notAllowedHandler: a callable with the signature: function($request, $response, $allowedHttpMethods)
* - callableResolver: an instance of \Slim\Interfaces\CallableResolverInterface
*
* @property-read array settings
* @property-read \Slim\Interfaces\Http\EnvironmentInterface environment
* @property-read \Psr\Http\Message\ServerRequestInterface request
* @property-read \Psr\Http\Message\ResponseInterface response
* @property-read \Slim\Interfaces\RouterInterface router
* @property-read \Slim\Interfaces\InvocationStrategyInterface foundHandler
* @property-read callable errorHandler
* @property-read callable notFoundHandler
* @property-read callable notAllowedHandler
* @property-read \Slim\Interfaces\CallableResolverInterface callableResolver
* @property-read array $settings
* @property-read \Slim\Interfaces\Http\EnvironmentInterface $environment
* @property-read \Psr\Http\Message\ServerRequestInterface $request
* @property-read \Psr\Http\Message\ResponseInterface $response
* @property-read \Slim\Interfaces\RouterInterface $router
* @property-read \Slim\Interfaces\InvocationStrategyInterface $foundHandler
* @property-read callable $errorHandler
* @property-read callable $notFoundHandler
* @property-read callable $notAllowedHandler
* @property-read \Slim\Interfaces\CallableResolverInterface $callableResolver
*/
class Container extends PimpleContainer implements ContainerInterface
{
Expand Down
2 changes: 1 addition & 1 deletion Slim/Handlers/AbstractError.php
Expand Up @@ -90,7 +90,7 @@ protected function renderThrowableAsText($throwable)
/**
* Wraps the error_log function so that this can be easily tested
*
* @param $message
* @param string $message
*/
protected function logError($message)
{
Expand Down
2 changes: 1 addition & 1 deletion Slim/Interfaces/RouterInterface.php
Expand Up @@ -75,7 +75,7 @@ public function popGroup();
public function getNamedRoute($name);

/**
* @param $identifier
* @param string $identifier
*
* @return \Slim\Interfaces\RouteInterface
*/
Expand Down
7 changes: 5 additions & 2 deletions Slim/Router.php
Expand Up @@ -167,8 +167,9 @@ public function map($methods, $pattern, $handler)
// According to RFC methods are defined in uppercase (See RFC 7231)
$methods = array_map("strtoupper", $methods);

// Add route
/** @var \Slim\Route */
$route = $this->createRoute($methods, $pattern, $handler);
// Add route
$this->routes[$route->getIdentifier()] = $route;
$this->routeCounter++;

Expand Down Expand Up @@ -335,7 +336,8 @@ public function popGroup()
}

/**
* @param $identifier
*
* @param string $identifier
* @return \Slim\Interfaces\RouteInterface
*/
public function lookupRoute($identifier)
Expand Down Expand Up @@ -371,6 +373,7 @@ public function relativePathFor($name, array $data = [], array $queryParams = []
$routeDatas = array_reverse($routeDatas);

$segments = [];
$segmentName = '';
foreach ($routeDatas as $routeData) {
foreach ($routeData as $item) {
if (is_string($item)) {
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon
@@ -0,0 +1,4 @@
parameters:
ignoreErrors:
# - '#Parameter \$to of method Slim\\App::redirect\(\) has invalid typehint type Slim\\UriInterface#'
# - '#Variable \$_FILES in isset\(\) always exists and is not nullable#'
Copy link
Author

Choose a reason for hiding this comment

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

Some example config, to show how to ignore certain (found) errors