From 545298c44d4aa2efb9d929ad836bbb9e2112587f Mon Sep 17 00:00:00 2001 From: feek <5747667+mr-feek@users.noreply.github.com> Date: Mon, 22 Jun 2020 11:28:59 -0700 Subject: [PATCH] [Chore] Introduce psalm (#962) * chore: introduce psalm * chore: remove dead code * chore: run psalm workflow * chore: run psalm in grumphp * normalize composer.json * chore: analyse --> analyze * chore: just remove psalm when running tests instead of worrying about dependency mismatch hell Co-authored-by: mr-feek --- .github/workflows/run-static-analysis.yml | 20 +++++++++++++++ .github/workflows/run-tests.yml | 2 +- composer.json | 4 ++- grumphp.yml | 9 +++++++ psalm-baseline.xml | 15 ++++++++++++ psalm.xml | 16 ++++++++++++ src/Alias.php | 2 ++ src/Console/MetaCommand.php | 4 +-- src/Generator.php | 30 ----------------------- 9 files changed, 68 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/run-static-analysis.yml create mode 100644 psalm-baseline.xml create mode 100644 psalm.xml diff --git a/.github/workflows/run-static-analysis.yml b/.github/workflows/run-static-analysis.yml new file mode 100644 index 0000000..cfa730a --- /dev/null +++ b/.github/workflows/run-static-analysis.yml @@ -0,0 +1,20 @@ +name: Run Static Analysis + +on: + push: + pull_request: + schedule: + - cron: '0 0 * * *' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Analyze + run: composer analyze diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 57508d3..4d47be0 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -61,7 +61,7 @@ jobs: - name: Install dependencies run: | - composer remove phpro/grumphp --no-interaction --no-update --dev + composer remove phpro/grumphp vimeo/psalm --no-interaction --no-update --dev composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update --no-progress composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest diff --git a/composer.json b/composer.json index 3010b5b..d198d2d 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,8 @@ "mockery/mockery": "^1.3", "orchestra/testbench": "^3 || ^4 || ^5", "phpro/grumphp": "^0.17.1", - "squizlabs/php_codesniffer": "^3.5" + "squizlabs/php_codesniffer": "^3.5", + "vimeo/psalm": "^3.12" }, "extra": { "branch-alias": { @@ -58,6 +59,7 @@ } }, "scripts": { + "analyze": "psalm", "check-style": "phpcs -p --standard=PSR2 src/", "fix-style": "phpcbf -p --standard=PSR2 src/", "test": "phpunit" diff --git a/grumphp.yml b/grumphp.yml index b73d14f..cb67b1d 100644 --- a/grumphp.yml +++ b/grumphp.yml @@ -16,3 +16,12 @@ parameters: whitelist_patterns: - /^src\/.*/ - /^config\/.*/ + psalm: + config: psalm.xml + ignore_patterns: [] + no_cache: false + report: null + output_format: null + threads: null + triggered_by: ['php'] + show_info: false diff --git a/psalm-baseline.xml b/psalm-baseline.xml new file mode 100644 index 0000000..3f479d3 --- /dev/null +++ b/psalm-baseline.xml @@ -0,0 +1,15 @@ + + + + + '\Laravel\Lumen\Application' + \Auth + \DB + \Cache + \Cache + \Queue + \SSH + \Storage + + + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..86fd1f4 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/src/Alias.php b/src/Alias.php index c185529..c85b129 100644 --- a/src/Alias.php +++ b/src/Alias.php @@ -21,6 +21,7 @@ use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer; class Alias { protected $alias; + /** @psalm-var class-string $facade */ protected $facade; protected $extends = null; protected $extendsClass = null; @@ -43,6 +44,7 @@ class Alias /** * @param ConfigRepository $config * @param string $alias + * @psalm-param class-string $facade * @param string $facade * @param array $magicMethods * @param array $interfaces diff --git a/src/Console/MetaCommand.php b/src/Console/MetaCommand.php index 071f613..40e8c9b 100644 --- a/src/Console/MetaCommand.php +++ b/src/Console/MetaCommand.php @@ -43,7 +43,7 @@ class MetaCommand extends Command /** @var \Illuminate\Contracts\View\Factory */ protected $view; - /** @var \Illuminate\Contracts\Config */ + /** @var \Illuminate\Contracts\Config\Repository */ protected $config; protected $methods = [ @@ -61,7 +61,7 @@ class MetaCommand extends Command * * @param \Illuminate\Contracts\Filesystem\Filesystem $files * @param \Illuminate\Contracts\View\Factory $view - * @param \Illuminate\Contracts\Config $config + * @param \Illuminate\Contracts\Config\Repository $config */ public function __construct($files, $view, $config) { diff --git a/src/Generator.php b/src/Generator.php index 74d82bb..afe2fed 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -283,36 +283,6 @@ class Generator ); } - /** - * Get the driver/connection/store from the managers - * - * @param $alias - * @return array|bool|string - */ - public function getDriver($alias) - { - try { - if ($alias == "Auth") { - $driver = \Auth::driver(); - } elseif ($alias == "DB") { - $driver = \DB::connection(); - } elseif ($alias == "Cache") { - $driver = get_class(\Cache::driver()); - $store = get_class(\Cache::getStore()); - return array($driver, $store); - } elseif ($alias == "Queue") { - $driver = \Queue::connection(); - } else { - return false; - } - - return get_class($driver); - } catch (\Exception $e) { - $this->error("Could not determine driver/connection for $alias."); - return false; - } - } - /** * Write a string as error output. *