From 378289cbe1b49b3f7116df3393d29e08c61a9686 Mon Sep 17 00:00:00 2001 From: Farhad Safarov Date: Tue, 12 Nov 2019 16:36:05 +0300 Subject: [PATCH] initial commit --- .gitignore | 2 ++ .travis.yml | 25 ++++++++++++++++++ LICENSE | 21 ++++++++++++++++ README.md | 8 ++++++ composer.json | 33 ++++++++++++++++++++++++ psalm.xml | 15 +++++++++++ src/Handler/ClassHandler.php | 42 +++++++++++++++++++++++++++++++ src/Issue/ContainerDependency.php | 14 +++++++++++ src/Plugin.php | 19 ++++++++++++++ 9 files changed, 179 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 composer.json create mode 100644 psalm.xml create mode 100644 src/Handler/ClassHandler.php create mode 100644 src/Issue/ContainerDependency.php create mode 100644 src/Plugin.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7579f74 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +vendor +composer.lock diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e8478fa --- /dev/null +++ b/.travis.yml @@ -0,0 +1,25 @@ +language: php + +php: + - 7.1 + - 7.2 + - 7.3 + +before_install: + - phpenv config-rm xdebug.ini || true + +install: + - composer install + - if [[ "$DEPS" = 'high' ]]; then travis_retry composer $DEFAULT_COMPOSER_FLAGS update; fi + - if [[ "$DEPS" = 'low' ]]; then travis_retry composer $DEFAULT_COMPOSER_FLAGS --prefer-lowest --prefer-stable update; fi + - if [[ "$DEPS" = 'stable' ]]; then travis_retry composer $DEFAULT_COMPOSER_FLAGS --prefer-stable update; fi + +script: composer check + +env: + matrix: + - DEPS="low" + - DEPS="high" + - DEPS="stable" + global: + - DEFAULT_COMPOSER_FLAGS="--no-interaction --no-suggest" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d7d8ff1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Farhad Safarov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c37a19f --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Symfony Psalm Plugin + +### Installation + +``` +composer require --dev seferov/symfony-psalm-plugin +vendor/bin/psalm-plugin enable seferov/symfony-psalm-plugin +``` diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..eb73cae --- /dev/null +++ b/composer.json @@ -0,0 +1,33 @@ +{ + "name": "seferov/symfony-psalm-plugin", + "description": "Psalm Plugin for Symfony", + "type": "psalm-plugin", + "require": { + "php": "^7.1", + "vimeo/psalm": "^3.2", + "symfony/framework-bundle": "^3.0 || ^4.0" + }, + "license": "MIT", + "authors": [ + { + "name": "Farhad Safarov", + "email": "farhad.safarov@gmail.com" + } + ], + "autoload": { + "psr-4": { + "Seferov\\SymfonyPsalmPlugin\\": "src" + } + }, + "extra": { + "psalm" : { + "pluginClass": "Seferov\\SymfonyPsalmPlugin\\Plugin" + } + }, + "scripts": { + "check": [ + "@analyze" + ], + "analyze": "psalm" + } +} diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..9d2a538 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/src/Handler/ClassHandler.php b/src/Handler/ClassHandler.php new file mode 100644 index 0000000..2f19f82 --- /dev/null +++ b/src/Handler/ClassHandler.php @@ -0,0 +1,42 @@ +stmts as $stmt) { + if ($stmt instanceof Node\Stmt\ClassMethod && '__construct' === $stmt->name->name) { + foreach ($stmt->params as $param) { + if ($param->type instanceof Node\Name && ContainerInterface::class === $param->type->getAttributes()['resolvedName']) { + IssueBuffer::accepts( + new ContainerDependency(new CodeLocation($statements_source, $stmt)), + $statements_source->getSuppressedIssues() + ); + } + } + } + } + + return null; + } +} diff --git a/src/Issue/ContainerDependency.php b/src/Issue/ContainerDependency.php new file mode 100644 index 0000000..1d39889 --- /dev/null +++ b/src/Issue/ContainerDependency.php @@ -0,0 +1,14 @@ +registerHooksFromClass(ClassHandler::class); + } +}