Skip to content

Commit e974f92

Browse files
authored
SEC25-123: Add Psalm PHP static analysis and CI/CD integration (#29)
Add Psalm PHP static analysis and CI/CD integration Adds Psalm PHP static analysis with SARIF upload to GitHub Code Scanning.
1 parent 91a31c6 commit e974f92

4 files changed

Lines changed: 2744 additions & 951 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
schedule:
9+
- cron: '30 12 * * 1'
10+
11+
jobs:
12+
analyze:
13+
strategy:
14+
matrix:
15+
php-versions: [ '8.0', '8.1', '8.2', '8.3' ]
16+
name: Analyze PHP ${{ matrix.php-versions }}
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 10
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
name: Check Out Code
23+
24+
- name: Setup PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php-versions }}
28+
tools: pecl
29+
extensions: pdo
30+
31+
- name: Validate composer.json and composer.lock
32+
run: composer validate
33+
34+
- name: Setup Composer Access
35+
run: composer config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Cache Composer packages
38+
id: composer-cache
39+
uses: actions/cache@v4
40+
with:
41+
path: vendor
42+
key: ${{ runner.os }}-composer-${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}
43+
restore-keys: |
44+
${{ runner.os }}-composer-${{ matrix.php-versions }}-
45+
${{ runner.os }}-composer-
46+
47+
- name: Install dependencies
48+
if: steps.composer-cache.outputs.cache-hit != 'true'
49+
run: composer install --prefer-dist --no-progress --optimize-autoloader
50+
51+
- name: Perform CodeQL Analysis using Psalm
52+
run: |
53+
if [ "${{ github.event_name }}" == "pull_request" ]; then
54+
vendor/bin/psalm --diff --output-format=sarif --report=psalm-report.sarif || true
55+
else
56+
vendor/bin/psalm --no-diff --output-format=sarif --report=psalm-report.sarif || true
57+
fi
58+
continue-on-error: true
59+
60+
- name: Upload SARIF report
61+
uses: github/codeql-action/upload-sarif@v3
62+
with:
63+
sarif_file: psalm-report.sarif

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@
77
"php": ">=8.0",
88
"ext-pdo": "*"
99
},
10+
"config": {
11+
"platform": {
12+
"php": "8.0"
13+
}
14+
},
1015
"require-dev": {
1116
"phpunit/phpunit": "^9.4",
1217
"symfony/yaml": "^5.0",
1318
"phpspec/prophecy": "^1.22.0",
1419
"doctrine/instantiator": "^1.5",
15-
"symfony/deprecation-contracts": "^2.4"
20+
"symfony/deprecation-contracts": "^2.4",
21+
"vimeo/psalm": "^5.26"
1622
},
1723
"scripts":{
18-
"test": "./vendor/bin/phpunit -c phpunit.xml"
24+
"test": "./vendor/bin/phpunit -c phpunit.xml",
25+
"psalm": "vendor/bin/psalm"
1926
},
2027
"autoload": {
2128
"psr-4": {

0 commit comments

Comments
 (0)