From 9aa259672a401dff5ab5e09f342f9a16f2d1549b Mon Sep 17 00:00:00 2001 From: Fabien Bourigault Date: Tue, 5 Jan 2021 00:19:56 +0100 Subject: [PATCH] Setup PHPStan at level 1 --- .gitattributes | 4 ++ .gitignore | 1 + .phpstan/baseline.neon | 9 +++++ .phpstan/stubs/Event.stub | 38 +++++++++++++++++++ .phpstan/stubs/ExtensionGuesserInterface.stub | 31 +++++++++++++++ .phpstan/stubs/MimeTypeGuesserInterface.stub | 38 +++++++++++++++++++ composer.json | 1 + phpstan.neon.dist | 27 +++++++++++++ 8 files changed, 149 insertions(+) create mode 100644 .phpstan/baseline.neon create mode 100644 .phpstan/stubs/Event.stub create mode 100644 .phpstan/stubs/ExtensionGuesserInterface.stub create mode 100644 .phpstan/stubs/MimeTypeGuesserInterface.stub create mode 100644 phpstan.neon.dist diff --git a/.gitattributes b/.gitattributes index ee9ea83fb..26a33c44a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,8 +1,12 @@ * text=auto /.github/ export-ignore +/.phpstan/ export-ignore /Tests/ export-ignore /.gitattributes export-ignore /.github_changelog_generator export-ignore /.php_cs.dist export-ignore /.scrutinizer.yml export-ignore +/.styleci.yml export-ignore +/.travis.yml export-ignore +/.phpstan.neon.dist export-ignore /.phpunit.xml.dist export-ignore diff --git a/.gitignore b/.gitignore index 172110277..1d5d2c729 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ /bin/ /composer.lock /composer.phar +/phpstan.neon /phpunit.xml /Tests/Functional/app/public/media/cache /Tests/Functional/app/web/media/cache diff --git a/.phpstan/baseline.neon b/.phpstan/baseline.neon new file mode 100644 index 000000000..876a6c3e1 --- /dev/null +++ b/.phpstan/baseline.neon @@ -0,0 +1,9 @@ +parameters: + ignoreErrors: + - message: '#^Access to undefined constant Liip\\ImagineBundle\\Config\\Filter\\Type\\FilterAbstract::NAME\.$#' + paths: + - ../Config/Filter/Type/FilterAbstract.php + - message: '#^Unsafe usage of new static\(\)\.$#' + paths: + - ../Async/CacheResolved.php + - ../Async/ResolveCache.php diff --git a/.phpstan/stubs/Event.stub b/.phpstan/stubs/Event.stub new file mode 100644 index 000000000..307c4be5d --- /dev/null +++ b/.phpstan/stubs/Event.stub @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\EventDispatcher; + +/** + * @deprecated since Symfony 4.3, use "Symfony\Contracts\EventDispatcher\Event" instead + */ +class Event +{ + private $propagationStopped = false; + + /** + * @return bool Whether propagation was already stopped for this event + * + * @deprecated since Symfony 4.3, use "Symfony\Contracts\EventDispatcher\Event" instead + */ + public function isPropagationStopped() + { + return $this->propagationStopped; + } + + /** + * @deprecated since Symfony 4.3, use "Symfony\Contracts\EventDispatcher\Event" instead + */ + public function stopPropagation() + { + $this->propagationStopped = true; + } +} diff --git a/.phpstan/stubs/ExtensionGuesserInterface.stub b/.phpstan/stubs/ExtensionGuesserInterface.stub new file mode 100644 index 000000000..69fe6efb2 --- /dev/null +++ b/.phpstan/stubs/ExtensionGuesserInterface.stub @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpFoundation\File\MimeType; + +use Symfony\Component\Mime\MimeTypesInterface; + +/** + * Guesses the file extension corresponding to a given mime type. + * + * @deprecated since Symfony 4.3, use {@link MimeTypesInterface} instead + */ +interface ExtensionGuesserInterface +{ + /** + * Makes a best guess for a file extension, given a mime type. + * + * @param string $mimeType The mime type + * + * @return string The guessed extension or NULL, if none could be guessed + */ + public function guess($mimeType); +} diff --git a/.phpstan/stubs/MimeTypeGuesserInterface.stub b/.phpstan/stubs/MimeTypeGuesserInterface.stub new file mode 100644 index 000000000..eab444890 --- /dev/null +++ b/.phpstan/stubs/MimeTypeGuesserInterface.stub @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpFoundation\File\MimeType; + +use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException; +use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; +use Symfony\Component\Mime\MimeTypesInterface; + +/** + * Guesses the mime type of a file. + * + * @author Bernhard Schussek + * + * @deprecated since Symfony 4.3, use {@link MimeTypesInterface} instead + */ +interface MimeTypeGuesserInterface +{ + /** + * Guesses the mime type of the file with the given path. + * + * @param string $path The path to the file + * + * @return string|null The mime type or NULL, if none could be guessed + * + * @throws FileNotFoundException If the file does not exist + * @throws AccessDeniedException If the file could not be read + */ + public function guess($path); +} diff --git a/composer.json b/composer.json index 0242118d9..90cf42acf 100644 --- a/composer.json +++ b/composer.json @@ -36,6 +36,7 @@ "doctrine/persistence": "^1.3|^2.0", "enqueue/enqueue-bundle": "^0.9|^0.10", "league/flysystem": "^1.0|^2.0", + "phpstan/phpstan": "^0.12.64", "psr/log": "^1.0", "symfony/browser-kit": "^3.4|^4.3|^5.0", "symfony/console": "^3.4|^4.3|^5.0", diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 000000000..ac9e8d527 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,27 @@ +includes: + - .phpstan/baseline.neon +parameters: + level: 1 + paths: + - Async + - Binary + - Command + - Component + - Config + - Controller + - DependencyInjection + - Events + - Exception + - Factory + - Form + - Imagine + - Model + - Resources + - Service + - Templating + - Utility + - LiipImagineBundle.php + scanFiles: + - .phpstan/stubs/Event.stub + - .phpstan/stubs/ExtensionGuesserInterface.stub + - .phpstan/stubs/MimeTypeGuesserInterface.stub