Skip to content

Commit ce60eaa

Browse files
authored
Merge pull request #141 from Sysix/psalm
add psalm
2 parents 9091978 + 923a045 commit ce60eaa

18 files changed

+115
-65
lines changed

.gitattributes

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44
/.gitignore export-ignore
55
/phpunit.xml export-ignore
66
/phpstan.neon export-ignore
7-
/.php-cs-fixer.dist.php export-ignore
7+
/.php-cs-fixer.dist.php export-ignore
8+
/psalm.xml export-ignore
9+
/docker-compose.yml export-ignore
10+
/Dockerfile export-ignore

.github/workflows/psalm.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Run Psalm
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: docker://ghcr.io/psalm/psalm-github-actions
12+
with:
13+
composer_require_dev: true

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM php:8.2-fpm
2+
3+
4+
# install non php modules
5+
RUN apt-get update \
6+
&& apt-get install --no-install-recommends -y \
7+
libssl-dev \
8+
libzip-dev \
9+
libxml2-dev \
10+
libonig-dev \
11+
libc-client-dev \
12+
libkrb5-dev \
13+
zlib1g-dev \
14+
zip \
15+
unzip \
16+
git \
17+
&& rm -rf /var/lib/apt/lists/*
18+
19+
# Configure imap
20+
RUN docker-php-ext-install \
21+
zip \
22+
mbstring \
23+
xml \
24+
curl
25+
26+
COPY --from=composer /usr/bin/composer /usr/bin/composer
27+
28+
WORKDIR /var/www/html

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"test": "phpunit",
77
"lint": "phpstan analyse --ansi --error-format raw",
88
"codestyle:check": "php-cs-fixer check",
9-
"codestyle:fix": "php-cs-fixer fix"
9+
"codestyle:fix": "php-cs-fixer fix",
10+
"psalm": "psalm"
1011
},
1112
"keywords": [
1213
"lex-office",
@@ -25,7 +26,9 @@
2526
"phpstan/phpstan": "^1.10",
2627
"phpunit/phpunit": "^10.4",
2728
"guzzlehttp/guzzle": "^7.8",
28-
"friendsofphp/php-cs-fixer": "^3.41"
29+
"friendsofphp/php-cs-fixer": "^3.41",
30+
"vimeo/psalm": "^5.18",
31+
"psalm/plugin-phpunit": "^0.18.4"
2932
},
3033
"suggest": {
3134
"guzzlehttp/guzzle": "^7.0",

docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: '3.7'
2+
services:
3+
php-fpm:
4+
build:
5+
context: .
6+
dockerfile: Dockerfile
7+
volumes:
8+
- './:/var/www/html'

psalm.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="8"
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="false"
10+
>
11+
<projectFiles>
12+
<directory name="src" />
13+
<directory name="tests" />
14+
<ignoreFiles>
15+
<directory name="vendor" />
16+
</ignoreFiles>
17+
</projectFiles>
18+
<issueHandlers>
19+
<PropertyNotSetInConstructor errorLevel="suppress" />
20+
<DeprecatedMethod errorLevel="suppress" />
21+
<RedundantPropertyInitializationCheck errorLevel="suppress" />
22+
</issueHandlers>
23+
<plugins>
24+
<pluginClass class="Psalm\PhpUnitPlugin\Plugin" />
25+
</plugins>
26+
</psalm>

src/Api.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@ public function __construct(
4747

4848
public function newRequest(string $method, string $resource, array $headers = []): self
4949
{
50-
$this->setRequest(
50+
return $this->setRequest(
5151
new Request($method, $this->createApiUri($resource), $headers)
5252
);
53-
54-
return $this;
5553
}
5654

5755
public function setRequest(RequestInterface $request): self

src/Clients/File.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public function get(string $id, string $acceptHeader = '*/*'): ResponseInterface
1818
{
1919
$this->api->newRequest('GET', $this->resource . '/' . rawurlencode($id));
2020

21-
$this->api->setRequest($this->api->getRequest()->withHeader('Accept', $acceptHeader));
22-
23-
return $this->api->getResponse();
21+
return $this->api
22+
->setRequest($this->api->getRequest()->withHeader('Accept', $acceptHeader))
23+
->getResponse();
2424
}
2525

2626
/**
@@ -44,8 +44,8 @@ public function upload(string $filepath, string $type): ResponseInterface
4444
'Content-Type' => 'multipart/form-data; boundary=' . $body->getBoundary()
4545
]);
4646

47-
$api->setRequest($api->getRequest()->withBody($body));
48-
49-
return $api->getResponse();
47+
return $api
48+
->setRequest($api->getRequest()->withBody($body))
49+
->getResponse();
5050
}
5151
}

src/Clients/Voucher.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public function upload(string $id, string $filepath): ResponseInterface
3737
'Content-Type' => 'multipart/form-data; boundary=' . $body->getBoundary()
3838
]);
3939

40-
$api->setRequest($api->getRequest()->withBody($body));
41-
42-
return $api->getResponse();
40+
return $api
41+
->setRequest($api->getRequest()->withBody($body))
42+
->getResponse();
4343
}
4444

4545
/**

src/Utils.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,23 @@ public static function getJsonFromResponse(ResponseInterface $response): mixed
2424
}
2525

2626
/**
27-
* @param array{size?: int, metadata?: mixed[], mode?: bool, seekable?: bool} $options
27+
* @param array{size?: int, metadata?: mixed[]} $options
2828
*/
2929
public static function streamFor(string $resource = '', array $options = []): Stream
3030
{
31-
if (is_scalar($resource)) {
32-
$stream = fopen('php://temp', 'r+');
33-
if ($resource !== '' && $stream) {
34-
fwrite($stream, $resource);
35-
fseek($stream, 0);
36-
37-
return new Stream($stream, $options);
38-
}
31+
$stream = fopen('php://temp', 'r+');
32+
if ($resource !== '' && $stream) {
33+
fwrite($stream, $resource);
34+
fseek($stream, 0);
35+
36+
return new Stream($stream, $options);
3937
}
4038

4139
throw new InvalidArgumentException('Invalid resource type: ' . gettype($resource));
4240
}
4341

4442
/**
45-
* @param int<1, max> $depth
43+
* @param int<1, 2147483647> $depth
4644
*/
4745
public static function jsonEncode(mixed $value, int $options = 0, int $depth = 512): string
4846
{
@@ -55,7 +53,7 @@ public static function jsonEncode(mixed $value, int $options = 0, int $depth = 5
5553
}
5654

5755
/**
58-
* @param int<1, max> $depth
56+
* @param int<1, 2147483647> $depth
5957
*/
6058
public static function jsonDecode(string $json, bool $assoc = false, int $depth = 512, int $options = 0): mixed
6159
{
@@ -69,7 +67,7 @@ public static function jsonDecode(string $json, bool $assoc = false, int $depth
6967

7068
public static function createStream(mixed $content): StreamInterface
7169
{
72-
return Utils::streamFor(Utils::jsonEncode($content));
70+
return self::streamFor(self::jsonEncode($content));
7371
}
7472

7573
/**

0 commit comments

Comments
 (0)