Skip to content

Commit 85e2bed

Browse files
committed
Issue dotkernel#45: Replace Psalm with PHPStan
Signed-off-by: horea <[email protected]>
1 parent d760b5e commit 85e2bed

File tree

9 files changed

+98
-55
lines changed

9 files changed

+98
-55
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
on:
2+
- push
3+
4+
name: Run PHPStan checks
5+
6+
jobs:
7+
mutation:
8+
name: PHPStan ${{ matrix.php }}-${{ matrix.os }}
9+
10+
runs-on: ${{ matrix.os }}
11+
12+
strategy:
13+
matrix:
14+
os:
15+
- ubuntu-latest
16+
17+
php:
18+
- "8.2"
19+
- "8.3"
20+
- "8.4"
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Install PHP
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: "${{ matrix.php }}"
30+
coverage: pcov
31+
ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On
32+
tools: composer:v2, cs2pr
33+
34+
- name: Determine composer cache directory
35+
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
36+
37+
- name: Cache dependencies installed with composer
38+
uses: actions/cache@v4
39+
with:
40+
path: ${{ env.COMPOSER_CACHE_DIR }}
41+
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
42+
restore-keys: |
43+
php${{ matrix.php }}-composer-
44+
45+
- name: Install dependencies with composer
46+
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
47+
48+
- name: Run static analysis with PHPStan
49+
run: vendor/bin/phpstan analyse

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
> [!IMPORTANT]
44
> dot-cli is a wrapper on top of [laminas-cli](https://github.com/laminas/laminas-cli)
55
6+
Dotkernel component to build console applications based on [laminas-cli](https://github.com/laminas/laminas-cli).
7+
8+
## Badges
9+
610
![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-cli)
7-
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-cli/3.8.1)
11+
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-cli/3.9.0)
812

913
[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-cli)](https://github.com/dotkernel/dot-cli/issues)
1014
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-cli)](https://github.com/dotkernel/dot-cli/network)
@@ -13,8 +17,7 @@
1317

1418
[![Build Static](https://github.com/dotkernel/dot-cli/actions/workflows/continuous-integration.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-cli/actions/workflows/continuous-integration.yml)
1519
[![codecov](https://codecov.io/gh/dotkernel/dot-cli/graph/badge.svg?token=0DFCK2GUBT)](https://codecov.io/gh/dotkernel/dot-cli)
16-
17-
Dotkernel component to build console applications based on [laminas-cli](https://github.com/laminas/laminas-cli).
20+
[![PHPStan](https://github.com/dotkernel/dot-cli/actions/workflows/static-analysis.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-cli/actions/workflows/static-analysis.yml)
1821

1922
## Requirements
2023

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
"require-dev": {
3636
"laminas/laminas-coding-standard": "^3.0",
3737
"mikey179/vfsstream": "^1.6.7",
38-
"phpunit/phpunit": "^10.2",
39-
"vimeo/psalm": "^6.0"
38+
"phpstan/phpstan": "^2.1",
39+
"phpstan/phpstan-phpunit": "^2.0",
40+
"phpunit/phpunit": "^10.2"
4041
},
4142
"autoload-dev": {
4243
"psr-4": {
@@ -52,7 +53,6 @@
5253
"cs-check": "phpcs",
5354
"cs-fix": "phpcbf",
5455
"test": "phpunit --colors=always",
55-
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
56-
"static-analysis": "psalm --shepherd --stats"
56+
"static-analysis": "phpstan analyse --memory-limit 1G"
5757
}
5858
}

docs/book/v3/overview.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
# Overview
22

33
> dot-cli is a wrapper on top of [laminas-cli](https://github.com/laminas/laminas-cli)
4+
5+
## Badges
6+
7+
![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-cli)
8+
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-cli/3.9.0)
9+
10+
[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-cli)](https://github.com/dotkernel/dot-cli/issues)
11+
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-cli)](https://github.com/dotkernel/dot-cli/network)
12+
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-cli)](https://github.com/dotkernel/dot-cli/stargazers)
13+
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-cli)](https://github.com/dotkernel/dot-cli/blob/3.0/LICENSE)
14+
15+
[![Build Static](https://github.com/dotkernel/dot-cli/actions/workflows/continuous-integration.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-cli/actions/workflows/continuous-integration.yml)
16+
[![codecov](https://codecov.io/gh/dotkernel/dot-cli/graph/badge.svg?token=0DFCK2GUBT)](https://codecov.io/gh/dotkernel/dot-cli)
17+
[![PHPStan](https://github.com/dotkernel/dot-cli/actions/workflows/static-analysis.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-cli/actions/workflows/static-analysis.yml)

phpstan.neon

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
includes:
2+
- vendor/phpstan/phpstan-phpunit/extension.neon
3+
parameters:
4+
level: 5
5+
paths:
6+
- src
7+
- test
8+
treatPhpDocTypesAsCertain: false

psalm-baseline.xml

Lines changed: 0 additions & 13 deletions
This file was deleted.

psalm.xml

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/Command/DemoCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DemoCommandTest extends TestCase
2020
public function testWillCreateCommand(): void
2121
{
2222
$command = new DemoCommand();
23-
$this->assertInstanceOf(DemoCommand::class, $command);
23+
$this->assertContainsOnlyInstancesOf(DemoCommand::class, [$command]);
2424
}
2525

2626
/**

test/FileLockerTest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,28 @@ public function testAccessors(): void
3232
$fileLocker = new FileLocker();
3333
$this->assertFalse($fileLocker->isEnabled());
3434
$fileLocker->enable();
35-
$this->assertInstanceOf(FileLocker::class, $fileLocker);
35+
$this->assertContainsOnlyInstancesOf(FileLocker::class, [$fileLocker]);
3636
$this->assertTrue($fileLocker->isEnabled());
3737
$fileLocker->disable();
38-
$this->assertInstanceOf(FileLocker::class, $fileLocker);
38+
$this->assertContainsOnlyInstancesOf(FileLocker::class, [$fileLocker]);
3939
$this->assertFalse($fileLocker->isEnabled());
4040
$fileLocker->setEnabled(true);
41-
$this->assertInstanceOf(FileLocker::class, $fileLocker);
41+
$this->assertContainsOnlyInstancesOf(FileLocker::class, [$fileLocker]);
4242
$this->assertTrue($fileLocker->isEnabled());
4343
$fileLocker->setEnabled(false);
44-
$this->assertInstanceOf(FileLocker::class, $fileLocker);
44+
$this->assertContainsOnlyInstancesOf(FileLocker::class, [$fileLocker]);
4545
$this->assertFalse($fileLocker->isEnabled());
4646
$this->assertNull($fileLocker->getDirPath());
4747
$fileLocker->setDirPath('test');
48-
$this->assertInstanceOf(FileLocker::class, $fileLocker);
48+
$this->assertContainsOnlyInstancesOf(FileLocker::class, [$fileLocker]);
4949
$this->assertSame('test', $fileLocker->getDirPath());
5050
$this->assertNull($fileLocker->getCommandName());
5151
$fileLocker->setCommandName('test');
52-
$this->assertInstanceOf(FileLocker::class, $fileLocker);
52+
$this->assertContainsOnlyInstancesOf(FileLocker::class, [$fileLocker]);
5353
$this->assertSame('test', $fileLocker->getCommandName());
5454
$this->assertNull($fileLocker->getLockFile());
5555
$fileLocker->setLockFile('test');
56-
$this->assertInstanceOf(FileLocker::class, $fileLocker);
56+
$this->assertContainsOnlyInstancesOf(FileLocker::class, [$fileLocker]);
5757
$this->assertSame('test', $fileLocker->getLockFile());
5858
$this->assertSame('test/command-test.lock', $fileLocker->getLockFilePath());
5959
}
@@ -65,7 +65,7 @@ public function testWillInitLockFile(): void
6565
$fileLocker = new FileLocker(true, $config['dirPath'], 'test');
6666
$this->assertNull($fileLocker->getLockFile());
6767
$fileLocker->initLockFile();
68-
$this->assertInstanceOf(FileLocker::class, $fileLocker);
68+
$this->assertContainsOnlyInstancesOf(FileLocker::class, [$fileLocker]);
6969
$this->assertIsResource($fileLocker->getLockFile());
7070
}
7171

@@ -79,7 +79,7 @@ public function testWillNotLockWhenDisabled(): void
7979
$fileLocker = new FileLocker(false, $config['dirPath'], 'test');
8080
$this->assertNull($fileLocker->getLockFile());
8181
$fileLocker->lock();
82-
$this->assertInstanceOf(FileLocker::class, $fileLocker);
82+
$this->assertContainsOnlyInstancesOf(FileLocker::class, [$fileLocker]);
8383
$this->assertNull($fileLocker->getLockFile());
8484
}
8585

@@ -93,7 +93,7 @@ public function testWillNotLockWithoutValidCommandName(): void
9393
$fileLocker = new FileLocker(true, $config['dirPath']);
9494
$this->assertNull($fileLocker->getLockFile());
9595
$fileLocker->lock();
96-
$this->assertInstanceOf(FileLocker::class, $fileLocker);
96+
$this->assertContainsOnlyInstancesOf(FileLocker::class, [$fileLocker]);
9797
$this->assertNull($fileLocker->getLockFile());
9898
}
9999

@@ -107,7 +107,7 @@ public function testWillLockWhenLockedAndEnabledAndHasValidCommandName(): void
107107
$fileLocker = new FileLocker(true, $config['dirPath'], 'test');
108108
$this->assertNull($fileLocker->getLockFile());
109109
$fileLocker->lock();
110-
$this->assertInstanceOf(FileLocker::class, $fileLocker);
110+
$this->assertContainsOnlyInstancesOf(FileLocker::class, [$fileLocker]);
111111
$this->assertIsResource($fileLocker->getLockFile());
112112
$this->assertFileExists($fileLocker->getLockFilePath());
113113
}
@@ -119,7 +119,7 @@ public function testWillNotUnlockWhenDisabled(): void
119119
$fileLocker = new FileLocker(false, $config['dirPath'], 'test');
120120
$this->assertNull($fileLocker->getLockFile());
121121
$fileLocker->unlock();
122-
$this->assertInstanceOf(FileLocker::class, $fileLocker);
122+
$this->assertContainsOnlyInstancesOf(FileLocker::class, [$fileLocker]);
123123
$this->assertNull($fileLocker->getLockFile());
124124
}
125125

@@ -130,7 +130,7 @@ public function testWillNotUnlockWithoutValidCommandName(): void
130130
$fileLocker = new FileLocker(false, $config['dirPath']);
131131
$this->assertNull($fileLocker->getLockFile());
132132
$fileLocker->unlock();
133-
$this->assertInstanceOf(FileLocker::class, $fileLocker);
133+
$this->assertContainsOnlyInstancesOf(FileLocker::class, [$fileLocker]);
134134
$this->assertNull($fileLocker->getLockFile());
135135
}
136136

@@ -141,7 +141,7 @@ public function testWillNotUnlockWhenEnabledAndWithoutValidCommandName(): void
141141
$fileLocker = new FileLocker(true, $config['dirPath']);
142142
$this->assertNull($fileLocker->getLockFile());
143143
$fileLocker->unlock();
144-
$this->assertInstanceOf(FileLocker::class, $fileLocker);
144+
$this->assertContainsOnlyInstancesOf(FileLocker::class, [$fileLocker]);
145145
$this->assertNull($fileLocker->getLockFile());
146146
}
147147

@@ -154,11 +154,11 @@ public function testWillUnlockWhenLockedAndEnabledAndHasValidCommandName(): void
154154

155155
$fileLocker = new FileLocker(true, $config['dirPath'], 'test');
156156
$fileLocker->lock();
157-
$this->assertInstanceOf(FileLocker::class, $fileLocker);
157+
$this->assertContainsOnlyInstancesOf(FileLocker::class, [$fileLocker]);
158158
$this->assertIsResource($fileLocker->getLockFile());
159159
$this->assertFileExists($fileLocker->getLockFilePath());
160160
$fileLocker->unlock();
161-
$this->assertInstanceOf(FileLocker::class, $fileLocker);
161+
$this->assertContainsOnlyInstancesOf(FileLocker::class, [$fileLocker]);
162162
$this->assertFileIsReadable($fileLocker->getLockFilePath());
163163
$this->assertFileIsWritable($fileLocker->getLockFilePath());
164164
}

0 commit comments

Comments
 (0)