Skip to content

Commit 182b2d2

Browse files
committed
test: Upgrade to Psalm 6
1 parent 6465371 commit 182b2d2

File tree

14 files changed

+46
-37
lines changed

14 files changed

+46
-37
lines changed

.github/workflows/backend.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ jobs:
104104
extensions: ${{ env.extensions }}
105105
ini-values: ${{ env.ini }}
106106
coverage: pcov
107-
tools: phpunit:11.5.44, psalm:5.26.1
107+
tools: phpunit:11.5.44, psalm:6.13.1
108108

109109
- name: Setup problem matchers
110110
run: |
@@ -127,7 +127,7 @@ jobs:
127127
run: phpunit -c phpunit.ci.xml --coverage-clover ${{ github.workspace }}/clover.xml
128128

129129
- name: Statically analyze using Psalm
130-
if: always() && steps.finishPrepare.outcome == 'success' && matrix.php != '8.4' && matrix.php != '8.5'
130+
if: always() && steps.finishPrepare.outcome == 'success' && matrix.php != '8.5'
131131
run: psalm --output-format=github --php-version=${{ matrix.php }} --report=sarif/psalm.sarif --report-show-info=false
132132

133133
- name: Upload coverage results to Codecov
@@ -144,7 +144,7 @@ jobs:
144144
env_vars: PHP
145145

146146
- name: Upload code scanning results to GitHub
147-
if: always() && steps.finishPrepare.outcome == 'success' && github.repository == 'getkirby/kirby' && matrix.php != '8.4' && matrix.php != '8.5'
147+
if: always() && steps.finishPrepare.outcome == 'success' && github.repository == 'getkirby/kirby' && matrix.php != '8.5'
148148
uses: github/codeql-action/upload-sarif@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # pin@v3
149149
with:
150150
sarif_file: sarif

psalm.xml.dist

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,25 @@
2525
</errorLevel>
2626
</InvalidScope>
2727

28-
<!-- TODO: This check gets flagged by Psalm for unknown reasons in PHP 8.2 -->
29-
<MethodSignatureMismatch>
30-
<errorLevel type="suppress">
31-
<file name="src/Toolkit/Date.php" />
32-
</errorLevel>
33-
</MethodSignatureMismatch>
34-
3528
<!-- Don't warn about duplicate array keys as Psalm will throw false positive when unpacking arrays -->
3629
<DuplicateArrayKey errorLevel="suppress" />
3730

3831
<!-- Don't warn about missing template params as Psalm does not recognize this correctly when using `@uses` for traits in class docblock -->
3932
<MissingTemplateParam errorLevel="suppress" />
33+
34+
<!-- Don't warn about missing override attribute -->
35+
<MissingOverrideAttribute errorLevel="suppress" />
36+
37+
<!-- Don't warn about possibly unused parts, Psalm cannot know what Kirby parts are used by developers -->
38+
<PossiblyUnusedMethod errorLevel="suppress" />
39+
<PossiblyUnusedParam errorLevel="suppress" />
40+
<PossiblyUnusedProperty errorLevel="suppress" />
41+
<PossiblyUnusedReturnValue errorLevel="suppress" />
42+
<UnusedClass errorLevel="suppress" />
43+
<UnusedClosureParam errorLevel="suppress" />
44+
<UnusedForeachValue errorLevel="suppress" />
45+
<UnusedVariable errorLevel="suppress" />
46+
<UndefinedClass errorLevel="suppress" />
4047
</issueHandlers>
4148

4249
<plugins>

src/Cms/Pagination.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ public function pageUrl(int|null $page = null): string|null
140140
}
141141

142142
match ($this->method) {
143-
'query' => $url->query->$variable = $page,
144-
'param' => $url->params->$variable = $page
143+
'query' => $url->query()->$variable = $page,
144+
'param' => $url->params()->$variable = $page
145145
};
146146

147147
return $url->toString();

src/Cms/Url.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public static function home(): string
4141
* @param string $separator To be used instead of space and
4242
* other non-word characters.
4343
* @param string $allowed List of all allowed characters (regex)
44-
* @param int $maxlength The maximum length of the slug
4544
* @return string The safe string
4645
*/
4746
public static function slug(

src/Content/Version.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,9 @@ protected function previewTokenFromUrl(string $url): string
424424
{
425425
// get rid of all modifiers after the path
426426
$uri = new Uri($url);
427-
$uri->fragment = null;
428-
$uri->params = null;
429-
$uri->query = null;
427+
$uri->setFragment(null);
428+
$uri->setParams(null);
429+
$uri->setQuery(null);
430430

431431
$data = [
432432
'url' => $uri->toString(),
@@ -676,10 +676,10 @@ protected function urlFromOption(string $url): string
676676
protected function urlWithQueryParams(string $baseUrl, string $token): string
677677
{
678678
$uri = new Uri($baseUrl);
679-
$uri->query->_token = $token;
679+
$uri->query()->_token = $token;
680680

681681
if ($this->id->is('changes') === true) {
682-
$uri->query->_version = 'changes';
682+
$uri->query()->_version = 'changes';
683683
}
684684

685685
return $uri->toString();

src/Http/Url.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,15 @@ public static function short(
181181
): string {
182182
$uri = static::toObject($url);
183183

184-
$uri->fragment = null;
185-
$uri->query = null;
186-
$uri->password = null;
187-
$uri->port = null;
188-
$uri->scheme = null;
189-
$uri->username = null;
184+
$uri->setFragment(null);
185+
$uri->setQuery(null);
186+
$uri->setPassword(null);
187+
$uri->setPort(null);
188+
$uri->setScheme(null);
189+
$uri->setUsername(null);
190190

191191
// remove the trailing slash from the path
192-
$uri->slash = false;
192+
$uri->setSlash(false);
193193

194194
$url = $base ? $uri->base() : $uri->toString();
195195
$url = str_replace('www.', '', $url ?? '');

src/Panel/Home.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ public static function url(): string
228228

229229
// remove all params to avoid
230230
// possible attack vectors
231-
$uri->params = '';
232-
$uri->query = '';
231+
$uri->setParams('');
232+
$uri->setQuery('');
233233

234234
// get a clean version of the URL
235235
$url = $uri->toString();

src/Session/FileSessionStore.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,15 @@ public function collectGarbage(): void
371371
public function __destruct()
372372
{
373373
// unlock all locked files
374-
foreach ($this->isLocked as $name => $locked) {
374+
foreach (array_keys($this->isLocked) as $name) {
375375
$expiryTime = (int)Str::before($name, '.');
376376
$id = Str::after($name, '.');
377377

378378
$this->unlock($expiryTime, $id);
379379
}
380380

381381
// close all file handles
382-
foreach ($this->handles as $name => $handle) {
382+
foreach (array_keys($this->handles) as $name) {
383383
$this->closeHandle($name);
384384
}
385385
}

src/Toolkit/A.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ public static function sort(
911911
}
912912

913913
// rebuild the original array
914-
foreach ($helper as $key => $val) {
914+
foreach (array_keys($helper) as $key) {
915915
$result[$key] = $array[$key];
916916
}
917917

src/Toolkit/Collection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,8 @@ public static function sortArgs(string $sort): array
967967
* @param string|null $direction asc or desc
968968
* @param int|null $method The sort flag, SORT_REGULAR, SORT_NUMERIC etc.
969969
* @return $this|static
970+
*
971+
* @psalm-suppress UnusedVariable
970972
*/
971973
public function sort(...$args): static
972974
{

0 commit comments

Comments
 (0)