From 9a4effd752b6f2260d1538061832993ae3ecec6c Mon Sep 17 00:00:00 2001 From: Bastien Mottier Date: Wed, 24 Jan 2024 00:10:00 +0100 Subject: [PATCH] Set coding style --- src/AdsTxt.php | 32 +++++++++++------------ src/Interfaces/AdsTxtLineInterface.php | 1 + src/Lines/AbstractAdsTxtLine.php | 36 +++++++++++++------------- src/Lines/Comment.php | 2 +- src/Lines/Record.php | 8 +++--- src/Parsers/RecordParser.php | 6 ++--- tests/AdsTxtFetcherTest.php | 1 - tests/AdsTxtParserTest.php | 1 - tests/AdsTxtTest.php | 1 - tests/Lines/RecordTest.php | 2 -- tests/Parsers/RecordParserTest.php | 1 - 11 files changed, 41 insertions(+), 50 deletions(-) diff --git a/src/AdsTxt.php b/src/AdsTxt.php index f6321dd..1e728b1 100644 --- a/src/AdsTxt.php +++ b/src/AdsTxt.php @@ -22,22 +22,6 @@ class AdsTxt */ private bool $valid = true; - /** - * Get the string representation of the ads.txt content. - * - * @return string Returns the ads.txt content as a string. - */ - public function pretty(bool $withComment = true): string - { - $output = ''; - - foreach ($this->lines as $line) { - $output .= sprintf('%s%s', $line->pretty($withComment), PHP_EOL); - } - - return trim($output); - } - /** * Add a line to the ads.txt content. * @@ -168,6 +152,22 @@ public function isValid(): bool return $this->valid; } + /** + * Get the string representation of the ads.txt content. + * + * @return string Returns the ads.txt content as a string. + */ + public function pretty(bool $withComment = true): string + { + $output = ''; + + foreach ($this->lines as $line) { + $output .= sprintf('%s%s', $line->pretty($withComment), PHP_EOL); + } + + return trim($output); + } + /** * Check if a given line exists in the AdsTxt instance. * diff --git a/src/Interfaces/AdsTxtLineInterface.php b/src/Interfaces/AdsTxtLineInterface.php index e7144c3..1e6f4af 100644 --- a/src/Interfaces/AdsTxtLineInterface.php +++ b/src/Interfaces/AdsTxtLineInterface.php @@ -11,5 +11,6 @@ interface AdsTxtLineInterface { public function equals(AdsTxtLineInterface $adsTxtLine): bool; + public function pretty(bool $withComment = true): string; } diff --git a/src/Lines/AbstractAdsTxtLine.php b/src/Lines/AbstractAdsTxtLine.php index 710f44a..8d7b3d2 100644 --- a/src/Lines/AbstractAdsTxtLine.php +++ b/src/Lines/AbstractAdsTxtLine.php @@ -6,14 +6,19 @@ abstract class AbstractAdsTxtLine implements AdsTxtLineInterface { - protected string $rawValue = ''; + protected array $error = []; protected array $notice = []; + protected string $rawValue = ''; protected array $warning = []; - protected array $error = []; - public function getWarning() + public function addError(string $error) { - return $this->warning; + $this->error[] = $error; + } + + public function addNotice(string $notice) + { + $this->notice[] = $notice; } public function addWarning(string $warning) @@ -21,33 +26,28 @@ public function addWarning(string $warning) $this->warning[] = $warning; } - public function getNotice() + public function getError() { - return $this->notice; + return $this->error; } - public function addNotice(string $notice) + public function getNotice() { - $this->notice[] = $notice; + return $this->notice; } - public function getError() + public function getRawValue(): string { - return $this->error; + return $this->rawValue; } - public function addError(string $error) + public function getWarning() { - $this->error[] = $error; + return $this->warning; } public function setRawValue(string $rawValue) { $this->rawValue = $rawValue; } - - public function getRawValue(): string - { - return $this->rawValue; - } -} \ No newline at end of file +} diff --git a/src/Lines/Comment.php b/src/Lines/Comment.php index ce5c51f..6be12ae 100644 --- a/src/Lines/Comment.php +++ b/src/Lines/Comment.php @@ -38,6 +38,6 @@ public function getComment(): string public function pretty(bool $withComment = true): string { - return !$withComment ? '' : sprintf("# %s", $this->getComment()); + return !$withComment ? '' : sprintf('# %s', $this->getComment()); } } diff --git a/src/Lines/Record.php b/src/Lines/Record.php index 8d9e09d..a2938df 100644 --- a/src/Lines/Record.php +++ b/src/Lines/Record.php @@ -3,7 +3,6 @@ namespace Badraxas\Adstxt\Lines; use Badraxas\Adstxt\Enums\Relationship; -use Badraxas\Adstxt\Exceptions\Lines\RecordArgumentException; use Badraxas\Adstxt\Interfaces\AdsTxtLineInterface; /** @@ -18,8 +17,8 @@ class Record extends AbstractAdsTxtLine * * @param string $domain the domain associated with the record * @param mixed $publisherId the ID of the publisher associated with the record - * @param string $relationship The relationship of the record (e.g., DIRECT, RESELLER). - * @param null|string $certificationId the certification ID of the record (optional) + * @param string $relationship The relationship of the record (e.g., DIRECT, RESELLER). + * @param null|string $certificationId the certification ID of the record (optional) * @param null|Comment $comment the comment associated with the record (optional) */ public function __construct( @@ -28,8 +27,7 @@ public function __construct( private readonly string $relationship, private readonly ?string $certificationId = null, private readonly ?Comment $comment = null - ) { - } + ) {} /** * Compares the current Record object with another AdsTxtLineInterface object. diff --git a/src/Parsers/RecordParser.php b/src/Parsers/RecordParser.php index 4d25ee7..050aae3 100644 --- a/src/Parsers/RecordParser.php +++ b/src/Parsers/RecordParser.php @@ -2,8 +2,6 @@ namespace Badraxas\Adstxt\Parsers; -use Badraxas\Adstxt\Enums\Relationship; -use Badraxas\Adstxt\Exceptions\Lines\RecordArgumentException; use Badraxas\Adstxt\Interfaces\AdsTxtLineInterface; use Badraxas\Adstxt\Interfaces\ParserInterface; use Badraxas\Adstxt\Lines\Comment; @@ -40,7 +38,6 @@ public function parse(string $line): AdsTxtLineInterface $invalid->addError('Record contains more than 4 comma separated values and is therefore improperly formatted'); return $invalid; - } $domain = trim($exploded_line[0]); @@ -120,6 +117,7 @@ private function validatePublisherId($publisherId): bool private function validateRelationship($relationship): bool { $relationship = strtoupper($relationship); - return $relationship === 'DIRECT' || $relationship === 'RESELLER'; + + return 'DIRECT' === $relationship || 'RESELLER' === $relationship; } } diff --git a/tests/AdsTxtFetcherTest.php b/tests/AdsTxtFetcherTest.php index e190635..240eec8 100644 --- a/tests/AdsTxtFetcherTest.php +++ b/tests/AdsTxtFetcherTest.php @@ -2,7 +2,6 @@ use Badraxas\Adstxt\AdsTxt; use Badraxas\Adstxt\AdsTxtFetcher; -use Badraxas\Adstxt\Enums\Relationship; use Badraxas\Adstxt\Exceptions\AdsTxtParser\UrlOpenException; use Badraxas\Adstxt\Lines\Record; use PHPUnit\Framework\MockObject\Exception; diff --git a/tests/AdsTxtParserTest.php b/tests/AdsTxtParserTest.php index 9e3c750..a925d46 100644 --- a/tests/AdsTxtParserTest.php +++ b/tests/AdsTxtParserTest.php @@ -2,7 +2,6 @@ use Badraxas\Adstxt\AdsTxt; use Badraxas\Adstxt\AdsTxtParser; -use Badraxas\Adstxt\Enums\Relationship; use Badraxas\Adstxt\Exceptions\AdsTxtParser\FileOpenException; use Badraxas\Adstxt\Lines\Blank; use Badraxas\Adstxt\Lines\Comment; diff --git a/tests/AdsTxtTest.php b/tests/AdsTxtTest.php index 00b292a..3e0ca10 100644 --- a/tests/AdsTxtTest.php +++ b/tests/AdsTxtTest.php @@ -1,7 +1,6 @@