Skip to content

Commit

Permalink
php-cs-fixer fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zbateson committed Apr 23, 2024
1 parent 4ec0f2c commit 663ed66
Show file tree
Hide file tree
Showing 112 changed files with 193 additions and 187 deletions.
4 changes: 2 additions & 2 deletions src/ErrorBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ public function getAllErrors(bool $validate = false, string $minPsrLevel = LogLe
{
$arr = \array_values(\array_map(
function($e) use ($validate, $minPsrLevel) {
return $e->getAllErrors($validate, $minPsrLevel) ?? [];
return $e->getAllErrors($validate, $minPsrLevel);
},
$this->getErrorBagChildren()
)) ?? [];
));
return \array_merge($this->getErrors($validate, $minPsrLevel), ...$arr);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Header/AbstractHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(

/**
* Filters $this->allParts into the parts required by $this->parts
* and assignes it.
* and assigns it.
*
* The AbstractHeader::filterAndAssignToParts method filters out CommentParts.
*/
Expand Down Expand Up @@ -118,7 +118,7 @@ public function getAllParts() : array
public function getComments() : array
{
if ($this->comments === null) {
$this->comments = \array_map(fn ($c) => $c->getComment(), \array_merge(...\array_map(
$this->comments = \array_map(fn (IHeaderPart $c) => $c->getComment(), \array_merge(...\array_map(
fn ($p) => ($p instanceof CommentPart) ? [$p] : $p->getComments(),
$this->allParts
)));
Expand Down
2 changes: 1 addition & 1 deletion src/Header/AddressHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
namespace ZBateson\MailMimeParser\Header;

use Psr\Log\LoggerInterface;
use ZBateson\MailMimeParser\MailMimeParser;
use ZBateson\MailMimeParser\Header\Consumer\AddressBaseConsumerService;
use ZBateson\MailMimeParser\Header\Part\AddressGroupPart;
use ZBateson\MailMimeParser\Header\Part\AddressPart;
use ZBateson\MailMimeParser\MailMimeParser;

/**
* A header containing one or more email addresses and/or groups of addresses.
Expand Down
2 changes: 0 additions & 2 deletions src/Header/Consumer/AddressBaseConsumerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ protected function getTokenSeparators() : array
*
* The start token for AddressBaseConsumerService is part of an
* {@see AddressPart} (or a sub-consumer) and so must be passed on.
*
* @return static
*/
protected function advanceToNextToken(Iterator $tokens, bool $isStartToken) : static
{
Expand Down
2 changes: 1 addition & 1 deletion src/Header/Consumer/AddressConsumerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use Psr\Log\LoggerInterface;
use ZBateson\MailMimeParser\Header\Part\AddressGroupPart;
use ZBateson\MailMimeParser\Header\Part\AddressPart;
use ZBateson\MailMimeParser\Header\Part\MimeTokenPartFactory;
use ZBateson\MailMimeParser\Header\Part\MimeToken;
use ZBateson\MailMimeParser\Header\Part\MimeTokenPartFactory;

/**
* Parses a single part of an address header.
Expand Down
2 changes: 0 additions & 2 deletions src/Header/Consumer/CommentConsumerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ protected function getPartForToken(string $token, bool $isLiteral) : ?IHeaderPar
* The default implementation checks if the current token is an end token,
* and will not advance past it. Because a comment part of a header can be
* nested, its implementation must advance past its own 'end' token.
*
* @return static
*/
protected function advanceToNextToken(Iterator $tokens, bool $isStartToken) : static
{
Expand Down
15 changes: 6 additions & 9 deletions src/Header/Consumer/ParameterConsumerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public function __construct(

/**
* Disables advancing for start tokens.
*
* @return static
*/
protected function advanceToNextToken(Iterator $tokens, bool $isStartToken) : static
{
Expand All @@ -73,24 +71,23 @@ protected function processParts(array $parts) : array
{
$factory = $this->partFactory;
return \array_values(\array_map(
function ($partsArray) use ($factory) {
if (count($partsArray) > 1) {
function($partsArray) use ($factory) {
if (\count($partsArray) > 1) {
return $factory->newSplitParameterPart($partsArray);
}
return $partsArray[0];
},
\array_merge_recursive(...\array_map(
function ($p) {
function($p) {
// if $p->getIndex is non-null, it's a split-parameter part
// and an array of one element consisting of name => ParameterPart
// is returned, which is then merged into name => array-of-parameter-parts
// or ';' object_id . ';' for non-split parts with a value of a single
// element array of [ParameterPart]
if ($p instanceOf ParameterPart && $p->getIndex() !== null) {
return [strtolower($p->getName()) => [$p]];
} else {
return [';' . spl_object_id($p) . ';' => [$p]];
if ($p instanceof ParameterPart && $p->getIndex() !== null) {
return [\strtolower($p->getName()) => [$p]];
}
return [';' . \spl_object_id($p) . ';' => [$p]];
},
$parts
))
Expand Down
2 changes: 1 addition & 1 deletion src/Header/Consumer/ParameterNameValueConsumerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

use Psr\Log\LoggerInterface;
use ZBateson\MailMimeParser\Header\IHeaderPart;
use ZBateson\MailMimeParser\Header\Part\MimeTokenPartFactory;
use ZBateson\MailMimeParser\Header\Part\ContainerPart;
use ZBateson\MailMimeParser\Header\Part\MimeTokenPartFactory;

/**
* Parses an individual part of a parameter header.
Expand Down
2 changes: 1 addition & 1 deletion src/Header/Consumer/ParameterValueConsumerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function getTokenSeparators() : array
{
return \array_merge(parent::getTokenSeparators(), ['=', ';']);
}

/**
* Returns true if the token is an '=' character.
*/
Expand Down
2 changes: 0 additions & 2 deletions src/Header/Consumer/QuotedStringConsumerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ protected function getTokenSeparators() : array

/**
* Constructs a LiteralPart and returns it.
*
* @param bool $isLiteral
*/
protected function getPartForToken(string $token, bool $isLiteral) : ?IHeaderPart
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
use ZBateson\MailMimeParser\Header\Part\MimeToken;

/**
*
* Provides a getTokenSplitPattern for consumers that could have quoted parts
* that are mime-header-encoded.
*
* @author Zaahid Bateson
*/
Expand Down
2 changes: 0 additions & 2 deletions src/Header/Consumer/ReceivedConsumerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ protected function getTokenSplitPattern() : string
/**
* Overridden to /not/ advance when the end token matches a start token for
* a sub-consumer.
*
* @return static
*/
protected function advanceToNextToken(Iterator $tokens, bool $isStartToken) : static
{
Expand Down
2 changes: 1 addition & 1 deletion src/Header/DateHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
use DateTime;
use DateTimeImmutable;
use Psr\Log\LoggerInterface;
use ZBateson\MailMimeParser\MailMimeParser;
use ZBateson\MailMimeParser\Header\Consumer\DateConsumerService;
use ZBateson\MailMimeParser\Header\Part\DatePart;
use ZBateson\MailMimeParser\MailMimeParser;

/**
* Reads a DatePart value header in either RFC 2822 or RFC 822 format.
Expand Down
2 changes: 1 addition & 1 deletion src/Header/GenericHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
namespace ZBateson\MailMimeParser\Header;

use Psr\Log\LoggerInterface;
use ZBateson\MailMimeParser\MailMimeParser;
use ZBateson\MailMimeParser\Header\Consumer\GenericConsumerMimeLiteralPartService;
use ZBateson\MailMimeParser\MailMimeParser;

/**
* Reads a generic header.
Expand Down
2 changes: 1 addition & 1 deletion src/Header/IdHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
namespace ZBateson\MailMimeParser\Header;

use Psr\Log\LoggerInterface;
use ZBateson\MailMimeParser\MailMimeParser;
use ZBateson\MailMimeParser\Header\Consumer\IdBaseConsumerService;
use ZBateson\MailMimeParser\Header\Part\CommentPart;
use ZBateson\MailMimeParser\Header\Part\MimeTokenPartFactory;
use ZBateson\MailMimeParser\MailMimeParser;

/**
* Represents a Content-ID, Message-ID, In-Reply-To or References header.
Expand Down
6 changes: 3 additions & 3 deletions src/Header/MimeEncodedHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

use Psr\Log\LoggerInterface;
use ZBateson\MailMimeParser\Header\Consumer\IConsumerService;
use ZBateson\MailMimeParser\Header\Part\MimeTokenPartFactory;
use ZBateson\MailMimeParser\Header\Part\MimeToken;
use ZBateson\MailMimeParser\Header\Part\MimeTokenPartFactory;

/**
* Allows a header to be mime-encoded and be decoded with a consumer after
Expand Down Expand Up @@ -55,12 +55,12 @@ protected function parseHeaderValue(IConsumerService $consumer, string $value) :
$this->mimeEncodedParsedParts = \array_map([$this->mimeTokenPartFactory, 'newInstance'], $aMimeParts);
parent::parseHeaderValue(
$consumer,
\implode(\array_map(fn ($part) => $part->getValue(), $this->mimeEncodedParsedParts))
\implode('', \array_map(fn ($part) => $part->getValue(), $this->mimeEncodedParsedParts))
);
}

protected function getErrorBagChildren() : array
{
return \array_values(\array_filter(array_merge($this->getAllParts(), $this->mimeEncodedParsedParts)));
return \array_values(\array_filter(\array_merge($this->getAllParts(), $this->mimeEncodedParsedParts)));
}
}
2 changes: 1 addition & 1 deletion src/Header/ParameterHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
namespace ZBateson\MailMimeParser\Header;

use Psr\Log\LoggerInterface;
use ZBateson\MailMimeParser\MailMimeParser;
use ZBateson\MailMimeParser\Header\Consumer\IConsumerService;
use ZBateson\MailMimeParser\Header\Consumer\ParameterConsumerService;
use ZBateson\MailMimeParser\Header\Part\NameValuePart;
use ZBateson\MailMimeParser\MailMimeParser;

/**
* Represents a header containing an optional main value part and subsequent
Expand Down
7 changes: 3 additions & 4 deletions src/Header/Part/AddressPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ class AddressPart extends NameValuePart
{
protected function getValueFromParts(array $parts) : string
{
return \implode(\array_map(
function ($p) {
return \implode('', \array_map(
function($p) {
if ($p instanceof AddressPart) {
return $p->getValue();
} elseif ($p instanceof QuotedLiteralPart && $p->getValue() !== '') {
return '"' . \preg_replace('/(["\\\])/', '\\\$1', $p->getValue()) . '"';
} else {
return \preg_replace('/\s+/', '', $p->getValue());
}
return \preg_replace('/\s+/', '', $p->getValue());
},
$parts
));
Expand Down
2 changes: 1 addition & 1 deletion src/Header/Part/CommentPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function getValueFromParts(array $parts) : string
{
$partFactory = $this->partFactory;
return parent::getValueFromParts(\array_map(
function ($p) use ($partFactory) {
function($p) use ($partFactory) {
if ($p instanceof CommentPart) {
return $partFactory->newQuotedLiteralPart([$partFactory->newToken('(' . $p->getComment() . ')')]);
} elseif ($p instanceof QuotedLiteralPart) {
Expand Down
4 changes: 2 additions & 2 deletions src/Header/Part/ContainerPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
namespace ZBateson\MailMimeParser\Header\Part;

use Psr\Log\LoggerInterface;
use ZBateson\MbWrapper\MbWrapper;
use ZBateson\MailMimeParser\ErrorBag;
use ZBateson\MbWrapper\MbWrapper;

/**
* Base HeaderPart for a part that consists of other parts.
Expand Down Expand Up @@ -64,7 +64,7 @@ protected function filterIgnoredSpaces(array $parts) : array
$spaced = \array_merge($parts, [$ends]);
$filtered = \array_slice(\array_reduce(
\array_slice(\array_keys($spaced), 0, -1),
function ($carry, $key) use ($spaced, $ends) {
function($carry, $key) use ($spaced, $ends) {
$p = $spaced[$key];
$l = \end($carry);
$a = $spaced[$key + 1];
Expand Down
2 changes: 1 addition & 1 deletion src/Header/Part/HeaderPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function convertEncoding(string $str, string $from = 'ISO-8859-1', boo
return $str;
}

public function getComments(): array
public function getComments() : array
{
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Header/Part/HeaderPartFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function newSplitParameterPart(array $children) : SplitParameterPart
/**
* Initializes and returns a new QuotedLiteralPart.
*
* @param HeaderPart[] $children
* @param HeaderPart[] $parts
*/
public function newQuotedLiteralPart(array $parts) : QuotedLiteralPart
{
Expand Down
2 changes: 1 addition & 1 deletion src/Header/Part/ParameterPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function getNameFromParts(array $parts) : string
$name = parent::getNameFromParts($parts);
if (\preg_match('~^\s*([^\*]+)\*(\d*)(\*)?$~', $name, $matches)) {
$name = $matches[1];
$this->index = ($matches[2] !== '') ? intval($matches[2]) : null;
$this->index = ($matches[2] !== '') ? (int) ($matches[2]) : null;
$this->encoded = (($matches[2] === '') || !empty($matches[3]));
}
return $name;
Expand Down
2 changes: 1 addition & 1 deletion src/Header/Part/ReceivedDomainPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ReceivedDomainPart extends ReceivedPart
protected ?string $address = null;

/**
* @param HeaderPart[] $subParts
* @param HeaderPart[] $children
*/
public function __construct(
LoggerInterface $logger,
Expand Down
2 changes: 1 addition & 1 deletion src/Header/Part/SplitParameterPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function getValueFromParts(array $parts) : string

$combined = $this->combineAdjacentUnencodedParts($sorted);

return \implode(\array_map(
return \implode('', \array_map(
fn ($p) => ($p instanceof ParameterPart && $p->encoded)
? $this->decodePartValue($p->getValue(), ($p->charset === null) ? $charset : $p->charset)
: $p->getValue(),
Expand Down
1 change: 0 additions & 1 deletion src/Header/Part/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace ZBateson\MailMimeParser\Header\Part;

use Psr\Log\LoggerInterface;
use ZBateson\MailMimeParser\Header\Part\HeaderPart;
use ZBateson\MbWrapper\MbWrapper;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Header/ReceivedHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

use DateTime;
use Psr\Log\LoggerInterface;
use ZBateson\MailMimeParser\MailMimeParser;
use ZBateson\MailMimeParser\Header\Consumer\ReceivedConsumerService;
use ZBateson\MailMimeParser\Header\Part\DatePart;
use ZBateson\MailMimeParser\MailMimeParser;

/**
* Represents a Received header.
Expand Down
2 changes: 1 addition & 1 deletion src/Header/SubjectHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
namespace ZBateson\MailMimeParser\Header;

use Psr\Log\LoggerInterface;
use ZBateson\MailMimeParser\MailMimeParser;
use ZBateson\MailMimeParser\Header\Consumer\SubjectConsumerService;
use ZBateson\MailMimeParser\MailMimeParser;

/**
* Reads a subject header.
Expand Down
11 changes: 5 additions & 6 deletions src/MailMimeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class MailMimeParser
* @var array<array|string|DefinitionSource> an array of global definitions
* being used.
*/
private static array $globalDefinitions = [ self::DEFAULT_DEFINITIONS_FILE ];
private static array $globalDefinitions = [self::DEFAULT_DEFINITIONS_FILE];

/**
* Returns the default ContainerBuilder with default loaded definitions.
Expand All @@ -104,14 +104,13 @@ private static function getGlobalContainerBuilder() : ContainerBuilder
*/
public static function setGlobalPhpDiConfigurations(array $phpDiConfigs, bool $useDefaultDefinitionsFile = true) : void
{
self::$globalDefinitions = array_merge(
($useDefaultDefinitionsFile) ? [ self::DEFAULT_DEFINITIONS_FILE ] : [],
self::$globalDefinitions = \array_merge(
($useDefaultDefinitionsFile) ? [self::DEFAULT_DEFINITIONS_FILE] : [],
$phpDiConfigs
);
self::$globalContainer = null;
}


public static function addGlobalPhpDiContainerDefinition(array|string|DefinitionSource $phpDiConfig) : void
{
self::$globalDefinitions[] = $phpDiConfig;
Expand All @@ -120,7 +119,7 @@ public static function addGlobalPhpDiContainerDefinition(array|string|Definition

public static function resetGlobalPhpDiContainerDefinitions() : void
{
self::$globalDefinitions = [ self::DEFAULT_DEFINITIONS_FILE ];
self::$globalDefinitions = [self::DEFAULT_DEFINITIONS_FILE];
self::$globalContainer = null;
}

Expand All @@ -142,7 +141,7 @@ public static function getGlobalContainer() : Container
*/
public static function setGlobalLogger(LoggerInterface $logger) : void
{
self::$globalDefinitions[] = [ LoggerInterface::class => $logger ];
self::$globalDefinitions[] = [LoggerInterface::class => $logger];
self::$globalContainer = null;
}

Expand Down
Loading

0 comments on commit 663ed66

Please sign in to comment.