Skip to content

Commit 06bcfdc

Browse files
authored
feat: add phpstan & phpcs (#96)
* feat: update and enable workflow * feat: add phpstan workflow and configuration * feat: update phpcs * feat: add permissions for PHPStan workflow * feat: add continue-on-error for PHPStan step * fix: update opensearch plugin disable flag * fix: update phpstan dependency version * feat: allow phpstan extension installer in composer * fix: remove checkGenericClassInNonGenericObjectType flag
1 parent 7108ef0 commit 06bcfdc

3 files changed

Lines changed: 128 additions & 6 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
name: Check phpcs
1+
name: PHPCS
22

33
on: [pull_request]
44

55
permissions:
66
contents: read
77

88
env:
9-
PHP_VERSION: "8.3"
9+
PHP_VERSION: "8.4"
1010

1111
jobs:
1212
check-phpcs:
1313
runs-on: ubuntu-latest
1414

15-
if: false
16-
1715
steps:
1816
- name: Checkout code
19-
uses: actions/checkout@cbb722410c2e876e24abbe8de2cc27693e501dcb
17+
uses: actions/checkout@v4
2018

2119
- name: Set up PHP
22-
uses: shivammathur/setup-php@19ba822314c230a9039afce40e65d6c2b352ebfb
20+
uses: shivammathur/setup-php@v2
2321
with:
2422
php-version: ${{ env.PHP_VERSION }}
2523

2624
- name: Install Magento Coding Standard
2725
run: composer create-project magento/magento-coding-standard --stability=dev /tmp/magento-coding-standard
2826

2927
- name: Run PHPCS
28+
continue-on-error: true
3029
run: /tmp/magento-coding-standard/vendor/bin/phpcs -p -s --standard=Magento2 src/

.github/workflows/phpstan.yml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: PHPStan
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
phpstan:
15+
name: PHPStan Analysis
16+
runs-on: ubuntu-latest
17+
18+
services:
19+
mariadb:
20+
image: mariadb:11.4
21+
env:
22+
MYSQL_ROOT_PASSWORD: magento
23+
MYSQL_DATABASE: magento
24+
ports:
25+
- 3306:3306
26+
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
27+
28+
opensearch:
29+
image: opensearchproject/opensearch:3
30+
ports:
31+
- 9200:9200
32+
env:
33+
discovery.type: single-node
34+
DISABLE_SECURITY_PLUGIN: true
35+
OPENSEARCH_JAVA_OPTS: -Xms512m -Xmx512m
36+
options: --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=10
37+
38+
steps:
39+
- name: Checkout code
40+
uses: actions/checkout@v4
41+
with:
42+
path: mageforge
43+
44+
- name: Setup PHP
45+
uses: shivammathur/setup-php@v2
46+
with:
47+
php-version: "8.4"
48+
extensions: mbstring, intl, gd, xml, soap, zip, bcmath, pdo_mysql, curl, sockets
49+
tools: composer:v2
50+
51+
- name: Cache Composer packages
52+
id: composer-cache
53+
uses: actions/cache@v4
54+
with:
55+
path: ~/.composer/cache/files
56+
key: ${{ runner.os }}-composer-2.4.8-${{ hashFiles('**/composer.json') }}
57+
restore-keys: ${{ runner.os }}-composer-2.4.8
58+
59+
- name: Clone Magento
60+
run: |
61+
git clone --depth=1 --branch=2.4.8 https://github.com/magento/magento2.git magento2
62+
63+
- name: Install Magento
64+
working-directory: magento2
65+
env:
66+
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
67+
run: |
68+
composer config minimum-stability stable
69+
composer config prefer-stable true
70+
composer install --no-interaction --no-progress
71+
bin/magento setup:install \
72+
--base-url=http://localhost \
73+
--db-host=127.0.0.1 \
74+
--db-name=magento \
75+
--db-user=root \
76+
--db-password=magento \
77+
--admin-firstname=Admin \
78+
--admin-lastname=User \
79+
--admin-email=admin@example.com \
80+
--admin-user=admin \
81+
--admin-password=admin12345 \
82+
--language=en_US \
83+
--currency=USD \
84+
--timezone=Europe/Berlin \
85+
--use-rewrites=1 \
86+
--backend-frontname=admin \
87+
--search-engine=opensearch \
88+
--opensearch-host=localhost \
89+
--opensearch-port=9200 \
90+
--opensearch-index-prefix=magento \
91+
--cleanup-database
92+
93+
- name: Install MageForge Module and PHPStan
94+
working-directory: magento2
95+
run: |
96+
# Add local repository
97+
composer config repositories.mageforge-local path ../mageforge
98+
99+
# Install module
100+
composer require --no-update openforgeproject/mageforge:@dev
101+
102+
# Allow PHPStan extension installer
103+
composer config --no-plugins allow-plugins.phpstan/extension-installer true
104+
105+
# Install PHPStan and Magento extension
106+
composer require --dev --no-update bitexpert/phpstan-magento "phpstan/phpstan:^2.0" phpstan/extension-installer
107+
108+
# Update
109+
composer update --with-dependencies
110+
111+
# Enable module
112+
bin/magento module:enable OpenForgeProject_MageForge
113+
bin/magento setup:upgrade
114+
115+
- name: Run PHPStan
116+
working-directory: magento2
117+
continue-on-error: true
118+
run: |
119+
vendor/bin/phpstan analyse -c vendor/openforgeproject/mageforge/phpstan.neon vendor/openforgeproject/mageforge/src

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 6
3+
paths:
4+
- src

0 commit comments

Comments
 (0)