Kylob/BootPress

View on GitHub
src/Admin/Files.php

Summary

Maintainability
F
1 wk
Test Coverage

save accesses the super-global variable $_POST.
Open

    public static function save(array $files, array $remove = array())
    {
        $page = Page::html();
        if (($retrieve = $page->post('retrieve')) && isset($files[$retrieve])) {
            exit(is_file($files[$retrieve]) ? file_get_contents($files[$retrieve]) : '');
Severity: Minor
Found in src/Admin/Files.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

Function view has a Cognitive Complexity of 107 (exceeds 5 allowed). Consider refactoring.
Open

    public static function view($dir, array $extensions = array(), $recursive = false)
    {
        extract(Admin::params(array('bp', 'blog', 'auth', 'page', 'website')));
        $dir = rtrim($dir, '/').'/';

Severity: Minor
Found in src/Admin/Files.php - About 2 days 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 view has 272 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function view($dir, array $extensions = array(), $recursive = false)
    {
        extract(Admin::params(array('bp', 'blog', 'auth', 'page', 'website')));
        $dir = rtrim($dir, '/').'/';

Severity: Major
Found in src/Admin/Files.php - About 1 day to fix

    File Files.php has 584 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    namespace BootPress\Admin;
    
    use BootPress\Blog\Twig\Parser;
    Severity: Major
    Found in src/Admin/Files.php - About 1 day to fix

      Function save has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function save(array $files, array $remove = array())
          {
              $page = Page::html();
              if (($retrieve = $page->post('retrieve')) && isset($files[$retrieve])) {
                  exit(is_file($files[$retrieve]) ? file_get_contents($files[$retrieve]) : '');
      Severity: Minor
      Found in src/Admin/Files.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 image has 114 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private static function image($path, $eject = '')
          {
              $html = '';
              $imagick = (extension_loaded('imagick') && class_exists('Imagick')) ? true : false;
              $types = array('jpg', 'gif', 'png');
      Severity: Major
      Found in src/Admin/Files.php - About 4 hrs to fix

        Function iterate has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function iterate($path, $recursive = false, $types = null)
            {
                $dirs = $files = array();
                if (is_dir($path)) {
                    $cut = strlen($path);
        Severity: Minor
        Found in src/Admin/Files.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

        Method save has 69 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function save(array $files, array $remove = array())
            {
                $page = Page::html();
                if (($retrieve = $page->post('retrieve')) && isset($files[$retrieve])) {
                    exit(is_file($files[$retrieve]) ? file_get_contents($files[$retrieve]) : '');
        Severity: Major
        Found in src/Admin/Files.php - About 2 hrs to fix

          Method iterate has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function iterate($path, $recursive = false, $types = null)
              {
                  $dirs = $files = array();
                  if (is_dir($path)) {
                      $cut = strlen($path);
          Severity: Minor
          Found in src/Admin/Files.php - About 1 hr to fix

            Function image has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                private static function image($path, $eject = '')
                {
                    $html = '';
                    $imagick = (extension_loaded('imagick') && class_exists('Imagick')) ? true : false;
                    $types = array('jpg', 'gif', 'png');
            Severity: Minor
            Found in src/Admin/Files.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 resource has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                private static function resource($path)
                {
                    if (preg_match('/\.(jpg|jpeg|gif|png|ico)$/i', $path) && is_file($path) && ($dimensions = getimagesize($path))) {
                        list($width, $height, $type) = $dimensions;
                        switch ($type) {
            Severity: Minor
            Found in src/Admin/Files.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

            Avoid too many return statements within this method.
            Open

                        return $page->sendJson($data);
            Severity: Major
            Found in src/Admin/Files.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return '<div id="admin_manage_files">'.$files.'</div><br>'.$form;
              Severity: Major
              Found in src/Admin/Files.php - About 30 mins to fix

                Function format has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    public static function format($path, $slashes = false, $capitals = false)
                    {
                        if ($capitals === false) {
                            $path = strtolower($path);
                        }
                Severity: Minor
                Found in src/Admin/Files.php - About 25 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 view() contains an exit expression.
                Open

                                exit('success');
                Severity: Minor
                Found in src/Admin/Files.php by phpmd

                ExitExpression

                Since: 0.2

                An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

                Example

                class Foo {
                    public function bar($param)  {
                        if ($param === 42) {
                            exit(23);
                        }
                    }
                }

                Source https://phpmd.org/rules/design.html#exitexpression

                The method save() contains an exit expression.
                Open

                                exit('This file is not writable');
                Severity: Minor
                Found in src/Admin/Files.php by phpmd

                ExitExpression

                Since: 0.2

                An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

                Example

                class Foo {
                    public function bar($param)  {
                        if ($param === 42) {
                            exit(23);
                        }
                    }
                }

                Source https://phpmd.org/rules/design.html#exitexpression

                The method save() contains an exit expression.
                Open

                                exit('There was an error');
                Severity: Minor
                Found in src/Admin/Files.php by phpmd

                ExitExpression

                Since: 0.2

                An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

                Example

                class Foo {
                    public function bar($param)  {
                        if ($param === 42) {
                            exit(23);
                        }
                    }
                }

                Source https://phpmd.org/rules/design.html#exitexpression

                The method view() contains an exit expression.
                Open

                            exit('error');
                Severity: Minor
                Found in src/Admin/Files.php by phpmd

                ExitExpression

                Since: 0.2

                An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

                Example

                class Foo {
                    public function bar($param)  {
                        if ($param === 42) {
                            exit(23);
                        }
                    }
                }

                Source https://phpmd.org/rules/design.html#exitexpression

                The method save() contains an exit expression.
                Open

                                exit('Saved');
                Severity: Minor
                Found in src/Admin/Files.php by phpmd

                ExitExpression

                Since: 0.2

                An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

                Example

                class Foo {
                    public function bar($param)  {
                        if ($param === 42) {
                            exit(23);
                        }
                    }
                }

                Source https://phpmd.org/rules/design.html#exitexpression

                The method save() contains an exit expression.
                Open

                                            exit($e->getMessage());
                Severity: Minor
                Found in src/Admin/Files.php by phpmd

                ExitExpression

                Since: 0.2

                An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

                Example

                class Foo {
                    public function bar($param)  {
                        if ($param === 42) {
                            exit(23);
                        }
                    }
                }

                Source https://phpmd.org/rules/design.html#exitexpression

                The method save() contains an exit expression.
                Open

                                            exit($e->getMessage());
                Severity: Minor
                Found in src/Admin/Files.php by phpmd

                ExitExpression

                Since: 0.2

                An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

                Example

                class Foo {
                    public function bar($param)  {
                        if ($param === 42) {
                            exit(23);
                        }
                    }
                }

                Source https://phpmd.org/rules/design.html#exitexpression

                The method save() contains an exit expression.
                Open

                                exit('Saved');
                Severity: Minor
                Found in src/Admin/Files.php by phpmd

                ExitExpression

                Since: 0.2

                An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

                Example

                class Foo {
                    public function bar($param)  {
                        if ($param === 42) {
                            exit(23);
                        }
                    }
                }

                Source https://phpmd.org/rules/design.html#exitexpression

                The method save() contains an exit expression.
                Open

                                            exit(preg_replace('#'.str_replace('/', '[\\\\//]{1}', preg_quote($linter)).'#', str_replace('.ini', '', $save).'.ini', $e->getMessage()));
                Severity: Minor
                Found in src/Admin/Files.php by phpmd

                ExitExpression

                Since: 0.2

                An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

                Example

                class Foo {
                    public function bar($param)  {
                        if ($param === 42) {
                            exit(23);
                        }
                    }
                }

                Source https://phpmd.org/rules/design.html#exitexpression

                The method save() contains an exit expression.
                Open

                                            exit(preg_replace('#'.str_replace('/', '[\\\\//]{1}', preg_quote($linter)).'#', str_replace('.php', '', $save).'.php', $output));
                Severity: Minor
                Found in src/Admin/Files.php by phpmd

                ExitExpression

                Since: 0.2

                An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

                Example

                class Foo {
                    public function bar($param)  {
                        if ($param === 42) {
                            exit(23);
                        }
                    }
                }

                Source https://phpmd.org/rules/design.html#exitexpression

                The method save() contains an exit expression.
                Open

                            exit(is_file($files[$retrieve]) ? file_get_contents($files[$retrieve]) : '');
                Severity: Minor
                Found in src/Admin/Files.php by phpmd

                ExitExpression

                Since: 0.2

                An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

                Example

                class Foo {
                    public function bar($param)  {
                        if ($param === 42) {
                            exit(23);
                        }
                    }
                }

                Source https://phpmd.org/rules/design.html#exitexpression

                Each PHP statement must be on a line by itself
                Open

                                case 3: $type = 'png'; break;
                Severity: Minor
                Found in src/Admin/Files.php by phpcodesniffer

                Terminating statement must be on a line by itself
                Open

                                case 3: $type = 'png'; break;
                Severity: Minor
                Found in src/Admin/Files.php by phpcodesniffer

                The CASE body must start on the line following the statement
                Open

                                case 17: $type = 'ico'; break;
                Severity: Minor
                Found in src/Admin/Files.php by phpcodesniffer

                Each PHP statement must be on a line by itself
                Open

                                case 17: $type = 'ico'; break;
                Severity: Minor
                Found in src/Admin/Files.php by phpcodesniffer

                Terminating statement must be on a line by itself
                Open

                                case 2: $type = 'jpg'; break;
                Severity: Minor
                Found in src/Admin/Files.php by phpcodesniffer

                The CASE body must start on the line following the statement
                Open

                                case 1: $type = 'gif'; break;
                Severity: Minor
                Found in src/Admin/Files.php by phpcodesniffer

                The CASE body must start on the line following the statement
                Open

                                case 3: $type = 'png'; break;
                Severity: Minor
                Found in src/Admin/Files.php by phpcodesniffer

                Terminating statement must be on a line by itself
                Open

                                case 1: $type = 'gif'; break;
                Severity: Minor
                Found in src/Admin/Files.php by phpcodesniffer

                Each PHP statement must be on a line by itself
                Open

                                case 1: $type = 'gif'; break;
                Severity: Minor
                Found in src/Admin/Files.php by phpcodesniffer

                The CASE body must start on the line following the statement
                Open

                                case 2: $type = 'jpg'; break;
                Severity: Minor
                Found in src/Admin/Files.php by phpcodesniffer

                Each PHP statement must be on a line by itself
                Open

                                case 2: $type = 'jpg'; break;
                Severity: Minor
                Found in src/Admin/Files.php by phpcodesniffer

                Terminating statement must be on a line by itself
                Open

                                case 17: $type = 'ico'; break;
                Severity: Minor
                Found in src/Admin/Files.php by phpcodesniffer

                Closing brace must be on a line by itself
                Open

                                case 1: $type = 'gif'; break;
                Severity: Minor
                Found in src/Admin/Files.php by phpcodesniffer

                Closing brace must be on a line by itself
                Open

                                case 3: $type = 'png'; break;
                Severity: Minor
                Found in src/Admin/Files.php by phpcodesniffer

                Closing brace must be on a line by itself
                Open

                                case 2: $type = 'jpg'; break;
                Severity: Minor
                Found in src/Admin/Files.php by phpcodesniffer

                Closing brace must be on a line by itself
                Open

                                case 17: $type = 'ico'; break;
                Severity: Minor
                Found in src/Admin/Files.php by phpcodesniffer

                There are no issues that match your filters.

                Category
                Status