Skip to content

Commit 57b086b

Browse files
test(coding standards): Fix some psalm errors
1 parent 0f5d74f commit 57b086b

File tree

4 files changed

+36
-70
lines changed

4 files changed

+36
-70
lines changed

src/AlertsClient.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
* range?: string,
2424
* since?: string,
2525
* until?: string,
26-
* simulated?: boolean,
27-
* has_active_decision?: boolean,
26+
* simulated?: bool,
27+
* has_active_decision?: bool,
2828
* decision_type?: string,
29-
* limit?: number,
29+
* limit?: int,
3030
* origin?: string
3131
* }
3232
*
@@ -38,7 +38,7 @@
3838
* range?: string,
3939
* since?: string,
4040
* until?: string,
41-
* has_active_decision?: boolean,
41+
* has_active_decision?: bool,
4242
* alert_source?: string
4343
* }
4444
*
@@ -142,7 +142,7 @@ public function delete(array $query): array
142142

143143
/**
144144
* @param positive-int $id
145-
* @return TStoredAlert
145+
* @return ?TStoredAlert
146146
*/
147147
public function getById(int $id): ?array
148148
{
@@ -151,11 +151,11 @@ public function getById(int $id): ?array
151151
'GET',
152152
\sprintf('%s/%d', Constants::ALERTS, $id)
153153
);
154-
// workaround for mutes 404 status.
155-
if (empty($result['id'])) {
156-
\assert($result['message'] === 'object not found');
154+
// workaround for muted 404 status.
155+
if (!isset($result['id'])) {
157156
return null;
158157
}
158+
/** @var TStoredAlert */
159159
return $result;
160160
}
161161

src/Configuration/Alert.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getConfigTreeBuilder(): TreeBuilder
4747
->end()
4848
;
4949
// @formatter:on
50-
50+
5151
return $treeBuilder;
5252
}
5353
}

src/Payload/Alert.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@
7171
* leakspeed: string,
7272
* simulated: bool,
7373
* remediation: bool,
74-
* source: TSource,
74+
* source?: TSource,
7575
* events: list<TEvent>,
7676
* decisions?: list<TDecision>,
7777
* meta?: list<TMeta>,
78-
* labels?: list<non-empty-string>
78+
* labels?: list<string>
7979
* }
8080
*/
8181
class Alert implements \JsonSerializable
8282
{
8383
/**
84-
* @var list<TProps>
84+
* @var TProps
8585
*/
8686
private $properties;
8787

@@ -96,7 +96,7 @@ class Alert implements \JsonSerializable
9696
private $decisions = [];
9797

9898
/**
99-
* @var TSource
99+
* @var ?TSource
100100
*/
101101
private $source;
102102

@@ -141,8 +141,20 @@ public function __construct(
141141
public static function fromArray(array $data): self
142142
{
143143
return new self(
144-
$data,
145-
$data['source'] ?? [],
144+
[
145+
'scenario' => $data['scenario'],
146+
'scenario_hash' => $data['scenario_hash'],
147+
'scenario_version' => $data['scenario_version'],
148+
'message' => $data['message'],
149+
'events_count' => $data['events_count'],
150+
'start_at' => $data['start_at'],
151+
'stop_at' => $data['stop_at'],
152+
'capacity' => $data['capacity'],
153+
'leakspeed' => $data['leakspeed'],
154+
'simulated' => $data['simulated'],
155+
'remediation' => $data['remediation'],
156+
],
157+
$data['source'] ?? null,
146158
$data['events'] ?? [],
147159
$data['decisions'] ?? [],
148160
$data['meta'] ?? [],

tools/coding-standards/psalm/psalm.xml

Lines changed: 9 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="5"
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"
3+
errorLevel="5"
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"
88
>
99
<projectFiles>
10-
<directory name="../../../src" />
10+
<directory name="../../../src"/>
1111
<ignoreFiles>
12-
<directory name="../../../vendor" />
13-
<directory name="../vendor" />
12+
<directory name="../../../vendor"/>
13+
<directory name="../vendor"/>
1414
</ignoreFiles>
1515
</projectFiles>
1616
<issueHandlers>
1717
<UndefinedInterfaceMethod>
1818
<errorLevel type="suppress">
1919
<referencedMethod name="Symfony\Component\Config\Definition\Builder\NodeParentInterface::integerNode"/>
2020
<referencedMethod name="Symfony\Component\Config\Definition\Builder\NodeParentInterface::scalarNode"/>
21-
<referencedMethod name="Symfony\Component\Config\Definition\Builder\NodeParentInterface::stringNode"/>
2221
</errorLevel>
2322
</UndefinedInterfaceMethod>
2423
<UndefinedMethod>
@@ -29,36 +28,6 @@
2928
<file name="../../../src/Payload/Alert.php"/>
3029
</errorLevel>
3130
</UndefinedMethod>
32-
<PropertyTypeCoercion>
33-
<errorLevel type="suppress">
34-
<referencedProperty name="CrowdSec\LapiClient\Payload\Alert::$properties"/>
35-
<referencedProperty name="CrowdSec\LapiClient\Payload\Alert::$source"/>
36-
<referencedProperty name="CrowdSec\LapiClient\Payload\Alert::$decisions"/>
37-
<referencedProperty name="CrowdSec\LapiClient\Payload\Alert::$events"/>
38-
<referencedProperty name="CrowdSec\LapiClient\Payload\Alert::$meta"/>
39-
<referencedProperty name="CrowdSec\LapiClient\Metrics::$items"/>
40-
</errorLevel>
41-
</PropertyTypeCoercion>
42-
<MissingClassConstType>
43-
<errorLevel type="suppress">
44-
<directory name="../../../src"/>
45-
</errorLevel>
46-
</MissingClassConstType>
47-
<NonInvariantDocblockPropertyType>
48-
<errorLevel type="suppress">
49-
<file name="../../../src/AbstractLapiClient.php"/>
50-
</errorLevel>
51-
</NonInvariantDocblockPropertyType>
52-
<MoreSpecificReturnType>
53-
<errorLevel type="suppress">
54-
<file name="../../../src/AlertsClient.php"/>
55-
</errorLevel>
56-
</MoreSpecificReturnType>
57-
<LessSpecificReturnStatement>
58-
<errorLevel type="suppress">
59-
<file name="../../../src/AlertsClient.php"/>
60-
</errorLevel>
61-
</LessSpecificReturnStatement>
6231
<UndefinedDocblockClass>
6332
<errorLevel type="suppress">
6433
<file name="../../../src/AlertsClient.php"/>
@@ -67,35 +36,20 @@
6736
<InvalidReturnStatement>
6837
<errorLevel type="suppress">
6938
<file name="../../../src/AlertsClient.php"/>
70-
<file name="../../../src/Payload/Alert.php"/>
7139
</errorLevel>
7240
</InvalidReturnStatement>
7341
<RiskyTruthyFalsyComparison>
7442
<errorLevel type="suppress">
7543
<file name="../../../src/Bouncer.php"/>
7644
</errorLevel>
7745
</RiskyTruthyFalsyComparison>
78-
<InvalidArgument>
79-
<errorLevel type="suppress">
80-
<file name="../../../src/Payload/Alert.php"/>
81-
</errorLevel>
82-
</InvalidArgument>
83-
<InvalidReturnType>
84-
<errorLevel type="suppress">
85-
<file name="../../../src/Payload/Alert.php"/>
86-
</errorLevel>
87-
</InvalidReturnType>
88-
<PropertyNotSetInConstructor>
89-
<errorLevel type="suppress">
90-
<file name="../../../src/Payload/Alert.php"/>
91-
</errorLevel>
92-
</PropertyNotSetInConstructor>
9346
<PossiblyNullReference>
9447
<errorLevel type="suppress">
9548
<file name="../../../src/Configuration.php"/>
9649
<file name="../../../src/Configuration/Metrics.php"/>
9750
<file name="../../../src/Configuration/Metrics/Items.php"/>
9851
<file name="../../../src/Configuration/Metrics/Meta.php"/>
52+
<file name="../../../src/Configuration/Alert.php"/>
9953
</errorLevel>
10054
</PossiblyNullReference>
10155
</issueHandlers>

0 commit comments

Comments
 (0)