Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/Improve php-cs-fixer rules and apply necessary changes to code #663

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,35 @@
return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP71Migration' => true, // @PHP72Migration does not exist
'@PHP71Migration:risky' => true, // @PHP72Migration:risky does not exist
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'declare_strict_types' => true,
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => false,
],
'native_constant_invocation' => true,
'native_function_invocation' => [
'strict' => false,
'include' => ['@compiler_optimized'],
],
'single_quote' => true,
'include' => true,
'no_superfluous_phpdoc_tags' => true,
'ordered_class_elements' => true,
'no_extra_blank_lines' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'ordered_imports' => true,
'php_unit_dedicate_assert' => ['target' => 'newest'],
'php_unit_method_casing' => true,
'php_unit_test_case_static_method_calls' => ['call_type' => 'this'],
'phpdoc_to_comment' => false,
'void_return' => true,
'phpdoc_align' => true,
'phpdoc_annotation_without_dot' => true,
'phpdoc_indent' => true,
'phpdoc_inline_tag_normalizer' => true,
'phpdoc_no_access' => true,
'phpdoc_no_alias_tag' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_return_self_reference' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_summary' => true,
'phpdoc_tag_type' => true,
'phpdoc_to_comment' => true,
'phpdoc_trim' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => true,
'phpdoc_var_without_name' => true
])
->setFinder(PhpCsFixer\Finder::create()
->exclude('vendor')
Expand Down
4 changes: 2 additions & 2 deletions src/PhpImap/DataPartInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DataPartInfo
*/
public $encoding;

/** @var string|null */
/** @var null|string */
public $charset;

/**
Expand All @@ -58,7 +58,7 @@ class DataPartInfo
*/
public $options;

/** @var string|null */
/** @var null|string */
protected $data;

/**
Expand Down
32 changes: 16 additions & 16 deletions src/PhpImap/Imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ final class Imap
];

/**
* @param resource|false $imap_stream
* @param false|resource $imap_stream
*
* @return true
*
Expand Down Expand Up @@ -143,7 +143,7 @@ public static function check($imap_stream): object
throw new UnexpectedValueException('Could not check imap mailbox!', 0, self::HandleErrors(\imap_errors(), 'imap_check'));
}

/** @var object */
/* @var object */
return $result;
}

Expand Down Expand Up @@ -233,7 +233,7 @@ public static function createmailbox($imap_stream, string $mailbox): bool

/**
* @param false|resource $imap_stream
* @param string|int $msg_number
* @param int|string $msg_number
*
* @return true
*/
Expand Down Expand Up @@ -339,13 +339,13 @@ public static function fetch_overview(
throw new UnexpectedValueException('Could not fetch overview for message from mailbox!', 0, self::HandleErrors(\imap_errors(), 'imap_fetch_overview'));
}

/** @psalm-var list<object> */
/* @psalm-var list<object> */
return $result;
}

/**
* @param false|resource $imap_stream
* @param string|int $section
* @param int|string $section
*/
public static function fetchbody(
$imap_stream,
Expand Down Expand Up @@ -418,7 +418,7 @@ public static function fetchstructure(
throw new UnexpectedValueException('Could not fetch message structure from mailbox!', 0, self::HandleErrors(\imap_errors(), 'imap_fetchstructure'));
}

/** @psalm-var PARTSTRUCTURE */
/* @psalm-var PARTSTRUCTURE */
return $result;
}

Expand Down Expand Up @@ -446,7 +446,7 @@ public static function get_quotaroot(
}

/**
* @param resource|false $imap_stream
* @param false|resource $imap_stream
*
* @return object[]
*
Expand Down Expand Up @@ -479,12 +479,12 @@ public static function getmailboxes(
throw new UnexpectedValueException('Call to imap_getmailboxes() with supplied arguments returned false, not array!', 0, self::HandleErrors(\imap_errors(), 'imap_getmailboxes'));
}

/** @psalm-var list<object> */
/* @psalm-var list<object> */
return $result;
}

/**
* @param resource|false $imap_stream
* @param false|resource $imap_stream
*
* @return object[]
*
Expand All @@ -507,7 +507,7 @@ public static function getsubscribed(
throw new UnexpectedValueException('Call to imap_getsubscribed() with supplied arguments returned false, not array!', 0, self::HandleErrors(\imap_errors(), 'imap_getsubscribed'));
}

/** @psalm-var list<object> */
/* @psalm-var list<object> */
return $result;
}

Expand Down Expand Up @@ -716,7 +716,7 @@ public static function open(
}

/**
* @param resource|false $imap_stream
* @param false|resource $imap_stream
*
* @psalm-pure
*/
Expand Down Expand Up @@ -779,7 +779,7 @@ public static function reopen(

/**
* @param false|resource $imap_stream
* @param string|false|resource $file
* @param false|resource|string $file
*
* @return true
*/
Expand Down Expand Up @@ -852,7 +852,7 @@ public static function search(
throw new UnexpectedValueException('Could not search mailbox!', 0, self::HandleErrors($errors, 'imap_search'));
}

/** @psalm-var list<int> */
/* @psalm-var list<int> */
return $result;
}

Expand Down Expand Up @@ -954,7 +954,7 @@ public static function sort(
throw new UnexpectedValueException('Could not sort messages!', 0, self::HandleErrors(\imap_errors(), 'imap_sort'));
}

/** @psalm-var list<int> */
/* @psalm-var list<int> */
return $result;
}

Expand Down Expand Up @@ -1001,7 +1001,7 @@ public static function subscribe($imap_stream, string $mailbox): void
/**
* @psalm-param value-of<self::TIMEOUT_TYPES> $timeout_type
*
* @return true|int
* @return int|true
*/
public static function timeout(
int $timeout_type,
Expand Down Expand Up @@ -1095,7 +1095,7 @@ private static function EnsureResource($maybe, string $method, int $argument)
throw new InvalidArgumentException('Argument '.(string) $argument.' passed to '.$method.' must be a valid resource!');
}

/** @var resource */
/* @var resource */
return $maybe;
}

Expand Down
12 changes: 6 additions & 6 deletions src/PhpImap/IncomingMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class IncomingMail extends IncomingMailHeader
*/
protected $dataInfo = [[], []];

/** @var string|null */
/** @var null|string */
private $textPlain;

/** @var string|null */
/** @var null|string */
private $textHtml;

/**
Expand Down Expand Up @@ -70,7 +70,7 @@ public function __get(string $name): string
$this->$name .= \trim($data->fetch());
}

/** @var string */
/* @var string */
return $this->$name;
}

Expand Down Expand Up @@ -99,7 +99,7 @@ public function setHeader(IncomingMailHeader $header): void
}

/**
* @param DataPartInfo::TEXT_PLAIN|DataPartInfo::TEXT_HTML $type
* @param DataPartInfo::TEXT_HTML|DataPartInfo::TEXT_PLAIN $type
*/
public function addDataPartInfo(DataPartInfo $dataInfo, int $type): void
{
Expand Down Expand Up @@ -197,7 +197,7 @@ public function replaceInternalLinks(string $baseUri): string
}
}

/** @psalm-var string */
/* @psalm-var string */
return \str_replace($search, $replace, $fetchedHtml);
}

Expand All @@ -219,7 +219,7 @@ public function embedImageAttachments(): void
$cid = \str_replace('cid:', '', $match);

foreach ($attachments as $attachment) {
/**
/*
* Inline images can contain a "Content-Disposition: inline", but only a "Content-ID" is also enough.
* See https://github.com/barbushin/php-imap/issues/569.
*/
Expand Down
42 changes: 21 additions & 21 deletions src/PhpImap/IncomingMailAttachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,70 @@
*
* @author Barbushin Sergey http://linkedin.com/in/barbushin
*
* @property string|false|null $filePath lazy attachment data file
* @property null|false|string $filePath lazy attachment data file
*
* @psalm-type fileinfoconst = 0|2|16|1024|1040|8|32|128|256|16777216
*/
class IncomingMailAttachment
{
/** @var string|null */
/** @var null|string */
public $id;

/** @var string|null */
/** @var null|string */
public $contentId;

/** @var int|null */
/** @var null|int */
public $type;

/** @var int|null */
/** @var null|int */
public $encoding;

/** @var string|null */
/** @var null|string */
public $subtype;

/** @var string|null */
/** @var null|string */
public $description;

/** @var string|null */
/** @var null|string */
public $name;

/** @var int|null */
/** @var null|int */
public $sizeInBytes;

/** @var string|null */
/** @var null|string */
public $disposition;

/** @var string|null */
/** @var null|string */
public $charset;

/** @var bool|null */
/** @var null|bool */
public $emlOrigin;

/** @var string|null */
/** @var null|string */
public $fileInfoRaw;

/** @var string|null */
/** @var null|string */
public $fileInfo;

/** @var string|null */
/** @var null|string */
public $mime;

/** @var string|null */
/** @var null|string */
public $mimeEncoding;

/** @var string|null */
/** @var null|string */
public $fileExtension;

/** @var string|null */
/** @var null|string */
public $mimeType;

/** @var string|null */
/** @var null|string */
private $file_path;

/** @var DataPartInfo|null */
/** @var null|DataPartInfo */
private $dataInfo;

/** @var string|null */
/** @var null|string */
private $filePath;

/**
Expand Down
Loading