Skip to content

Commit 0ee1b1c

Browse files
authored
Add new PHP versions to build workflow (#15)
* Add new PHP versions to build workflow * Fix normalizing leading slashes for getPath() and __toString() methods to Uri class
1 parent bb3f88f commit 0ee1b1c

File tree

11 files changed

+128
-72
lines changed

11 files changed

+128
-72
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
/infection.json.dist export-ignore
99
/phpcs.xml export-ignore
1010
/phpunit.xml.dist export-ignore
11-
/psalm.xml export-ignore
11+
/psalm.xml.dist export-ignore

.github/workflows/build.yml

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
on:
2-
- pull_request
3-
- push
2+
pull_request:
3+
paths-ignore:
4+
- 'docs/**'
5+
- 'README.md'
6+
- 'CHANGELOG.md'
7+
- '.gitignore'
8+
- '.gitattributes'
9+
- 'psalm.xml.dist'
10+
11+
push:
12+
paths-ignore:
13+
- 'docs/**'
14+
- 'README.md'
15+
- 'CHANGELOG.md'
16+
- '.gitignore'
17+
- '.gitattributes'
18+
- 'psalm.xml.dist'
419

520
name: build
621

@@ -22,40 +37,42 @@ jobs:
2237
php:
2338
- "7.4"
2439
- "8.0"
40+
- "8.1"
41+
- "8.2"
2542

2643
steps:
27-
- name: Checkout
28-
uses: actions/checkout@v2
44+
- name: Checkout.
45+
uses: actions/checkout@v3
2946

30-
- name: Install PHP
47+
- name: Install PHP with extensions.
3148
uses: shivammathur/setup-php@v2
3249
with:
3350
php-version: ${{ matrix.php }}
3451
ini-values: date.timezone='UTC'
3552
tools: composer:v2
3653
coverage: pcov
3754

38-
- name: Determine composer cache directory on Linux
55+
- name: Determine composer cache directory on Linux.
3956
if: matrix.os == 'ubuntu-latest'
4057
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
4158

42-
- name: Determine composer cache directory on Windows
59+
- name: Determine composer cache directory on Windows.
4360
if: matrix.os == 'windows-latest'
4461
run: echo "COMPOSER_CACHE_DIR=~\AppData\Local\Composer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
4562

46-
- name: Cache dependencies installed with composer
47-
uses: actions/cache@v2
63+
- name: Cache dependencies installed with composer.
64+
uses: actions/cache@v3
4865
with:
4966
path: ${{ env.COMPOSER_CACHE_DIR }}
5067
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
5168
restore-keys: |
5269
php${{ matrix.php }}-composer-
5370
54-
- name: Update composer
71+
- name: Update composer.
5572
run: composer self-update
5673

57-
- name: Install dependencies with composer
74+
- name: Install dependencies with composer.
5875
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
5976

60-
- name: Run tests with phpunit
77+
- name: Run tests with phpunit.
6178
run: vendor/bin/phpunit --colors=always

.github/workflows/static.yml

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
on:
2-
- pull_request
3-
- push
2+
pull_request:
3+
paths-ignore:
4+
- 'docs/**'
5+
- 'README.md'
6+
- 'CHANGELOG.md'
7+
- '.gitignore'
8+
- '.gitattributes'
9+
- 'phpunit.xml.dist'
10+
11+
push:
12+
paths-ignore:
13+
- 'docs/**'
14+
- 'README.md'
15+
- 'CHANGELOG.md'
16+
- '.gitignore'
17+
- '.gitattributes'
18+
- 'phpunit.xml.dist'
419

520
name: static
621

@@ -18,37 +33,39 @@ jobs:
1833
php:
1934
- "7.4"
2035
- "8.0"
36+
- "8.1"
37+
- "8.2"
2138

2239
steps:
23-
- name: Checkout
24-
uses: actions/checkout@v2
40+
- name: Checkout.
41+
uses: actions/checkout@v3
2542

26-
- name: Install PHP
43+
- name: Install PHP with extensions.
2744
uses: shivammathur/setup-php@v2
2845
with:
2946
php-version: ${{ matrix.php }}
3047
ini-values: memory_limit=-1
3148
tools: composer:v2
3249

33-
- name: Determine composer cache directory
50+
- name: Determine composer cache directory.
3451
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
3552

36-
- name: Cache dependencies installed with composer
37-
uses: actions/cache@v2
53+
- name: Cache dependencies installed with composer.
54+
uses: actions/cache@v3
3855
with:
3956
path: ${{ env.COMPOSER_CACHE_DIR }}
4057
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
4158
restore-keys: |
4259
php${{ matrix.php }}-composer-
4360
44-
- name: Update composer
61+
- name: Update composer.
4562
run: composer self-update
4663

47-
- name: Install dependencies with composer
64+
- name: Install dependencies with composer.
4865
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
4966

50-
- name: PHPCS check
67+
- name: PHPCS check.
5168
run: vendor/bin/phpcs
5269

53-
- name: Psalm static analysis
70+
- name: Psalm static analysis.
5471
run: vendor/bin/psalm --no-progress

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.phpunit.result.cache
22
composer.lock
33
phpunit.xml
4+
psalm.xml
45
vendor

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
},
2626
"require-dev": {
2727
"phpunit/phpunit": "^9.5",
28-
"php-http/psr7-integration-tests": "1.1.1",
29-
"squizlabs/php_codesniffer": "^3.6",
30-
"vimeo/psalm": "^4.8"
28+
"php-http/psr7-integration-tests": "1.2",
29+
"squizlabs/php_codesniffer": "^3.7",
30+
"vimeo/psalm": "^4.9|^5.2"
3131
},
3232
"provide": {
3333
"psr/http-message-implementation": "1.0",

infection.json.dist

Lines changed: 0 additions & 16 deletions
This file was deleted.

phpunit.xml.dist

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
5-
bootstrap="./vendor/autoload.php"
6-
executionOrder="depends,defects"
7-
beStrictAboutCoversAnnotation="true"
8-
beStrictAboutOutputDuringTests="true"
9-
beStrictAboutTodoAnnotatedTests="true"
10-
convertWarningsToExceptions="true"
11-
convertNoticesToExceptions="true"
12-
convertErrorsToExceptions="true"
13-
stopOnFailure="false"
14-
verbose="true"
15-
colors="true"
3+
bootstrap="vendor/autoload.php"
4+
executionOrder="random"
5+
beStrictAboutCoversAnnotation="true"
6+
beStrictAboutOutputDuringTests="true"
7+
beStrictAboutTodoAnnotatedTests="true"
8+
convertWarningsToExceptions="true"
9+
convertNoticesToExceptions="true"
10+
convertErrorsToExceptions="true"
11+
resolveDependencies="true"
12+
stopOnFailure="false"
13+
failOnWarning="true"
14+
failOnRisky="true"
15+
verbose="true"
16+
colors="true"
1617
>
1718
<php>
1819
<ini name="error_reporting" value="-1" />
@@ -30,9 +31,9 @@
3031
</testsuite>
3132
</testsuites>
3233

33-
<filter>
34-
<whitelist>
35-
<directory suffix=".php">./src/</directory>
36-
</whitelist>
37-
</filter>
34+
<coverage processUncoveredFiles="true">
35+
<include>
36+
<directory suffix=".php">./src</directory>
37+
</include>
38+
</coverage>
3839
</phpunit>

psalm.xml renamed to psalm.xml.dist

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?xml version="1.0"?>
22
<psalm
33
errorLevel="1"
4+
findUnusedPsalmSuppress="true"
45
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
56
xmlns="https://getpsalm.org/schema/config"
67
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
78
>
89
<projectFiles>
9-
<directory name="src" />
10+
<directory name="src"/>
11+
<ignoreFiles>
12+
<directory name="vendor"/>
13+
</ignoreFiles>
1014
</projectFiles>
1115

1216
<issueHandlers>

src/ResponseTrait.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public function getStatusCode(): int
147147
* @psalm-suppress DocblockTypeContradiction
148148
* @psalm-suppress TypeDoesNotContainType
149149
* @psalm-suppress RedundantCondition
150+
* @psalm-suppress NoValue
150151
*/
151152
public function withStatus($code, $reasonPhrase = ''): ResponseInterface
152153
{
@@ -184,7 +185,6 @@ public function withStatus($code, $reasonPhrase = ''): ResponseInterface
184185
* @link http://tools.ietf.org/html/rfc7231#section-6
185186
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
186187
* @return string Reason phrase; must return an empty string if none present.
187-
* @psalm-suppress RedundantCondition
188188
*/
189189
public function getReasonPhrase(): string
190190
{
@@ -197,7 +197,6 @@ public function getReasonPhrase(): string
197197
* @param StreamInterface|string|resource|null $body
198198
* @param array $headers
199199
* @param string $protocol
200-
* @psalm-suppress MixedArgumentTypeCoercion
201200
*/
202201
private function init(
203202
int $statusCode = 200,

src/Uri.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,14 @@ public function __toString(): string
120120
}
121121

122122
if ($this->path !== '') {
123-
$this->cache .= $authority ? '/' . ltrim($this->path, '/') : $this->path;
123+
if ($authority === '') {
124+
// If the path is starting with more than one "/" and no authority is present,
125+
// the starting slashes MUST be reduced to one.
126+
$this->cache .= $this->path[0] === '/' ? '/' . ltrim($this->path, '/') : $this->path;
127+
} else {
128+
// If the path is rootless and an authority is present, the path MUST be prefixed by "/".
129+
$this->cache .= $this->path[0] === '/' ? $this->path : '/' . $this->path;
130+
}
124131
}
125132

126133
if ($this->query !== '') {
@@ -193,7 +200,16 @@ public function getPort(): ?int
193200
*/
194201
public function getPath(): string
195202
{
196-
return $this->path;
203+
if ($this->path === '' || $this->path === '/') {
204+
return $this->path;
205+
}
206+
207+
if ($this->path[0] !== '/') {
208+
// If the path is rootless and an authority is present, the path MUST be prefixed by "/".
209+
return $this->host === '' ? $this->path : '/' . $this->path;
210+
}
211+
212+
return '/' . ltrim($this->path, '/');
197213
}
198214

199215
/**
@@ -438,8 +454,7 @@ private function normalizePath(string $path): string
438454
return $path;
439455
}
440456

441-
$path = $this->encode($path, '/(?:[^a-zA-Z0-9_\-\.~:@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/');
442-
return $path === '' ? '' : (($path[0] === '/') ? '/' . ltrim($path, '/') : $path);
457+
return $this->encode($path, '/(?:[^a-zA-Z0-9_\-\.~:@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/');
443458
}
444459

445460
/**
@@ -490,7 +505,6 @@ private function normalizeFragment(string $fragment): string
490505
* @param string $string
491506
* @param string $pattern
492507
* @return string
493-
* @psalm-suppress MixedArgument
494508
*/
495509
private function encode(string $string, string $pattern): string
496510
{

0 commit comments

Comments
 (0)