techno-express/mailreader

View on GitHub

Showing 14 of 21 total issues

Function getBody has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
Open

    public function getBody(string $returnType = null)
    {
        $body = '';
        $detectedContentType = false;
        $contentTransferEncoding = null;
Severity: Minor
Found in decode/MailParser.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

Function decode has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

    public function decode($attachment_directory = null, $saving = true)
    {
        if ($this->raw !== null) {
            if (!empty($attachment_directory))
                $this->attachment_directory = $attachment_directory;
Severity: Minor
Found in decode/MailParser.php - About 5 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 decodePart has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

    private function decodePart($body_part, $saving = true)
    {
        if (isset($body_part->ctype_parameters) && \is_array($body_part->ctype_parameters)) {
            if (\array_key_exists('name', $body_part->ctype_parameters)) {
                $filename = $body_part->ctype_parameters['name'];
Severity: Minor
Found in decode/MailParser.php - About 3 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 extractHeadersAndBody has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    private function extractHeadersAndBody()
    {
        $lines = \preg_split("/(\r?\n|\r)/", $this->raw);

        $currentHeader = '';
Severity: Minor
Found in decode/MailParser.php - About 3 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 create_mail_pipe_db has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    function create_mail_pipe_db($dbc = null)
    {
        if ($dbc instanceof \PDO) {
            $rows = $dbc->query("SHOW TABLES LIKE 'emails'")->rowCount();
            if ($rows < 1) {
Severity: Minor
Found in decode/functions.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 create_mail_pipe_db has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    function create_mail_pipe_db($dbc = null)
    {
        if ($dbc instanceof \PDO) {
            $rows = $dbc->query("SHOW TABLES LIKE 'emails'")->rowCount();
            if ($rows < 1) {
Severity: Minor
Found in decode/functions.php - About 1 hr to fix

    Function saveAttachment has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        private function saveAttachment($filename, $contents, $mime_type = 'unknown', $saving = true)
        {
            $filename = \mb_convert_encoding($filename, $this->charset, $this->charset);
            $dot_ext = '.' . $this->getFileExtension($filename);
            $unlocked_and_unique = false;
    Severity: Minor
    Found in decode/MailParser.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

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

        public function __call($function, $args)
        {
            $prefix = \substr($function, 0, 3);
            $property = \strtolower(\substr($function, 3, \strlen($function)));
    
    
    Severity: Major
    Found in decode/Messages.php and 1 other location - About 1 hr to fix
    decode/MessageAttachments.php on lines 26..35

    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

    Further Reading

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

        public function __call($function, $args)
        {
            $prefix = \substr($function, 0, 3);
            $property = \strtolower(\substr($function, 3, \strlen($function)));
    
    
    Severity: Major
    Found in decode/MessageAttachments.php and 1 other location - About 1 hr to fix
    decode/Messages.php on lines 28..37

    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

    Further Reading

    Function findDirectory has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        public function findDirectory($startingDirectory = null, $directoryNamed = 'mailPiped')
        {
            $home = (\getenv('USERPROFILE') !== false) ? \getenv('USERPROFILE') : \getenv('HOME');
            $info = ($home !== false) ? $home : \dirname(__FILE__);
            $findConfigPath = $info . \DIRECTORY_SEPARATOR;
    Severity: Minor
    Found in decode/MailReader.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

    Method saveToDb has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function saveToDb()
        {
            $insert = $this->pdo->prepare("INSERT INTO emails (user, toaddr, sender, fromaddr, date, subject, plain, html) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
    
            // Replace non UTF-8 characters with their UTF-8 equivalent, or drop them
    Severity: Minor
    Found in decode/MailReader.php - About 1 hr to fix

      Function getMessages has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getMessages(string $email, int $offset = 0, int $max = 20)
          {
              $dbc = $this->pdo;
              if ($dbc instanceof \PDO) {
                  $emails = $dbc->prepare("SELECT * FROM emails WHERE toaddr=:mail LIMIT :offset, :max");
      Severity: Minor
      Found in decode/MailReader.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 saveToDb has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          private function saveToDb()
          {
              $insert = $this->pdo->prepare("INSERT INTO emails (user, toaddr, sender, fromaddr, date, subject, plain, html) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
      
              // Replace non UTF-8 characters with their UTF-8 equivalent, or drop them
      Severity: Minor
      Found in decode/MailReader.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 getMessageAttachments has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getMessageAttachments(int $message_id)
          {
              $dbc = $this->pdo;
              if ($dbc instanceof \PDO) {
                  $files = $dbc->prepare("SELECT * FROM files WHERE email=:id");
      Severity: Minor
      Found in decode/MailReader.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

      Severity
      Category
      Status
      Source
      Language