allanmcarvalho/cakephp-datatables

View on GitHub

Showing 20 of 20 total issues

OptionsOption has 51 functions (exceeds 20 allowed). Consider refactoring.
Open

final class OptionsOption extends ChildOptionAbstract {

    const ALLOWED_PAGING_TYPES = [
        'numbers',
        'simple',
Severity: Major
Found in src/Table/Option/Section/OptionsOption.php - About 7 hrs to fix

    Column has 30 functions (exceeds 20 allowed). Consider refactoring.
    Open

    final class Column {
    
        const TYPE_DATE = 'date';
        const TYPE_NUM = 'num';
        const TYPE_NUM_FMT = 'num-fmt';
    Severity: Minor
    Found in src/Table/Column.php - About 3 hrs to fix

      File OptionsOption.php has 319 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      /**
       * Copyright (c) Allan Carvalho 2020.
       * Under Mit License
       * php version 7.2
      Severity: Minor
      Found in src/Table/Option/Section/OptionsOption.php - About 3 hrs to fix

        FeaturesOption has 24 functions (exceeds 20 allowed). Consider refactoring.
        Open

        final class FeaturesOption extends ChildOptionAbstract {
        
            /**
             * @var array
             * @inheritDoc
        Severity: Minor
        Found in src/Table/Option/Section/FeaturesOption.php - About 2 hrs to fix

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

              public function setSearchCols(array $searchCols): MainOption {
                  Validator::getInstance()->checkKeysValueTypesOrFail($searchCols, ['integer'], ['array', 'NULL'], '$searchCols');
                  foreach ($searchCols as $searchCol) {
                      if ($searchCol !== null) {
                          foreach ($searchCol as $key => $item) {
          Severity: Minor
          Found in src/Table/Option/Section/OptionsOption.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 isInCurrentUrl has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              public function isInCurrentUrl(array $url = []): bool {
                  $currentController = Router::getRequest()->getParam('controller');
                  $currentAction = Router::getRequest()->getParam('action');
                  $currentQuery = Router::getRequest()->getQuery();
                  $currentPrefix = Router::getRequest()->getParam('prefix');
          Severity: Minor
          Found in src/Tools/Functions.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 checkKeysValueTypesOrFail has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              public function checkKeysValueTypesOrFail(?array $array, $allowedKeyTypes = [], $allowedValueTypes = [], string $inString = null): void {
                  if (empty($array)) {
                      return;
                  }
                  $allowedKeyTypesType = getType($allowedKeyTypes);
          Severity: Minor
          Found in src/Tools/Validator.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 normalizeDataTableField has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              private function normalizeDataTableField(string $dataBaseField, ?string $title): Column {
                  $ormTable = $this->_tables->getOrmTable();
                  $explodedDataBaseField = explode('.', $dataBaseField);
                  if (count($explodedDataBaseField) === 2) {
                      $table = Inflector::camelize($explodedDataBaseField[0]);
          Severity: Minor
          Found in src/Table/Columns.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 isInCurrentUrl has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function isInCurrentUrl(array $url = []): bool {
                  $currentController = Router::getRequest()->getParam('controller');
                  $currentAction = Router::getRequest()->getParam('action');
                  $currentQuery = Router::getRequest()->getQuery();
                  $currentPrefix = Router::getRequest()->getParam('prefix');
          Severity: Minor
          Found in src/Tools/Functions.php - About 1 hr to fix

            Method normalizeDataTableField has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function normalizeDataTableField(string $dataBaseField, ?string $title): Column {
                    $ormTable = $this->_tables->getOrmTable();
                    $explodedDataBaseField = explode('.', $dataBaseField);
                    if (count($explodedDataBaseField) === 2) {
                        $table = Inflector::camelize($explodedDataBaseField[0]);
            Severity: Minor
            Found in src/Table/Columns.php - About 1 hr to fix

              Method checkKeysValueTypesOrFail has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function checkKeysValueTypesOrFail(?array $array, $allowedKeyTypes = [], $allowedValueTypes = [], string $inString = null): void {
                      if (empty($array)) {
                          return;
                      }
                      $allowedKeyTypesType = getType($allowedKeyTypes);
              Severity: Minor
              Found in src/Tools/Validator.php - About 1 hr to fix

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

                    public function setType(?string $type): self {
                        $validTypesString = str_replace(' and ', ' or ', Text::toList(static::VALID_TYPES));
                        if (!in_array($type, static::VALID_TYPES) && !empty($type)) {
                            throw new InvalidArgumentException("Type must be $validTypesString. Found: '$type'.");
                        }
                Severity: Minor
                Found in src/Table/Column.php and 1 other location - About 55 mins to fix
                src/Table/Column.php on lines 442..449

                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 99.

                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

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

                    public function setOrderDataType(?string $orderDataType): self {
                        $validOrderDataTypeString = str_replace(' and ', ' or ', Text::toList(static::VALID_ORDER_DATA_TYPES));
                        if (!in_array($orderDataType, static::VALID_ORDER_DATA_TYPES) && !empty($orderDataType)) {
                            throw new InvalidArgumentException("In \$orderDataType you can use only $validOrderDataTypeString. Found: '$orderDataType'.");
                        }
                Severity: Minor
                Found in src/Table/Column.php and 1 other location - About 55 mins to fix
                src/Table/Column.php on lines 696..703

                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 99.

                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 setDefault has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function setDefault(Column $column): void {
                        $ignoredMethods = ['setDefault', 'setTitle', 'setDatabase', 'setName'];
                        $methods = get_class_methods($this);
                        foreach ($methods as $method) {
                            if (substr($method, 0, 3) === 'set' && !in_array($method, $ignoredMethods)) {
                Severity: Minor
                Found in src/Table/Column.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

                Method getUrlMd5 has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    private function getUrlMd5(string $controller, string $action, array $query = [], ?string $prefix = null, array $pass = []): string {
                Severity: Minor
                Found in src/Tools/Functions.php - About 35 mins to fix

                  Function setRenderer has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function setRenderer($renderer): MainOption {
                          $rendererType = getType($renderer);
                          if (!in_array($rendererType, ['string', 'array'])) {
                              throw new InvalidArgumentException("\$renderer must be a string or array. Found: $rendererType.");
                          }
                  Severity: Minor
                  Found in src/Table/Option/Section/OptionsOption.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 setOrderFixed has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function setOrderFixed(array $orderFixed): MainOption {
                          if (getType(Functions::getInstance()->arrayKeyFirst($orderFixed)) === 'string') {
                              foreach ($orderFixed as $key => $objectItem) {
                                  if (!in_array($key, ['pre', 'post'])) {
                                      throw new InvalidArgumentException("You must use only 'pre' or 'post' key for objects type. Found: $key.");
                  Severity: Minor
                  Found in src/Table/Option/Section/OptionsOption.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 setOrder has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function setOrder(array $order): MainOption {
                          Validator::getInstance()->checkKeysValueTypesOrFail($order, 'integer', 'array', '$order');
                          foreach ($order as $item) {
                              Validator::getInstance()->checkArraySizeOrFail($item, 2, 'In setOrder($order) you must pass the index and order (asc or desc). Eg.: [0, \'asc\'].');
                              Validator::getInstance()->checkKeysValueTypesOrFail($item, 'integer', ['integer', 'string'], '$order');
                  Severity: Minor
                  Found in src/Table/Option/Section/OptionsOption.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

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

                      public function getConfigBundle(string $tableAndConfig, bool $cache = true): ConfigBundle {
                          $exploded = explode('::', $tableAndConfig);
                          if (count($exploded) !== 2) {
                              throw new InvalidArgumentException('Table param must be a concatenation of Tables class and config. Eg.: Foo::method.');
                          }
                  Severity: Minor
                  Found in src/Tools/Builder.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

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

                      private function checkOrderDefault(array $orderFixed) {
                          Validator::getInstance()->checkKeysValueTypesOrFail($orderFixed, ['integer', 'string'], 'array', '$orderFixed');
                          foreach ($orderFixed as $item) {
                              Validator::getInstance()->checkArraySizeOrFail($item, 2, "In \$orderFixed you must pass the index and after the order (asc or desc). Eg.: [0, 'asc'].");
                              $param1 = $item[Functions::getInstance()->arrayKeyFirst($item)];
                  Severity: Minor
                  Found in src/Table/Option/Section/OptionsOption.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

                  Severity
                  Category
                  Status
                  Source
                  Language