Skip to content

Commit e86c61e

Browse files
committed
Add Psalm
1 parent f92ec92 commit e86c61e

File tree

6 files changed

+119
-2
lines changed

6 files changed

+119
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Development toolkit for CodeIgniter libraries and projects
1616

1717
* [NexusPHP Tachycardia](https://github.com/NexusPHP/tachycardia)
1818
* [PHPStan](https://phpstan.org/user-guide/getting-started)
19-
* [PHPUnit](http://phpunit.readthedocs.io)
19+
* [PHPUnit](https://phpunit.readthedocs.io)
20+
* [Psalm](https://psalm.dev)
2021

2122
### Mocking
2223

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"phpstan/phpstan-deprecation-rules": "^1.0",
3333
"phpstan/phpstan-phpunit": "^1.0",
3434
"phpunit/phpunit": "^9.3",
35-
"roave/security-advisories": "dev-latest"
35+
"roave/security-advisories": "dev-latest",
36+
"vimeo/psalm": "^4.22"
3637
},
3738
"minimum-stability": "dev",
3839
"prefer-stable": true,

psalm.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="7"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
autoloader="psalm_autoload.php"
9+
cacheDirectory="build/psalm/"
10+
>
11+
<projectFiles>
12+
<directory name="app/" />
13+
<directory name="tests/" />
14+
<ignoreFiles>
15+
<directory name="vendor" />
16+
<directory name="app/Views" />
17+
</ignoreFiles>
18+
</projectFiles>
19+
</psalm>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Psalm
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
paths:
8+
- '**.php'
9+
- 'composer.*'
10+
- 'psalm*'
11+
- '.github/workflows/psalm.yml'
12+
push:
13+
branches:
14+
- develop
15+
paths:
16+
- '**.php'
17+
- 'composer.*'
18+
- 'psalm*'
19+
- '.github/workflows/psalm.yml'
20+
21+
jobs:
22+
build:
23+
name: PHP ${{ matrix.php-versions }} Psalm Analysis
24+
runs-on: ubuntu-latest
25+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
php-versions: ['7.4', '8.0', '8.1']
30+
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v3
34+
35+
- name: Setup PHP
36+
uses: shivammathur/setup-php@v2
37+
with:
38+
php-version: ${{ matrix.php-versions }}
39+
tools: phpstan, phpunit
40+
extensions: intl, json, mbstring, xml
41+
coverage: none
42+
env:
43+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Get composer cache directory
46+
id: composer-cache
47+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
48+
49+
- name: Cache composer dependencies
50+
uses: actions/cache@v3
51+
with:
52+
path: ${{ steps.composer-cache.outputs.dir }}
53+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
54+
restore-keys: ${{ runner.os }}-composer-
55+
56+
- name: Create Psalm cache directory
57+
run: mkdir -p build/psalm
58+
59+
- name: Cache Psalm results
60+
uses: actions/cache@v3
61+
with:
62+
path: build/psalm
63+
key: ${{ runner.os }}-psalm-${{ github.sha }}
64+
restore-keys: ${{ runner.os }}-psalm-
65+
66+
- name: Install dependencies
67+
run: |
68+
if [ -f composer.lock ]; then
69+
composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
70+
else
71+
composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
72+
fi
73+
74+
- name: Run Psalm analysis
75+
run: vendor/bin/psalm

src/Template/psalm.xml

Whitespace-only changes.

src/Template/psalm_autoload.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
require __DIR__ . '/vendor/codeigniter4/framework/system/Test/bootstrap.php';
6+
7+
$helperDirs = [
8+
'app/Helpers',
9+
'vendor/codeigniter4/framework/system/Helpers',
10+
];
11+
12+
foreach ($helperDirs as $dir) {
13+
$dir = __DIR__ . '/' . $dir;
14+
chdir($dir);
15+
16+
foreach (glob('*_helper.php') as $filename) {
17+
$filePath = realpath($dir . '/' . $filename);
18+
19+
require_once $filePath;
20+
}
21+
}

0 commit comments

Comments
 (0)