Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade phpstan/psalm #325

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:
with:
home: ${{ runner.temp }}/.phive
binPath: ${{ github.workspace }}/tools/phive
trustGpgKeys: "CF1A108D0E7AE720,12CE0F1D262429A5"
trustGpgKeys: "CF1A108D0E7AE720,12CE0F1D262429A5,51C67305FFC2E5C0"

- name: Run PHP CodeSniffer
run: vendor/bin/phpcs --report=checkstyle src/ tests/ | cs2pr
Expand Down
4 changes: 2 additions & 2 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="1.9.12" installed="1.9.12" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.4.0" installed="5.4.0" location="./tools/psalm" copy="false"/>
<phar name="phpstan" version="2.0.1" installed="2.0.1" location="./tools/phpstan" copy="true"/>
<phar name="psalm" version="5.26.1" installed="5.26.1" location="./tools/psalm" copy="true"/>
</phive>
3 changes: 0 additions & 3 deletions .stickler.yml

This file was deleted.

21 changes: 18 additions & 3 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
parameters:
ignoreErrors:
-
message: "#^Access to an undefined property Cake\\\\Datasource\\\\EntityInterface\\:\\:\\$version\\.$#"
message: '#^Strict comparison using \!\=\= between string and array\{\} will always evaluate to true\.$#'
identifier: notIdentical.alwaysTrue
count: 1
path: src/Document.php

-
message: '#^Access to an undefined property Cake\\Datasource\\EntityInterface\:\:\$version\.$#'
identifier: property.notFound
count: 1
path: src/Index.php

-
message: "#^Method Cake\\\\ElasticSearch\\\\Query\\:\\:find\\(\\) should return static\\(Cake\\\\ElasticSearch\\\\Query\\<TSubject of array\\|Cake\\\\ElasticSearch\\\\Document\\>\\) but returns Cake\\\\ElasticSearch\\\\Query\\<Cake\\\\ElasticSearch\\\\Document\\>\\.$#"
message: '#^Method Cake\\ElasticSearch\\Query\:\:find\(\) should return static\(Cake\\ElasticSearch\\Query\<TSubject of array\|Cake\\ElasticSearch\\Document\>\) but returns Cake\\ElasticSearch\\Query\<Cake\\ElasticSearch\\Document\>\.$#'
identifier: return.type
count: 1
path: src/Query.php

-
message: "#^PHPDoc tag @return with type Cake\\\\ElasticSearch\\\\Query\\<TSubject of array\\|Cake\\\\ElasticSearch\\\\Document\\> is not subtype of native type static\\(Cake\\\\ElasticSearch\\\\Query\\<TSubject of array\\|Cake\\\\ElasticSearch\\\\Document\\>\\)\\.$#"
message: '#^PHPDoc tag @return with type Cake\\ElasticSearch\\Query\<TSubject of array\|Cake\\ElasticSearch\\Document\> is not subtype of native type static\(Cake\\ElasticSearch\\Query\<TSubject of array\|Cake\\ElasticSearch\\Document\>\)\.$#'
identifier: return.phpDocType
count: 1
path: src/Query.php

-
message: '#^Strict comparison using \!\=\= between mixed and null will always evaluate to true\.$#'
identifier: notIdentical.alwaysTrue
count: 1
path: src/QueryBuilder.php
18 changes: 9 additions & 9 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ includes:
- phpstan-baseline.neon

parameters:
level: 6
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
treatPhpDocTypesAsCertain: false
bootstrapFiles:
- tests/bootstrap.php
- vendor/cakephp/cakephp/src/Core/Exception/CakeException.php
paths:
- src/
level: 6
paths:
- src/
bootstrapFiles:
- tests/bootstrap.php
ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.generics

47 changes: 22 additions & 25 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="dev-master@">
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<file src="src/Datasource/Connection.php">
<InvalidReturnStatement occurrences="1">
<code>$this-&gt;_client-&gt;getConfig()</code>
<InvalidReturnStatement>
<code><![CDATA[$this->_client->getConfig()]]></code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="1">
<code>array</code>
<InvalidReturnType>
<code><![CDATA[array]]></code>
</InvalidReturnType>
<LessSpecificImplementedReturnType occurrences="1">
<code>array</code>
<LessSpecificImplementedReturnType>
<code><![CDATA[array]]></code>
</LessSpecificImplementedReturnType>
</file>
<file src="src/Index.php">
<NoInterfaceProperties occurrences="5">
<code>$entity-&gt;version</code>
<code>$entity-&gt;id</code>
<code>$entity-&gt;id</code>
<code>$entity-&gt;id</code>
<code>$entity-&gt;id</code>
<NoInterfaceProperties>
<code><![CDATA[$entity->id]]></code>
<code><![CDATA[$entity->id]]></code>
<code><![CDATA[$entity->id]]></code>
<code><![CDATA[$entity->id]]></code>
<code><![CDATA[$entity->version]]></code>
</NoInterfaceProperties>
</file>
<file src="src/Marshaller.php">
<InvalidDocblock occurrences="1">
<code>public function one(array $data, array $options = []): Document</code>
</InvalidDocblock>
<NoInterfaceProperties occurrences="1">
<code>$record-&gt;id</code>
<NoInterfaceProperties>
<code><![CDATA[$record->id]]></code>
</NoInterfaceProperties>
</file>
<file src="src/Query.php">
<InvalidArgument occurrences="3">
<code>$query</code>
<code>$query</code>
<code>false</code>
</InvalidArgument>
<LessSpecificImplementedReturnType occurrences="1">
<code>\Traversable</code>
<LessSpecificImplementedReturnType>
<code><![CDATA[\Traversable]]></code>
</LessSpecificImplementedReturnType>
</file>
<file src="src/View/Form/DocumentContext.php">
<InvalidReturnStatement>
<code><![CDATA[$entity]]></code>
</InvalidReturnStatement>
</file>
</files>
5 changes: 4 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
autoloader="tests/bootstrap.php"
usePhpDocMethodsWithoutMagicCall="true"
errorBaseline="psalm-baseline.xml"
errorBaseline="./psalm-baseline.xml"
findUnusedPsalmSuppress="true"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
Expand Down
2 changes: 1 addition & 1 deletion src/Marshaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(Index $index)
*
* @param array $data The data to hydrate.
* @param array $options List of options
* @return \Cake\ElasticSearch\Document;
* @return \Cake\ElasticSearch\Document
*/
public function one(array $data, array $options = []): Document
{
Expand Down
1 change: 0 additions & 1 deletion src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,6 @@ public function formatResults(?Closure $formatter = null, int|bool $mode = self:
$this->_formatters = [];
}
if ($formatter === null) {
/** @psalm-suppress RedundantCondition */
if ($mode !== self::OVERWRITE) {
throw new InvalidArgumentException('$formatter can be null only when $mode is overwrite.');
}
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/View/Form/DocumentContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,13 +537,13 @@ public function testErrorNestedFields()
],
'en' => [
['family_name' => 'ZZ', 'given_name' => 'AA'],
]
]
],
],
]);
$row->setError('name', [
'ja' => [
['family_name' => ['_empty' => 'Invalid value']]
]
['family_name' => ['_empty' => 'Invalid value']],
],
]);

$articles = $this->setupIndex();
Expand Down
Loading