Skip to content

Commit bfc78d5

Browse files
committed
add NoDiscard attributes
1 parent e17aed3 commit bfc78d5

16 files changed

Lines changed: 184 additions & 0 deletions

src/Alpha.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private function __construct(float $value)
2424
/**
2525
* @psalm-pure
2626
*/
27+
#[\NoDiscard]
2728
public static function max(): self
2829
{
2930
return new self(1);
@@ -34,6 +35,7 @@ public static function max(): self
3435
*
3536
* @return Attempt<self>
3637
*/
38+
#[\NoDiscard]
3739
public static function of(float $value): Attempt
3840
{
3941
return Attempt::of(static fn() => new self($value));
@@ -44,6 +46,7 @@ public static function of(float $value): Attempt
4446
*
4547
* @return Attempt<self>
4648
*/
49+
#[\NoDiscard]
4750
public static function fromHexadecimal(string $hex): Attempt
4851
{
4952
if (\mb_strlen($hex) === 1) {
@@ -53,6 +56,7 @@ public static function fromHexadecimal(string $hex): Attempt
5356
return self::of(\round(\hexdec($hex) / 255, 2));
5457
}
5558

59+
#[\NoDiscard]
5660
public function add(self $alpha): self
5761
{
5862
return new self(
@@ -63,6 +67,7 @@ public function add(self $alpha): self
6367
);
6468
}
6569

70+
#[\NoDiscard]
6671
public function subtract(self $alpha): self
6772
{
6873
return new self(
@@ -73,26 +78,31 @@ public function subtract(self $alpha): self
7378
);
7479
}
7580

81+
#[\NoDiscard]
7682
public function equals(self $alpha): bool
7783
{
7884
return $this->value === $alpha->toFloat();
7985
}
8086

87+
#[\NoDiscard]
8188
public function atMaximum(): bool
8289
{
8390
return $this->value === 1.0;
8491
}
8592

93+
#[\NoDiscard]
8694
public function atMinimum(): bool
8795
{
8896
return $this->value === 0.0;
8997
}
9098

99+
#[\NoDiscard]
91100
public function toFloat(): float
92101
{
93102
return $this->value;
94103
}
95104

105+
#[\NoDiscard]
96106
public function toHexadecimal(): string
97107
{
98108
return \str_pad(
@@ -105,6 +115,7 @@ public function toHexadecimal(): string
105115
);
106116
}
107117

118+
#[\NoDiscard]
108119
public function toString(): string
109120
{
110121
return (string) $this->value;

src/Black.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ private function __construct(
2323
*
2424
* @param int<0, 100> $value
2525
*/
26+
#[\NoDiscard]
2627
public static function at(int $value): self
2728
{
2829
return new self($value);
@@ -33,6 +34,7 @@ public static function at(int $value): self
3334
*
3435
* @return Attempt<self>
3536
*/
37+
#[\NoDiscard]
3638
public static function of(int $value): Attempt
3739
{
3840
if ($value < 0 || $value > 100) {
@@ -42,6 +44,7 @@ public static function of(int $value): Attempt
4244
return Attempt::result(new self($value));
4345
}
4446

47+
#[\NoDiscard]
4548
public function add(self $black): self
4649
{
4750
return new self(
@@ -52,6 +55,7 @@ public function add(self $black): self
5255
);
5356
}
5457

58+
#[\NoDiscard]
5559
public function subtract(self $black): self
5660
{
5761
return new self(
@@ -62,16 +66,19 @@ public function subtract(self $black): self
6266
);
6367
}
6468

69+
#[\NoDiscard]
6570
public function equals(self $black): bool
6671
{
6772
return $this->value === $black->toInt();
6873
}
6974

75+
#[\NoDiscard]
7076
public function atMaximum(): bool
7177
{
7278
return $this->value === 100;
7379
}
7480

81+
#[\NoDiscard]
7582
public function atMinimum(): bool
7683
{
7784
return $this->value === 0;
@@ -80,11 +87,13 @@ public function atMinimum(): bool
8087
/**
8188
* @return int<0, 100>
8289
*/
90+
#[\NoDiscard]
8391
public function toInt(): int
8492
{
8593
return $this->value;
8694
}
8795

96+
#[\NoDiscard]
8897
public function toString(): string
8998
{
9099
return (string) $this->value;

src/Blue.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ private function __construct(
2323
*
2424
* @param int<0, 255> $value
2525
*/
26+
#[\NoDiscard]
2627
public static function at(int $value): self
2728
{
2829
return new self($value);
@@ -33,6 +34,7 @@ public static function at(int $value): self
3334
*
3435
* @return Attempt<self>
3536
*/
37+
#[\NoDiscard]
3638
public static function of(int $value): Attempt
3739
{
3840
if ($value < 0 || $value > 255) {
@@ -47,6 +49,7 @@ public static function of(int $value): Attempt
4749
*
4850
* @return Attempt<self>
4951
*/
52+
#[\NoDiscard]
5053
public static function fromHexadecimal(string $hex): Attempt
5154
{
5255
if (\mb_strlen($hex) === 1) {
@@ -59,13 +62,15 @@ public static function fromHexadecimal(string $hex): Attempt
5962
/**
6063
* @return Attempt<self>
6164
*/
65+
#[\NoDiscard]
6266
public static function fromIntensity(Intensity $intensity): Attempt
6367
{
6468
return self::of(
6569
(int) \round((255 * $intensity->toInt()) / 100),
6670
);
6771
}
6872

73+
#[\NoDiscard]
6974
public function add(self $blue): self
7075
{
7176
return new self(
@@ -76,6 +81,7 @@ public function add(self $blue): self
7681
);
7782
}
7883

84+
#[\NoDiscard]
7985
public function subtract(self $blue): self
8086
{
8187
return new self(
@@ -86,16 +92,19 @@ public function subtract(self $blue): self
8692
);
8793
}
8894

95+
#[\NoDiscard]
8996
public function equals(self $blue): bool
9097
{
9198
return $this->integer === $blue->toInt();
9299
}
93100

101+
#[\NoDiscard]
94102
public function atMaximum(): bool
95103
{
96104
return $this->integer === 255;
97105
}
98106

107+
#[\NoDiscard]
99108
public function atMinimum(): bool
100109
{
101110
return $this->integer === 0;
@@ -104,11 +113,13 @@ public function atMinimum(): bool
104113
/**
105114
* @return int<0, 255>
106115
*/
116+
#[\NoDiscard]
107117
public function toInt(): int
108118
{
109119
return $this->integer;
110120
}
111121

122+
#[\NoDiscard]
112123
public function toString(): string
113124
{
114125
return \str_pad(

0 commit comments

Comments
 (0)