lib/Ajde/Template.php

Summary

Maintainability
B
6 hrs
Test Coverage

Ajde_Template has 25 functions (exceeds 20 allowed). Consider refactoring.
Open

class Ajde_Template extends Ajde_Object_Standard
{
    protected $_contents = null;
    protected $_table = [];

Severity: Minor
Found in lib/Ajde/Template.php - About 2 hrs to fix

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

        private static function _getFileInfo($base, $action, $format = 'html')
        {
            // go see what templates are available
            $dirPrefixPatterns = [
                APP_DIR,
    Severity: Minor
    Found in lib/Ajde/Template.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 _getFileInfo has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private static function _getFileInfo($base, $action, $format = 'html')
        {
            // go see what templates are available
            $dirPrefixPatterns = [
                APP_DIR,
    Severity: Minor
    Found in lib/Ajde/Template.php - About 1 hr to fix

      Missing class import via use statement (line '55', column '23').
      Open

                  throw new Ajde_Exception('Call to undefined method '.get_class($this)."::$method()", 90006);
      Severity: Minor
      Found in lib/Ajde/Template.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 '19', column '30').
      Open

                  $exception = new Ajde_Core_Exception_Routing(sprintf('Template file in %s,
      Severity: Minor
      Found in lib/Ajde/Template.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 assigning values to variables in if clauses and the like (line '18', column '14').
      Open

          protected function setFileinfo()
          {
              if (($fileInfo = $this->getFileInfo()) === false) {
                  $exception = new Ajde_Core_Exception_Routing(sprintf('Template file in %s,
                          for action %s with format %s not found',
      Severity: Minor
      Found in lib/Ajde/Template.php by phpmd

      IfStatementAssignment

      Since: 2.7.0

      Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($foo = 'bar') { // possible typo
                  // ...
              }
              if ($baz = 0) { // always false
                  // ...
              }
          }
      }

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

      Avoid assigning values to variables in if clauses and the like (line '92', column '25').
      Open

          private static function _getFileInfo($base, $action, $format = 'html')
          {
              // go see what templates are available
              $dirPrefixPatterns = [
                  APP_DIR,
      Severity: Minor
      Found in lib/Ajde/Template.php by phpmd

      IfStatementAssignment

      Since: 2.7.0

      Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($foo = 'bar') { // possible typo
                  // ...
              }
              if ($baz = 0) { // always false
                  // ...
              }
          }
      }

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

      Avoid assigning values to variables in if clauses and the like (line '86', column '29').
      Open

          private static function _getFileInfo($base, $action, $format = 'html')
          {
              // go see what templates are available
              $dirPrefixPatterns = [
                  APP_DIR,
      Severity: Minor
      Found in lib/Ajde/Template.php by phpmd

      IfStatementAssignment

      Since: 2.7.0

      Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($foo = 'bar') { // possible typo
                  // ...
              }
              if ($baz = 0) { // always false
                  // ...
              }
          }
      }

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

      Avoid using static access to class 'Ajde_Fs_Find' in method '_getFileInfo'.
      Open

                              if ($fileMatch = Ajde_Fs_Find::findFile($prefixedBase.TEMPLATE_DIR.$layoutDir,
                                  $filePattern)
      Severity: Minor
      Found in lib/Ajde/Template.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

      Avoid using static access to class 'Ajde_Event' in method 'getContents'.
      Open

                  Ajde_Event::trigger($this, 'afterGetContents');
      Severity: Minor
      Found in lib/Ajde/Template.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

      Avoid using static access to class 'Ajde_Fs_Find' in method '_getFileInfo'.
      Open

                          if ($fileMatch = Ajde_Fs_Find::findFile($prefixedBase.TEMPLATE_DIR, $filePattern)) {
      Severity: Minor
      Found in lib/Ajde/Template.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

      The method __fallback uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  throw new Ajde_Exception('Call to undefined method '.get_class($this)."::$method()", 90006);
              }
      Severity: Minor
      Found in lib/Ajde/Template.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

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

      Avoid using static access to class 'Ajde' in method 'setFileinfo'.
      Open

                  Ajde::routingError($exception);
      Severity: Minor
      Found in lib/Ajde/Template.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

      Avoid using static access to class 'Ajde_Event' in method 'getContents'.
      Open

                  Ajde_Event::trigger($this, 'beforeGetContents');
      Severity: Minor
      Found in lib/Ajde/Template.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

      The property $_table is not named in camelCase.
      Open

      class Ajde_Template extends Ajde_Object_Standard
      {
          protected $_contents = null;
          protected $_table = [];
      
      
      Severity: Minor
      Found in lib/Ajde/Template.php by phpmd

      CamelCasePropertyName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name attributes.

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      The property $_contents is not named in camelCase.
      Open

      class Ajde_Template extends Ajde_Object_Standard
      {
          protected $_contents = null;
          protected $_table = [];
      
      
      Severity: Minor
      Found in lib/Ajde/Template.php by phpmd

      CamelCasePropertyName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name attributes.

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      The class Ajde_Template is not named in CamelCase.
      Open

      class Ajde_Template extends Ajde_Object_Standard
      {
          protected $_contents = null;
          protected $_table = [];
      
      
      Severity: Minor
      Found in lib/Ajde/Template.php by phpmd

      CamelCaseClassName

      Since: 0.2

      It is considered best practice to use the CamelCase notation to name classes.

      Example

      class class_name {
      }

      Source

      The method __fallback is not named in camelCase.
      Open

          public function __fallback($method, $arguments)
          {
              $helper = $this->getParser()->getHelper();
              if (method_exists($helper, $method)) {
                  return call_user_func_array([$helper, $method], $arguments);
      Severity: Minor
      Found in lib/Ajde/Template.php by phpmd

      CamelCaseMethodName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name methods.

      Example

      class ClassName {
          public function get_name() {
          }
      }

      Source

      The method _getFileInfo is not named in camelCase.
      Open

          private static function _getFileInfo($base, $action, $format = 'html')
          {
              // go see what templates are available
              $dirPrefixPatterns = [
                  APP_DIR,
      Severity: Minor
      Found in lib/Ajde/Template.php by phpmd

      CamelCaseMethodName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name methods.

      Example

      class ClassName {
          public function get_name() {
          }
      }

      Source

      There are no issues that match your filters.

      Category
      Status