Skip to content

Commit 3ff30e8

Browse files
authored
Merge pull request #27 from codeigniter4/psalm
Psalm
2 parents f92ec92 + a1747c7 commit 3ff30e8

File tree

6 files changed

+115
-2
lines changed

6 files changed

+115
-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: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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: Psalm Analysis
24+
runs-on: ubuntu-latest
25+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v3
30+
31+
- name: Setup PHP
32+
uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: '8.0'
35+
tools: phpstan, phpunit
36+
extensions: intl, json, mbstring, xml
37+
coverage: none
38+
env:
39+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Get composer cache directory
42+
id: composer-cache
43+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
44+
45+
- name: Cache composer dependencies
46+
uses: actions/cache@v3
47+
with:
48+
path: ${{ steps.composer-cache.outputs.dir }}
49+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
50+
restore-keys: ${{ runner.os }}-composer-
51+
52+
- name: Create Psalm cache directory
53+
run: mkdir -p build/psalm
54+
55+
- name: Cache Psalm results
56+
uses: actions/cache@v3
57+
with:
58+
path: build/psalm
59+
key: ${{ runner.os }}-psalm-${{ github.sha }}
60+
restore-keys: ${{ runner.os }}-psalm-
61+
62+
- name: Install dependencies
63+
run: |
64+
if [ -f composer.lock ]; then
65+
composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
66+
else
67+
composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
68+
fi
69+
70+
- name: Run Psalm analysis
71+
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)