Skip to content

Commit 96ecaa9

Browse files
Flyingmanatmotyl
andauthored
Add phpstan configuration, dependencies and github action (#1875)
* Add phpstan configuration file run with: vendor/bin/phpstan analyze -c .github/phpstan.neon * add phpstan execution to github action * move failing paths into experimental section * extend buildmatrix for phpstan * avoid output polution by experimental workflows the errors triggered github check annotations Co-authored-by: Tymoteusz Motylewski <[email protected]>
1 parent 1c9f198 commit 96ecaa9

File tree

5 files changed

+142
-2
lines changed

5 files changed

+142
-2
lines changed

.github/phpstan.neon

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
includes:
2+
- ../vendor/macopedia/phpstan-magento1/extension.neon
3+
parameters:
4+
magentoRootPath: %currentWorkingDirectory%
5+
paths:
6+
#lets start small with just few modules
7+
- %currentWorkingDirectory%/app/code/core/Mage/Admin
8+
# - %currentWorkingDirectory%/app/code/core/Mage/Adminhtml
9+
# - %currentWorkingDirectory%/app/code/core/Mage/AdminNotification
10+
# - %currentWorkingDirectory%/app/code/core/Mage/Api
11+
# - %currentWorkingDirectory%/app/code/core/Mage/Api2
12+
# - %currentWorkingDirectory%/app/code/core/Mage/Authorizenet
13+
# - %currentWorkingDirectory%/app/code/core/Mage/Backup
14+
# - %currentWorkingDirectory%/app/code/core/Mage/Bundle
15+
# - %currentWorkingDirectory%/app/code/core/Mage/Captcha
16+
# - %currentWorkingDirectory%/app/code/core/Mage/Catalog
17+
# - %currentWorkingDirectory%/app/code/core/Mage/CatalogIndex
18+
# - %currentWorkingDirectory%/app/code/core/Mage/CatalogInventory
19+
# - %currentWorkingDirectory%/app/code/core/Mage/CatalogRule
20+
# - %currentWorkingDirectory%/app/code/core/Mage/CatalogSearch
21+
# - %currentWorkingDirectory%/app/code/core/Mage/Centinel
22+
# - %currentWorkingDirectory%/app/code/core/Mage/Checkout
23+
- %currentWorkingDirectory%/app/code/core/Mage/Cms
24+
# - %currentWorkingDirectory%/app/code/core/Mage/ConfigurableSwatches
25+
# - %currentWorkingDirectory%/app/code/core/Mage/Contacts
26+
# - %currentWorkingDirectory%/app/code/core/Mage/Core
27+
# - %currentWorkingDirectory%/app/code/core/Mage/Cron
28+
# - %currentWorkingDirectory%/app/code/core/Mage/CurrencySymbol
29+
# - %currentWorkingDirectory%/app/code/core/Mage/Customer
30+
# - %currentWorkingDirectory%/app/code/core/Mage/Dataflow
31+
# - %currentWorkingDirectory%/app/code/core/Mage/Directory
32+
# - %currentWorkingDirectory%/app/code/core/Mage/Downloadable
33+
# - %currentWorkingDirectory%/app/code/core/Mage/Eav
34+
# - %currentWorkingDirectory%/app/code/core/Mage/GiftMessage
35+
# - %currentWorkingDirectory%/app/code/core/Mage/GoogleAnalytics
36+
# - %currentWorkingDirectory%/app/code/core/Mage/GoogleCheckout
37+
# - %currentWorkingDirectory%/app/code/core/Mage/ImportExport
38+
# - %currentWorkingDirectory%/app/code/core/Mage/Index
39+
# - %currentWorkingDirectory%/app/code/core/Mage/Install
40+
- %currentWorkingDirectory%/app/code/core/Mage/Log
41+
# - %currentWorkingDirectory%/app/code/core/Mage/Media
42+
# - %currentWorkingDirectory%/app/code/core/Mage/Newsletter
43+
# - %currentWorkingDirectory%/app/code/core/Mage/Oauth
44+
# - %currentWorkingDirectory%/app/code/core/Mage/Page
45+
# - %currentWorkingDirectory%/app/code/core/Mage/PageCache
46+
# - %currentWorkingDirectory%/app/code/core/Mage/Paygate
47+
# - %currentWorkingDirectory%/app/code/core/Mage/Payment
48+
# - %currentWorkingDirectory%/app/code/core/Mage/Paypal
49+
# - %currentWorkingDirectory%/app/code/core/Mage/PaypalUk
50+
# - %currentWorkingDirectory%/app/code/core/Mage/Persistent
51+
# - %currentWorkingDirectory%/app/code/core/Mage/Poll
52+
# - %currentWorkingDirectory%/app/code/core/Mage/ProductAlert
53+
# - %currentWorkingDirectory%/app/code/core/Mage/Rating
54+
# - %currentWorkingDirectory%/app/code/core/Mage/Reports
55+
# - %currentWorkingDirectory%/app/code/core/Mage/Review
56+
# - %currentWorkingDirectory%/app/code/core/Mage/Rss
57+
# - %currentWorkingDirectory%/app/code/core/Mage/Rule
58+
# - %currentWorkingDirectory%/app/code/core/Mage/Sales
59+
# - %currentWorkingDirectory%/app/code/core/Mage/SalesRule
60+
# - %currentWorkingDirectory%/app/code/core/Mage/Sendfriend
61+
# - %currentWorkingDirectory%/app/code/core/Mage/Shipping
62+
# - %currentWorkingDirectory%/app/code/core/Mage/Sitemap
63+
# - %currentWorkingDirectory%/app/code/core/Mage/Tag
64+
# - %currentWorkingDirectory%/app/code/core/Mage/Tax
65+
# - %currentWorkingDirectory%/app/code/core/Mage/Uploader
66+
# - %currentWorkingDirectory%/app/code/core/Mage/Usa
67+
# - %currentWorkingDirectory%/app/code/core/Mage/Weee
68+
# - %currentWorkingDirectory%/app/code/core/Mage/Widget
69+
# - %currentWorkingDirectory%/app/code/core/Mage/Wishlist
70+
excludePaths:
71+
#incompatible interfaces
72+
- */app/code/core/Mage/Admin/Model/Acl/Assert/Ip.php
73+
- */app/code/core/Mage/Admin/Model/Acl/Assert/Time.php
74+
75+
- */app/code/core/Mage/Admin/Model/Config.php
76+
- */app/code/core/Mage/Admin/Model/Roles.php
77+
- */app/code/core/Mage/Admin/Model/User.php
78+
# due to errors (variable passed to a factory):
79+
- */app/code/core/Mage/Cms/Helper/Page.php
80+
- */app/code/core/Mage/Cms/Helper/Data.php
81+
level: 0
82+
# universalObjectCratesClasses:
83+
# - Varien_Object
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
includes:
2+
- ./phpstan.neon
3+
parameters:
4+
level: 1

.github/workflows/static-code-analyses.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ jobs:
3030
- name: Check .phtml files
3131
run: '! find app/design -type f -name "*.phtml" -exec php -d error_reporting=32767 -l {} \; 2>&1 1> /dev/null | grep "^"'
3232

33+
php_stan:
34+
name: PHP Stan ${{ matrix.directories }} - ${{ matrix.config_files }}
35+
runs-on: [ubuntu-latest]
36+
strategy:
37+
max-parallel: 2
38+
matrix:
39+
directories: [
40+
'',
41+
#'lib/',
42+
]
43+
config_files: [
44+
'.github/phpstan.neon',
45+
]
46+
steps:
47+
- uses: actions/checkout@v2
48+
- name: Install dependencies
49+
run: composer install --prefer-dist --no-progress --no-suggest --ignore-platform-reqs
50+
- name: ensure existance of ./app/code/local
51+
run: mkdir -p app/code/local
52+
- name: PHPStan Static Analysis
53+
run: php vendor/bin/phpstan.phar analyze -c ${{ matrix.config_files }} ${{ matrix.directories }}
54+
3355
php_syntax_experimental:
3456
name: PHP Syntax ${{ matrix.php-versions }} - experimental
3557
runs-on: ${{ matrix.operating-system }}
@@ -59,3 +81,30 @@ jobs:
5981
continue-on-error: true
6082
run: '! find app/design -type f -name "*.phtml" -exec php -d error_reporting=32767 -l {} \; 2>&1 1> /dev/null | grep "^"'
6183

84+
85+
php_stan_experimental:
86+
name: PHP Stan ${{ matrix.directories }} - ${{ matrix.config_files }} - experimental
87+
runs-on: [ubuntu-latest]
88+
needs: php_stan
89+
strategy:
90+
max-parallel: 1
91+
fail-fast: false
92+
matrix:
93+
directories: [
94+
''
95+
]
96+
config_files: [
97+
'.github/phpstan_experimental_level.neon',
98+
]
99+
include:
100+
- directories: 'lib/'
101+
config_files: '.github/phpstan.neon'
102+
steps:
103+
- uses: actions/checkout@v2
104+
- name: Install dependencies
105+
run: composer install --prefer-dist --no-progress --no-suggest --ignore-platform-reqs
106+
- name: ensure existance of ./app/code/local
107+
run: mkdir -p app/code/local
108+
- name: PHPStan Static Analysis
109+
continue-on-error: true
110+
run: php vendor/bin/phpstan.phar analyze --error-format=raw -c ${{ matrix.config_files }} ${{ matrix.directories }}

app/code/core/Mage/Admin/Model/Observer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Mage_Admin_Model_Observer
3939
* Handler for controller_action_predispatch event
4040
*
4141
* @param Varien_Event_Observer $observer
42-
* @return boolean
42+
* @return void
4343
*/
4444
public function actionPreDispatchAdmin($observer)
4545
{
@@ -106,7 +106,7 @@ public function actionPreDispatchAdmin($observer)
106106
->setActionName('login')
107107
->setDispatched(false);
108108
}
109-
return false;
109+
return;
110110
}
111111
}
112112
}

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"php": ">=7.0 <7.5 || >=8.0 <8.1",
1111
"magento-hackathon/magento-composer-installer": "^3.1 || ^2.1 || ^4.0"
1212
},
13+
"require-dev": {
14+
"macopedia/phpstan-magento1": "^1.0",
15+
"phpstan/phpstan": "^0.12"
16+
},
1317
"authors": [
1418
{
1519
"name": "Lee Saferite",

0 commit comments

Comments
 (0)