Skip to content

Commit 45151da

Browse files
authored
Adopt Psalm (#19)
* Adopt Psalm * Psalm fixes * Fix testSetResponseLoopFormatter
1 parent 4281463 commit 45151da

File tree

8 files changed

+35
-393
lines changed

8 files changed

+35
-393
lines changed

.github/workflows/static.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ name: static analysis
77
jobs:
88
mutation:
99
name: PHP ${{ matrix.php-version }}-${{ matrix.os }}
10-
env:
11-
extensions: ast
1210

1311
runs-on: ${{ matrix.os }}
1412

@@ -28,7 +26,6 @@ jobs:
2826
uses: "shivammathur/setup-php@v2"
2927
with:
3028
php-version: "${{ matrix.php-version }}"
31-
extensions: ${{ env.extensions }}
3229
tools: composer:v2, cs2pr
3330
coverage: none
3431

@@ -46,5 +43,5 @@ jobs:
4643
- name: Install dependencies with composer
4744
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
4845

49-
- name: Static analysis with phan
50-
run: vendor/bin/phan --no-progress-bar --output-mode checkstyle | cs2pr --graceful-warnings --colorize
46+
- name: Static analysis with psalm
47+
run: vendor/bin/psalm --shepherd --stats --output-format=checkstyle | cs2pr --graceful-warnings --colorize

.phan/config.php

-374
This file was deleted.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ The package tests are checked with [Infection](https://infection.github.io/) mut
3636

3737
### Static analysis
3838

39-
The code is statically analyzed with [Phan](https://github.com/phan/phan/wiki). To run static analysis:
39+
The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:
4040

4141
```php
42-
./vendor/bin/phan
42+
./vendor/bin/psalm
4343
```

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
},
2929
"require-dev": {
3030
"infection/infection": "^0.16.3",
31-
"phan/phan": "^3.0",
3231
"phpunit/phpunit": "^9.3",
33-
"nyholm/psr7": "^1.0"
32+
"nyholm/psr7": "^1.0",
33+
"vimeo/psalm": "^4.0"
3434
},
3535
"autoload": {
3636
"psr-4": {

psalm.xml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="3"
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+
>
9+
<projectFiles>
10+
<directory name="src" />
11+
<ignoreFiles>
12+
<directory name="vendor" />
13+
</ignoreFiles>
14+
</projectFiles>
15+
</psalm>

src/DataResponse.php

+12-8
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public function getBody(): StreamInterface
3636
return $this->dataStream;
3737
}
3838

39-
if ($this->responseFormatter !== null) {
40-
$this->response = $this->formatResponse();
39+
if (($response = $this->formatResponse()) !== null) {
40+
$this->response = $response;
4141
return $this->dataStream = $this->response->getBody();
4242
}
4343

@@ -165,13 +165,17 @@ public function getData()
165165
return is_object($this->data) ? clone $this->data : $this->data;
166166
}
167167

168-
private function formatResponse(): ResponseInterface
168+
private function formatResponse(): ?ResponseInterface
169169
{
170-
$response = $this->responseFormatter->format($this);
171-
if ($response instanceof self) {
172-
throw new \RuntimeException('DataResponseFormatterInterface should not return instance of DateResponse.');
170+
if ($this->responseFormatter !== null) {
171+
$response = $this->responseFormatter->format($this);
172+
if ($response instanceof self) {
173+
throw new \RuntimeException('DataResponseFormatterInterface should not return instance of DataResponse.');
174+
}
175+
176+
return $response;
177+
} else {
178+
return null;
173179
}
174-
175-
return $response;
176180
}
177181
}

src/Formatter/XmlDataResponseFormatter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function withUseObjectTags(bool $useObjectTags): self
113113
}
114114

115115
/**
116-
* @param DOMElement $element
116+
* @param DOMElement|DOMDocument $element
117117
* @param mixed $data
118118
*/
119119
private function buildXml($element, $data): void

tests/DataResponseTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testSetEmptyResponseFormatter(): void
6666
public function testSetResponseLoopFormatter(): void
6767
{
6868
$this->expectException(\RuntimeException::class);
69-
$this->expectExceptionMessage('DataResponseFormatterInterface should not return instance of DateResponse.');
69+
$this->expectExceptionMessage('DataResponseFormatterInterface should not return instance of DataResponse.');
7070

7171
$dataResponse = new DataResponse('test', Status::OK, '', new Psr17Factory());
7272
$dataResponse = $dataResponse->withResponseFormatter(new LoopDataResponseFormatter());

0 commit comments

Comments
 (0)