Skip to content

Commit 2c73db9

Browse files
committed
Add PHP 8.4 (alpha build) tests support
1 parent 278a169 commit 2c73db9

11 files changed

+46
-49
lines changed

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

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

2019
/**
2120
* @var non-empty-string
22-
*
2321
* @psalm-readonly-allow-private-mutation
2422
*/
2523
private string $algo = SourceFactory::DEFAULT_HASH_ALGO;
2624

2725
/**
2826
* @var int<1, max>
29-
*
3027
* @psalm-readonly-allow-private-mutation
3128
*/
3229
private int $chunkSize = SourceFactory::DEFAULT_CHUNK_SIZE;
3330

3431
/**
3532
* @psalm-taint-sink file $filename
33+
*
3634
* @param non-empty-string $filename
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}
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}.
4038
*/
4139
public function __construct(
4240
string $filename,

src/Provider/PsrStreamSourceProvider.php

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
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;
811
use Phplrt\Source\SourceFactory;
912
use Psr\Http\Message\StreamInterface;
1013

src/Provider/SourceProviderInterface.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
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-
* @throws SourceExceptionInterface in case of an error in creating the
19-
* source object
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.
2021
*/
2122
public function create($source): ?ReadableInterface;
2223
}

src/Source.php

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

2929
/**
3030
* @var non-empty-string
31-
*
3231
* @psalm-readonly-allow-private-mutation
3332
*/
3433
private string $algo = SourceFactory::DEFAULT_HASH_ALGO;
3534

3635
/**
3736
* @var non-empty-string
38-
*
3937
* @psalm-readonly-allow-private-mutation
4038
*/
4139
private string $temp = SourceFactory::DEFAULT_TEMP_STREAM;
4240

4341
/**
4442
* @psalm-taint-sink file $temp
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
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.
4847
*/
4948
public function __construct(
5049
string $content,

src/SourceFactory.php

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

55
namespace Phplrt\Source;
66

7+
use Phplrt\Contracts\Source\SourceFactoryInterface;
78
use Phplrt\Contracts\Source\FileInterface;
89
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,21 +41,18 @@ final class SourceFactory implements SourceFactoryInterface
4141

4242
/**
4343
* @var non-empty-string
44-
*
4544
* @psalm-readonly-allow-private-mutation
4645
*/
4746
public string $algo = self::DEFAULT_HASH_ALGO;
4847

4948
/**
5049
* @var non-empty-string
51-
*
5250
* @psalm-readonly-allow-private-mutation
5351
*/
5452
public string $temp = self::DEFAULT_TEMP_STREAM;
5553

5654
/**
5755
* @var int<1, max>
58-
*
5956
* @psalm-readonly-allow-private-mutation
6057
*/
6158
public int $chunkSize = self::DEFAULT_CHUNK_SIZE;
@@ -66,12 +63,12 @@ final class SourceFactory implements SourceFactoryInterface
6663
private array $providers = [];
6764

6865
/**
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
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.
7572
*/
7673
public function __construct(
7774
string $algo = self::DEFAULT_HASH_ALGO,
@@ -139,7 +136,7 @@ public function create($source): ReadableInterface
139136
throw NotCreatableException::fromInvalidType($source);
140137
}
141138

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

@@ -166,7 +163,7 @@ public function createFromFile(string $filename): FileInterface
166163
/**
167164
* @throws NotReadableException
168165
*/
169-
public function createFromStream($stream, ?string $name = null): ReadableInterface
166+
public function createFromStream($stream, string $name = null): ReadableInterface
170167
{
171168
assert($name !== '', 'Name must not be empty');
172169

src/SourceFactoryTrait.php

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

55
namespace Phplrt\Source;
66

7+
use Phplrt\Contracts\Source\SourceFactoryInterface;
78
use Phplrt\Contracts\Source\FileInterface;
89
use Phplrt\Contracts\Source\ReadableInterface;
910
use Phplrt\Contracts\Source\SourceExceptionInterface;
10-
use Phplrt\Contracts\Source\SourceFactoryInterface;
1111
use Psr\Http\Message\StreamInterface;
1212

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

4950
/**
5051
* @psalm-taint-sink file $pathname
52+
*
5153
* @param non-empty-string|null $pathname
5254
*
5355
* @return ($pathname is null ? ReadableInterface : FileInterface)
5456
* @throws SourceExceptionInterface
5557
*/
56-
public static function empty(?string $pathname = null): ReadableInterface
58+
public static function empty(string $pathname = null): ReadableInterface
5759
{
5860
return static::fromSources('', $pathname);
5961
}
6062

6163
/**
6264
* @psalm-taint-sink file $pathname
65+
*
6366
* @param non-empty-string|null $pathname
6467
*
6568
* @return ($pathname is null ? ReadableInterface : FileInterface)
6669
* @throws SourceExceptionInterface
6770
*/
68-
public static function fromSources(string $sources, ?string $pathname = null): ReadableInterface
71+
public static function fromSources(string $sources, string $pathname = null): ReadableInterface
6972
{
7073
$factory = static::getSourceFactory();
7174

@@ -112,7 +115,7 @@ public static function fromPathname(string $pathname): FileInterface
112115
*
113116
* @deprecated since phplrt 3.4 and will be removed in 4.0, use {@see fromResource()} instead.
114117
*/
115-
public static function fromPsrStream(StreamInterface $stream, ?string $pathname = null): ReadableInterface
118+
public static function fromPsrStream(StreamInterface $stream, string $pathname = null): ReadableInterface
116119
{
117120
trigger_deprecation('phplrt/source', '3.4', <<<'MSG'
118121
Using "%s::fromPsrStream($stream)" with %s argument is deprecated,
@@ -129,7 +132,7 @@ public static function fromPsrStream(StreamInterface $stream, ?string $pathname
129132
* @return ($pathname is null ? ReadableInterface : FileInterface)
130133
* @throws SourceExceptionInterface
131134
*/
132-
public static function fromResource($resource, ?string $pathname = null): ReadableInterface
135+
public static function fromResource($resource, string $pathname = null): ReadableInterface
133136
{
134137
$factory = static::getSourceFactory();
135138

src/Stream.php

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

2322
/**
2423
* @var resource
25-
*
2624
* @psalm-readonly-allow-private-mutation
2725
*/
2826
private $stream;
2927

3028
/**
3129
* @var non-empty-string
32-
*
3330
* @psalm-readonly-allow-private-mutation
3431
*/
3532
private string $algo = SourceFactory::DEFAULT_HASH_ALGO;
3633

3734
/**
3835
* @var int<1, max>
39-
*
4036
* @psalm-readonly-allow-private-mutation
4137
*/
4238
private int $chunkSize = SourceFactory::DEFAULT_CHUNK_SIZE;
4339

4440
/**
4541
* @param resource $stream
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}
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}.
4945
*/
5046
public function __construct(
5147
$stream,
@@ -158,10 +154,10 @@ public function __serialize(): array
158154
}
159155

160156
return [
161-
'uri' => $meta['uri'],
162-
'mode' => $meta['mode'],
163-
'seek' => $this->offset,
164-
'algo' => $this->algo,
157+
'uri' => $meta['uri'],
158+
'mode' => $meta['mode'],
159+
'seek' => $this->offset,
160+
'algo' => $this->algo,
165161
'chunk' => $this->chunkSize,
166162
];
167163
}

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-
*
1211
* @psalm-readonly-allow-private-mutation
1312
*/
1413
private string $filename;
1514

1615
/**
1716
* @psalm-taint-sink file $filename
1817
* @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-
*
1211
* @psalm-readonly-allow-private-mutation
1312
*/
1413
private string $filename;
1514

1615
/**
1716
* @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)