Skip to content

Commit 5a5f2b3

Browse files
authored
Added psalm and phpstan (#22)
* Added psalm and phpstan * minor * Update PHP version * better baseline
1 parent 57c64c1 commit 5a5f2b3

File tree

7 files changed

+133
-34
lines changed

7 files changed

+133
-34
lines changed

.github/.editorconfig

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[*.yml]
2+
indent_size = 2

.github/workflows/ci.yml

+64-23
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,69 @@
11
name: CI
22

33
on:
4-
pull_request:
5-
push:
6-
branches: [master]
4+
pull_request:
5+
push:
6+
branches: [ master ]
77

88
jobs:
9-
cs:
10-
name: 'Code Style'
11-
runs-on: ubuntu-latest
12-
13-
steps:
14-
- name: Checkout code
15-
uses: actions/checkout@v2
16-
17-
- name: Setup PHP
18-
uses: shivammathur/setup-php@v2
19-
with:
20-
php-version: 8.1
21-
coverage: none
22-
tools: php-cs-fixer:3.34, cs2pr
23-
24-
- name: Display PHP-CS-Fixer version
25-
run: php-cs-fixer --version
26-
27-
- name: PHP-CS-Fixer
28-
run: php-cs-fixer fix --dry-run --format=checkstyle | cs2pr
9+
cs:
10+
name: 'Code Style'
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v2
16+
17+
- name: Setup PHP
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: 8.2
21+
coverage: none
22+
tools: php-cs-fixer:3.34, cs2pr
23+
24+
- name: Display PHP-CS-Fixer version
25+
run: php-cs-fixer --version
26+
27+
- name: PHP-CS-Fixer
28+
run: php-cs-fixer fix --dry-run --format=checkstyle | cs2pr
29+
30+
phpstan:
31+
name: PHPStan
32+
runs-on: ubuntu-latest
33+
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v3
37+
38+
- name: Setup PHP
39+
uses: shivammathur/setup-php@v2
40+
with:
41+
php-version: 8.2
42+
coverage: none
43+
tools: phpstan:1.10, cs2pr
44+
45+
- name: Download dependencies
46+
uses: ramsey/composer-install@v2
47+
48+
- name: PHPStan
49+
run: phpstan analyze --no-progress --error-format=checkstyle | cs2pr
50+
51+
psalm:
52+
name: Psalm
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Checkout code
56+
uses: actions/checkout@v3
57+
58+
- name: Setup PHP
59+
uses: shivammathur/setup-php@v2
60+
with:
61+
php-version: 8.2
62+
coverage: none
63+
tools: vimeo/psalm:5.15
64+
65+
- name: Download dependencies
66+
uses: ramsey/composer-install@v2
67+
68+
- name: Psalm
69+
run: psalm --no-progress --output-format=github

phpstan-baseline.neon

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parameters:
2+
ignoreErrors: []

phpstan.neon.dist

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
includes:
2+
- ./phpstan-baseline.neon
3+
4+
parameters:
5+
level: 5
6+
reportUnmatchedIgnoredErrors: false
7+
paths:
8+
- src
9+

psalm.baseline.xml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
3+
<file src="src/Command/TranslationStatsCommand.php">
4+
<UnusedVariable>
5+
<code>$source</code>
6+
<code>$source</code>
7+
</UnusedVariable>
8+
</file>
9+
<file src="src/Service/DataProvider.php">
10+
<UnusedForeachValue>
11+
<code>$rows</code>
12+
</UnusedForeachValue>
13+
<UnusedVariable>
14+
<code>$language</code>
15+
</UnusedVariable>
16+
</file>
17+
</files>

psalm.xml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
findUnusedBaselineEntry="true"
9+
findUnusedCode="true"
10+
errorBaseline="psalm.baseline.xml"
11+
>
12+
<projectFiles>
13+
<directory name="src" />
14+
<ignoreFiles>
15+
<directory name="vendor" />
16+
</ignoreFiles>
17+
</projectFiles>
18+
<issueHandlers>
19+
<PossiblyUnusedMethod>
20+
<errorLevel type="suppress">
21+
<directory name="src" />
22+
</errorLevel>
23+
</PossiblyUnusedMethod>
24+
<UnusedClass>
25+
<errorLevel type="suppress">
26+
<directory name="src" />
27+
</errorLevel>
28+
</UnusedClass>
29+
</issueHandlers>
30+
</psalm>

src/Model/ComponentCollection.php

+9-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace App\Model;
66

7+
/**
8+
* @implements \Iterator<int, GithubIssue>
9+
*/
710
class ComponentCollection implements \Countable, \Iterator
811
{
912
private ?GithubIssue $issue;
@@ -44,37 +47,32 @@ public function getLanguage(): string
4447
return $this->language;
4548
}
4649

47-
public function current()
50+
public function current(): GithubIssue
4851
{
4952
return $this->data[$this->cursor];
5053
}
5154

52-
public function next()
55+
public function next(): void
5356
{
5457
++$this->cursor;
55-
if ($this->valid()) {
56-
return $this->data[$this->cursor];
57-
}
58-
59-
return false;
6058
}
6159

62-
public function key()
60+
public function key(): int
6361
{
6462
return $this->cursor;
6563
}
6664

67-
public function valid()
65+
public function valid(): bool
6866
{
6967
return isset($this->data[$this->cursor]);
7068
}
7169

72-
public function rewind()
70+
public function rewind(): void
7371
{
7472
$this->cursor = 0;
7573
}
7674

77-
public function count()
75+
public function count(): int
7876
{
7977
return count($this->data);
8078
}

0 commit comments

Comments
 (0)