From a6b7ec139dc68b14b4a8ca3f98c1685fb9376e88 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Mon, 23 Sep 2024 11:43:45 +0000 Subject: [PATCH] Fix styling --- src/Robots.php | 12 ++++++------ src/RobotsHeaders.php | 4 ++-- src/RobotsMeta.php | 2 +- src/RobotsTxt.php | 8 ++++---- tests/RobotsTxtTest.php | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Robots.php b/src/Robots.php index 3715bca..7aceb30 100644 --- a/src/Robots.php +++ b/src/Robots.php @@ -6,11 +6,11 @@ class Robots { - protected RobotsTxt | null $robotsTxt; + protected ?RobotsTxt $robotsTxt; public function __construct( - protected string | null $userAgent = null, - RobotsTxt | string | null $source = null, + protected ?string $userAgent = null, + RobotsTxt|string|null $source = null, ) { if ($source instanceof RobotsTxt) { $this->robotsTxt = $source; @@ -21,7 +21,7 @@ public function __construct( } } - public function withTxt(RobotsTxt | string $source): self + public function withTxt(RobotsTxt|string $source): self { $this->robotsTxt = $source instanceof RobotsTxt ? $source @@ -30,12 +30,12 @@ public function withTxt(RobotsTxt | string $source): self return $this; } - public static function create(string $userAgent = null, string $source = null): self + public static function create(?string $userAgent = null, ?string $source = null): self { return new self($userAgent, $source); } - public function mayIndex(string $url, string $userAgent = null): bool + public function mayIndex(string $url, ?string $userAgent = null): bool { $userAgent = $userAgent ?? $this->userAgent; diff --git a/src/RobotsHeaders.php b/src/RobotsHeaders.php index 62bbf23..67b9824 100644 --- a/src/RobotsHeaders.php +++ b/src/RobotsHeaders.php @@ -36,7 +36,7 @@ public function mayIndex(string $userAgent = '*'): bool public function mayFollow(string $userAgent = '*'): bool { - return $this->none($userAgent) ? false : ! $this->nofollow($userAgent); + return $this->none($userAgent) ? false : ! $this->nofollow($userAgent); } public function noindex(string $userAgent = '*'): bool @@ -57,7 +57,7 @@ public function nofollow(string $userAgent = '*'): bool public function none(string $userAgent = '*'): bool { - return + return $this->robotHeadersProperties[$userAgent]['none'] ?? $this->robotHeadersProperties['*']['none'] ?? false; diff --git a/src/RobotsMeta.php b/src/RobotsMeta.php index 7156ec7..5368737 100644 --- a/src/RobotsMeta.php +++ b/src/RobotsMeta.php @@ -50,7 +50,7 @@ public function nofollow(): bool return $this->robotsMetaTagProperties['nofollow'] ?? false; } - #[ArrayShape(['noindex' => "bool", 'nofollow' => "bool"])] + #[ArrayShape(['noindex' => 'bool', 'nofollow' => 'bool'])] protected function findRobotsMetaTagProperties(string $html): array { $metaTagLine = $this->findRobotsMetaTagLine($html); diff --git a/src/RobotsTxt.php b/src/RobotsTxt.php index de906e8..f5d0e14 100644 --- a/src/RobotsTxt.php +++ b/src/RobotsTxt.php @@ -64,7 +64,7 @@ public static function create(string $source): self return new self($source); } - public function allows(string $url, string | null $userAgent = '*'): bool + public function allows(string $url, ?string $userAgent = '*'): bool { $requestUri = ''; @@ -83,11 +83,11 @@ public function allows(string $url, string | null $userAgent = '*'): bool } $disallowsPerUserAgent = $this->includeGlobalGroup - ? $this->disallowsPerUserAgent + ? $this->disallowsPerUserAgent : array_filter($this->disallowsPerUserAgent, fn ($key) => $key !== '*', ARRAY_FILTER_USE_KEY); - + $normalizedUserAgent = strtolower(trim($userAgent ?? '')); - + $disallows = $this->matchExactly ? $this->getDisallowsExactly($normalizedUserAgent, $disallowsPerUserAgent) : $this->getDisallowsContaining($normalizedUserAgent, $disallowsPerUserAgent); diff --git a/tests/RobotsTxtTest.php b/tests/RobotsTxtTest.php index e0306a2..290848a 100644 --- a/tests/RobotsTxtTest.php +++ b/tests/RobotsTxtTest.php @@ -52,7 +52,7 @@ public function test_allowed_link_for_custom_user_agent() $robots = RobotsTxt::readFrom(__DIR__.'/data/robots.txt'); $this->assertFalse($robots->allows('/test', 'google')); - + $this->assertTrue($robots ->exactMatchesOnly() ->allows('/no-agents', 'Mozilla/5.0 (compatible; UserAgent007/1.1)') @@ -61,7 +61,7 @@ public function test_allowed_link_for_custom_user_agent() ->withPartialMatches() ->allows('/no-agents', 'Mozilla/5.0 (compatible; UserAgent007/1.1)') ); - + $this->assertTrue($robots ->ignoreGlobalGroup() ->withPartialMatches()