Skip to content

Commit

Permalink
Set coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
badraxas committed Jan 23, 2024
1 parent bdd9db7 commit 9a4effd
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 50 deletions.
32 changes: 16 additions & 16 deletions src/AdsTxt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions src/Interfaces/AdsTxtLineInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
interface AdsTxtLineInterface
{
public function equals(AdsTxtLineInterface $adsTxtLine): bool;

public function pretty(bool $withComment = true): string;
}
36 changes: 18 additions & 18 deletions src/Lines/AbstractAdsTxtLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@

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)
{
$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;
}
}
}
2 changes: 1 addition & 1 deletion src/Lines/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
8 changes: 3 additions & 5 deletions src/Lines/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Badraxas\Adstxt\Lines;

use Badraxas\Adstxt\Enums\Relationship;
use Badraxas\Adstxt\Exceptions\Lines\RecordArgumentException;
use Badraxas\Adstxt\Interfaces\AdsTxtLineInterface;

/**
Expand All @@ -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(
Expand All @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions src/Parsers/RecordParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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;
}
}
1 change: 0 additions & 1 deletion tests/AdsTxtFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion tests/AdsTxtParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion tests/AdsTxtTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

use Badraxas\Adstxt\AdsTxt;
use Badraxas\Adstxt\Enums\Relationship;
use Badraxas\Adstxt\Lines\Blank;
use Badraxas\Adstxt\Lines\Comment;
use Badraxas\Adstxt\Lines\Invalid;
Expand Down
2 changes: 0 additions & 2 deletions tests/Lines/RecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Lines;

use Badraxas\Adstxt\Enums\Relationship;
use Badraxas\Adstxt\Exceptions\Lines\RecordArgumentException;
use Badraxas\Adstxt\Lines\Comment;
use Badraxas\Adstxt\Lines\Record;
use PHPUnit\Framework\TestCase;
Expand Down
1 change: 0 additions & 1 deletion tests/Parsers/RecordParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Parsers;

use Badraxas\Adstxt\Enums\Relationship;
use Badraxas\Adstxt\Lines\Record;
use Badraxas\Adstxt\Parsers\RecordParser;
use PHPUnit\Framework\TestCase;
Expand Down

0 comments on commit 9a4effd

Please sign in to comment.