diff --git a/.editorconfig b/.editorconfig index f1adb2f..9d216b9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 656db77..be847a8 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -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 diff --git a/.github/workflows/test-suite.yaml b/.github/workflows/test-suite.yaml index 62707f8..bc7ea42 100644 --- a/.github/workflows/test-suite.yaml +++ b/.github/workflows/test-suite.yaml @@ -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 diff --git a/app/config/container.php b/app/config/container.php index e495512..ab60874 100644 --- a/app/config/container.php +++ b/app/config/container.php @@ -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), diff --git a/app/src/Bootstrap/BootManager.php b/app/src/Bootstrap/BootManager.php index ab17611..88ec84c 100644 --- a/app/src/Bootstrap/BootManager.php +++ b/app/src/Bootstrap/BootManager.php @@ -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); diff --git a/app/src/Controllers/DirectoryController.php b/app/src/Controllers/DirectoryController.php index b2d1d01..d01b9d7 100644 --- a/app/src/Controllers/DirectoryController.php +++ b/app/src/Controllers/DirectoryController.php @@ -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(); }); diff --git a/app/src/Controllers/FileInfoController.php b/app/src/Controllers/FileInfoController.php index 8f13188..b0040d4 100644 --- a/app/src/Controllers/FileInfoController.php +++ b/app/src/Controllers/FileInfoController.php @@ -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()), ]; } } diff --git a/app/src/Controllers/ZipController.php b/app/src/Controllers/ZipController.php index 13c6edb..8e7638e 100644 --- a/app/src/Controllers/ZipController.php +++ b/app/src/Controllers/ZipController.php @@ -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. */ diff --git a/app/src/Exceptions/ErrorHandler.php b/app/src/Exceptions/ErrorHandler.php index 8fd4f41..353b6b8 100644 --- a/app/src/Exceptions/ErrorHandler.php +++ b/app/src/Exceptions/ErrorHandler.php @@ -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')], ])); diff --git a/app/src/Factories/FinderFactory.php b/app/src/Factories/FinderFactory.php index 27c4482..7a1a19c 100644 --- a/app/src/Factories/FinderFactory.php +++ b/app/src/Factories/FinderFactory.php @@ -77,6 +77,6 @@ class FinderFactory ), $this->hiddenFiles->implode(','))); } - return Glob::matchStart($this->pattern, $file->getRealPath()); + return Glob::matchStart($this->pattern, (string) $file->getRealPath()); } } diff --git a/app/src/Factories/TwigFactory.php b/app/src/Factories/TwigFactory.php index d0807dc..ae0d6f3 100644 --- a/app/src/Factories/TwigFactory.php +++ b/app/src/Factories/TwigFactory.php @@ -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) ); } diff --git a/app/src/HiddenFiles.php b/app/src/HiddenFiles.php index f4e1ccd..241762f 100644 --- a/app/src/HiddenFiles.php +++ b/app/src/HiddenFiles.php @@ -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')) { diff --git a/app/src/TemporaryFile.php b/app/src/TemporaryFile.php index 8f1ed49..ce2390f 100644 --- a/app/src/TemporaryFile.php +++ b/app/src/TemporaryFile.php @@ -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); } } diff --git a/app/src/ViewFunctions/Asset.php b/app/src/ViewFunctions/Asset.php index 0f1d807..8216dba 100644 --- a/app/src/ViewFunctions/Asset.php +++ b/app/src/ViewFunctions/Asset.php @@ -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) ?? [] ); } } diff --git a/app/src/ViewFunctions/Config.php b/app/src/ViewFunctions/Config.php index 63174dd..daf8de4 100644 --- a/app/src/ViewFunctions/Config.php +++ b/app/src/ViewFunctions/Config.php @@ -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) { diff --git a/app/src/ViewFunctions/Url.php b/app/src/ViewFunctions/Url.php index 37a1d46..73c8711 100644 --- a/app/src/ViewFunctions/Url.php +++ b/app/src/ViewFunctions/Url.php @@ -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. */ diff --git a/composer.json b/composer.json index c745e3a..718e4b1 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/composer.lock b/composer.lock index d3e7c57..7033878 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..6a52251 --- /dev/null +++ b/phpstan-baseline.neon @@ -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\\, 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\\, string given\\.$#" + count: 1 + path: tests/Middlewares/PruneCacheMiddlewareTest.php + + - + message: "#^Parameter \\#1 \\$originalClassName of method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) expects class\\-string\\, 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 + diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..02b651d --- /dev/null +++ b/phpstan.neon.dist @@ -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 diff --git a/psalm-baseline.xml b/psalm-baseline.xml deleted file mode 100644 index a84b9ad..0000000 --- a/psalm-baseline.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - current - - - - - 'memcached_config' - 'redis_config' - - - - - name - - - diff --git a/psalm.xml b/psalm.xml deleted file mode 100644 index 1cd16b8..0000000 --- a/psalm.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stubs/DI/Container.stub b/stubs/DI/Container.stub new file mode 100644 index 0000000..765b68e --- /dev/null +++ b/stubs/DI/Container.stub @@ -0,0 +1,14 @@ + $parameters + * + * @phpstan-return mixed + */ + public function call($callable, array $parameters = []); +} diff --git a/tests/Bootstrap/AppManangerTest.php b/tests/Bootstrap/AppManangerTest.php index fe70884..545eaaa 100644 --- a/tests/Bootstrap/AppManangerTest.php +++ b/tests/Bootstrap/AppManangerTest.php @@ -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()); diff --git a/tests/Controllers/IndexControllerTest.php b/tests/Controllers/IndexControllerTest.php index 51b8602..df02604 100644 --- a/tests/Controllers/IndexControllerTest.php +++ b/tests/Controllers/IndexControllerTest.php @@ -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); diff --git a/tests/Factories/TranslationFactoryTest.php b/tests/Factories/TranslationFactoryTest.php index aba6d35..d532267 100644 --- a/tests/Factories/TranslationFactoryTest.php +++ b/tests/Factories/TranslationFactoryTest.php @@ -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')); diff --git a/tests/Middlewares/CacheControlMiddlewareTest.php b/tests/Middlewares/CacheControlMiddlewareTest.php index b234f18..e17d424 100644 --- a/tests/Middlewares/CacheControlMiddlewareTest.php +++ b/tests/Middlewares/CacheControlMiddlewareTest.php @@ -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; diff --git a/tests/TestCase.php b/tests/TestCase.php index cfb52cf..3042279 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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; diff --git a/tests/ViewFunctions/IconTest.php b/tests/ViewFunctions/IconTest.php index e0abf31..7e74b5b 100644 --- a/tests/ViewFunctions/IconTest.php +++ b/tests/ViewFunctions/IconTest.php @@ -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; diff --git a/tests/ViewFunctions/TranslateTest.php b/tests/ViewFunctions/TranslateTest.php index 3dd9ff6..d70fbd5 100644 --- a/tests/ViewFunctions/TranslateTest.php +++ b/tests/ViewFunctions/TranslateTest.php @@ -11,7 +11,7 @@ use Tests\TestCase; class TranslateTest extends TestCase { /** @var Translator Translator component */ - protected $tranlator; + protected $translator; public function setUp(): void {