Skip to content

Commit

Permalink
Fix up PHPstan level 7
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Aug 29, 2020
1 parent 71a61f6 commit 00512b6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"test": "php phpunit.phar",
"test-setup": "[ ! -f phpunit.phar ] && wget https://phar.phpunit.de/phpunit-8.5.2.phar && mv phpunit-8.5.2.phar phpunit.phar || true",
"test-coverage" : "php phpunit.phar --log-junit tmp/coverage/unitreport.xml --coverage-html tmp/coverage --coverage-clover tmp/coverage/coverage.xml",
"stan": "phpstan analyse -c tests/phpstan.neon -l 5 src/",
"stan": "phpstan analyse -c tests/phpstan.neon src/",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^0.12 && mv composer.backup composer.json",
"cs-check": "phpcs -p -v --standard=vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml --extensions=php src/ tests/ config/",
"cs-fix": "phpcbf -p --standard=vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml --extensions=php src/ tests/ config/"
Expand Down
11 changes: 5 additions & 6 deletions src/Controller/Component/CacheComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@ public function shutdown(EventInterface $event): void {
}
/** @var callable $when */
$when = $this->getConfig('when');
if ($when !== null && $when($event->getSubject()->getRequest()) !== true) {
/** @var \Cake\Controller\Controller $controller */
$controller = $event->getSubject();
if ($when !== null && $when($controller->getRequest()) !== true) {
return;
}

/** @var \Cake\Http\Response $response */
$response = $event->getSubject()->getResponse();

$content = (string)$response->getBody();
$content = (string)$controller->getResponse()->getBody();
if (!$content) {
return;
}
Expand Down Expand Up @@ -112,7 +111,7 @@ protected function _writeContent(string $content, $duration) {
$url = str_replace($this->getController()->getRequest()->getAttribute('base'), '', $url);
$cacheKey = CacheKey::generate($url, $this->getConfig('prefix'));

$ext = $this->getController()->getResponse()->mapType($this->getController()->getResponse()->getType());
$ext = (string)$this->getController()->getResponse()->mapType($this->getController()->getResponse()->getType());
$content = $this->_compress($content, $ext);

$content = '<!--cachetime:' . $cacheTime . ';ext:' . $ext . '-->' . $content;
Expand Down
4 changes: 2 additions & 2 deletions src/Routing/Middleware/CacheMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected function getContent(string $url, string $cacheKey) {
return null;
}

return file_get_contents($file);
return file_get_contents($file) ?: null;
}

return Cache::read($cacheKey, $engine) ?: null;
Expand Down Expand Up @@ -229,7 +229,7 @@ protected function _deliverCacheFile(ServerRequest $request, Response $response,

$modifiedTime = $cacheStart ?: time();
if (!$cacheEnd) {
$cacheEnd = $this->getConfig('cacheTime');
$cacheEnd = $this->getConfig('cacheTime', '+1 hour');
}

$response = $response->withCache($modifiedTime, $cacheEnd);
Expand Down
1 change: 1 addition & 0 deletions src/Shell/CacheShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protected function fileStatus($url) {
$count = iterator_count($fi);
$this->out($count . ' cache files found.');
if ($this->param('verbose')) {
/** @var \SplFileInfo $f */
foreach ($fi as $f) {
$this->out(' - ' . $f->getFileName());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getContent($url) {
return null;
}

return file_get_contents($file);
return file_get_contents($file) ?: null;
}

return Cache::read($cacheKey, $engine) ?: null;
Expand Down
7 changes: 6 additions & 1 deletion tests/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
parameters:
autoload_files:
level: 7

checkMissingIterableValueType: false

bootstrapFiles:
- %rootDir%/../../../tests/bootstrap.php
- %rootDir%/../../../tests/shim.php
ignoreErrors:
- '#Parameter \#1 \$function of function call_user_func expects callable\(\): mixed, mixed given.#'
- '#Cannot cast array\|string\|null to string#'

0 comments on commit 00512b6

Please sign in to comment.