Skip to content

Commit 278a169

Browse files
committed
Add PHP 8.4 tests support
1 parent b0f55a5 commit 278a169

12 files changed

+50
-47
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
19+
php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
2020
os: [ ubuntu-latest, macos-latest, windows-latest ]
2121
stability: [ prefer-lowest, prefer-stable ]
2222
steps:

src/Exception/HashCalculationException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final public function __construct(string $message, int $code = 0, ?\Throwable $p
1818
parent::__construct($message, $code, $previous);
1919
}
2020

21-
public static function fromInvalidHashAlgo(string $algo, \Throwable $prev = null): self
21+
public static function fromInvalidHashAlgo(string $algo, ?\Throwable $prev = null): self
2222
{
2323
$message = 'Cannot get the source hash because the algorithm "%s" '
2424
. 'is not supported by the PHP environment or is incorrect';

src/Exception/NotReadableException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static function createFromLastInternalError(): \ErrorException
7171
*
7272
* @return static
7373
*/
74-
public static function fromOpeningFile(string $filename, \Throwable $prev = null): self
74+
public static function fromOpeningFile(string $filename, ?\Throwable $prev = null): self
7575
{
7676
$message = 'An error occurred while trying to open the file "%s" for reading';
7777

src/File.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,31 @@ class File extends Readable implements FileInterface
1212
{
1313
/**
1414
* @var non-empty-string
15+
*
1516
* @psalm-readonly-allow-private-mutation
1617
*/
1718
private string $filename;
1819

1920
/**
2021
* @var non-empty-string
22+
*
2123
* @psalm-readonly-allow-private-mutation
2224
*/
2325
private string $algo = SourceFactory::DEFAULT_HASH_ALGO;
2426

2527
/**
2628
* @var int<1, max>
29+
*
2730
* @psalm-readonly-allow-private-mutation
2831
*/
2932
private int $chunkSize = SourceFactory::DEFAULT_CHUNK_SIZE;
3033

3134
/**
3235
* @psalm-taint-sink file $filename
33-
*
3436
* @param non-empty-string $filename
35-
* @param non-empty-string $algo Hashing algorithm for the source.
36-
* @param int<1, max> $chunkSize The chunk size used while non-blocking
37-
* reading the file inside the {@see \Fiber}.
37+
* @param non-empty-string $algo hashing algorithm for the source
38+
* @param int<1, max> $chunkSize the chunk size used while non-blocking
39+
* reading the file inside the {@see \Fiber}
3840
*/
3941
public function __construct(
4042
string $filename,

src/Provider/PsrStreamSourceProvider.php

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
namespace Phplrt\Source\Provider;
66

77
use Phplrt\Contracts\Source\ReadableInterface;
8-
use Phplrt\Source\Exception\NotFoundException;
9-
use Phplrt\Source\Exception\NotReadableException;
10-
use Phplrt\Source\File;
118
use Phplrt\Source\SourceFactory;
129
use Psr\Http\Message\StreamInterface;
1310

src/Provider/SourceProviderInterface.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
interface SourceProviderInterface
1111
{
1212
/**
13-
* @param mixed $source Arbitrary source reference from which you can
14-
* create a {@see ReadableInterface} instance.
13+
* @param mixed $source arbitrary source reference from which you can
14+
* create a {@see ReadableInterface} instance
1515
*
16-
* @return ReadableInterface|null Returns {@see null} in case of the object
17-
* cannot be created.
18-
*
19-
* @throws SourceExceptionInterface In case of an error in creating the
20-
* source object.
16+
* @return ReadableInterface|null returns {@see null} in case of the object
17+
* cannot be created
18+
* @throws SourceExceptionInterface in case of an error in creating the
19+
* source object
2120
*/
2221
public function create($source): ?ReadableInterface;
2322
}

src/Source.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,23 @@ class Source extends Readable implements PreferContentReadingInterface
2828

2929
/**
3030
* @var non-empty-string
31+
*
3132
* @psalm-readonly-allow-private-mutation
3233
*/
3334
private string $algo = SourceFactory::DEFAULT_HASH_ALGO;
3435

3536
/**
3637
* @var non-empty-string
38+
*
3739
* @psalm-readonly-allow-private-mutation
3840
*/
3941
private string $temp = SourceFactory::DEFAULT_TEMP_STREAM;
4042

4143
/**
4244
* @psalm-taint-sink file $temp
43-
*
44-
* @param non-empty-string $algo Hashing algorithm for the source.
45-
* @param non-empty-string $temp The name of the temporary stream, which is
46-
* used as a resource during the reading of the source.
45+
* @param non-empty-string $algo hashing algorithm for the source
46+
* @param non-empty-string $temp the name of the temporary stream, which is
47+
* used as a resource during the reading of the source
4748
*/
4849
public function __construct(
4950
string $content,

src/SourceFactory.php

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

55
namespace Phplrt\Source;
66

7-
use Phplrt\Contracts\Source\SourceFactoryInterface;
87
use Phplrt\Contracts\Source\FileInterface;
98
use Phplrt\Contracts\Source\ReadableInterface;
9+
use Phplrt\Contracts\Source\SourceFactoryInterface;
1010
use Phplrt\Source\Exception\NotCreatableException;
1111
use Phplrt\Source\Exception\NotFoundException;
1212
use Phplrt\Source\Exception\NotReadableException;
@@ -41,18 +41,21 @@ final class SourceFactory implements SourceFactoryInterface
4141

4242
/**
4343
* @var non-empty-string
44+
*
4445
* @psalm-readonly-allow-private-mutation
4546
*/
4647
public string $algo = self::DEFAULT_HASH_ALGO;
4748

4849
/**
4950
* @var non-empty-string
51+
*
5052
* @psalm-readonly-allow-private-mutation
5153
*/
5254
public string $temp = self::DEFAULT_TEMP_STREAM;
5355

5456
/**
5557
* @var int<1, max>
58+
*
5659
* @psalm-readonly-allow-private-mutation
5760
*/
5861
public int $chunkSize = self::DEFAULT_CHUNK_SIZE;
@@ -63,12 +66,12 @@ final class SourceFactory implements SourceFactoryInterface
6366
private array $providers = [];
6467

6568
/**
66-
* @param non-empty-string $algo Hashing algorithm for the sources.
67-
* @param non-empty-string $temp The name of the temporary stream, which is
68-
* used as a resource during the reading of the source.
69-
* @param int<1, max> $chunkSize The chunk size used while non-blocking
70-
* reading the file inside the {@see \Fiber} context.
71-
* @param list<SourceProviderInterface> $providers List of source providers.
69+
* @param non-empty-string $algo hashing algorithm for the sources
70+
* @param non-empty-string $temp the name of the temporary stream, which is
71+
* used as a resource during the reading of the source
72+
* @param int<1, max> $chunkSize the chunk size used while non-blocking
73+
* reading the file inside the {@see \Fiber} context
74+
* @param list<SourceProviderInterface> $providers list of source providers
7275
*/
7376
public function __construct(
7477
string $algo = self::DEFAULT_HASH_ALGO,
@@ -136,7 +139,7 @@ public function create($source): ReadableInterface
136139
throw NotCreatableException::fromInvalidType($source);
137140
}
138141

139-
public function createFromString(string $content = '', string $name = null): ReadableInterface
142+
public function createFromString(string $content = '', ?string $name = null): ReadableInterface
140143
{
141144
assert($name !== '', 'Name must not be empty');
142145

@@ -163,7 +166,7 @@ public function createFromFile(string $filename): FileInterface
163166
/**
164167
* @throws NotReadableException
165168
*/
166-
public function createFromStream($stream, string $name = null): ReadableInterface
169+
public function createFromStream($stream, ?string $name = null): ReadableInterface
167170
{
168171
assert($name !== '', 'Name must not be empty');
169172

src/SourceFactoryTrait.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Phplrt\Source;
66

7-
use Phplrt\Contracts\Source\SourceFactoryInterface;
87
use Phplrt\Contracts\Source\FileInterface;
98
use Phplrt\Contracts\Source\ReadableInterface;
109
use Phplrt\Contracts\Source\SourceExceptionInterface;
10+
use Phplrt\Contracts\Source\SourceFactoryInterface;
1111
use Psr\Http\Message\StreamInterface;
1212

1313
trait SourceFactoryTrait
@@ -31,7 +31,6 @@ public static function getSourceFactory(): SourceFactoryInterface
3131
* ? FileInterface
3232
* : ReadableInterface)
3333
* )
34-
*
3534
* @throws SourceExceptionInterface
3635
*
3736
* @psalm-suppress NoValue : Allow any value
@@ -49,26 +48,24 @@ public static function new($source): ReadableInterface
4948

5049
/**
5150
* @psalm-taint-sink file $pathname
52-
*
5351
* @param non-empty-string|null $pathname
5452
*
5553
* @return ($pathname is null ? ReadableInterface : FileInterface)
5654
* @throws SourceExceptionInterface
5755
*/
58-
public static function empty(string $pathname = null): ReadableInterface
56+
public static function empty(?string $pathname = null): ReadableInterface
5957
{
6058
return static::fromSources('', $pathname);
6159
}
6260

6361
/**
6462
* @psalm-taint-sink file $pathname
65-
*
6663
* @param non-empty-string|null $pathname
6764
*
6865
* @return ($pathname is null ? ReadableInterface : FileInterface)
6966
* @throws SourceExceptionInterface
7067
*/
71-
public static function fromSources(string $sources, string $pathname = null): ReadableInterface
68+
public static function fromSources(string $sources, ?string $pathname = null): ReadableInterface
7269
{
7370
$factory = static::getSourceFactory();
7471

@@ -115,7 +112,7 @@ public static function fromPathname(string $pathname): FileInterface
115112
*
116113
* @deprecated since phplrt 3.4 and will be removed in 4.0, use {@see fromResource()} instead.
117114
*/
118-
public static function fromPsrStream(StreamInterface $stream, string $pathname = null): ReadableInterface
115+
public static function fromPsrStream(StreamInterface $stream, ?string $pathname = null): ReadableInterface
119116
{
120117
trigger_deprecation('phplrt/source', '3.4', <<<'MSG'
121118
Using "%s::fromPsrStream($stream)" with %s argument is deprecated,
@@ -132,7 +129,7 @@ public static function fromPsrStream(StreamInterface $stream, string $pathname =
132129
* @return ($pathname is null ? ReadableInterface : FileInterface)
133130
* @throws SourceExceptionInterface
134131
*/
135-
public static function fromResource($resource, string $pathname = null): ReadableInterface
132+
public static function fromResource($resource, ?string $pathname = null): ReadableInterface
136133
{
137134
$factory = static::getSourceFactory();
138135

src/Stream.php

+11-7
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,37 @@ class Stream extends Readable
1515
* reading the data.
1616
*
1717
* @var int<0, max>
18+
*
1819
* @psalm-readonly-allow-private-mutation
1920
*/
2021
private int $offset;
2122

2223
/**
2324
* @var resource
25+
*
2426
* @psalm-readonly-allow-private-mutation
2527
*/
2628
private $stream;
2729

2830
/**
2931
* @var non-empty-string
32+
*
3033
* @psalm-readonly-allow-private-mutation
3134
*/
3235
private string $algo = SourceFactory::DEFAULT_HASH_ALGO;
3336

3437
/**
3538
* @var int<1, max>
39+
*
3640
* @psalm-readonly-allow-private-mutation
3741
*/
3842
private int $chunkSize = SourceFactory::DEFAULT_CHUNK_SIZE;
3943

4044
/**
4145
* @param resource $stream
42-
* @param non-empty-string $algo Hashing algorithm for the source.
43-
* @param int<1, max> $chunkSize The chunk size used while non-blocking
44-
* reading the file inside the {@see \Fiber}.
46+
* @param non-empty-string $algo hashing algorithm for the source
47+
* @param int<1, max> $chunkSize the chunk size used while non-blocking
48+
* reading the file inside the {@see \Fiber}
4549
*/
4650
public function __construct(
4751
$stream,
@@ -154,10 +158,10 @@ public function __serialize(): array
154158
}
155159

156160
return [
157-
'uri' => $meta['uri'],
158-
'mode' => $meta['mode'],
159-
'seek' => $this->offset,
160-
'algo' => $this->algo,
161+
'uri' => $meta['uri'],
162+
'mode' => $meta['mode'],
163+
'seek' => $this->offset,
164+
'algo' => $this->algo,
161165
'chunk' => $this->chunkSize,
162166
];
163167
}

src/VirtualFile.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ class VirtualFile extends Source implements VirtualFileInterface
88
{
99
/**
1010
* @var non-empty-string
11+
*
1112
* @psalm-readonly-allow-private-mutation
1213
*/
1314
private string $filename;
1415

1516
/**
1617
* @psalm-taint-sink file $filename
1718
* @psalm-taint-sink file $temp
18-
*
1919
* @param non-empty-string $filename
2020
* @param non-empty-string $algo
2121
* @param non-empty-string $temp

src/VirtualStreamingFile.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ class VirtualStreamingFile extends Stream implements VirtualFileInterface
88
{
99
/**
1010
* @var non-empty-string
11+
*
1112
* @psalm-readonly-allow-private-mutation
1213
*/
1314
private string $filename;
1415

1516
/**
1617
* @psalm-taint-sink file $filename
17-
*
1818
* @param non-empty-string $filename
1919
* @param resource $stream
2020
* @param non-empty-string $algo

0 commit comments

Comments
 (0)