Skip to content

Commit 83a747a

Browse files
LordSimalADmad
andauthored
introduce phpstan (#866)
Introduce phpstan Co-authored-by: ADmad <[email protected]>
1 parent 8dbc15a commit 83a747a

File tree

15 files changed

+84
-42
lines changed

15 files changed

+84
-42
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ indent_style = space
1010
indent_size = 4
1111
insert_final_newline = true
1212
trim_trailing_whitespace = true
13+
14+
[*.neon]
15+
indent_style = tab

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,14 @@ jobs:
112112
tools: cs2pr
113113

114114
- name: Composer Install
115-
run: composer psalm-setup
115+
run: composer stan-setup
116116

117117
- name: Run phpcs
118118
run: vendor/bin/phpcs --report=checkstyle src/ tests/ | cs2pr
119119

120120
- name: Run psalm
121-
if: always()
122121
run: vendor/bin/psalm.phar --output-format=github
122+
123+
- name: Run phpstan
124+
if: always()
125+
run: vendor/bin/phpstan.phar analyse --error-format=github

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,16 @@
5454
"scripts": {
5555
"cs-check": "phpcs --colors --parallel=16 -p src/ tests/",
5656
"cs-fix": "phpcbf --colors --parallel=16 -p src/ tests/",
57-
"test": "phpunit",
57+
"phpstan": "phpstan.phar analyse",
5858
"psalm": "psalm.phar --show-info=false",
59-
"psalm-setup": "cp composer.json composer.backup && composer require --dev psalm/phar:^4.22 && mv composer.backup composer.json"
59+
"stan": [
60+
"@phpstan",
61+
"@psalm"
62+
],
63+
"stan-baseline": "phpstan.phar --generate-baseline",
64+
"psalm-baseline": "psalm.phar --set-baseline=psalm-baseline.xml",
65+
"stan-setup": "cp composer.json composer.backup && composer require --dev symfony/polyfill-php81 phpstan/phpstan:~1.7.0 psalm/phar:~4.23.0 && mv composer.backup composer.json",
66+
"test": "phpunit"
6067
},
6168
"prefer-stable": true,
6269
"config": {

phpstan-baseline.neon

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^PHPDoc type array\\<string, mixed\\>\\|Cake\\\\Cache\\\\CacheEngine of property DebugKit\\\\Cache\\\\Engine\\\\DebugEngine\\:\\:\\$_config is not covariant with PHPDoc type array\\<string, mixed\\> of overridden property Cake\\\\Cache\\\\CacheEngine\\:\\:\\$_config\\.$#"
5+
count: 1
6+
path: src/Cache/Engine/DebugEngine.php
7+
8+
-
9+
message: "#^Property DebugKit\\\\Cache\\\\Engine\\\\DebugEngine\\:\\:\\$_engine \\(Cake\\\\Cache\\\\CacheEngine\\) in isset\\(\\) is not nullable\\.$#"
10+
count: 1
11+
path: src/Cache/Engine/DebugEngine.php
12+
13+
-
14+
message: "#^Unreachable statement \\- code above always terminates\\.$#"
15+
count: 1
16+
path: src/Cache/Engine/DebugEngine.php
17+
18+
-
19+
message: "#^Call to function file_get_contents\\(\\) on a separate line has no effect\\.$#"
20+
count: 1
21+
path: src/Command/BenchmarkCommand.php
22+
23+
-
24+
message: "#^Method DebugKit\\\\Mailer\\\\Transport\\\\DebugKitTransport\\:\\:send\\(\\) should return array\\{headers\\: string, message\\: string\\} but returns array\\{headers\\: non\\-empty\\-array\\<string\\>, message\\: array\\{text\\: string, html\\: string\\}\\}\\.$#"
25+
count: 1
26+
path: src/Mailer/Transport/DebugKitTransport.php
27+
28+
-
29+
message: "#^Parameter \\#1 \\$request of method DebugKit\\\\ToolbarService\\:\\:saveData\\(\\) expects Cake\\\\Http\\\\ServerRequest, Psr\\\\Http\\\\Message\\\\ServerRequestInterface given\\.$#"
30+
count: 1
31+
path: src/Middleware/DebugKitMiddleware.php
32+
33+
-
34+
message: "#^Call to an undefined method Cake\\\\ORM\\\\Locator\\\\LocatorInterface\\:\\:genericInstances\\(\\)\\.$#"
35+
count: 1
36+
path: src/Panel/SqlLogPanel.php

phpstan.neon

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
4+
parameters:
5+
level: 6
6+
checkMissingIterableValueType: false
7+
checkGenericClassInNonGenericObjectType: false
8+
treatPhpDocTypesAsCertain: false
9+
bootstrapFiles:
10+
- tests/bootstrap.php
11+
- vendor/cakephp/cakephp/src/Core/Exception/CakeException.php
12+
paths:
13+
- src/

psalm-baseline.xml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@
4545
<code>new $className($config)</code>
4646
</PropertyTypeCoercion>
4747
</file>
48-
<file src="src/Middleware/DebugKitMiddleware.php">
49-
<ArgumentTypeCoercion occurrences="1">
50-
<code>$request</code>
51-
</ArgumentTypeCoercion>
52-
</file>
5348
<file src="src/Panel/DeprecationsPanel.php">
5449
<InvalidScalarArgument occurrences="4">
5550
<code>$pluginName</code>
@@ -66,11 +61,6 @@
6661
<code>$vendorName</code>
6762
</InvalidScalarArgument>
6863
</file>
69-
<file src="src/Panel/LogPanel.php">
70-
<UndefinedInterfaceMethod occurrences="1">
71-
<code>count</code>
72-
</UndefinedInterfaceMethod>
73-
</file>
7464
<file src="src/Panel/PanelRegistry.php">
7565
<LessSpecificImplementedReturnType occurrences="1">
7666
<code>string|null</code>
@@ -83,16 +73,10 @@
8373
</UnsafeInstantiation>
8474
</file>
8575
<file src="src/Panel/SqlLogPanel.php">
86-
<TypeDoesNotContainType occurrences="1">
87-
<code>!$connection instanceof ConnectionInterface</code>
88-
</TypeDoesNotContainType>
8976
<UndefinedInterfaceMethod occurrences="1">
9077
<code>genericInstances</code>
9178
</UndefinedInterfaceMethod>
9279
</file>
93-
<file src="src/Plugin.php">
94-
<InvalidArgument occurrences="1"/>
95-
</file>
9680
<file src="src/View/Helper/ToolbarHelper.php">
9781
<DeprecatedMethod occurrences="1">
9882
<code>makeNeatArray</code>

psalm.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<psalm
3-
resolveFromConfigFile="true"
3+
reportMixedIssues="false"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xmlns="https://getpsalm.org/schema/config"
66
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
@@ -16,11 +16,16 @@
1616
</projectFiles>
1717

1818
<issueHandlers>
19+
<LessSpecificReturnType errorLevel="info" />
20+
1921
<MissingClosureReturnType errorLevel="info" />
2022

2123
<PropertyNotSetInConstructor errorLevel="info" />
2224
<MissingConstructor errorLevel="info" />
2325
<MissingClosureParamType errorLevel="info" />
2426
<MissingParamType errorLevel="info" />
27+
28+
<DocblockTypeContradiction errorLevel="info" />
29+
<RedundantConditionGivenDocblockType errorLevel="info" />
2530
</issueHandlers>
2631
</psalm>

src/Controller/DashboardController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function index()
6262
public function reset()
6363
{
6464
$this->request->allowMethod('post');
65+
/** @var \DebugKit\Model\Table\RequestsTable $requestsModel */
6566
$requestsModel = $this->fetchTable('DebugKit.Requests');
6667

6768
$requestsModel->Panels->deleteAll('1=1');

src/Controller/MailPreviewController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function sent($panelId, $number)
9999
*
100100
* @param string $name The Mailer name
101101
* @param string $method The mailer preview method
102-
* @return \Psr\Http\Message\ResponseInterface|null
102+
* @return \Psr\Http\Message\ResponseInterface|void
103103
*/
104104
public function email($name, $method)
105105
{
@@ -158,9 +158,8 @@ protected function respondWithPart($email, $partType)
158158
if ($partType === 'text') {
159159
$part = '<pre>' . $part . '</pre>';
160160
}
161-
$response = $response->withStringBody($part);
162161

163-
return $response;
162+
return $response->withStringBody($part);
164163
}
165164

166165
/**

src/DebugSql.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static function sql(Query $query, $showValues = true, $showHtml = null, $
7373

7474
$sql = (string)$query;
7575
if ($showValues) {
76-
$sql = static::interpolate($sql, $query->getValueBinder()->bindings());
76+
$sql = self::interpolate($sql, $query->getValueBinder()->bindings());
7777
}
7878

7979
/** @var array $trace */
@@ -92,16 +92,16 @@ public static function sql(Query $query, $showValues = true, $showHtml = null, $
9292
$file = str_replace($search, '', $file);
9393
}
9494

95-
$template = static::$templateHtml;
95+
$template = self::$templateHtml;
9696
$sqlHighlight = true;
9797
if ((PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') || $showHtml === false) {
98-
$template = static::$templateText;
98+
$template = self::$templateText;
9999
$sqlHighlight = false;
100100
if ($file && $line) {
101101
$lineInfo = sprintf('%s (line %s)', $file, $line);
102102
}
103103
}
104-
if ($showHtml === null && $template !== static::$templateText) {
104+
if ($showHtml === null && $template !== self::$templateText) {
105105
$showHtml = true;
106106
}
107107

@@ -113,7 +113,7 @@ public static function sql(Query $query, $showValues = true, $showHtml = null, $
113113
);
114114

115115
if ($showHtml) {
116-
$template = static::$templateHtml;
116+
$template = self::$templateHtml;
117117
if ($file && $line) {
118118
$lineInfo = sprintf('<span><strong>%s</strong> (line <strong>%s</strong>)</span>', $file, $line);
119119
}

0 commit comments

Comments
 (0)