Skip to content

Commit

Permalink
Update PHP-CS-Fixer rules (#403)
Browse files Browse the repository at this point in the history
* @PHP71Migration

* native_constant_invocation

* phpunit_*

* static_lambda

* array_indentation

* Updated PHP-CS-Fixer rules

* Updated PHPUnit deprecated methods
  • Loading branch information
Slamdunk authored Mar 1, 2019
1 parent 4ac25b7 commit 53f2eda
Show file tree
Hide file tree
Showing 27 changed files with 733 additions and 714 deletions.
105 changes: 62 additions & 43 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,69 @@
<?php

declare(strict_types=1);

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@DoctrineAnnotation' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHPUnit60Migration:risky' => true,
'@PHP70Migration' => true,
'@PHP70Migration:risky' => true,
'align_multiline_comment' => ['comment_type' => 'all_multiline'],
'array_syntax' => ['syntax' => 'short'],
'blank_line_before_statement' => true,
'concat_space' => ['spacing' => 'one'],
'error_suppression' => false,
'escape_implicit_backslashes' => true,
'explicit_indirect_variable' => true,
'explicit_string_variable' => true,
'heredoc_to_nowdoc' => true,
'list_syntax' => ['syntax' => 'long'],
'method_argument_space' => ['ensure_fully_multiline' => true],
'method_chaining_indentation' => true,
'multiline_comment_opening_closing' => true,
'multiline_whitespace_before_semicolons' => ['strategy' => 'new_line_for_chained_calls'],
'native_function_invocation' => true,
'no_break_comment' => true,
'no_extra_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']],
'no_null_property_initialization' => true,
'no_php4_constructor' => true,
'no_short_echo_tag' => true,
'no_superfluous_elseif' => true,
'no_unneeded_curly_braces' => true,
'no_unneeded_final_method' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'ordered_imports' => true,
'php_unit_strict' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_order' => true,
'phpdoc_types_order' => true,
'random_api_migration' => true,
'semicolon_after_instruction' => true,
'silenced_deprecation_error' => false,
'simplified_null_return' => false, // @TODO: enable when PHP ^7.1
'single_line_comment_style' => true,
'strict_comparison' => true,
'@DoctrineAnnotation' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHPUnit60Migration:risky' => true,
'@PHP71Migration' => true,
'@PHP70Migration:risky' => true, // @TODO with next major version
'align_multiline_comment' => ['comment_type' => 'all_multiline'],
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => ['default' => 'align_single_space'],
'blank_line_before_statement' => true,
'class_definition' => ['singleItemSingleLine' => true],
'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'],
'error_suppression' => false,
'escape_implicit_backslashes' => true,
'explicit_indirect_variable' => true,
'explicit_string_variable' => true,
'fully_qualified_strict_types' => true,
'heredoc_to_nowdoc' => true,
'list_syntax' => ['syntax' => 'long'],
'method_argument_space' => ['ensure_fully_multiline' => true],
'method_chaining_indentation' => true,
'multiline_comment_opening_closing' => true,
'multiline_whitespace_before_semicolons' => ['strategy' => 'new_line_for_chained_calls'],
'native_constant_invocation' => true,
'native_function_invocation' => true,
'no_alternative_syntax' => true,
'no_break_comment' => true,
'no_extra_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']],
'no_null_property_initialization' => true,
'no_php4_constructor' => true,
'no_short_echo_tag' => true,
'no_superfluous_elseif' => true,
'no_unneeded_curly_braces' => true,
'no_unneeded_final_method' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => true,
'php_unit_method_casing' => true,
'php_unit_ordered_covers' => true,
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_strict' => true,
'php_unit_test_annotation' => true,
'php_unit_test_case_static_method_calls' => true,
'php_unit_test_class_requires_covers' => false,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_order' => true,
'phpdoc_types_order' => true,
'random_api_migration' => true,
'semicolon_after_instruction' => true,
'silenced_deprecation_error' => false,
'simplified_null_return' => true,
'single_line_comment_style' => true,
'space_after_semicolon' => true,
'static_lambda' => true,
'strict_comparison' => true,
'string_line_ending' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
Expand All @@ -52,4 +72,3 @@ return PhpCsFixer\Config::create()
->in(__DIR__ . '/tests')
)
;

14 changes: 7 additions & 7 deletions .travis/readme-index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
declare(strict_types=1);

$readMeFilepath = \dirname(__DIR__) . '/README.md';
$readMeFile = new \SplFileObject($readMeFilepath);
$readMeFile = new \SplFileObject($readMeFilepath);
$readMeFile->setFlags(SplFileObject::DROP_NEW_LINE);

$cliRedBackground = "\033[37;41m";
$cliReset = "\033[0m";
$exitStatus = 0;
$cliReset = "\033[0m";
$exitStatus = 0;

$linesWithSpaces = [];
$tableOfContentsStarted = 0;
$linesWithSpaces = [];
$tableOfContentsStarted = 0;
$currentTableOfContentsChapters = [];
$chaptersFound = [];
$chaptersFound = [];
foreach ($readMeFile as $lineNumber => $line) {
if (\preg_match('/\s$/', $line)) {
$linesWithSpaces[] = \sprintf('%5s: %s', 1 + $lineNumber, $line);
Expand Down Expand Up @@ -45,7 +45,7 @@
}

$currentTableOfContentsChaptersFilename = __DIR__ . '/current-chapters';
$chaptersFoundFilename = __DIR__ . '/chapters-found';
$chaptersFoundFilename = __DIR__ . '/chapters-found';

\file_put_contents($currentTableOfContentsChaptersFilename, \implode(\PHP_EOL, $currentTableOfContentsChapters));
\file_put_contents($chaptersFoundFilename, \implode(\PHP_EOL, $chaptersFound));
Expand Down
6 changes: 3 additions & 3 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class Connection implements ConnectionInterface
public function __construct(ImapResourceInterface $resource, string $server)
{
$this->resource = $resource;
$this->server = $server;
$this->server = $server;
}

/**
Expand Down Expand Up @@ -209,13 +209,13 @@ private function initMailboxNames(): void
}

$this->mailboxNames = [];
$mailboxesInfo = \imap_getmailboxes($this->resource->getStream(), $this->server, '*');
$mailboxesInfo = \imap_getmailboxes($this->resource->getStream(), $this->server, '*');
if (!\is_array($mailboxesInfo)) {
throw new ImapGetmailboxesException('imap_getmailboxes failed');
}

foreach ($mailboxesInfo as $mailboxInfo) {
$name = \mb_convert_encoding(\str_replace($this->server, '', $mailboxInfo->name), 'UTF-8', 'UTF7-IMAP');
$name = \mb_convert_encoding(\str_replace($this->server, '', $mailboxInfo->name), 'UTF-8', 'UTF7-IMAP');
$this->mailboxNames[$name] = $mailboxInfo;
}
}
Expand Down
36 changes: 18 additions & 18 deletions src/Exception/AbstractException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ abstract class AbstractException extends \RuntimeException
* @var array
*/
private static $errorLabels = [
\E_ERROR => 'E_ERROR',
\E_WARNING => 'E_WARNING',
\E_PARSE => 'E_PARSE',
\E_NOTICE => 'E_NOTICE',
\E_CORE_ERROR => 'E_CORE_ERROR',
\E_CORE_WARNING => 'E_CORE_WARNING',
\E_COMPILE_ERROR => 'E_COMPILE_ERROR',
\E_COMPILE_WARNING => 'E_COMPILE_WARNING',
\E_USER_ERROR => 'E_USER_ERROR',
\E_USER_WARNING => 'E_USER_WARNING',
\E_USER_NOTICE => 'E_USER_NOTICE',
\E_STRICT => 'E_STRICT',
\E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
\E_DEPRECATED => 'E_DEPRECATED',
\E_USER_DEPRECATED => 'E_USER_DEPRECATED',
\E_ERROR => 'E_ERROR',
\E_WARNING => 'E_WARNING',
\E_PARSE => 'E_PARSE',
\E_NOTICE => 'E_NOTICE',
\E_CORE_ERROR => 'E_CORE_ERROR',
\E_CORE_WARNING => 'E_CORE_WARNING',
\E_COMPILE_ERROR => 'E_COMPILE_ERROR',
\E_COMPILE_WARNING => 'E_COMPILE_WARNING',
\E_USER_ERROR => 'E_USER_ERROR',
\E_USER_WARNING => 'E_USER_WARNING',
\E_USER_NOTICE => 'E_USER_NOTICE',
\E_STRICT => 'E_STRICT',
\E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
\E_DEPRECATED => 'E_DEPRECATED',
\E_USER_DEPRECATED => 'E_USER_DEPRECATED',
];

/**
Expand All @@ -39,9 +39,9 @@ final public function __construct(string $message, int $code = 0, \Throwable $pr
$errorType = \sprintf('[%s] ', self::$errorLabels[$code]);
}

$joinString = "\n- ";
$alerts = \imap_alerts();
$errors = \imap_errors();
$joinString = "\n- ";
$alerts = \imap_alerts();
$errors = \imap_errors();
$completeMessage = \sprintf(
"%s%s\nimap_alerts (%s):%s\nimap_errors (%s):%s",
$errorType,
Expand Down
6 changes: 3 additions & 3 deletions src/ImapResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class ImapResource implements ImapResourceInterface
public function __construct($resource, MailboxInterface $mailbox = null)
{
$this->resource = $resource;
$this->mailbox = $mailbox;
$this->mailbox = $mailbox;
}

/**
Expand Down Expand Up @@ -95,8 +95,8 @@ private static function isMailboxOpen(MailboxInterface $mailbox, $resource): boo
}

self::$lastMailboxUsedCache = null;
$check = \imap_check($resource);
$return = false !== $check && $check->Mailbox === $currentMailboxName;
$check = \imap_check($resource);
$return = false !== $check && $check->Mailbox === $currentMailboxName;

if (true === $return) {
self::$lastMailboxUsedCache = $currentMailboxName;
Expand Down
8 changes: 4 additions & 4 deletions src/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ final class Mailbox implements MailboxInterface
public function __construct(ImapResourceInterface $resource, string $name, \stdClass $info)
{
$this->resource = new ImapResource($resource->getStream(), $this);
$this->name = $name;
$this->info = $info;
$this->name = $name;
$this->info = $info;
}

/**
Expand Down Expand Up @@ -206,7 +206,7 @@ public function getMessageSequence(string $sequence): MessageIteratorInterface
{
\imap_errors();

$overview = \imap_fetch_overview($this->resource->getStream(), $sequence, FT_UID);
$overview = \imap_fetch_overview($this->resource->getStream(), $sequence, \FT_UID);
if (empty($overview)) {
if (false !== \imap_last_error()) {
throw new InvalidSearchCriteriaException(\sprintf('Invalid sequence [%s]', $sequence));
Expand Down Expand Up @@ -275,7 +275,7 @@ public function addMessage(string $message, string $options = null, DateTimeInte
*/
public function getThread(): array
{
\set_error_handler(function () {});
\set_error_handler(static function () {});

/** @var array|false $tree */
$tree = \imap_thread($this->resource->getStream());
Expand Down
4 changes: 2 additions & 2 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ protected function lazyLoadStructure(): void
$messageNumber = $this->getNumber();

$errorMessage = null;
$errorNumber = 0;
\set_error_handler(function ($nr, $message) use (&$errorMessage, &$errorNumber) {
$errorNumber = 0;
\set_error_handler(static function ($nr, $message) use (&$errorMessage, &$errorNumber) {
$errorMessage = $message;
$errorNumber = $nr;
});
Expand Down
36 changes: 18 additions & 18 deletions src/Message/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,35 +98,35 @@ abstract class AbstractPart implements PartInterface
* @var array
*/
private static $typesMap = [
\TYPETEXT => self::TYPE_TEXT,
\TYPEMULTIPART => self::TYPE_MULTIPART,
\TYPEMESSAGE => self::TYPE_MESSAGE,
\TYPETEXT => self::TYPE_TEXT,
\TYPEMULTIPART => self::TYPE_MULTIPART,
\TYPEMESSAGE => self::TYPE_MESSAGE,
\TYPEAPPLICATION => self::TYPE_APPLICATION,
\TYPEAUDIO => self::TYPE_AUDIO,
\TYPEIMAGE => self::TYPE_IMAGE,
\TYPEVIDEO => self::TYPE_VIDEO,
\TYPEMODEL => self::TYPE_MODEL,
\TYPEOTHER => self::TYPE_OTHER,
\TYPEAUDIO => self::TYPE_AUDIO,
\TYPEIMAGE => self::TYPE_IMAGE,
\TYPEVIDEO => self::TYPE_VIDEO,
\TYPEMODEL => self::TYPE_MODEL,
\TYPEOTHER => self::TYPE_OTHER,
];

/**
* @var array
*/
private static $encodingsMap = [
\ENC7BIT => self::ENCODING_7BIT,
\ENC8BIT => self::ENCODING_8BIT,
\ENCBINARY => self::ENCODING_BINARY,
\ENCBASE64 => self::ENCODING_BASE64,
\ENC7BIT => self::ENCODING_7BIT,
\ENC8BIT => self::ENCODING_8BIT,
\ENCBINARY => self::ENCODING_BINARY,
\ENCBASE64 => self::ENCODING_BASE64,
\ENCQUOTEDPRINTABLE => self::ENCODING_QUOTED_PRINTABLE,
];

/**
* @var array
*/
private static $attachmentKeys = [
'name' => true,
'filename' => true,
'name*' => true,
'name' => true,
'filename' => true,
'name*' => true,
'filename*' => true,
];

Expand All @@ -144,9 +144,9 @@ public function __construct(
string $partNumber,
\stdClass $structure
) {
$this->resource = $resource;
$this->resource = $resource;
$this->messageNumber = $messageNumber;
$this->partNumber = $partNumber;
$this->partNumber = $partNumber;
$this->setStructure($structure);
}

Expand Down Expand Up @@ -490,7 +490,7 @@ private function lazyParseStructure(): void

// In our context, \ENCOTHER is as useful as an uknown encoding
$this->encoding = self::$encodingsMap[$this->structure->encoding] ?? self::ENCODING_UNKNOWN;
$this->subtype = $this->structure->subtype;
$this->subtype = $this->structure->subtype;

foreach (['disposition', 'bytes', 'description'] as $optional) {
if (isset($this->structure->{$optional})) {
Expand Down
4 changes: 2 additions & 2 deletions src/Message/EmailAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ final class EmailAddress
*/
public function __construct(string $mailbox, string $hostname = null, string $name = null)
{
$this->mailbox = $mailbox;
$this->mailbox = $mailbox;
$this->hostname = $hostname;
$this->name = $name;
$this->name = $name;

if (null !== $hostname) {
$this->address = $mailbox . '@' . $hostname;
Expand Down
2 changes: 1 addition & 1 deletion src/Message/EmbeddedMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getHeaders(): Headers
public function getRawHeaders(): string
{
if (null === $this->rawHeaders) {
$rawHeaders = \explode("\r\n\r\n", $this->getRawMessage(), 2);
$rawHeaders = \explode("\r\n\r\n", $this->getRawMessage(), 2);
$this->rawHeaders = \current($rawHeaders);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Message/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private function parseHeader(string $key, $value)
/** @var \stdClass $address */
foreach ($value as $address) {
if (isset($address->mailbox)) {
$address->host = $address->host ?? null;
$address->host = $address->host ?? null;
$address->personal = isset($address->personal) ? $this->decode($address->personal) : null;
}
}
Expand Down
Loading

0 comments on commit 53f2eda

Please sign in to comment.