src/Component.php

Summary

Maintainability
F
1 wk
Test Coverage

File Component.php has 798 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace BootPress\Page;

use Symfony\Component\HttpFoundation\Cookie;
Severity: Major
Found in src/Component.php - About 1 day to fix

    Component has 39 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Component
    {
        /** 
         * A Dependency Injection object that you can access at ``$page->global``.  If you access it and this static property is null, we will set up a [Pimple\Container](http://pimple.sensiolabs.org/) object for you.
         *
    Severity: Minor
    Found in src/Component.php - About 5 hrs to fix

      Function url has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          public function url($action = '', $url = '', $key = '', $value = null)
          {
              if (empty($action)) {
                  return htmlspecialchars($this->url['full']);
              } elseif ($action == 'set') {
      Severity: Minor
      Found in src/Component.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 process has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function process($section, $param, $code = 0, $type = '')
          {
              // Used in $this->send(), $this->display(), $this->styles(), and $this->scripts()
              if (!isset($this->filters[$section])) {
                  return $param;
      Severity: Minor
      Found in src/Component.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 folder has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          public function folder($dir, $path, $file = 'index.php')
          {
              $dir = $this->dir($dir);
              if (strpos($dir, $this->dir['page']) === 0 && is_dir($dir)) {
                  $folder = substr($dir, strlen($this->dir['page']));
      Severity: Minor
      Found in src/Component.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 isolated has 58 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function isolated(array $url = array(), Request $request = null)
          {
              extract(array_merge(array(
                  'dir' => null,
                  'base' => null,
      Severity: Major
      Found in src/Component.php - About 2 hrs to fix

        Function isolated has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function isolated(array $url = array(), Request $request = null)
            {
                extract(array_merge(array(
                    'dir' => null,
                    'base' => null,
        Severity: Minor
        Found in src/Component.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 url has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function url($action = '', $url = '', $key = '', $value = null)
            {
                if (empty($action)) {
                    return htmlspecialchars($this->url['full']);
                } elseif ($action == 'set') {
        Severity: Major
        Found in src/Component.php - About 2 hrs to fix

          Function redirect has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function redirect()
              {
                  $redirect = false;
                  $file = $this->file('301.txt');
                  if (is_file($file)) {
          Severity: Minor
          Found in src/Component.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 display has 44 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function display($content)
              {
                  $html = array();
                  if (preg_match('/<\s*!doctype\s.*>/i', $content, $match)) {
                      $content = mb_substr(mb_strstr($content, $match[0]), mb_strlen($match[0]));
          Severity: Minor
          Found in src/Component.php - About 1 hr to fix

            Method folder has 44 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function folder($dir, $path, $file = 'index.php')
                {
                    $dir = $this->dir($dir);
                    if (strpos($dir, $this->dir['page']) === 0 && is_dir($dir)) {
                        $folder = substr($dir, strlen($this->dir['page']));
            Severity: Minor
            Found in src/Component.php - About 1 hr to fix

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

                  public function link($link, $prepend = false)
                  {
                      $link = (array) $link;
                      if ($prepend !== false) {
                          $link = array_reverse($link); // so they are added in the correct order
              Severity: Minor
              Found in src/Component.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 filter has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function filter($section, callable $function, array $params = array('this'), $order = 10)
                  {
                      if ($section == 'response') {
                          foreach ($params as $key => $value) {
                              if (empty($value) || $value == 'this') {
              Severity: Minor
              Found in src/Component.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 metadata has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function metadata($head = null)
                  {
                      // Used in $this->display()
                      $metadata = array();
                      if (empty($head) || !preg_match('/<\s*meta\s(?=[^>]*?\b(charset)\s*=)/i', $head)) {
              Severity: Minor
              Found in src/Component.php - About 1 hr to fix

                Function metadata has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function metadata($head = null)
                    {
                        // Used in $this->display()
                        $metadata = array();
                        if (empty($head) || !preg_match('/<\s*meta\s(?=[^>]*?\b(charset)\s*=)/i', $head)) {
                Severity: Minor
                Found in src/Component.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 link has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function link($link, $prepend = false)
                    {
                        $link = (array) $link;
                        if ($prepend !== false) {
                            $link = array_reverse($link); // so they are added in the correct order
                Severity: Minor
                Found in src/Component.php - About 1 hr to fix

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

                      public function commonDir(array $files)
                      {
                          $files = array_values($files);
                          $cut = 0;
                          $count = count($files);
                  Severity: Minor
                  Found in src/Component.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 html has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public static function html(array $url = array(), Request $request = null, $overthrow = false)
                      {
                          if ($overthrow || null === static::$instance) {
                              $page = static::isolated($url, $request);
                              if ($page->url['format'] == 'html' && isset($url['base']) && is_string($url['base'])) {
                  Severity: Minor
                  Found in src/Component.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 redirect has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function redirect()
                      {
                          $redirect = false;
                          $file = $this->file('301.txt');
                          if (is_file($file)) {
                  Severity: Minor
                  Found in src/Component.php - About 1 hr to fix

                    Function display has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function display($content)
                        {
                            $html = array();
                            if (preg_match('/<\s*!doctype\s.*>/i', $content, $match)) {
                                $content = mb_substr(mb_strstr($content, $match[0]), mb_strlen($match[0]));
                    Severity: Minor
                    Found in src/Component.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 send has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function send($response = '', $status = 200, array $headers = array())
                        {
                            if (!$response instanceof Response) {
                                if (func_num_args() == 1 && is_numeric($response)) {
                                    $status = (int) $response;
                    Severity: Minor
                    Found in src/Component.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 tag has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function tag($name, array $attributes, $content = null)
                        {
                            $args = func_get_args();
                            $tag = array_shift($args);
                            $attributes = array_shift($args);
                    Severity: Minor
                    Found in src/Component.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 enforce has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function enforce($url, $redirect = 301)
                        {
                            list($url, $path, $suffix, $query) = $this->formatLocalPath($url, 'array');
                            $compare = $this->url['path'];
                            if (!empty($path)) {
                    Severity: Minor
                    Found in src/Component.php - About 35 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 __get has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function &__get($name)
                        {
                            // This method must return a reference and not use ternary operators for __set()ing multi-dimensional arrays
                            // http://stackoverflow.com/questions/4310473/using-set-with-arrays-solved-but-why
                            // http://stackoverflow.com/questions/5966918/return-null-by-reference-via-get
                    Severity: Minor
                    Found in src/Component.php - About 35 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 scripts has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        protected function scripts()
                        {
                            // Used in $this->display()
                            if (isset($this->data['jquery'])) {
                                $jquery = array_filter(array_unique($this->data['jquery']));
                    Severity: Minor
                    Found in src/Component.php - About 35 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 dir has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function dir($folder = null)
                        {
                            $folders = func_get_args();
                            if ($folder == 'set') {
                                list($folder, $name, $dir) = $folders;
                    Severity: Minor
                    Found in src/Component.php - About 35 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 style has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function style($css)
                        {
                            if (is_array($css)) {
                                foreach ($css as $tag => $rules) {
                                    if (is_array($rules)) {
                    Severity: Minor
                    Found in src/Component.php - About 35 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 htmlspecialchars($this->formatLocalPath($base.$query.$fragment));
                    Severity: Major
                    Found in src/Component.php - About 30 mins to fix

                      The method send() contains an exit expression.
                      Open

                              return ($this->testing === false) ? exit : $response;
                      Severity: Minor
                      Found in src/Component.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

                      There are no issues that match your filters.

                      Category
                      Status