Skip to content

Commit 417b871

Browse files
authored
Merge pull request #10 from Innmind/no-discard-attributes
Add `NoDiscard` attribute on mutation free methods
2 parents 6d23039 + cdde913 commit 417b871

File tree

10 files changed

+36
-0
lines changed

10 files changed

+36
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@ private function __construct(UrlPattern $pattern)
1818
/**
1919
* @psalm-pure
2020
*/
21+
#[\NoDiscard]
2122
public static function of(UrlPattern $pattern): self
2223
{
2324
return new self($pattern);
2425
}
2526

27+
#[\NoDiscard]
2628
public function matches(string $url): bool
2729
{
2830
return $this->pattern->matches($url);
2931
}
3032

33+
#[\NoDiscard]
3134
public function toString(): string
3235
{
3336
return 'Allow: '.$this->pattern->toString();

src/CrawlDelay.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ private function __construct(int $value)
2626
*
2727
* @param 0|positive-int $value
2828
*/
29+
#[\NoDiscard]
2930
public static function of(int $value): self
3031
{
3132
return new self($value);
@@ -36,6 +37,7 @@ public static function of(int $value): self
3637
*
3738
* @return Maybe<self>
3839
*/
40+
#[\NoDiscard]
3941
public static function maybe(string $value): Maybe
4042
{
4143
/** @psalm-suppress ArgumentTypeCoercion It doesn't understand the last filter */
@@ -49,11 +51,13 @@ public static function maybe(string $value): Maybe
4951
/**
5052
* @return 0|positive-int
5153
*/
54+
#[\NoDiscard]
5255
public function toInt(): int
5356
{
5457
return $this->value;
5558
}
5659

60+
#[\NoDiscard]
5761
public function toString(): string
5862
{
5963
return 'Crawl-delay: '.$this->value;

src/Directives.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ private function __construct(
4747
* @param Sequence<Allow> $allow
4848
* @param Sequence<Disallow> $disallow
4949
*/
50+
#[\NoDiscard]
5051
public static function of(
5152
UserAgent $userAgent,
5253
?Sequence $allow = null,
@@ -61,6 +62,7 @@ public static function of(
6162
);
6263
}
6364

65+
#[\NoDiscard]
6466
public function withAllow(Allow $allow): self
6567
{
6668
return new self(
@@ -71,6 +73,7 @@ public function withAllow(Allow $allow): self
7173
);
7274
}
7375

76+
#[\NoDiscard]
7477
public function withDisallow(Disallow $disallow): self
7578
{
7679
return new self(
@@ -81,6 +84,7 @@ public function withDisallow(Disallow $disallow): self
8184
);
8285
}
8386

87+
#[\NoDiscard]
8488
public function withCrawlDelay(CrawlDelay $crawlDelay): self
8589
{
8690
return self::of(
@@ -91,11 +95,13 @@ public function withCrawlDelay(CrawlDelay $crawlDelay): self
9195
);
9296
}
9397

98+
#[\NoDiscard]
9499
public function targets(string $userAgent): bool
95100
{
96101
return $this->userAgent->matches($userAgent);
97102
}
98103

104+
#[\NoDiscard]
99105
public function disallows(Url $url): bool
100106
{
101107
$url = $this->clean($url)->toString();
@@ -115,11 +121,13 @@ public function disallows(Url $url): bool
115121
/**
116122
* @return Maybe<CrawlDelay>
117123
*/
124+
#[\NoDiscard]
118125
public function crawlDelay(): Maybe
119126
{
120127
return $this->crawlDelay;
121128
}
122129

130+
#[\NoDiscard]
123131
public function asContent(): Content
124132
{
125133
$lines = $this

src/Disallow.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ private function __construct(UrlPattern $pattern)
2020
/**
2121
* @psalm-pure
2222
*/
23+
#[\NoDiscard]
2324
public static function of(UrlPattern $pattern): self
2425
{
2526
return new self($pattern);
2627
}
2728

29+
#[\NoDiscard]
2830
public function matches(string $url): bool
2931
{
3032
if (Str::of($this->pattern->toString())->empty()) {
@@ -34,6 +36,7 @@ public function matches(string $url): bool
3436
return $this->pattern->matches($url);
3537
}
3638

39+
#[\NoDiscard]
3740
public function toString(): string
3841
{
3942
return 'Disallow: '.$this->pattern->toString();

src/Parser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ private function __construct(
3434
/**
3535
* @return Maybe<RobotsTxt>
3636
*/
37+
#[\NoDiscard]
3738
public function __invoke(Url $url): Maybe
3839
{
3940
return ($this->fulfill)(

src/Parser/Walker.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ private function __construct()
3333
*
3434
* @return Sequence<Directives>
3535
*/
36+
#[\NoDiscard]
3637
public function __invoke(Sequence $lines): Sequence
3738
{
3839
return $lines

src/RobotsTxt.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,25 @@ private function __construct(Url $url, Sequence $directives)
3333
*
3434
* @param Sequence<Directives> $directives
3535
*/
36+
#[\NoDiscard]
3637
public static function of(Url $url, Sequence $directives): self
3738
{
3839
return new self($url, $directives);
3940
}
4041

42+
#[\NoDiscard]
4143
public function url(): Url
4244
{
4345
return $this->url;
4446
}
4547

48+
#[\NoDiscard]
4649
public function directives(): Sequence
4750
{
4851
return $this->directives;
4952
}
5053

54+
#[\NoDiscard]
5155
public function disallows(string $userAgent, Url $url): bool
5256
{
5357
return $this
@@ -62,6 +66,7 @@ public function disallows(string $userAgent, Url $url): bool
6266
);
6367
}
6468

69+
#[\NoDiscard]
6570
public function asContent(): Content
6671
{
6772
return Content::ofLines(

src/UrlPattern.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ private function __construct(string $pattern)
2424
/**
2525
* @psalm-pure
2626
*/
27+
#[\NoDiscard]
2728
public static function of(string $pattern): self
2829
{
2930
return new self($pattern);
3031
}
3132

33+
#[\NoDiscard]
3234
public function matches(string $url): bool
3335
{
3436
if ($this->pattern === '*' || Str::of($this->pattern)->empty()) {
@@ -48,6 +50,7 @@ public function matches(string $url): bool
4850
return $this->fallUnder($url);
4951
}
5052

53+
#[\NoDiscard]
5154
public function toString(): string
5255
{
5356
return $this->pattern;

src/UserAgent.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,25 @@ private function __construct(Sequence $agents)
2828
/**
2929
* @psalm-pure
3030
*/
31+
#[\NoDiscard]
3132
public static function of(string $agent): self
3233
{
3334
return new self(Sequence::of(Str::of($agent)));
3435
}
3536

37+
#[\NoDiscard]
3638
public function and(string $agent): self
3739
{
3840
return new self(($this->agents)(Str::of($agent)));
3941
}
4042

43+
#[\NoDiscard]
4144
public function merge(self $agents): self
4245
{
4346
return new self($this->agents->append($agents->agents));
4447
}
4548

49+
#[\NoDiscard]
4650
public function matches(string $userAgent): bool
4751
{
4852
$userAgent = Str::of($userAgent)->toLower();
@@ -56,6 +60,7 @@ public function matches(string $userAgent): bool
5660
);
5761
}
5862

63+
#[\NoDiscard]
5964
public function asContent(): Content
6065
{
6166
return Content::ofLines(

0 commit comments

Comments
 (0)