Skip to content

Commit 21a9823

Browse files
authored
Static analysis with Psalm (#8116)
* Remove useless ternaries If these expressions are truish inside the condition, they will still be truish inside the if. * Describe properties more accurately These are not objects, they are strings holding class names for classes that implement TreeWalker. * Remove duplicate key Comparison::IS and Comparison::EQ are the same. I chose to remove IS because it does not seem to exist anymore on master * Remove unwanted . before = operator This worked, but makes no sense. * Setup static analysis with Psalm * Move PHPStan to Github actions
1 parent 8a9954e commit 21a9823

File tree

11 files changed

+840
-19
lines changed

11 files changed

+840
-19
lines changed

.github/workflows/ci.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
static-analysis-phpstan:
8+
name: "Static Analysis with PHPStan"
9+
runs-on: "ubuntu-latest"
10+
11+
strategy:
12+
matrix:
13+
php-version:
14+
- "7.4"
15+
16+
steps:
17+
- name: "Checkout code"
18+
uses: "actions/checkout@v2"
19+
20+
- name: "Install PHP"
21+
uses: "shivammathur/setup-php@v2"
22+
with:
23+
coverage: "none"
24+
php-version: "${{ matrix.php-version }}"
25+
tools: cs2pr
26+
27+
- name: "Cache dependencies installed with composer"
28+
uses: "actions/cache@v1"
29+
with:
30+
path: "~/.composer/cache"
31+
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
32+
restore-keys: "php-${{ matrix.php-version }}-composer-locked-"
33+
34+
- name: "Install dependencies with composer"
35+
run: "composer install --no-progress --no-suggest --no-interaction --prefer-dist"
36+
37+
- name: "Run a static analysis with phpstan/phpstan"
38+
run: "php vendor/bin/phpstan analyse --error-format=checkstyle | cs2pr"
39+
40+
static-analysis-psalm:
41+
name: "Static Analysis with Psalm"
42+
runs-on: "ubuntu-latest"
43+
44+
strategy:
45+
matrix:
46+
php-version:
47+
- "7.4"
48+
49+
steps:
50+
- name: "Checkout code"
51+
uses: "actions/checkout@v2"
52+
53+
- name: "Install PHP"
54+
uses: "shivammathur/setup-php@v2"
55+
with:
56+
coverage: "none"
57+
php-version: "${{ matrix.php-version }}"
58+
59+
- name: "Cache dependencies installed with composer"
60+
uses: "actions/cache@v1"
61+
with:
62+
path: "~/.composer/cache"
63+
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
64+
restore-keys: "php-${{ matrix.php-version }}-composer-locked-"
65+
66+
- name: "Install dependencies with composer"
67+
run: "composer install --no-interaction --no-progress --no-suggest"
68+
69+
- name: "Run a static analysis with vimeo/psalm"
70+
run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=$(nproc)"

.travis.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,6 @@ jobs:
8484
- wget https://scrutinizer-ci.com/ocular.phar
8585
- php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
8686

87-
- stage: Code Quality
88-
env: DB=none STATIC_ANALYSIS
89-
php: 7.4
90-
install: travis_retry composer install --prefer-dist
91-
before_script:
92-
- echo "extension=memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
93-
- echo "extension=redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
94-
- travis_retry composer require --dev --prefer-dist --prefer-stable phpstan/phpstan:^0.9
95-
script: vendor/bin/phpstan analyse -l 1 -c phpstan.neon lib
96-
9787
- stage: Code Quality
9888
env: DB=none BENCHMARK
9989
before_script: wget https://phpbench.github.io/phpbench/phpbench.phar https://phpbench.github.io/phpbench/phpbench.phar.pubkey

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
{"name": "Marco Pivetta", "email": "[email protected]"}
1414
],
1515
"config": {
16+
"platform": {
17+
"php": "7.1.3"
18+
},
1619
"sort-packages": true
1720
},
1821
"require": {
@@ -31,8 +34,10 @@
3134
},
3235
"require-dev": {
3336
"doctrine/coding-standard": "^5.0",
37+
"phpstan/phpstan": "^0.12.18",
3438
"phpunit/phpunit": "^7.5",
35-
"symfony/yaml": "^3.4|^4.0|^5.0"
39+
"symfony/yaml": "^3.4|^4.0|^5.0",
40+
"vimeo/psalm": "^3.11"
3641
},
3742
"suggest": {
3843
"symfony/yaml": "If you want to use YAML Metadata Mapping Driver"

0 commit comments

Comments
 (0)