Skip to content

Commit

Permalink
fix phpstan message
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangut committed May 1, 2020
1 parent bed04ea commit 1903dbb
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 39 deletions.
43 changes: 38 additions & 5 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ return Config::create()
],
'binary_operator_spaces' => true,
'blank_line_after_opening_tag' => true,
'blank_line_before_statement' => [
'statements' => ['continue', 'declare', 'try'],
],
'braces' => [
'allow_single_line_closure' => true,
],
'cast_spaces' => true,
'class_attributes_separation' => true,
'class_keyword_remove' => false,
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'compact_nullable_typehint' => true,
'concat_space' => [
Expand All @@ -45,6 +53,8 @@ return Config::create()
'declare_equal_normalize' => true,
'declare_strict_types' => true,
'dir_constant' => true,
'escape_implicit_backslashes' => true,
'function_to_constant' => true,
'function_typehint_space' => true,
'hash_to_slash_comment' => true,
'header_comment' => [
Expand All @@ -53,19 +63,28 @@ return Config::create()
],
'heredoc_to_nowdoc' => true,
'include' => true,
'is_null' => true,
'linebreak_after_opening_tag' => true,
'list_syntax' => [
'syntax' => 'short',
],
'logical_operators' => true,
'lowercase_cast' => true,
'lowercase_static_reference' => true,
'magic_constant_casing' => true,
'magic_method_casing' => true,
'modernize_types_casting' => true,
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
],
'multiline_comment_opening_closing' => true,
'native_constant_invocation' => true,
'native_function_casing' => true,
'native_function_invocation' => true,
'native_function_type_declaration_casing' => true,
'new_with_braces' => true,
'no_alias_functions' => true,
'no_alternative_syntax' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_comment' => true,
Expand All @@ -76,25 +95,34 @@ return Config::create()
'no_mixed_echo_print' => true,
'no_multiline_whitespace_around_double_arrow' => true,
'no_multiline_whitespace_before_semicolons' => true,
'no_null_property_initialization' => true,
'no_php4_constructor' => true,
'no_short_bool_cast' => true,
'no_short_echo_tag' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_around_offset' => true,
'no_superfluous_elseif' => true,
'no_trailing_comma_in_list_call' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_unneeded_control_parentheses' => true,
'no_unreachable_default_argument_value' => true,
'no_unneeded_curly_braces' => true,
'no_unneeded_final_method' => true,
'no_unreachable_default_argument_value' => true,
'no_unset_cast' => true,
'no_unset_on_property' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'non_printable_character' => true,
'normalize_index_brace' => true,
'nullable_type_declaration_for_default_null_value' => true,
'ordered_class_elements' => [
'order' => ['use_trait']
],
'ordered_imports' => [
'imports_order' => ['const', 'class', 'function'],
'importsOrder' => ['class', 'const', 'function'],
],
'php_unit_construct' => true,
'php_unit_dedicate_assert' => true,
Expand All @@ -119,14 +147,16 @@ return Config::create()
'phpdoc_types' => true,
'phpdoc_var_without_name' => true,
'pow_to_exponentiation' => true,
'psr4' => true,
'random_api_migration' => true,
'return_type_declaration' => [
'space_before' => 'none',
],
'return_type_declaration' => true,
'self_accessor' => true,
'self_static_accessor' => true,
'set_type_to_cast' => true,
'single_trait_insert_per_statement' => true,
'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
'single_line_comment_style' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_increment' => true,
Expand All @@ -136,6 +166,9 @@ return Config::create()
'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'visibility_required' => [
'elements' => ['const', 'property', 'method']
],
'void_return' => true,
'whitespace_after_comma_in_array' => true,
'yoda_style' => false,
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"brainmaestro/composer-git-hooks": "^2.8",
"filp/whoops": "^2.4",
"friendsofphp/php-cs-fixer": "^2.16",
"infection/infection": "^0.13|^0.15",
"infection/infection": "^0.13|^0.15|^0.16",
"laminas/laminas-diactoros": "^2.1",
"overtrue/phplint": "^1.2",
"phpmd/phpmd": "^2.8",
Expand All @@ -43,7 +43,7 @@
"phpunit/phpunit": "^7.5|^8.0",
"povils/phpmnd": "^2.1",
"roave/security-advisories": "dev-master",
"sebastian/phpcpd": "^4.0",
"sebastian/phpcpd": "^4.0|^5.0",
"squizlabs/php_codesniffer": "^3.5",
"thecodingmachine/phpstan-strict-rules": "^0.12"
},
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ parameters:
path: src/Handler/ErrorHandler.php
- message: '/^Parameter #(4|5) \$(filename|lineno) of class ErrorException constructor expects (string|int), (string|int)\|null given\.$/'
path: src/ExceptionHandler.php
- message: '/^Call to function is_subclass_of\(\) with Whoops\\Handler\\HandlerInterface and .Jgut\\\\Slim\\\\Exception. will always evaluate to false\.$/'
- message: '/^Call to function is_subclass_of\(\) with Whoops\\Handler\\HandlerInterface and .Jgut\\\\Slim\\\\Exception\\\\Whoops\\\\Renderer\\\\HtmlRenderer. will always evaluate to false\.$/'
path: src/Whoops/Handler/ErrorHandler.php
- message: '/^Method Whoops\\Handler\\Handler::set(Exception|Inspector|Run)\(\) has no return typehint specified\.$/'
path: src/Whoops/Renderer/RendererTrait.php
2 changes: 1 addition & 1 deletion src/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function handleException(\Throwable $exception): void
*
* @return bool
*/
public function handleError(int $severity, string $message, string $file = null, int $line = null): bool
public function handleError(int $severity, string $message, ?string $file = null, ?int $line = null): bool
{
if ((\error_reporting() & $severity) !== 0) {
throw new \ErrorException($message, $severity, $severity, $file, $line);
Expand Down
2 changes: 1 addition & 1 deletion src/Whoops/Renderer/PlainTextRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PlainTextRenderer extends PlainTextHandler
* @param string $defaultTitle
* @param LoggerInterface|null $logger
*/
public function __construct(string $defaultTitle = 'Slim Application error', LoggerInterface $logger = null)
public function __construct(string $defaultTitle = 'Slim Application error', ?LoggerInterface $logger = null)
{
parent::__construct($logger);

Expand Down
2 changes: 0 additions & 2 deletions tests/Exception/ExceptionHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public function testHandleExceptionFromError(): void
$errorHandler->expects(static::once())
->method('__invoke')
->will($this->returnValue($response));
/* @var ErrorHandlerInterface $errorHandler */

$exceptionHandler = new ExceptionHandlerStub(new ServerRequest(), $errorHandler, false, false, false);
$exceptionHandler->registerHandling();
Expand Down Expand Up @@ -105,7 +104,6 @@ public function testFatalError(): void
$errorHandler->expects(static::once())
->method('__invoke')
->will($this->returnValue($response));
/* @var ErrorHandlerInterface $errorHandler */

$exceptionHandler = new ExceptionHandlerStub(new ServerRequest(), $errorHandler, false, false, false, $error);
$exceptionHandler->registerHandling();
Expand Down
6 changes: 0 additions & 6 deletions tests/Exception/Handler/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public function testHandle(): void
->method('resolve')
->with(PlainTextRenderer::class)
->will($this->returnValue(new PlainTextRenderer()));
/* @var CallableResolverInterface $callableResolver */
$handler = new ErrorHandler($callableResolver, new ResponseFactory(), new Negotiator());
$handler->setErrorRenderers(['text/plain' => PlainTextRenderer::class]);

Expand All @@ -64,7 +63,6 @@ public function testDefaultHandle(): void
->method('resolve')
->with(HtmlRenderer::class)
->will($this->returnValue(new HtmlRenderer()));
/* @var CallableResolverInterface $callableResolver */
$handler = new ErrorHandlerStub($callableResolver, new ResponseFactory(), new Negotiator());

$response = $handler($request, $exception, false, false, true);
Expand All @@ -84,15 +82,13 @@ public function testLoggingError(): void
->method('resolve')
->withConsecutive([PlainTextRenderer::class], [HtmlRenderer::class])
->willReturnOnConsecutiveCalls(new PlainTextRenderer(), new HtmlRenderer());
/* @var CallableResolverInterface $callableResolver */
$handler = new ErrorHandlerStub($callableResolver, new ResponseFactory(), new Negotiator());

$logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor()
->getMock();
$logger->expects(static::once())
->method('log');
/* @var LoggerInterface $logger */
$handler->setLogger($logger);

$handler(new ServerRequest(), $exception, false, true, true);
Expand All @@ -110,15 +106,13 @@ public function testLoggingHttpError(): void
->method('resolve')
->withConsecutive([PlainTextRenderer::class], [HtmlRenderer::class])
->willReturnOnConsecutiveCalls(new PlainTextRenderer(), new HtmlRenderer());
/* @var CallableResolverInterface $callableResolver */
$handler = new ErrorHandlerStub($callableResolver, new ResponseFactory(), new Negotiator());

$logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor()
->getMock();
$logger->expects(static::once())
->method('log');
/* @var LoggerInterface $logger */
$handler->setLogger($logger);

$handler($request, $exception, false, true, false);
Expand Down
1 change: 0 additions & 1 deletion tests/Exception/Renderer/HtmlRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class HtmlRendererTest extends TestCase
*/
public function setUp(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$this->exception = new HttpForbiddenException($request);
$this->renderer = new HtmlRenderer();
Expand Down
1 change: 0 additions & 1 deletion tests/Exception/Renderer/JsonRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class JsonRendererTest extends TestCase
*/
public function setUp(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$this->exception = new HttpForbiddenException($request, 'Forbidden action');
}
Expand Down
1 change: 0 additions & 1 deletion tests/Exception/Renderer/PlainTextRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class PlainTextRendererTest extends TestCase
*/
public function setUp(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$this->exception = new HttpForbiddenException($request, 'Forbidden action');
$this->renderer = new PlainTextRenderer();
Expand Down
1 change: 0 additions & 1 deletion tests/Exception/Renderer/XmlRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class XmlRendererTest extends TestCase
*/
public function setUp(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$this->exception = new HttpForbiddenException($request, 'Forbidden action');
}
Expand Down
5 changes: 1 addition & 4 deletions tests/Exception/Whoops/Handler/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ public function testInvalidHandler(): void
->will($this->returnValue(function (): void {
// noop
}));
/* @var CallableResolverInterface $callableResolver */
$handler = new WhoopsErrorHandlerStub($callableResolver, new ResponseFactory(), new Negotiator(), new Whoops());

$response = $handler($request, $exception, false, false, true);
$handler($request, $exception, false, false, true);
}

public function testHandle(): void
Expand All @@ -66,7 +65,6 @@ public function testHandle(): void
->method('resolve')
->with(JsonRenderer::class)
->will($this->returnValue(new JsonRenderer()));
/* @var CallableResolverInterface $callableResolver */
$handler = new WhoopsErrorHandlerStub($callableResolver, new ResponseFactory(), new Negotiator(), new Whoops());

$response = $handler($request, $exception, false, false, true);
Expand All @@ -87,7 +85,6 @@ public function testDefaultHandle(): void
->method('resolve')
->with(HtmlRenderer::class)
->will($this->returnValue(new HtmlRenderer()));
/* @var CallableResolverInterface $callableResolver */
$handler = new WhoopsErrorHandlerStub($callableResolver, new ResponseFactory(), new Negotiator(), new Whoops());

$response = $handler($request, $exception, false, false, true);
Expand Down
2 changes: 0 additions & 2 deletions tests/Exception/Whoops/InspectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class InspectorTest extends TestCase
{
public function testAssign(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$originalException = new \InvalidArgumentException();
$exception = new HttpInternalServerErrorException($request, null, $originalException);
Expand All @@ -38,7 +37,6 @@ public function testAssign(): void

public function testStackTraceFrames(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$originalException = new \InvalidArgumentException();
$exception = new HttpInternalServerErrorException($request, null, $originalException);
Expand Down
1 change: 0 additions & 1 deletion tests/Exception/Whoops/Renderer/HtmlRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public function setUp(): void

public function testOutput(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$exception = new HttpInternalServerErrorException($request, 'Impossible error', new \ErrorException());
$inspector = new Inspector($exception);
Expand Down
4 changes: 0 additions & 4 deletions tests/Exception/Whoops/Renderer/JsonRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class JsonRendererTest extends TestCase
{
public function testOutput(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$exception = new HttpForbiddenException($request, 'Forbidden');
$inspector = new Inspector($exception);
Expand All @@ -52,7 +51,6 @@ public function testOutput(): void

public function testNotPrettifiedOutput(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$exception = new HttpForbiddenException($request, 'Forbidden');
$inspector = new Inspector($exception);
Expand All @@ -73,7 +71,6 @@ public function testNotPrettifiedOutput(): void

public function testNoTraceOutput(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$exception = new HttpForbiddenException($request, 'Forbidden');
$inspector = new Inspector($exception);
Expand All @@ -97,7 +94,6 @@ public function testNoTraceOutput(): void

public function testNotPrettifiedNoTraceOutput(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$exception = new HttpForbiddenException($request, 'Forbidden');
$inspector = new Inspector($exception);
Expand Down
2 changes: 0 additions & 2 deletions tests/Exception/Whoops/Renderer/PlainTextRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function setUp(): void

public function testOutput(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$originalException = new \ErrorException('Original exception');
$exception = new HttpNotImplementedException($request, null, $originalException);
Expand All @@ -60,7 +59,6 @@ public function testOutput(): void

public function testNoTraceOutput(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$exception = new HttpNotImplementedException($request);
$inspector = new Inspector($exception);
Expand Down
4 changes: 0 additions & 4 deletions tests/Exception/Whoops/Renderer/XmlRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class XmlRendererTest extends TestCase
{
public function testOutput(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$exception = new HttpForbiddenException($request, 'Forbidden action');
$inspector = new Inspector($exception);
Expand All @@ -53,7 +52,6 @@ public function testOutput(): void

public function testNotPrettifiedOutput(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$exception = new HttpForbiddenException($request, 'Forbidden action');
$inspector = new Inspector($exception);
Expand All @@ -77,7 +75,6 @@ public function testNotPrettifiedOutput(): void

public function testNoTraceOutput(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$exception = new HttpForbiddenException($request, 'Forbidden action');
$inspector = new Inspector($exception);
Expand All @@ -103,7 +100,6 @@ public function testNoTraceOutput(): void

public function testNotPrettifiedNoTraceOutput(): void
{
/* @var ServerRequestInterface $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$exception = new HttpForbiddenException($request, 'Forbidden action');
$inspector = new Inspector($exception);
Expand Down

0 comments on commit 1903dbb

Please sign in to comment.