barbushin/php-imap

View on GitHub

Showing 26 of 38 total issues

File Mailbox.php has 1041 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

namespace PhpImap;
Severity: Major
Found in src/PhpImap/Mailbox.php - About 2 days to fix

    Mailbox has 86 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Mailbox
    {
        const EXPECTED_SIZE_OF_MESSAGE_AS_ARRAY = 2;
    
        const MAX_LENGTH_FILEPATH = 255;
    Severity: Major
    Found in src/PhpImap/Mailbox.php - About 1 day to fix

      File Imap.php has 696 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      /**
       * @author Barbushin Sergey http://linkedin.com/in/barbushin
       * @author BAPCLTD-Marv
       */
      Severity: Major
      Found in src/PhpImap/Imap.php - About 1 day to fix

        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!');
                }
        Severity: Minor
        Found in src/PhpImap/Mailbox.php - About 1 day to fix

        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,
        Severity: Minor
        Found in src/PhpImap/Mailbox.php - About 6 hrs to fix

        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

        Imap has 41 functions (exceeds 20 allowed). Consider refactoring.
        Open

        final class Imap
        {
            /** @psalm-var list<int> */
            const SORT_CRITERIA = [
                SORTARRIVAL,
        Severity: Minor
        Found in src/PhpImap/Imap.php - About 5 hrs to fix

          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),
          Severity: Minor
          Found in src/PhpImap/Mailbox.php - About 4 hrs to fix

          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 113 lines of code (exceeds 40 allowed). Consider refactoring.
          Open

              public function getMailHeader(int $mailId): IncomingMailHeader
              {
                  $headersRaw = Imap::fetchheader(
                      $this->getImapStream(),
                      $mailId,
          Severity: Major
          Found in src/PhpImap/Mailbox.php - About 3 hrs to fix

            Method initMailPart has 96 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!');
                    }
            Severity: Major
            Found in src/PhpImap/Mailbox.php - About 3 hrs to fix

              Function embedImageAttachments has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function embedImageAttachments(): void
                  {
                      $fetchedHtml = (string) $this->__get('textHtml');
              
                      \preg_match_all("/\bcid:[^'\"\s]{1,256}/mi", $fetchedHtml, $matches);
              Severity: Minor
              Found in src/PhpImap/IncomingMail.php - About 2 hrs to fix

              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 downloadAttachment has a Cognitive Complexity of 17 (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) {
              Severity: Minor
              Found in src/PhpImap/Mailbox.php - About 2 hrs to fix

              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 59 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) {
              Severity: Major
              Found in src/PhpImap/Mailbox.php - About 1 hr to fix

                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');
                Severity: Minor
                Found in src/PhpImap/Mailbox.php - About 1 hr to fix

                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) {
                Severity: Minor
                Found in src/PhpImap/Mailbox.php - About 1 hr to fix

                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 replaceInternalLinks has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function replaceInternalLinks(string $baseUri): string
                    {
                        $baseUri = \rtrim($baseUri, '\\/').'/';
                        $fetchedHtml = $this->textHtml;
                        $search = [];
                Severity: Minor
                Found in src/PhpImap/IncomingMail.php - About 1 hr to fix

                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'])))) {
                Severity: Major
                Found in src/PhpImap/Mailbox.php - About 1 hr to fix

                  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);
                  Severity: Major
                  Found in src/PhpImap/Mailbox.php - About 1 hr to fix

                    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 = '';
                    
                    
                    Severity: Minor
                    Found in src/PhpImap/Mailbox.php - About 55 mins to fix

                    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)) {
                    Severity: Minor
                    Found in src/PhpImap/Mailbox.php - About 45 mins to fix

                    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 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 mixed */
                                $recipientMailbox = $recipient->mailbox;
                    Severity: Minor
                    Found in src/PhpImap/Mailbox.php - About 45 mins to fix

                    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

                    Severity
                    Category
                    Status
                    Source
                    Language