Skip to content

Commit bcda228

Browse files
committed
chore: miscellaneous changes
Signed-off-by: azjezz <azjezz@protonmail.com>
1 parent f7d74fc commit bcda228

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+501
-257
lines changed

docs/component/class.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
- [has_method](./../../src/Psl/Class/has_method.php#L14)
1919
- [is_abstract](./../../src/Psl/Class/is_abstract.php#L14)
2020
- [is_final](./../../src/Psl/Class/is_final.php#L14)
21+
- [is_readonly](./../../src/Psl/Class/is_readonly.php#L14)
2122

2223

docs/component/env.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
- [current_exec](./../../src/Psl/Env/current_exec.php#L12)
1818
- [get_var](./../../src/Psl/Env/get_var.php#L19)
1919
- [get_vars](./../../src/Psl/Env/get_vars.php#L14)
20-
- [join_paths](./../../src/Psl/Env/join_paths.php#L18)
20+
- [join_paths](./../../src/Psl/Env/join_paths.php#L20)
2121
- [remove_var](./../../src/Psl/Env/remove_var.php#L19)
2222
- [set_current_dir](./../../src/Psl/Env/set_current_dir.php#L16)
2323
- [set_var](./../../src/Psl/Env/set_var.php#L20)
24-
- [split_paths](./../../src/Psl/Env/split_paths.php#L16)
24+
- [split_paths](./../../src/Psl/Env/split_paths.php#L18)
2525
- [temp_dir](./../../src/Psl/Env/temp_dir.php#L21)
2626

2727

docs/component/network.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#### `Classes`
2121

22-
- [Address](./../../src/Psl/Network/Address.php#L7)
22+
- [Address](./../../src/Psl/Network/Address.php#L10)
2323
- [SocketOptions](./../../src/Psl/Network/SocketOptions.php#L14)
2424

2525
#### `Enums`

docs/component/option.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
#### `Functions`
1414

15-
- [from_nullable](./../../src/Psl/Option/from_nullable.php#L16)
16-
- [none](./../../src/Psl/Option/none.php#L12)
17-
- [some](./../../src/Psl/Option/some.php#L16)
15+
- [from_nullable](./../../src/Psl/Option/from_nullable.php#L18)
16+
- [none](./../../src/Psl/Option/none.php#L14)
17+
- [some](./../../src/Psl/Option/some.php#L18)
1818

1919
#### `Classes`
2020

docs/component/random-sequence.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818

1919
- [MersenneTwisterPHPVariantSequence](./../../src/Psl/RandomSequence/MersenneTwisterPHPVariantSequence.php#L10)
2020
- [MersenneTwisterSequence](./../../src/Psl/RandomSequence/MersenneTwisterSequence.php#L10)
21-
- [SecureSequence](./../../src/Psl/RandomSequence/SecureSequence.php#L15)
21+
- [SecureSequence](./../../src/Psl/RandomSequence/SecureSequence.php#L13)
2222

2323

src/Psl/Async/Awaitable.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* @implements PromiseInterface<T>
2929
*/
30-
final class Awaitable implements PromiseInterface
30+
final readonly class Awaitable implements PromiseInterface
3131
{
3232
private State $state;
3333

@@ -117,6 +117,8 @@ public static function error(Throwable $throwable): self
117117

118118
/**
119119
* @return bool True if the operation has completed.
120+
*
121+
* @psalm-mutation-free
120122
*/
121123
public function isComplete(): bool
122124
{

src/Psl/Async/Deferred.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @template T
2020
*/
21-
final class Deferred
21+
final readonly class Deferred
2222
{
2323
/**
2424
* @var Internal\State<T>
@@ -62,6 +62,8 @@ public function error(Throwable $throwable): void
6262

6363
/**
6464
* @return bool True if the operation has completed.
65+
*
66+
* @psalm-mutation-free
6567
*/
6668
public function isComplete(): bool
6769
{
@@ -70,6 +72,8 @@ public function isComplete(): bool
7072

7173
/**
7274
* @return Awaitable<T> The awaitable associated with this Deferred.
75+
*
76+
* @psalm-mutation-free
7377
*/
7478
public function getAwaitable(): Awaitable
7579
{

src/Psl/Async/Internal/State.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public function error(Throwable $throwable): void
133133

134134
/**
135135
* Suppress the `Throwable`s thrown to the loop error handler if and operation error is not handled by a callback.
136+
*
137+
* @psalm-external-mutation-free
136138
*/
137139
public function ignore(): void
138140
{
@@ -141,6 +143,8 @@ public function ignore(): void
141143

142144
/**
143145
* @return bool True if the operation has completed.
146+
*
147+
* @psalm-mutation-free
144148
*/
145149
public function isComplete(): bool
146150
{

src/Psl/Async/OptionalIncrementalTimeout.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ public function __construct(?float $timeout, Closure $handler)
4646
* If the timeout has already been exceeded, the handler is invoked, and its return value is provided.
4747
*
4848
* @return float|null The remaining time in seconds, null if no timeout is set, or the handler's return value if the timeout is exceeded.
49-
*
50-
* @external-mutation-free
5149
*/
5250
public function getRemaining(): ?float
5351
{

src/Psl/Async/Scheduler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @codeCoverageIgnore
2020
*/
21-
final class Scheduler
21+
final readonly class Scheduler
2222
{
2323
private function __construct()
2424
{

src/Psl/Channel/ChannelInterface.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface ChannelInterface extends Countable
1616
*
1717
* @return null|positive-int
1818
*
19-
* @mutation-free
19+
* @psalm-mutation-free
2020
*/
2121
public function getCapacity(): ?int;
2222

@@ -30,7 +30,7 @@ public function close(): void;
3030
/**
3131
* Returns true if the channel is closed.
3232
*
33-
* @mutation-free
33+
* @psalm-mutation-free
3434
*/
3535
public function isClosed(): bool;
3636

@@ -39,7 +39,7 @@ public function isClosed(): bool;
3939
*
4040
* @return int<0, max>
4141
*
42-
* @mutation-free
42+
* @psalm-mutation-free
4343
*/
4444
public function count(): int;
4545

@@ -48,14 +48,14 @@ public function count(): int;
4848
*
4949
* Unbounded channels are never full.
5050
*
51-
* @mutation-free
51+
* @psalm-mutation-free
5252
*/
5353
public function isFull(): bool;
5454

5555
/**
5656
* Returns true if the channel is empty.
5757
*
58-
* @mutation-free
58+
* @psalm-mutation-free
5959
*/
6060
public function isEmpty(): bool;
6161
}

src/Psl/Channel/Internal/BoundedChannelState.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,24 @@ final class BoundedChannelState implements ChannelInterface
3737
*/
3838
private array $messages = [];
3939

40+
/**
41+
* @var int<0, max>
42+
*/
4043
private int $size = 0;
4144

4245
public bool $closed = false;
4346

47+
/**
48+
* @var positive-int
49+
*/
50+
private readonly int $capacity;
51+
4452
/**
4553
* @param positive-int $capacity
4654
*/
47-
public function __construct(
48-
private int $capacity
49-
) {
55+
public function __construct(int $capacity)
56+
{
57+
$this->capacity = $capacity;
5058
}
5159

5260
public function __destruct()
@@ -71,7 +79,9 @@ public function waitForMessage(Suspension $suspension): void
7179
}
7280

7381
/**
74-
* {@inheritDoc}
82+
* @return positive-int
83+
*
84+
* @psalm-mutation-free
7585
*/
7686
public function getCapacity(): int
7787
{
@@ -99,31 +109,33 @@ public function close(): void
99109
}
100110

101111
/**
102-
* {@inheritDoc}
112+
* @psalm-mutation-free
103113
*/
104114
public function isClosed(): bool
105115
{
106116
return $this->closed;
107117
}
108118

109119
/**
110-
* {@inheritDoc}
120+
* @return int<0, max>
121+
*
122+
* @psalm-mutation-free
111123
*/
112124
public function count(): int
113125
{
114126
return $this->size;
115127
}
116128

117129
/**
118-
* {@inheritDoc}
130+
* @psalm-mutation-free
119131
*/
120132
public function isFull(): bool
121133
{
122134
return $this->capacity === $this->size;
123135
}
124136

125137
/**
126-
* {@inheritDoc}
138+
* @psalm-mutation-free
127139
*/
128140
public function isEmpty(): bool
129141
{
@@ -171,6 +183,7 @@ public function receive(): mixed
171183
}
172184

173185
$item = array_shift($this->messages);
186+
/** @psalm-suppress InvalidPropertyAssignmentValue - The size is always in sync with messages */
174187
$this->size--;
175188

176189
if ($suspension = array_shift($this->waitingForSpace)) {

src/Psl/Channel/Internal/ChannelSideTrait.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ trait ChannelSideTrait
1515
protected UnboundedChannelState|BoundedChannelState $state;
1616

1717
/**
18-
* @return int<1, max>|null
18+
* Returns the channel capacity if it’s bounded.
19+
*
20+
* @return null|positive-int
21+
*
22+
* @psalm-mutation-free
1923
*/
2024
public function getCapacity(): ?int
2125
{
@@ -28,25 +32,36 @@ public function close(): void
2832
$this->state->close();
2933
}
3034

35+
/**
36+
* @psalm-mutation-free
37+
*/
3138
public function isClosed(): bool
3239
{
3340
return $this->state->isClosed();
3441
}
3542

3643
/**
3744
* @return int<0, max>
45+
*
46+
* @psalm-mutation-free
3847
*/
3948
public function count(): int
4049
{
4150
/** @var int<0, max> */
4251
return $this->state->count();
4352
}
4453

54+
/**
55+
* @psalm-mutation-free
56+
*/
4557
public function isFull(): bool
4658
{
4759
return $this->state->isFull();
4860
}
4961

62+
/**
63+
* @psalm-mutation-free
64+
*/
5065
public function isEmpty(): bool
5166
{
5267
return $this->state->isEmpty();

src/Psl/Channel/Internal/UnboundedChannelState.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ public function waitForMessage(Suspension $suspension): void
4444
}
4545

4646
/**
47-
* {@inheritDoc}
47+
* @return null
48+
*
49+
* @psalm-mutation-free
4850
*/
49-
public function getCapacity(): ?int
51+
public function getCapacity(): null
5052
{
5153
return null;
5254
}
@@ -66,31 +68,33 @@ public function close(): void
6668
}
6769

6870
/**
69-
* {@inheritDoc}
71+
* @psalm-mutation-free
7072
*/
7173
public function isClosed(): bool
7274
{
7375
return $this->closed;
7476
}
7577

7678
/**
77-
* {@inheritDoc}
79+
* @return int<0, max>
80+
*
81+
* @psalm-mutation-free
7882
*/
7983
public function count(): int
8084
{
8185
return count($this->messages);
8286
}
8387

8488
/**
85-
* {@inheritDoc}
89+
* @psalm-mutation-free
8690
*/
8791
public function isFull(): bool
8892
{
8993
return false;
9094
}
9195

9296
/**
93-
* {@inheritDoc}
97+
* @psalm-mutation-free
9498
*/
9599
public function isEmpty(): bool
96100
{

src/Psl/Class/is_readonly.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Psl\Class;
6+
7+
use ReflectionClass;
8+
9+
/**
10+
* Checks if class is final.
11+
*
12+
* @param class-string $class_name
13+
*/
14+
function is_readonly(string $class_name): bool
15+
{
16+
/** @psalm-suppress MissingThrowsDocblock */
17+
return (new ReflectionClass($class_name))->isReadOnly();
18+
}

src/Psl/Collection/Exception/OutOfBoundsException.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
final class OutOfBoundsException extends Exception\OutOfBoundsException implements ExceptionInterface
1111
{
12+
/**
13+
* @psalm-mutation-free
14+
*/
1215
public static function for(string|int $offset): OutOfBoundsException
1316
{
1417
return new self(Str\format('Key (%s) was out-of-bounds.', $offset));

0 commit comments

Comments
 (0)