Replaced psalm with phpstan

This commit is contained in:
Chris Kankiewicz
2021-10-03 14:45:43 -07:00
parent fe235d8e7b
commit 2a30bd1ee4
30 changed files with 238 additions and 757 deletions

View File

@@ -16,6 +16,10 @@ indent_size = 4
trim_trailing_whitespace = false
indent_size = 4
[*.{neon,neon.dist}]
indent_style = space
indent_size = 2
[*.{yml,yaml}]
indent_size = 2
indent_style = space

View File

@@ -37,9 +37,9 @@ To automatically apply any fixes run the same command without the flags.
### Static Analysis
Psalm is used to generate a report of static analysis errors.
[PHPStan](https://phpstan.org) is used to generate a report of static analysis errors.
$ app/vendor/bin/psalm
$ app/vendor/bin/phpstan
### Run Tests

View File

@@ -52,7 +52,7 @@ jobs:
run: composer update
- name: Run Static Analysis
run: app/vendor/bin/psalm
run: app/vendor/bin/phpstan
tests:
name: Tests
@@ -67,7 +67,7 @@ jobs:
strategy:
matrix:
php-versions: ['7.3', '7.4', '8.0']
php-versions: ['7.4', '8.0']
steps:
- name: Checkout Repository

View File

@@ -58,7 +58,7 @@ return [
/** Container definitions */
App\HiddenFiles::class => DI\factory([App\HiddenFiles::class, 'fromConfig']),
Symfony\Component\Finder\Finder::class => DI\factory(Factories\FinderFactory::class),
Symfony\Contracts\Cache\CacheInterface::class => DI\Factory(Factories\CacheFactory::class),
Symfony\Contracts\Cache\CacheInterface::class => DI\factory(Factories\CacheFactory::class),
Symfony\Contracts\Translation\TranslatorInterface::class => DI\factory(Factories\TranslationFactory::class),
Slim\Views\Twig::class => DI\factory(Factories\TwigFactory::class),
Whoops\RunInterface::class => DI\create(Whoops\Run::class),

View File

@@ -10,9 +10,10 @@ class BootManager
/** Create the application service container. */
public static function createContainer(string $configPath, string $cachePath): Container
{
$container = (new ContainerBuilder)->addDefinitions(
...glob($configPath . '/*.php')
);
/** @var iterable $configFiles */
$configFiles = glob($configPath . '/*.php') ?: [];
$container = (new ContainerBuilder)->addDefinitions(...$configFiles);
if (self::containerCompilationEnabled()) {
$container->enableCompilation($cachePath);

View File

@@ -70,7 +70,7 @@ class DirectoryController
$readmes = (clone $files)->name('/^README(?:\..+)?$/i');
$readmes->filter(static function (SplFileInfo $file) {
return (bool) preg_match('/text\/.+/', mime_content_type($file->getPathname()));
return (bool) preg_match('/text\/.+/', (string) mime_content_type($file->getPathname()));
})->sort(static function (SplFileInfo $file1, SplFileInfo $file2) {
return $file1->getExtension() <=> $file2->getExtension();
});

View File

@@ -38,7 +38,7 @@ class FileInfoController
$path = $request->getQueryParams()['info'];
$file = new SplFileInfo(
realpath($this->config->get('base_path') . '/' . $path)
(string) realpath($this->config->get('base_path') . '/' . $path)
);
if (! $file->isFile()) {
@@ -50,9 +50,9 @@ class FileInfoController
}
$response->getBody()->write($this->cache->get(
sprintf('file-info-%s', sha1($file->getRealPath())),
sprintf('file-info-%s', sha1((string) $file->getRealPath())),
function () use ($file): string {
return json_encode(['hashes' => $this->calculateHashes($file)]);
return (string) json_encode(['hashes' => $this->calculateHashes($file)]);
}
));
@@ -63,9 +63,9 @@ class FileInfoController
protected function calculateHashes(SplFileInfo $file): array
{
return [
'md5' => hash_file('md5', $file->getRealPath()),
'sha1' => hash_file('sha1', $file->getRealPath()),
'sha256' => hash_file('sha256', $file->getRealPath()),
'md5' => hash_file('md5', (string) $file->getRealPath()),
'sha1' => hash_file('sha1', (string) $file->getRealPath()),
'sha256' => hash_file('sha256', (string) $file->getRealPath()),
];
}
}

View File

@@ -72,7 +72,7 @@ class ZipController
), ZipArchive::CREATE | ZipArchive::OVERWRITE);
foreach ($this->finder->in($path)->files() as $file) {
$zip->addFile($file->getRealPath(), $this->stripPath($file, $path));
$zip->addFile((string) $file->getRealPath(), $this->stripPath($file, $path));
}
$zip->close();
@@ -87,7 +87,7 @@ class ZipController
'/^%s%s?/', preg_quote($path, '/'), preg_quote(DIRECTORY_SEPARATOR, '/')
);
return preg_replace($pattern, '', $file->getPathname());
return (string) preg_replace($pattern, '', $file->getPathname());
}
/** Generate the file name for a path. */

View File

@@ -36,7 +36,7 @@ class ErrorHandler implements ErrorHandlerInterface
$response = (new Response)->withStatus(500);
if (in_array('application/json', explode(',', $request->getHeaderLine('Accept')))) {
$response->getBody()->write(json_encode([
$response->getBody()->write((string) json_encode([
'error' => ['message' => $this->translator->trans('error.unexpected')],
]));

View File

@@ -77,6 +77,6 @@ class FinderFactory
), $this->hiddenFiles->implode(',')));
}
return Glob::matchStart($this->pattern, $file->getRealPath());
return Glob::matchStart($this->pattern, (string) $file->getRealPath());
}
}

View File

@@ -3,6 +3,7 @@
namespace App\Factories;
use App\Config;
use App\ViewFunctions\ViewFunction;
use Invoker\CallableResolver;
use Slim\Views\Twig;
use Twig\Extension\CoreExtension;
@@ -33,16 +34,17 @@ class TwigFactory
$this->config->get('views_path')
), ['cache' => $this->config->get('view_cache')]);
$environment = $twig->getEnvironment();
$core = $environment->getExtension(CoreExtension::class);
/** @var CoreExtension $core */
$core = $twig->getEnvironment()->getExtension(CoreExtension::class);
$core->setDateFormat($this->config->get('date_format'), '%d days');
$core->setTimezone($this->config->get('timezone'));
foreach ($this->config->get('view_functions') as $function) {
/** @var ViewFunction&Callable $function */
$function = $this->callableResolver->resolve($function);
$environment->addFunction(
$twig->getEnvironment()->addFunction(
new TwigFunction($function->name(), $function)
);
}

View File

@@ -7,10 +7,10 @@ use Tightenco\Collect\Support\Collection;
class HiddenFiles extends Collection
{
/** {@inheritdoc} */
protected function __construct(...$args)
/** @inheritdoc */
protected function __construct($items = [])
{
parent::__construct(...$args);
parent::__construct($items);
}
/** {@inheritdoc} */
@@ -25,9 +25,8 @@ class HiddenFiles extends Collection
$items = $config->get('hidden_files');
if (is_readable($config->get('hidden_files_list'))) {
$items = array_merge($items, file(
$config->get('hidden_files_list'), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES
));
$hiddenFiles = file($config->get('hidden_files_list'), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$items = array_merge($items, $hiddenFiles ?: []);
}
if ($config->get('hide_app_files')) {

View File

@@ -10,7 +10,7 @@ class TemporaryFile
/** Create a new TemporaryFile object. */
public function __construct(string $dir, string $prefix = '')
{
$this->path = tempnam($dir, $prefix);
$this->path = (string) tempnam($dir, $prefix);
}
/** Destroy this TemporaryFile object. */
@@ -28,6 +28,6 @@ class TemporaryFile
/** Get the raw contents of the file. */
public function getContents(): string
{
return file_get_contents($this->path);
return (string) file_get_contents($this->path);
}
}

View File

@@ -41,7 +41,7 @@ class Asset extends ViewFunction
}
return Collection::make(
json_decode(file_get_contents($mixManifest), true) ?? []
json_decode((string) file_get_contents($mixManifest), true) ?? []
);
}
}

View File

@@ -22,6 +22,8 @@ class Config extends ViewFunction
* Retrieve an item from the view config.
*
* @param mixed $default
*
* @return mixed
*/
public function __invoke(string $key, $default = null)
{

View File

@@ -27,7 +27,7 @@ class Url extends ViewFunction
/** Strip all leading slashes (and a single dot) from a path. */
protected function stripLeadingSlashes(string $path): string
{
return preg_replace('/^\.?(\/|\\\)+/', '', $path);
return (string) preg_replace('/^\.?(\/|\\\)+/', '', $path);
}
/** Escape URL characters in path segments. */

View File

@@ -37,9 +37,9 @@
"require-dev": {
"johnkary/phpunit-speedtrap": "^4.0",
"phlak/coding-standards": "^2.0",
"phpstan/phpstan": "^0.12.99",
"psy/psysh": "^0.10",
"symfony/var-dumper": "^5.0",
"vimeo/psalm": "^4.3",
"yoast/phpunit-polyfills": "^1.0"
},
"suggest": {

702
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "b84da7491b0b4da7f437f0b6f2d6e6a6",
"content-hash": "51e0b90d4973d005f40ba9c8703ce1e4",
"packages": [
{
"name": "erusev/parsedown",
@@ -2753,245 +2753,6 @@
}
],
"packages-dev": [
{
"name": "amphp/amp",
"version": "v2.6.0",
"source": {
"type": "git",
"url": "https://github.com/amphp/amp.git",
"reference": "caa95edeb1ca1bf7532e9118ede4a3c3126408cc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/amphp/amp/zipball/caa95edeb1ca1bf7532e9118ede4a3c3126408cc",
"reference": "caa95edeb1ca1bf7532e9118ede4a3c3126408cc",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"require-dev": {
"amphp/php-cs-fixer-config": "dev-master",
"amphp/phpunit-util": "^1",
"ext-json": "*",
"jetbrains/phpstorm-stubs": "^2019.3",
"phpunit/phpunit": "^7 | ^8 | ^9",
"psalm/phar": "^3.11@dev",
"react/promise": "^2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
}
},
"autoload": {
"psr-4": {
"Amp\\": "lib"
},
"files": [
"lib/functions.php",
"lib/Internal/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Daniel Lowrey",
"email": "rdlowrey@php.net"
},
{
"name": "Aaron Piotrowski",
"email": "aaron@trowski.com"
},
{
"name": "Bob Weinand",
"email": "bobwei9@hotmail.com"
},
{
"name": "Niklas Keller",
"email": "me@kelunik.com"
}
],
"description": "A non-blocking concurrency framework for PHP applications.",
"homepage": "http://amphp.org/amp",
"keywords": [
"async",
"asynchronous",
"awaitable",
"concurrency",
"event",
"event-loop",
"future",
"non-blocking",
"promise"
],
"support": {
"irc": "irc://irc.freenode.org/amphp",
"issues": "https://github.com/amphp/amp/issues",
"source": "https://github.com/amphp/amp/tree/v2.6.0"
},
"funding": [
{
"url": "https://github.com/amphp",
"type": "github"
}
],
"time": "2021-07-16T20:06:06+00:00"
},
{
"name": "amphp/byte-stream",
"version": "v1.8.1",
"source": {
"type": "git",
"url": "https://github.com/amphp/byte-stream.git",
"reference": "acbd8002b3536485c997c4e019206b3f10ca15bd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/amphp/byte-stream/zipball/acbd8002b3536485c997c4e019206b3f10ca15bd",
"reference": "acbd8002b3536485c997c4e019206b3f10ca15bd",
"shasum": ""
},
"require": {
"amphp/amp": "^2",
"php": ">=7.1"
},
"require-dev": {
"amphp/php-cs-fixer-config": "dev-master",
"amphp/phpunit-util": "^1.4",
"friendsofphp/php-cs-fixer": "^2.3",
"jetbrains/phpstorm-stubs": "^2019.3",
"phpunit/phpunit": "^6 || ^7 || ^8",
"psalm/phar": "^3.11.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"Amp\\ByteStream\\": "lib"
},
"files": [
"lib/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Aaron Piotrowski",
"email": "aaron@trowski.com"
},
{
"name": "Niklas Keller",
"email": "me@kelunik.com"
}
],
"description": "A stream abstraction to make working with non-blocking I/O simple.",
"homepage": "http://amphp.org/byte-stream",
"keywords": [
"amp",
"amphp",
"async",
"io",
"non-blocking",
"stream"
],
"support": {
"irc": "irc://irc.freenode.org/amphp",
"issues": "https://github.com/amphp/byte-stream/issues",
"source": "https://github.com/amphp/byte-stream/tree/v1.8.1"
},
"funding": [
{
"url": "https://github.com/amphp",
"type": "github"
}
],
"time": "2021-03-30T17:13:30+00:00"
},
{
"name": "composer/package-versions-deprecated",
"version": "1.11.99.4",
"source": {
"type": "git",
"url": "https://github.com/composer/package-versions-deprecated.git",
"reference": "b174585d1fe49ceed21928a945138948cb394600"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/b174585d1fe49ceed21928a945138948cb394600",
"reference": "b174585d1fe49ceed21928a945138948cb394600",
"shasum": ""
},
"require": {
"composer-plugin-api": "^1.1.0 || ^2.0",
"php": "^7 || ^8"
},
"replace": {
"ocramius/package-versions": "1.11.99"
},
"require-dev": {
"composer/composer": "^1.9.3 || ^2.0@dev",
"ext-zip": "^1.13",
"phpunit/phpunit": "^6.5 || ^7"
},
"type": "composer-plugin",
"extra": {
"class": "PackageVersions\\Installer",
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"PackageVersions\\": "src/PackageVersions"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Marco Pivetta",
"email": "ocramius@gmail.com"
},
{
"name": "Jordi Boggiano",
"email": "j.boggiano@seld.be"
}
],
"description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)",
"support": {
"issues": "https://github.com/composer/package-versions-deprecated/issues",
"source": "https://github.com/composer/package-versions-deprecated/tree/1.11.99.4"
},
"funding": [
{
"url": "https://packagist.com",
"type": "custom"
},
{
"url": "https://github.com/composer",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
"type": "tidelift"
}
],
"time": "2021-09-13T08:41:34+00:00"
},
{
"name": "composer/semver",
"version": "3.2.5",
@@ -3137,43 +2898,6 @@
],
"time": "2021-07-31T17:03:58+00:00"
},
{
"name": "dnoegel/php-xdg-base-dir",
"version": "v0.1.1",
"source": {
"type": "git",
"url": "https://github.com/dnoegel/php-xdg-base-dir.git",
"reference": "8f8a6e48c5ecb0f991c2fdcf5f154a47d85f9ffd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dnoegel/php-xdg-base-dir/zipball/8f8a6e48c5ecb0f991c2fdcf5f154a47d85f9ffd",
"reference": "8f8a6e48c5ecb0f991c2fdcf5f154a47d85f9ffd",
"shasum": ""
},
"require": {
"php": ">=5.3.2"
},
"require-dev": {
"phpunit/phpunit": "~7.0|~6.0|~5.0|~4.8.35"
},
"type": "library",
"autoload": {
"psr-4": {
"XdgBaseDir\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "implementation of xdg base directory specification for php",
"support": {
"issues": "https://github.com/dnoegel/php-xdg-base-dir/issues",
"source": "https://github.com/dnoegel/php-xdg-base-dir/tree/v0.1.1"
},
"time": "2019-12-04T15:06:13+00:00"
},
{
"name": "doctrine/annotations",
"version": "1.13.2",
@@ -3395,107 +3119,6 @@
],
"time": "2020-05-25T17:44:05+00:00"
},
{
"name": "felixfbecker/advanced-json-rpc",
"version": "v3.2.1",
"source": {
"type": "git",
"url": "https://github.com/felixfbecker/php-advanced-json-rpc.git",
"reference": "b5f37dbff9a8ad360ca341f3240dc1c168b45447"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/felixfbecker/php-advanced-json-rpc/zipball/b5f37dbff9a8ad360ca341f3240dc1c168b45447",
"reference": "b5f37dbff9a8ad360ca341f3240dc1c168b45447",
"shasum": ""
},
"require": {
"netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0 || ^4.0",
"php": "^7.1 || ^8.0",
"phpdocumentor/reflection-docblock": "^4.3.4 || ^5.0.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0 || ^8.0"
},
"type": "library",
"autoload": {
"psr-4": {
"AdvancedJsonRpc\\": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"ISC"
],
"authors": [
{
"name": "Felix Becker",
"email": "felix.b@outlook.com"
}
],
"description": "A more advanced JSONRPC implementation",
"support": {
"issues": "https://github.com/felixfbecker/php-advanced-json-rpc/issues",
"source": "https://github.com/felixfbecker/php-advanced-json-rpc/tree/v3.2.1"
},
"time": "2021-06-11T22:34:44+00:00"
},
{
"name": "felixfbecker/language-server-protocol",
"version": "1.5.1",
"source": {
"type": "git",
"url": "https://github.com/felixfbecker/php-language-server-protocol.git",
"reference": "9d846d1f5cf101deee7a61c8ba7caa0a975cd730"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/felixfbecker/php-language-server-protocol/zipball/9d846d1f5cf101deee7a61c8ba7caa0a975cd730",
"reference": "9d846d1f5cf101deee7a61c8ba7caa0a975cd730",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"require-dev": {
"phpstan/phpstan": "*",
"squizlabs/php_codesniffer": "^3.1",
"vimeo/psalm": "^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"LanguageServerProtocol\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"ISC"
],
"authors": [
{
"name": "Felix Becker",
"email": "felix.b@outlook.com"
}
],
"description": "PHP classes for the Language Server Protocol",
"keywords": [
"language",
"microsoft",
"php",
"server"
],
"support": {
"issues": "https://github.com/felixfbecker/php-language-server-protocol/issues",
"source": "https://github.com/felixfbecker/php-language-server-protocol/tree/1.5.1"
},
"time": "2021-02-22T14:02:09+00:00"
},
{
"name": "friendsofphp/php-cs-fixer",
"version": "v3.1.0",
@@ -3695,57 +3318,6 @@
],
"time": "2020-11-13T09:40:50+00:00"
},
{
"name": "netresearch/jsonmapper",
"version": "v4.0.0",
"source": {
"type": "git",
"url": "https://github.com/cweiske/jsonmapper.git",
"reference": "8bbc021a8edb2e4a7ea2f8ad4fa9ec9dce2fcb8d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/cweiske/jsonmapper/zipball/8bbc021a8edb2e4a7ea2f8ad4fa9ec9dce2fcb8d",
"reference": "8bbc021a8edb2e4a7ea2f8ad4fa9ec9dce2fcb8d",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-pcre": "*",
"ext-reflection": "*",
"ext-spl": "*",
"php": ">=7.1"
},
"require-dev": {
"phpunit/phpunit": "~7.5 || ~8.0 || ~9.0",
"squizlabs/php_codesniffer": "~3.5"
},
"type": "library",
"autoload": {
"psr-0": {
"JsonMapper": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"OSL-3.0"
],
"authors": [
{
"name": "Christian Weiske",
"email": "cweiske@cweiske.de",
"homepage": "http://github.com/cweiske/jsonmapper/",
"role": "Developer"
}
],
"description": "Map nested JSON structures onto PHP classes",
"support": {
"email": "cweiske@cweiske.de",
"issues": "https://github.com/cweiske/jsonmapper/issues",
"source": "https://github.com/cweiske/jsonmapper/tree/v4.0.0"
},
"time": "2020-12-01T19:48:11+00:00"
},
{
"name": "nikic/php-parser",
"version": "v4.13.0",
@@ -3802,59 +3374,6 @@
},
"time": "2021-09-20T12:20:58+00:00"
},
{
"name": "openlss/lib-array2xml",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/nullivex/lib-array2xml.git",
"reference": "a91f18a8dfc69ffabe5f9b068bc39bb202c81d90"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nullivex/lib-array2xml/zipball/a91f18a8dfc69ffabe5f9b068bc39bb202c81d90",
"reference": "a91f18a8dfc69ffabe5f9b068bc39bb202c81d90",
"shasum": ""
},
"require": {
"php": ">=5.3.2"
},
"type": "library",
"autoload": {
"psr-0": {
"LSS": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Bryan Tong",
"email": "bryan@nullivex.com",
"homepage": "https://www.nullivex.com"
},
{
"name": "Tony Butler",
"email": "spudz76@gmail.com",
"homepage": "https://www.nullivex.com"
}
],
"description": "Array2XML conversion library credit to lalit.org",
"homepage": "https://www.nullivex.com",
"keywords": [
"array",
"array conversion",
"xml",
"xml conversion"
],
"support": {
"issues": "https://github.com/nullivex/lib-array2xml/issues",
"source": "https://github.com/nullivex/lib-array2xml/tree/master"
},
"time": "2019-03-29T20:06:56+00:00"
},
{
"name": "phar-io/manifest",
"version": "2.0.3",
@@ -4300,6 +3819,70 @@
},
"time": "2021-09-10T09:02:12+00:00"
},
{
"name": "phpstan/phpstan",
"version": "0.12.99",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "b4d40f1d759942f523be267a1bab6884f46ca3f7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/b4d40f1d759942f523be267a1bab6884f46ca3f7",
"reference": "b4d40f1d759942f523be267a1bab6884f46ca3f7",
"shasum": ""
},
"require": {
"php": "^7.1|^8.0"
},
"conflict": {
"phpstan/phpstan-shim": "*"
},
"bin": [
"phpstan",
"phpstan.phar"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.12-dev"
}
},
"autoload": {
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPStan - PHP Static Analysis Tool",
"support": {
"issues": "https://github.com/phpstan/phpstan/issues",
"source": "https://github.com/phpstan/phpstan/tree/0.12.99"
},
"funding": [
{
"url": "https://github.com/ondrejmirtes",
"type": "github"
},
{
"url": "https://github.com/phpstan",
"type": "github"
},
{
"url": "https://www.patreon.com/phpstan",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan",
"type": "tidelift"
}
],
"time": "2021-09-12T20:09:55+00:00"
},
{
"name": "phpunit/php-code-coverage",
"version": "9.2.7",
@@ -6782,111 +6365,6 @@
],
"time": "2021-07-28T10:34:58+00:00"
},
{
"name": "vimeo/psalm",
"version": "4.10.0",
"source": {
"type": "git",
"url": "https://github.com/vimeo/psalm.git",
"reference": "916b098b008f6de4543892b1e0651c1c3b92cbfa"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/vimeo/psalm/zipball/916b098b008f6de4543892b1e0651c1c3b92cbfa",
"reference": "916b098b008f6de4543892b1e0651c1c3b92cbfa",
"shasum": ""
},
"require": {
"amphp/amp": "^2.4.2",
"amphp/byte-stream": "^1.5",
"composer/package-versions-deprecated": "^1.8.0",
"composer/semver": "^1.4 || ^2.0 || ^3.0",
"composer/xdebug-handler": "^1.1 || ^2.0",
"dnoegel/php-xdg-base-dir": "^0.1.1",
"ext-ctype": "*",
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-simplexml": "*",
"ext-tokenizer": "*",
"felixfbecker/advanced-json-rpc": "^3.0.3",
"felixfbecker/language-server-protocol": "^1.5",
"netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0 || ^4.0",
"nikic/php-parser": "^4.12",
"openlss/lib-array2xml": "^1.0",
"php": "^7.1|^8",
"sebastian/diff": "^3.0 || ^4.0",
"symfony/console": "^3.4.17 || ^4.1.6 || ^5.0",
"webmozart/path-util": "^2.3"
},
"provide": {
"psalm/psalm": "self.version"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.2",
"brianium/paratest": "^4.0||^6.0",
"ext-curl": "*",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpdocumentor/reflection-docblock": "^5",
"phpmyadmin/sql-parser": "5.1.0||dev-master",
"phpspec/prophecy": ">=1.9.0",
"phpunit/phpunit": "^9.0",
"psalm/plugin-phpunit": "^0.16",
"slevomat/coding-standard": "^7.0",
"squizlabs/php_codesniffer": "^3.5",
"symfony/process": "^4.3 || ^5.0",
"weirdan/prophecy-shim": "^1.0 || ^2.0"
},
"suggest": {
"ext-igbinary": "^2.0.5"
},
"bin": [
"psalm",
"psalm-language-server",
"psalm-plugin",
"psalm-refactor",
"psalter"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.x-dev",
"dev-3.x": "3.x-dev",
"dev-2.x": "2.x-dev",
"dev-1.x": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"Psalm\\": "src/Psalm/"
},
"files": [
"src/functions.php",
"src/spl_object_id.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Matthew Brown"
}
],
"description": "A static analysis tool for finding errors in PHP applications",
"keywords": [
"code",
"inspection",
"php"
],
"support": {
"issues": "https://github.com/vimeo/psalm/issues",
"source": "https://github.com/vimeo/psalm/tree/4.10.0"
},
"time": "2021-09-04T21:00:09+00:00"
},
{
"name": "webmozart/assert",
"version": "1.10.0",
@@ -6945,56 +6423,6 @@
},
"time": "2021-03-09T10:59:23+00:00"
},
{
"name": "webmozart/path-util",
"version": "2.3.0",
"source": {
"type": "git",
"url": "https://github.com/webmozart/path-util.git",
"reference": "d939f7edc24c9a1bb9c0dee5cb05d8e859490725"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/webmozart/path-util/zipball/d939f7edc24c9a1bb9c0dee5cb05d8e859490725",
"reference": "d939f7edc24c9a1bb9c0dee5cb05d8e859490725",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"webmozart/assert": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.6",
"sebastian/version": "^1.0.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.3-dev"
}
},
"autoload": {
"psr-4": {
"Webmozart\\PathUtil\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Bernhard Schussek",
"email": "bschussek@gmail.com"
}
],
"description": "A robust cross-platform utility for normalizing, comparing and modifying file paths.",
"support": {
"issues": "https://github.com/webmozart/path-util/issues",
"source": "https://github.com/webmozart/path-util/tree/2.3.0"
},
"time": "2015-12-17T08:42:14+00:00"
},
{
"name": "yoast/phpunit-polyfills",
"version": "1.0.1",

72
phpstan-baseline.neon Normal file
View File

@@ -0,0 +1,72 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$factory of function DI\\\\factory expects callable\\(\\)\\: mixed, 'App\\\\\\\\Factories\\\\\\\\CacheFactory' given\\.$#"
count: 1
path: app/config/container.php
-
message: "#^Parameter \\#1 \\$factory of function DI\\\\factory expects callable\\(\\)\\: mixed, 'App\\\\\\\\Factories\\\\\\\\FinderFactory' given\\.$#"
count: 1
path: app/config/container.php
-
message: "#^Parameter \\#1 \\$factory of function DI\\\\factory expects callable\\(\\)\\: mixed, 'App\\\\\\\\Factories\\\\\\\\TranslationFactory' given\\.$#"
count: 1
path: app/config/container.php
-
message: "#^Parameter \\#1 \\$factory of function DI\\\\factory expects callable\\(\\)\\: mixed, 'App\\\\\\\\Factories\\\\\\\\TwigFactory' given\\.$#"
count: 1
path: app/config/container.php
-
message: "#^Parameter \\#1 \\$separator of function explode expects non\\-empty\\-string, string given\\.$#"
count: 1
path: app/src/Support/Str.php
-
message: "#^Parameter \\#1 \\$separator of function explode expects non\\-empty\\-string, string given\\.$#"
count: 1
path: app/src/ViewFunctions/Breadcrumbs.php
-
message: "#^Parameter \\#1 \\$finfo of function finfo_buffer expects resource, resource\\|false given\\.$#"
count: 1
path: tests/Controllers/ZipControllerTest.php
-
message: "#^Parameter \\#1 \\$finfo of function finfo_buffer expects resource, resource\\|false given\\.$#"
count: 1
path: tests/Exceptions/ErrorHandlerTest.php
-
message: "#^Parameter \\#1 \\$expected of method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) expects class\\-string\\<object\\>, string given\\.$#"
count: 1
path: tests/Factories/CacheFactoryTest.php
-
message: "#^Cannot call method getCallable\\(\\) on Twig\\\\TwigFunction\\|null\\.$#"
count: 11
path: tests/Factories/TwigFactoryTest.php
-
message: "#^Parameter \\#1 \\$className of method PHPUnit\\\\Framework\\\\TestCase\\:\\:getMockBuilder\\(\\) expects class\\-string\\<object\\>, string given\\.$#"
count: 1
path: tests/Middlewares/PruneCacheMiddlewareTest.php
-
message: "#^Parameter \\#1 \\$originalClassName of method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) expects class\\-string\\<object\\>, string given\\.$#"
count: 1
path: tests/Middlewares/PruneCacheMiddlewareTest.php
-
message: "#^Unable to resolve the template type RealInstanceType in call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\)$#"
count: 1
path: tests/Middlewares/PruneCacheMiddlewareTest.php
-
message: "#^Unable to resolve the template type RealInstanceType in call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:getMockBuilder\\(\\)$#"
count: 1
path: tests/Middlewares/PruneCacheMiddlewareTest.php

33
phpstan.neon.dist Normal file
View File

@@ -0,0 +1,33 @@
parameters:
paths:
- app
- tests
excludePaths:
- app/cache/*
- app/vendor/*
stubFiles:
- stubs/DI/Container.stub
level: 8
checkFunctionNameCase: true
checkMissingIterableValueType: false
implicitThrows: false
reportUnmatchedIgnoredErrors: false
# exceptions:
# check:
# missingCheckedExceptionInThrows: true
# tooWideThrowType: true
# uncheckedExceptionClasses:
# - 'PHPUnit\Framework\Exception'
# - 'SebastianBergmann\RecursionContext\InvalidArgumentException'
includes:
- phpstan-baseline.neon

View File

@@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.3.1@2feba22a005a18bf31d4c7b9bdb9252c73897476">
<file src="app/src/Controllers/DirectoryController.php">
<PossiblyInvalidMethodCall occurrences="1">
<code>current</code>
</PossiblyInvalidMethodCall>
</file>
<file src="app/src/Factories/CacheFactory.php">
<UndefinedFunction occurrences="2">
<code>'memcached_config'</code>
<code>'redis_config'</code>
</UndefinedFunction>
</file>
<file src="app/src/Factories/TwigFactory.php">
<InvalidMethodCall occurrences="1">
<code>name</code>
</InvalidMethodCall>
</file>
</files>

View File

@@ -1,63 +0,0 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm-baseline.xml"
>
<projectFiles>
<directory name="app" />
<ignoreFiles>
<directory name="app/cache" />
<directory name="app/vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<UndefinedInterfaceMethod>
<errorLevel type="suppress">
<referencedMethod name="Twig\Extension\ExtensionInterface::setdateformat" />
<file name="app/src/Factories/TwigFactory.php" />
</errorLevel>
</UndefinedInterfaceMethod>
<LessSpecificReturnType errorLevel="info" />
<!-- level 3 issues - slightly lazy code writing, but provably low false-negatives -->
<DeprecatedMethod errorLevel="info" />
<DeprecatedProperty errorLevel="info" />
<DeprecatedClass errorLevel="info" />
<DeprecatedConstant errorLevel="info" />
<DeprecatedFunction errorLevel="info" />
<DeprecatedInterface errorLevel="info" />
<DeprecatedTrait errorLevel="info" />
<InternalMethod errorLevel="info" />
<InternalProperty errorLevel="info" />
<InternalClass errorLevel="info" />
<MissingClosureReturnType errorLevel="info" />
<MissingReturnType errorLevel="info" />
<MissingPropertyType errorLevel="info" />
<InvalidDocblock errorLevel="info" />
<PropertyNotSetInConstructor errorLevel="info" />
<MissingConstructor errorLevel="info" />
<MissingClosureParamType errorLevel="info" />
<MissingParamType errorLevel="info" />
<RedundantCondition errorLevel="info" />
<DocblockTypeContradiction errorLevel="info" />
<RedundantConditionGivenDocblockType errorLevel="info" />
<UnresolvableInclude errorLevel="info" />
<RawObjectIteration errorLevel="info" />
<InvalidStringClass errorLevel="info" />
</issueHandlers>
</psalm>

14
stubs/DI/Container.stub Normal file
View File

@@ -0,0 +1,14 @@
<?php
namespace DI;
class Container
{
/**
* @phpstan-param callable|string $callable
* @phpstan-param array<mixed> $parameters
*
* @phpstan-return mixed
*/
public function call($callable, array $parameters = []);
}

View File

@@ -11,7 +11,7 @@ class AppManangerTest extends TestCase
{
public function test_it_returns_an_app_instance(): void
{
$app = (new AppManager($this->container))($this->testFilesPath);
$app = (new AppManager($this->container))();
$this->assertInstanceOf(App::class, $app);
$this->assertSame($this->container, $app->getContainer());

View File

@@ -34,11 +34,10 @@ class IndexControllerTest extends TestCase
public function test_it_handles_a_file_info_request(): void
{
$this->request->method('getQueryParams')->willReturn(['info' => 'file.test']);
$this->response = $this->createMock(ResponseInterface::class);
$this->container->expects($this->once())->method('call')->with(
Controllers\FileInfoController::class,
[$this->request, $this->response = new Response]
[$this->request, $this->response]
)->willReturn($this->response);
$controller = new Controllers\IndexController($this->container);

View File

@@ -5,6 +5,7 @@ namespace Tests\Factories;
use App\Exceptions\InvalidConfiguration;
use App\Factories\TranslationFactory;
use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Component\Translation\Translator;
use Tests\TestCase;
/** @covers \App\Factories\TranslationFactory */
@@ -12,12 +13,14 @@ class TranslationFactoryTest extends TestCase
{
public function test_it_registers_the_translation_component(): void
{
/** @var Translator $translator */
$translator = (new TranslationFactory($this->config, $this->cache))();
$this->assertEquals('en', $translator->getLocale());
$this->assertInstanceOf(MessageCatalogue::class, $translator->getCatalogue('de'));
$this->assertInstanceOf(MessageCatalogue::class, $translator->getCatalogue('en'));
$this->assertInstanceOf(MessageCatalogue::class, $translator->getCatalogue('es'));
$this->assertInstanceOf(MessageCatalogue::class, $translator->getCatalogue('et'));
$this->assertInstanceOf(MessageCatalogue::class, $translator->getCatalogue('fr'));
$this->assertInstanceOf(MessageCatalogue::class, $translator->getCatalogue('id'));
$this->assertInstanceOf(MessageCatalogue::class, $translator->getCatalogue('it'));

View File

@@ -14,6 +14,9 @@ use Tests\TestCase;
/** @covers \App\Middlewares\CacheControlMiddleware */
class CacheControlMiddlewareTest extends TestCase
{
/** @var ServerRequestInterface&MockObject */
protected $request;
/** @var RequestHandlerInterface&MockObject */
protected $handler;

View File

@@ -15,6 +15,9 @@ class TestCase extends BaseTestCase
/** @var Container The test container */
protected $container;
/** @var Config Application configuration */
protected $config;
/** @var CacheInterface The test cache */
protected $cache;

View File

@@ -2,8 +2,8 @@
namespace Tests\ViewFunctions;
use App\Config;
use App\ViewFunctions\Icon;
use PHLAK\Config\Config;
use Symfony\Component\Finder\SplFileInfo;
use Tests\TestCase;

View File

@@ -11,7 +11,7 @@ use Tests\TestCase;
class TranslateTest extends TestCase
{
/** @var Translator Translator component */
protected $tranlator;
protected $translator;
public function setUp(): void
{