Skip to content

Commit 9ee0798

Browse files
authored
Merge pull request #20 from Innmind/no-discard
Add `NoDiscard` attributes
2 parents 613b938 + 4a03f86 commit 9ee0798

20 files changed

Lines changed: 63 additions & 0 deletions

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/EnvironmentPath.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ private function __construct(
1616
/**
1717
* @psalm-pure
1818
*/
19+
#[\NoDiscard]
1920
public static function of(string $value): self
2021
{
2122
return new self($value);
2223
}
2324

25+
#[\NoDiscard]
2426
public function toString(): string
2527
{
2628
return $this->value;

src/Server.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ private function __construct(
2727
) {
2828
}
2929

30+
#[\NoDiscard]
3031
public static function osx(
3132
Clock $clock,
3233
Control $control,
@@ -35,13 +36,15 @@ public static function osx(
3536
return new self(OSX::of($clock, $control, $path));
3637
}
3738

39+
#[\NoDiscard]
3840
public static function linux(
3941
Clock $clock,
4042
Control $control,
4143
): self {
4244
return new self(Linux::of($clock, $control));
4345
}
4446

47+
#[\NoDiscard]
4548
public static function logger(self $server, LoggerInterface $logger): self
4649
{
4750
return new self(Logger::of(
@@ -53,6 +56,7 @@ public static function logger(self $server, LoggerInterface $logger): self
5356
/**
5457
* @return Attempt<Cpu>
5558
*/
59+
#[\NoDiscard]
5660
public function cpu(): Attempt
5761
{
5862
return $this->implementation->cpu();
@@ -61,11 +65,13 @@ public function cpu(): Attempt
6165
/**
6266
* @return Attempt<Memory>
6367
*/
68+
#[\NoDiscard]
6469
public function memory(): Attempt
6570
{
6671
return $this->implementation->memory();
6772
}
6873

74+
#[\NoDiscard]
6975
public function processes(): Processes
7076
{
7177
return $this->implementation->processes();
@@ -74,16 +80,19 @@ public function processes(): Processes
7480
/**
7581
* @return Attempt<LoadAverage>
7682
*/
83+
#[\NoDiscard]
7784
public function loadAverage(): Attempt
7885
{
7986
return $this->implementation->loadAverage();
8087
}
8188

89+
#[\NoDiscard]
8290
public function disk(): Disk
8391
{
8492
return $this->implementation->disk();
8593
}
8694

95+
#[\NoDiscard]
8796
public function tmp(): Path
8897
{
8998
return Path::of(\rtrim(\sys_get_temp_dir(), '/').'/');

src/Server/Cpu.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,31 @@ public static function of(
3434
return new self($user, $system, $idle, $cores);
3535
}
3636

37+
#[\NoDiscard]
3738
public function user(): Percentage
3839
{
3940
return $this->user;
4041
}
4142

43+
#[\NoDiscard]
4244
public function system(): Percentage
4345
{
4446
return $this->system;
4547
}
4648

49+
#[\NoDiscard]
4750
public function idle(): Percentage
4851
{
4952
return $this->idle;
5053
}
5154

55+
#[\NoDiscard]
5256
public function cores(): Cores
5357
{
5458
return $this->cores;
5559
}
5660

61+
#[\NoDiscard]
5762
public function toString(): string
5863
{
5964
return \sprintf(

src/Server/Cpu/Cores.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ public static function of(int $value): self
3030
/**
3131
* @return int<1, max>
3232
*/
33+
#[\NoDiscard]
3334
public function toInt(): int
3435
{
3536
return $this->value;
3637
}
3738

39+
#[\NoDiscard]
3840
public function toString(): string
3941
{
4042
return (string) $this->value;

src/Server/Cpu/Percentage.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ public static function maybe(float $value): Maybe
3131
return Maybe::just(new self($value));
3232
}
3333

34+
#[\NoDiscard]
3435
public function toFloat(): float
3536
{
3637
return $this->value;
3738
}
3839

40+
#[\NoDiscard]
3941
public function toString(): string
4042
{
4143
return \sprintf(

src/Server/Disk.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public static function logger(self $disk, LoggerInterface $logger): self
4646
/**
4747
* @return Sequence<Volume>
4848
*/
49+
#[\NoDiscard]
4950
public function volumes(): Sequence
5051
{
5152
return $this->implementation->volumes();
@@ -54,6 +55,7 @@ public function volumes(): Sequence
5455
/**
5556
* @return Maybe<Volume>
5657
*/
58+
#[\NoDiscard]
5759
public function get(MountPoint $point): Maybe
5860
{
5961
return $this->implementation->get($point);

src/Server/Disk/Volume.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,31 @@ public static function of(
3737
return new self($mountPoint, $size, $available, $used, $usage);
3838
}
3939

40+
#[\NoDiscard]
4041
public function mountPoint(): MountPoint
4142
{
4243
return $this->mountPoint;
4344
}
4445

46+
#[\NoDiscard]
4547
public function size(): Bytes
4648
{
4749
return $this->size;
4850
}
4951

52+
#[\NoDiscard]
5053
public function available(): Bytes
5154
{
5255
return $this->available;
5356
}
5457

58+
#[\NoDiscard]
5559
public function used(): Bytes
5660
{
5761
return $this->used;
5862
}
5963

64+
#[\NoDiscard]
6065
public function usage(): Usage
6166
{
6267
return $this->usage;

src/Server/Disk/Volume/MountPoint.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ public static function of(string $value): self
2727
return new self($value);
2828
}
2929

30+
#[\NoDiscard]
3031
public function equals(self $point): bool
3132
{
3233
return $point->is($this->value);
3334
}
3435

36+
#[\NoDiscard]
3537
public function is(string $point): bool
3638
{
3739
return $this->value === $point;
@@ -40,6 +42,7 @@ public function is(string $point): bool
4042
/**
4143
* @return non-empty-string
4244
*/
45+
#[\NoDiscard]
4346
public function toString(): string
4447
{
4548
return $this->value;

src/Server/Disk/Volume/Usage.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ public static function maybe(float $value): Maybe
3131
return Maybe::just(new self($value));
3232
}
3333

34+
#[\NoDiscard]
3435
public function toFloat(): float
3536
{
3637
return $this->value;
3738
}
3839

40+
#[\NoDiscard]
3941
public function toString(): string
4042
{
4143
return \sprintf(

0 commit comments

Comments
 (0)