Skip to content

Commit 263b9c6

Browse files
authored
Merge pull request #11 from Innmind/no-discard
Add `NoDiscard` attributes
2 parents c102a11 + ae9703b commit 263b9c6

11 files changed

Lines changed: 52 additions & 0 deletions

File tree

psalm.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@
1414
<directory name="vendor" />
1515
</ignoreFiles>
1616
</projectFiles>
17+
<issueHandlers>
18+
<UndefinedAttributeClass errorLevel="suppress" />
19+
</issueHandlers>
1720
</psalm>

src/Crontab.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ private function __construct(Command $command, Job ...$jobs)
4141
/**
4242
* @return Attempt<SideEffect>
4343
*/
44+
#[\NoDiscard]
4445
public function __invoke(Server $server): Attempt
4546
{
4647
$installOn = Script::of($this->command);
@@ -52,6 +53,7 @@ public function __invoke(Server $server): Attempt
5253
* @no-named-arguments
5354
* @psalm-pure
5455
*/
56+
#[\NoDiscard]
5557
public static function forConnectedUser(Job ...$jobs): self
5658
{
5759
return new self(Command::foreground('crontab'), ...$jobs);
@@ -63,6 +65,7 @@ public static function forConnectedUser(Job ...$jobs): self
6365
*
6466
* @param non-empty-string $user
6567
*/
68+
#[\NoDiscard]
6669
public static function forUser(string $user, Job ...$jobs): self
6770
{
6871
return new self(

src/Job.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function __construct(Schedule $schedule, Command $command)
3232
*
3333
* @throws \DomainException
3434
*/
35+
#[\NoDiscard]
3536
public static function of(string $value): self
3637
{
3738
return self::attempt($value)->unwrap();
@@ -42,6 +43,7 @@ public static function of(string $value): self
4243
*
4344
* @return Maybe<self>
4445
*/
46+
#[\NoDiscard]
4547
public static function maybe(string $value): Maybe
4648
{
4749
return self::attempt($value)->maybe();
@@ -52,6 +54,7 @@ public static function maybe(string $value): Maybe
5254
*
5355
* @return Attempt<self>
5456
*/
57+
#[\NoDiscard]
5558
public static function attempt(string $value): Attempt
5659
{
5760
$parts = Str::of($value)
@@ -78,6 +81,7 @@ public static function attempt(string $value): Attempt
7881
)));
7982
}
8083

84+
#[\NoDiscard]
8185
public function toString(): string
8286
{
8387
$command = $this->command->environment()->reduce(

src/Job/Schedule.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function __construct(
4747
*
4848
* @throws \DomainException
4949
*/
50+
#[\NoDiscard]
5051
public static function of(string $value): self
5152
{
5253
return self::maybe($value)->match(
@@ -60,6 +61,7 @@ public static function of(string $value): self
6061
*
6162
* @return Maybe<self>
6263
*/
64+
#[\NoDiscard]
6365
public static function maybe(string $value): Maybe
6466
{
6567
$parts = Str::of($value)->split(' ');
@@ -104,6 +106,7 @@ public static function maybe(string $value): Maybe
104106
/**
105107
* @psalm-pure
106108
*/
109+
#[\NoDiscard]
107110
public static function everyMinute(): self
108111
{
109112
return new self(
@@ -120,6 +123,7 @@ public static function everyMinute(): self
120123
*
121124
* @param int<0, 59> $minute
122125
*/
126+
#[\NoDiscard]
123127
public static function everyHourAt(int $minute): self
124128
{
125129
return new self(
@@ -137,6 +141,7 @@ public static function everyHourAt(int $minute): self
137141
* @param int<0, 23> $hour
138142
* @param int<0, 59> $minute
139143
*/
144+
#[\NoDiscard]
140145
public static function everyDayAt(int $hour, int $minute): self
141146
{
142147
return new self(
@@ -154,6 +159,7 @@ public static function everyDayAt(int $hour, int $minute): self
154159
* @param int<0, 23> $hour
155160
* @param int<0, 59> $minute
156161
*/
162+
#[\NoDiscard]
157163
public static function everyMondayAt(int $hour, int $minute): self
158164
{
159165
return new self(
@@ -171,6 +177,7 @@ public static function everyMondayAt(int $hour, int $minute): self
171177
* @param int<0, 23> $hour
172178
* @param int<0, 59> $minute
173179
*/
180+
#[\NoDiscard]
174181
public static function everyTuesdayAt(int $hour, int $minute): self
175182
{
176183
return new self(
@@ -188,6 +195,7 @@ public static function everyTuesdayAt(int $hour, int $minute): self
188195
* @param int<0, 23> $hour
189196
* @param int<0, 59> $minute
190197
*/
198+
#[\NoDiscard]
191199
public static function everyWednesdayAt(int $hour, int $minute): self
192200
{
193201
return new self(
@@ -205,6 +213,7 @@ public static function everyWednesdayAt(int $hour, int $minute): self
205213
* @param int<0, 23> $hour
206214
* @param int<0, 59> $minute
207215
*/
216+
#[\NoDiscard]
208217
public static function everyThursdayAt(int $hour, int $minute): self
209218
{
210219
return new self(
@@ -222,6 +231,7 @@ public static function everyThursdayAt(int $hour, int $minute): self
222231
* @param int<0, 23> $hour
223232
* @param int<0, 59> $minute
224233
*/
234+
#[\NoDiscard]
225235
public static function everyFridayAt(int $hour, int $minute): self
226236
{
227237
return new self(
@@ -239,6 +249,7 @@ public static function everyFridayAt(int $hour, int $minute): self
239249
* @param int<0, 23> $hour
240250
* @param int<0, 59> $minute
241251
*/
252+
#[\NoDiscard]
242253
public static function everySaturdayAt(int $hour, int $minute): self
243254
{
244255
return new self(
@@ -256,6 +267,7 @@ public static function everySaturdayAt(int $hour, int $minute): self
256267
* @param int<0, 23> $hour
257268
* @param int<0, 59> $minute
258269
*/
270+
#[\NoDiscard]
259271
public static function everySundayAt(int $hour, int $minute): self
260272
{
261273
return new self(
@@ -267,6 +279,7 @@ public static function everySundayAt(int $hour, int $minute): self
267279
);
268280
}
269281

282+
#[\NoDiscard]
270283
public function toString(): string
271284
{
272285
return \sprintf(

src/Job/Schedule/DaysOfMonth.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private function __construct(string $value)
2424
*
2525
* @throws \DomainException
2626
*/
27+
#[\NoDiscard]
2728
public static function of(string $value): self
2829
{
2930
return self::maybe($value)->match(
@@ -37,6 +38,7 @@ public static function of(string $value): self
3738
*
3839
* @return Maybe<self>
3940
*/
41+
#[\NoDiscard]
4042
public static function maybe(string $value): Maybe
4143
{
4244
return Maybe::just($value)
@@ -47,6 +49,7 @@ public static function maybe(string $value): Maybe
4749
/**
4850
* @psalm-pure
4951
*/
52+
#[\NoDiscard]
5053
public static function each(): self
5154
{
5255
return new self('*');
@@ -57,11 +60,13 @@ public static function each(): self
5760
*
5861
* @param int<1, 31> $day
5962
*/
63+
#[\NoDiscard]
6064
public static function at(int $day): self
6165
{
6266
return new self((string) $day);
6367
}
6468

69+
#[\NoDiscard]
6570
public function toString(): string
6671
{
6772
return $this->value;

src/Job/Schedule/DaysOfWeek.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private function __construct(string $value)
2424
*
2525
* @throws \DomainException
2626
*/
27+
#[\NoDiscard]
2728
public static function of(string $value): self
2829
{
2930
return self::maybe($value)->match(
@@ -37,6 +38,7 @@ public static function of(string $value): self
3738
*
3839
* @return Maybe<self>
3940
*/
41+
#[\NoDiscard]
4042
public static function maybe(string $value): Maybe
4143
{
4244
return Maybe::just($value)
@@ -47,6 +49,7 @@ public static function maybe(string $value): Maybe
4749
/**
4850
* @psalm-pure
4951
*/
52+
#[\NoDiscard]
5053
public static function each(): self
5154
{
5255
return new self('*');
@@ -57,11 +60,13 @@ public static function each(): self
5760
*
5861
* @param int<0, 6> $day
5962
*/
63+
#[\NoDiscard]
6064
public static function at(int $day): self
6165
{
6266
return new self((string) $day);
6367
}
6468

69+
#[\NoDiscard]
6570
public function toString(): string
6671
{
6772
return $this->value;

src/Job/Schedule/Hours.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private function __construct(string $value)
2424
*
2525
* @throws \DomainException
2626
*/
27+
#[\NoDiscard]
2728
public static function of(string $value): self
2829
{
2930
return self::maybe($value)->match(
@@ -37,6 +38,7 @@ public static function of(string $value): self
3738
*
3839
* @return Maybe<self>
3940
*/
41+
#[\NoDiscard]
4042
public static function maybe(string $value): Maybe
4143
{
4244
return Maybe::just($value)
@@ -47,6 +49,7 @@ public static function maybe(string $value): Maybe
4749
/**
4850
* @psalm-pure
4951
*/
52+
#[\NoDiscard]
5053
public static function each(): self
5154
{
5255
return new self('*');
@@ -57,11 +60,13 @@ public static function each(): self
5760
*
5861
* @param int<0, 23> $hour
5962
*/
63+
#[\NoDiscard]
6064
public static function at(int $hour): self
6165
{
6266
return new self((string) $hour);
6367
}
6468

69+
#[\NoDiscard]
6570
public function toString(): string
6671
{
6772
return $this->value;

src/Job/Schedule/Minutes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private function __construct(string $value)
2424
*
2525
* @throws \DomainException
2626
*/
27+
#[\NoDiscard]
2728
public static function of(string $value): self
2829
{
2930
return self::maybe($value)->match(
@@ -37,6 +38,7 @@ public static function of(string $value): self
3738
*
3839
* @return Maybe<self>
3940
*/
41+
#[\NoDiscard]
4042
public static function maybe(string $value): Maybe
4143
{
4244
return Maybe::just($value)
@@ -47,6 +49,7 @@ public static function maybe(string $value): Maybe
4749
/**
4850
* @psalm-pure
4951
*/
52+
#[\NoDiscard]
5053
public static function each(): self
5154
{
5255
return new self('*');
@@ -57,11 +60,13 @@ public static function each(): self
5760
*
5861
* @param int<0, 59> $minute
5962
*/
63+
#[\NoDiscard]
6064
public static function at(int $minute): self
6165
{
6266
return new self((string) $minute);
6367
}
6468

69+
#[\NoDiscard]
6570
public function toString(): string
6671
{
6772
return $this->value;

src/Job/Schedule/Months.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private function __construct(string $value)
2424
*
2525
* @throws \DomainException
2626
*/
27+
#[\NoDiscard]
2728
public static function of(string $value): self
2829
{
2930
return self::maybe($value)->match(
@@ -37,6 +38,7 @@ public static function of(string $value): self
3738
*
3839
* @return Maybe<self>
3940
*/
41+
#[\NoDiscard]
4042
public static function maybe(string $value): Maybe
4143
{
4244
return Maybe::just($value)
@@ -47,6 +49,7 @@ public static function maybe(string $value): Maybe
4749
/**
4850
* @psalm-pure
4951
*/
52+
#[\NoDiscard]
5053
public static function each(): self
5154
{
5255
return new self('*');
@@ -57,11 +60,13 @@ public static function each(): self
5760
*
5861
* @param int<1, 12> $month
5962
*/
63+
#[\NoDiscard]
6064
public static function at(int $month): self
6165
{
6266
return new self((string) $month);
6367
}
6468

69+
#[\NoDiscard]
6570
public function toString(): string
6671
{
6772
return $this->value;

src/Job/Schedule/Range.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function __construct(string $pattern)
1818
$this->pattern = $pattern;
1919
}
2020

21+
#[\NoDiscard]
2122
public function __invoke(string $value): bool
2223
{
2324
if ($value === '*') {

0 commit comments

Comments
 (0)