YetiForceCompany/YetiForceCRM

View on GitHub
app/SystemWarnings.php

Summary

Maintainability
B
6 hrs
Test Coverage
A
95%

Function getWarnings has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

    public static function getWarnings($folders, $active = true)
    {
        if (empty($folders)) {
            return [];
        }
Severity: Minor
Found in app/SystemWarnings.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 getWarnings has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function getWarnings($folders, $active = true)
    {
        if (empty($folders)) {
            return [];
        }
Severity: Minor
Found in app/SystemWarnings.php - About 1 hr to fix

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

        public static function getFolders()
        {
            $folders = [];
            $i = 0;
            foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(self::FOLDERS, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
    Severity: Minor
    Found in app/SystemWarnings.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

    The method getWarnings() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10.
    Open

        public static function getWarnings($folders, $active = true)
        {
            if (empty($folders)) {
                return [];
            }
    Severity: Minor
    Found in app/SystemWarnings.php by phpmd

    CyclomaticComplexity

    Since: 0.1

    Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

    Example

    // Cyclomatic Complexity = 11
    class Foo {
    1   public function example() {
    2       if ($a == $b) {
    3           if ($a1 == $b1) {
                    fiddle();
    4           } elseif ($a2 == $b2) {
                    fiddle();
                } else {
                    fiddle();
                }
    5       } elseif ($c == $d) {
    6           while ($c == $d) {
                    fiddle();
                }
    7        } elseif ($e == $f) {
    8           for ($n = 0; $n < $h; $n++) {
                    fiddle();
                }
            } else {
                switch ($z) {
    9               case 1:
                        fiddle();
                        break;
    10              case 2:
                        fiddle();
                        break;
    11              case 3:
                        fiddle();
                        break;
                    default:
                        fiddle();
                        break;
                }
            }
        }
    }

    Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

    Refactor this function to reduce its Cognitive Complexity from 29 to the 15 allowed.
    Open

        public static function getWarnings($folders, $active = true)
    Severity: Critical
    Found in app/SystemWarnings.php by sonar-php

    Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

    See

    Missing class import via use statement (line '32', column '59').
    Open

            foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(self::FOLDERS, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
    Severity: Minor
    Found in app/SystemWarnings.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    The method getWarnings has a boolean flag argument $active, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public static function getWarnings($folders, $active = true)
    Severity: Minor
    Found in app/SystemWarnings.php by phpmd

    BooleanArgumentFlag

    Since: 1.4.0

    A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

    Example

    class Foo {
        public function bar($flag = true) {
        }
    }

    Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

    Missing class import via use statement (line '74', column '20').
    Open

                $iterator = new \DirectoryIterator($dir);
    Severity: Minor
    Found in app/SystemWarnings.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Missing class import via use statement (line '32', column '28').
    Open

            foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(self::FOLDERS, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
    Severity: Minor
    Found in app/SystemWarnings.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Avoid using static access to class 'App\Language' in method 'getFolders'.
    Open

                    $folder = ['id' => $i, 'text' => Language::translate($fileName, 'Settings:SystemWarnings'), 'subPath' => $subPath, 'parent' => '#'];
    Severity: Minor
    Found in app/SystemWarnings.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Call to undeclared method \RecursiveIteratorIterator::getSubPathName
    Open

                    $subPath = $iterator->getSubPathName();
    Severity: Critical
    Found in app/SystemWarnings.php by phan

    Avoid variables with short names like $i. Configured minimum length is 3.
    Open

            $i = 0;
    Severity: Minor
    Found in app/SystemWarnings.php by phpmd

    ShortVariable

    Since: 0.2

    Detects when a field, local, or parameter has a very short name.

    Example

    class Something {
        private $q = 15; // VIOLATION - Field
        public static function main( array $as ) { // VIOLATION - Formal
            $r = 20 + $this->q; // VIOLATION - Local
            for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                $r += $this->q;
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#shortvariable

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Line exceeds 120 characters; contains 148 characters
    Open

                    $folder = ['id' => $i, 'text' => Language::translate($fileName, 'Settings:SystemWarnings'), 'subPath' => $subPath, 'parent' => '#'];
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $folder['parent'] = $folders[$parent]['id'];
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                ++$i;
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                if (!is_dir($dir)) {
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $folder = str_replace('/', '\\', $folder);
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                $actions[$instace->getPriority() . $fileName] = $instace;
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    }
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $folder['state']['selected'] = true;
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

            foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(self::FOLDERS, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Line exceeds 120 characters; contains 199 characters
    Open

            foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(self::FOLDERS, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $parent = rtrim(rtrim($subPath, $fileName), '/');
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $className = "\\App\\SystemWarnings\\$folder\\$fileName";
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                $instace->process();
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            if (!$active || (!$isIgnored && 1 !== $instace->getStatus())) {
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return array
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $i = 0;
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return array
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public static function getWarnings($folders, $active = true)
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            $isIgnored = 2 === $instace->getStatusValue();
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                return [];
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $instace = new $className();
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            }
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

        const FOLDERS = 'app/SystemWarnings';
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                if ($item->isDir()) {
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $subPath = str_replace(\DIRECTORY_SEPARATOR, '/', $subPath);
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    }
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param mixed $active
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            if (!$active || !$isIgnored) {
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            }
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

            krsort($actions);
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $folders = [];
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    if (\in_array($subPath, self::SELECTED_FOLDERS)) {
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (empty($folders)) {
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    if (!$item->isDot() && !$item->isDir()) {
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        if ($instace->preProcess()) {
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Returns a list of folders warnings.
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

            return $folders;
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $folders = array_keys(static::getFolders());
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                foreach ($iterator as $item) {
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $fileName = $item->getBasename('.php');
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $fileName = $item->getFilename();
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param array $folders
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    continue;
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $iterator = new \DirectoryIterator($dir);
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                $instace->setFolder($folder);
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (!\is_array($folders) && 'all' === $folders) {
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

        const SELECTED_FOLDERS = ['SystemRequirements', 'YetiForce', 'Security', 'Mail'];
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public static function getFolders()
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $folder = ['id' => $i, 'text' => Language::translate($fileName, 'Settings:SystemWarnings'), 'subPath' => $subPath, 'parent' => '#'];
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    if (isset($folders[$parent])) {
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $folders[$subPath] = $folder;
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Returns a list of warnings instance.
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $actions = [];
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

            return $actions;
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $subPath = $iterator->getSubPathName();
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    }
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

            foreach ($folders as $folder) {
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $dir = self::FOLDERS . '/' . $folder;
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        }
    Severity: Minor
    Found in app/SystemWarnings.php by phpcodesniffer

    There are no issues that match your filters.

    Category
    Status