Skip to content

Commit bf461e1

Browse files
committed
Apply phpcs
1 parent 6ec0933 commit bf461e1

12 files changed

Lines changed: 171 additions & 149 deletions

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
php: [ '8.1', '8.2', '8.3', '8.4' ]
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:

composer.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^8.1",
20-
"phplrt/source-contracts": "^3.7",
20+
"phplrt/source-contracts": "^4.0",
2121
"symfony/deprecation-contracts": "^2.5|^3.0"
2222
},
2323
"autoload": {
@@ -28,7 +28,6 @@
2828
"require-dev": {
2929
"phpunit/phpunit": "^10.5|^11.0",
3030
"psr/http-message": "^1.0|^2.0",
31-
"httpsoft/http-message": "^1.1",
3231
"phpstan/extension-installer": "^1.4",
3332
"phpstan/phpstan": "^1.11",
3433
"phpstan/phpstan-strict-rules": "^1.6"
@@ -39,19 +38,16 @@
3938
}
4039
},
4140
"provide": {
42-
"phplrt/source-contracts-implementation": "^3.7"
41+
"phplrt/source-contracts-implementation": "^4.0"
4342
},
4443
"extra": {
4544
"branch-alias": {
46-
"dev-master": "3.x-dev",
47-
"dev-main": "3.x-dev"
45+
"dev-master": "4.x-dev",
46+
"dev-main": "4.x-dev"
4847
}
4948
},
5049
"config": {
51-
"sort-packages": true,
52-
"allow-plugins": {
53-
"phpstan/extension-installer": true
54-
}
50+
"sort-packages": true
5551
},
5652
"minimum-stability": "dev",
5753
"prefer-stable": true

src/Exception/NotCreatableException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static function fromInvalidType(mixed $source): self
2222
{
2323
$message = \vsprintf('Cannot create %s instance from %s', [
2424
ReadableInterface::class,
25-
\get_debug_type($source)
25+
\get_debug_type($source),
2626
]);
2727

2828
return new static($message, self::CODE_INVALID_TYPE);

src/File.php

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,55 @@
1010

1111
class File extends Readable implements FileInterface
1212
{
13+
/**
14+
* @var non-empty-string
15+
*
16+
* @psalm-readonly-allow-private-mutation
17+
*/
18+
private string $filename;
19+
20+
/**
21+
* @var non-empty-string
22+
*
23+
* @psalm-readonly-allow-private-mutation
24+
*/
25+
private string $algo = SourceFactory::DEFAULT_HASH_ALGO;
26+
27+
/**
28+
* @var int<1, max>
29+
*
30+
* @psalm-readonly-allow-private-mutation
31+
*/
32+
private int $chunkSize = SourceFactory::DEFAULT_CHUNK_SIZE;
33+
1334
/**
1435
* @psalm-taint-sink file $filename
36+
* @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}
1540
*/
1641
public function __construct(
17-
/**
18-
* @var non-empty-string
19-
*/
20-
private readonly string $filename,
21-
/**
22-
* Hashing algorithm for the source.
23-
*
24-
* @var non-empty-string
25-
*/
26-
private readonly string $algo = SourceFactory::DEFAULT_HASH_ALGO,
27-
/**
28-
* The chunk size used while non-blocking reading the file inside
29-
* the {@see \Fiber}.
30-
*
31-
* @var int<1, max>
32-
*/
33-
private readonly int $chunkSize = SourceFactory::DEFAULT_CHUNK_SIZE,
42+
string $filename,
43+
string $algo = SourceFactory::DEFAULT_HASH_ALGO,
44+
int $chunkSize = SourceFactory::DEFAULT_CHUNK_SIZE
3445
) {
3546
assert($filename !== '', 'Filename must not be empty');
3647
assert($algo !== '', 'Hashing algorithm name must not be empty');
3748
assert($chunkSize >= 1, 'Chunk size must be greater than 0');
49+
50+
$this->chunkSize = $chunkSize;
51+
$this->algo = $algo;
52+
$this->filename = $filename;
3853
}
3954

4055
public function getContents(): string
4156
{
4257
try {
43-
if (\Fiber::getCurrent() !== null) {
58+
if (\PHP_MAJOR_VERSION >= 8
59+
&& \PHP_MINOR_VERSION >= 1
60+
&& \Fiber::getCurrent() !== null
61+
) {
4462
return $this->asyncGetContents();
4563
}
4664

@@ -93,7 +111,7 @@ private function syncGetContents(): string
93111
/**
94112
* @throws NotReadableException
95113
*/
96-
public function getStream(): mixed
114+
public function getStream()
97115
{
98116
$stream = \fopen($this->filename, 'rb');
99117

src/MemoizableInterface.php

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

src/Source.php

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,41 @@ class Source extends Readable implements PreferContentReadingInterface
1919
/**
2020
* @var resource|null
2121
*/
22-
private mixed $stream = null;
22+
private $stream;
23+
24+
/**
25+
* @var non-empty-string
26+
*
27+
* @psalm-readonly-allow-private-mutation
28+
*/
29+
private string $algo = SourceFactory::DEFAULT_HASH_ALGO;
30+
31+
/**
32+
* @var non-empty-string
33+
*
34+
* @psalm-readonly-allow-private-mutation
35+
*/
36+
private string $temp = SourceFactory::DEFAULT_TEMP_STREAM;
2337

2438
/**
2539
* @psalm-taint-sink file $temp
40+
* @param non-empty-string $algo hashing algorithm for the source
41+
* @param non-empty-string $temp the name of the temporary stream, which is
42+
* used as a resource during the reading of the source
2643
*/
2744
public function __construct(
28-
private readonly string $content,
2945
/**
30-
* Hashing algorithm for the source.
31-
*
32-
* @var non-empty-string
46+
* @psalm-readonly-allow-private-mutation
3347
*/
34-
private readonly string $algo = SourceFactory::DEFAULT_HASH_ALGO,
35-
/**
36-
* The name of the temporary stream, which is used as a resource during
37-
* the reading of the source.
38-
*
39-
* @var non-empty-string
40-
*/
41-
private readonly string $temp = SourceFactory::DEFAULT_TEMP_STREAM
48+
private string $content,
49+
string $algo = SourceFactory::DEFAULT_HASH_ALGO,
50+
string $temp = SourceFactory::DEFAULT_TEMP_STREAM
4251
) {
4352
assert($algo !== '', 'Hashing algorithm name must not be empty');
4453
assert($temp !== '', 'Temporary stream name must not be empty');
54+
55+
$this->temp = $temp;
56+
$this->algo = $algo;
4557
}
4658

4759
public function getContents(): string
@@ -52,7 +64,7 @@ public function getContents(): string
5264
/**
5365
* @throws NotAccessibleException
5466
*/
55-
public function getStream(): mixed
67+
public function getStream()
5668
{
5769
if (!\is_resource($this->stream)) {
5870
$this->stream = \fopen($this->temp, 'rb+');

src/SourceFactory.php

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,41 +39,54 @@ final class SourceFactory implements SourceFactoryInterface
3939
*/
4040
public const DEFAULT_TEMP_STREAM = 'php://memory';
4141

42+
/**
43+
* @var non-empty-string
44+
*
45+
* @psalm-readonly-allow-private-mutation
46+
*/
47+
public string $algo = self::DEFAULT_HASH_ALGO;
48+
49+
/**
50+
* @var non-empty-string
51+
*
52+
* @psalm-readonly-allow-private-mutation
53+
*/
54+
public string $temp = self::DEFAULT_TEMP_STREAM;
55+
56+
/**
57+
* @var int<1, max>
58+
*
59+
* @psalm-readonly-allow-private-mutation
60+
*/
61+
public int $chunkSize = self::DEFAULT_CHUNK_SIZE;
62+
4263
/**
4364
* @var list<SourceProviderInterface>
4465
*/
4566
private array $providers = [];
4667

4768
/**
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
4874
* @param list<SourceProviderInterface> $providers list of source providers
4975
*/
5076
public function __construct(
51-
/**
52-
* Hashing algorithm for the sources.
53-
*
54-
* @var non-empty-string
55-
*/
56-
public readonly string $algo = self::DEFAULT_HASH_ALGO,
57-
/**
58-
* The name of the temporary stream, which is used as a resource
59-
* during the reading of the source.
60-
*
61-
* @var non-empty-string
62-
*/
63-
public readonly string $temp = self::DEFAULT_TEMP_STREAM,
64-
/**
65-
* The chunk size used while non-blocking reading the file
66-
* inside the {@see \Fiber} context.
67-
*
68-
* @var int<1, max>
69-
*/
70-
public readonly int $chunkSize = self::DEFAULT_CHUNK_SIZE,
77+
string $algo = self::DEFAULT_HASH_ALGO,
78+
string $temp = self::DEFAULT_TEMP_STREAM,
79+
int $chunkSize = self::DEFAULT_CHUNK_SIZE,
7180
iterable $providers = []
7281
) {
7382
assert($algo !== '', 'Hashing algorithm name must not be empty');
7483
assert($temp !== '', 'Temporary stream name must not be empty');
7584
assert($chunkSize >= 1, 'Chunk size must be greater than 0');
7685

86+
$this->chunkSize = $chunkSize;
87+
$this->temp = $temp;
88+
$this->algo = $algo;
89+
7790
$this->providers = [
7891
...$providers,
7992
new PsrStreamSourceProvider($this),

src/SourceFactoryTrait.php

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Phplrt\Contracts\Source\ReadableInterface;
99
use Phplrt\Contracts\Source\SourceExceptionInterface;
1010
use Phplrt\Contracts\Source\SourceFactoryInterface;
11-
use Psr\Http\Message\StreamInterface;
1211

1312
trait SourceFactoryTrait
1413
{
@@ -32,13 +31,11 @@ public static function getSourceFactory(): SourceFactoryInterface
3231
* : ReadableInterface)
3332
* )
3433
* @throws SourceExceptionInterface
34+
*
35+
* @psalm-suppress NoValue : Allow any value
3536
*/
3637
public static function new(mixed $source): ReadableInterface
3738
{
38-
if ($source instanceof StreamInterface) {
39-
return static::fromPsrStream($source);
40-
}
41-
4239
$factory = self::getSourceFactory();
4340

4441
return $factory->create($source);
@@ -49,7 +46,6 @@ public static function new(mixed $source): ReadableInterface
4946
* @param non-empty-string|null $pathname
5047
*
5148
* @return ($pathname is null ? ReadableInterface : FileInterface)
52-
* @throws SourceExceptionInterface
5349
*/
5450
public static function empty(?string $pathname = null): ReadableInterface
5551
{
@@ -61,7 +57,6 @@ public static function empty(?string $pathname = null): ReadableInterface
6157
* @param non-empty-string|null $pathname
6258
*
6359
* @return ($pathname is null ? ReadableInterface : FileInterface)
64-
* @throws SourceExceptionInterface
6560
*/
6661
public static function fromSources(string $sources, ?string $pathname = null): ReadableInterface
6762
{
@@ -102,24 +97,6 @@ public static function fromPathname(string $pathname): FileInterface
10297
return new File($pathname);
10398
}
10499

105-
/**
106-
* @param non-empty-string|null $pathname
107-
*
108-
* @return ($pathname is null ? ReadableInterface : FileInterface)
109-
* @throws SourceExceptionInterface
110-
*
111-
* @deprecated since phplrt 3.4 and will be removed in 4.0, use {@see fromResource()} instead.
112-
*/
113-
public static function fromPsrStream(StreamInterface $stream, ?string $pathname = null): ReadableInterface
114-
{
115-
trigger_deprecation('phplrt/source', '3.4', <<<'MSG'
116-
Using "%s::fromPsrStream($stream)" with %s argument is deprecated,
117-
use "%1$s::fromResource($stream->detach())" instead.
118-
MSG, static::class, $stream::class);
119-
120-
return static::fromResource($stream->detach(), $pathname);
121-
}
122-
123100
/**
124101
* @param resource $resource
125102
* @param non-empty-string|null $pathname

0 commit comments

Comments
 (0)