File Mailbox.php
has 1092 lines of code (exceeds 250 allowed). Consider refactoring.
<?php
declare(strict_types=1);
namespace PhpImap;
Mailbox
has 90 functions (exceeds 20 allowed). Consider refactoring.
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.
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 getMailHeader
has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
public function getMailHeader(int $mailId): IncomingMailHeader
{
$headersRaw = Imap::fetchheader(
$this->getImapStream(),
$mailId,
Method getMailHeader
has 123 lines of code (exceeds 40 allowed). Consider refactoring.
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.
public function getMailsInfo(array $mailsIds): array
{
$mails = Imap::fetch_overview(
$this->getImapStream(),
\implode(',', $mailsIds),
Method initMailPart
has 95 lines of code (exceeds 40 allowed). Consider refactoring.
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.
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) {
Method downloadAttachment
has 64 lines of code (exceeds 40 allowed). Consider refactoring.
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.
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');
Function possiblyGetMailboxes
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
protected function possiblyGetMailboxes(array $t): array
{
$arr = [];
if ($t) {
foreach ($t as $index => $item) {
Consider simplifying this complex logical expression.
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.
if (TYPEMESSAGE === $partStructure->type && 'RFC822' === $partStructure->subtype && $not_attachment) {
$this->initMailPart($mail, $subPartStructure, $partNum, $markAsSeen);
} elseif (TYPEMULTIPART === $partStructure->type && 'ALTERNATIVE' === $partStructure->subtype && $not_attachment) {
$this->initMailPart($mail, $subPartStructure, $partNum, $markAsSeen);
Function convertToUtf8
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
public function convertToUtf8(string $string, string $fromCharset): string
{
$fromCharset = mb_strtolower($fromCharset);
$newString = '';
Function possiblyGetEmailAndNameFromRecipient
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
protected function possiblyGetEmailAndNameFromRecipient(object $recipient): ?array
{
if (isset($recipient->mailbox, $recipient->host)) {
$recipientMailbox = $recipient->mailbox;
Function flattenParts
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
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)) {
Method __construct
has 7 arguments (exceeds 5 allowed). Consider refactoring.
public function __construct(string $imapPath, string $login, string $password, string $attachmentsDir = null, string $serverEncoding = 'UTF-8', bool $trimImapPath = true, bool $attachmentFilenameMode = false)
Similar blocks of code found in 2 locations. Consider refactoring.
if (isset($head->to)) {
$toStrings = [];
foreach ($head->to as $to) {
$to_parsed = $this->possiblyGetEmailAndNameFromRecipient($to);
if ($to_parsed) {
Similar blocks of code found in 2 locations. Consider refactoring.
if (isset($head->cc)) {
$ccStrings = [];
foreach ($head->cc as $cc) {
$cc_parsed = $this->possiblyGetEmailAndNameFromRecipient($cc);
if ($cc_parsed) {
There are no issues that match your filters.