File Mailbox.php
has 1092 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
declare(strict_types=1);
namespace PhpImap;
Mailbox
has 90 functions (exceeds 20 allowed). Consider refactoring. Open
class Mailbox
{
public const EXPECTED_SIZE_OF_MESSAGE_AS_ARRAY = 2;
public const MAX_LENGTH_FILEPATH = 255;
Function initMailPart
has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring. Open
protected function initMailPart(IncomingMail $mail, object $partStructure, $partNum, bool $markAsSeen = true, bool $emlParse = false): void
{
if (!isset($mail->id)) {
throw new InvalidArgumentException('Argument 1 passeed to '.__METHOD__.'() did not have the id property set!');
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getMailHeader
has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring. Open
public function getMailHeader(int $mailId): IncomingMailHeader
{
$headersRaw = Imap::fetchheader(
$this->getImapStream(),
$mailId,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getMailHeader
has 123 lines of code (exceeds 40 allowed). Consider refactoring. Open
public function getMailHeader(int $mailId): IncomingMailHeader
{
$headersRaw = Imap::fetchheader(
$this->getImapStream(),
$mailId,
Function getMailsInfo
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
public function getMailsInfo(array $mailsIds): array
{
$mails = Imap::fetch_overview(
$this->getImapStream(),
\implode(',', $mailsIds),
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method initMailPart
has 95 lines of code (exceeds 40 allowed). Consider refactoring. Open
protected function initMailPart(IncomingMail $mail, object $partStructure, $partNum, bool $markAsSeen = true, bool $emlParse = false): void
{
if (!isset($mail->id)) {
throw new InvalidArgumentException('Argument 1 passeed to '.__METHOD__.'() did not have the id property set!');
}
Function downloadAttachment
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
public function downloadAttachment(DataPartInfo $dataInfo, array $params, object $partStructure, bool $emlOrigin = false): IncomingMailAttachment
{
if ('RFC822' == $partStructure->subtype && isset($partStructure->disposition) && 'attachment' == $partStructure->disposition) {
$fileName = \strtolower($partStructure->subtype).'.eml';
} elseif ('ALTERNATIVE' == $partStructure->subtype) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method downloadAttachment
has 64 lines of code (exceeds 40 allowed). Consider refactoring. Open
public function downloadAttachment(DataPartInfo $dataInfo, array $params, object $partStructure, bool $emlOrigin = false): IncomingMailAttachment
{
if ('RFC822' == $partStructure->subtype && isset($partStructure->disposition) && 'attachment' == $partStructure->disposition) {
$fileName = \strtolower($partStructure->subtype).'.eml';
} elseif ('ALTERNATIVE' == $partStructure->subtype) {
Function setConnectionArgs
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function setConnectionArgs(int $options = 0, int $retriesNum = 0, array $params = null): void
{
if (0 !== $options) {
if (($options & self::IMAP_OPTIONS_SUPPORTED_VALUES) !== $options) {
throw new InvalidParameterException('Please check your option for setConnectionArgs()! Unsupported option "'.$options.'". Available options: https://www.php.net/manual/de/function.imap-open.php');
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function possiblyGetMailboxes
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
protected function possiblyGetMailboxes(array $t): array
{
$arr = [];
if ($t) {
foreach ($t as $index => $item) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Consider simplifying this complex logical expression. Open
if ('RFC822' == $partStructure->subtype && isset($partStructure->disposition) && 'attachment' == $partStructure->disposition) {
$fileName = \strtolower($partStructure->subtype).'.eml';
} elseif ('ALTERNATIVE' == $partStructure->subtype) {
$fileName = \strtolower($partStructure->subtype).'.eml';
} elseif ((!isset($params['filename']) || empty(\trim($params['filename']))) && (!isset($params['name']) || empty(\trim($params['name'])))) {
Consider simplifying this complex logical expression. Open
if (TYPEMESSAGE === $partStructure->type && 'RFC822' === $partStructure->subtype && $not_attachment) {
$this->initMailPart($mail, $subPartStructure, $partNum, $markAsSeen);
} elseif (TYPEMULTIPART === $partStructure->type && 'ALTERNATIVE' === $partStructure->subtype && $not_attachment) {
// https://github.com/barbushin/php-imap/issues/198
$this->initMailPart($mail, $subPartStructure, $partNum, $markAsSeen);
Function convertToUtf8
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function convertToUtf8(string $string, string $fromCharset): string
{
$fromCharset = mb_strtolower($fromCharset);
$newString = '';
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function flattenParts
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function flattenParts(array $messageParts, array $flattenedParts = [], string $prefix = '', int $index = 1, bool $fullPrefix = true): array
{
foreach ($messageParts as $part) {
$flattenedParts[$prefix.$index] = $part;
if (isset($part->parts)) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method __construct
has 7 arguments (exceeds 5 allowed). Consider refactoring. Open
public function __construct(string $imapPath, string $login, string $password, string $attachmentsDir = null, string $serverEncoding = 'UTF-8', bool $trimImapPath = true, bool $attachmentFilenameMode = false)
Function possiblyGetEmailAndNameFromRecipient
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected function possiblyGetEmailAndNameFromRecipient(object $recipient): ?array
{
if (isset($recipient->mailbox, $recipient->host)) {
/** @var string */
$recipientMailbox = $recipient->mailbox;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (isset($head->cc)) {
$ccStrings = [];
foreach ($head->cc as $cc) {
$cc_parsed = $this->possiblyGetEmailAndNameFromRecipient($cc);
if ($cc_parsed) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 109.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (isset($head->to)) {
$toStrings = [];
foreach ($head->to as $to) {
$to_parsed = $this->possiblyGetEmailAndNameFromRecipient($to);
if ($to_parsed) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 109.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76