Rossmann-IT/yii2-cron

View on GitHub
src/models/Task.php

Summary

Maintainability
B
5 hrs
Test Coverage

Task has 29 functions (exceeds 20 allowed). Consider refactoring.
Open

class Task extends ActiveRecord implements TaskInterface {

    /**
     * @return array
     */
Severity: Minor
Found in src/models/Task.php - About 3 hrs to fix

    Method acquireLock has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function acquireLock() {
            if (!$this->id) {
                throw new \LogicException('Task ID must be set to acquire a lock');
            }
            $db = \Yii::$app->getDb();
    Severity: Minor
    Found in src/models/Task.php - About 1 hr to fix

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

          public function acquireLock() {
              if (!$this->id) {
                  throw new \LogicException('Task ID must be set to acquire a lock');
              }
              $db = \Yii::$app->getDb();
      Severity: Minor
      Found in src/models/Task.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

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

                  throw new \LogicException('Task ID must be set to acquire a lock');
      Severity: Minor
      Found in src/models/Task.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 '145', column '27').
      Open

                      throw new \InvalidArgumentException('SQL Dialect "' . $sqlDialect . '" is not implemented in ' . __METHOD__);
      Severity: Minor
      Found in src/models/Task.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 '\Yii' in method 'acquireLock'.
      Open

                          \Yii::error('Tried to lock the task with ID ' . $this->id . ', but the database reported zero affected rows');
      Severity: Minor
      Found in src/models/Task.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 '\Yii' in method 'attributeLabels'.
      Open

                  'id' => \Yii::t('cron', 'ID'),
      Severity: Minor
      Found in src/models/Task.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 '\Yii' in method 'attributeLabels'.
      Open

                  'command' => \Yii::t('cron', 'Command'),
      Severity: Minor
      Found in src/models/Task.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 '\Yii' in method 'attributeLabels'.
      Open

                  'ts' => \Yii::t('cron', 'Created'),
      Severity: Minor
      Found in src/models/Task.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 '\rossmann\cron\components\validation\CommandValidator' in method 'rules'.
      Open

                  ['command', CommandValidator::className(), 'skipOnEmpty' => false],
      Severity: Minor
      Found in src/models/Task.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 '\Yii' in method 'attributeLabels'.
      Open

                  'locked' => \Yii::t('cron', 'Locked'),
      Severity: Minor
      Found in src/models/Task.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 '\Yii' in method 'acquireLock'.
      Open

                      \Yii::info('Tried to acquire a lock for the task with ID ' . $this->id . ', but it is already/still locked');
      Severity: Minor
      Found in src/models/Task.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 '\Yii' in method 'attributeLabels'.
      Open

                  'comment' => \Yii::t('cron', 'Comment'),
      Severity: Minor
      Found in src/models/Task.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 '\Yii' in method 'attributeLabels'.
      Open

                  'ts_updated' => \Yii::t('cron', 'Updated'),
      Severity: Minor
      Found in src/models/Task.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 '\Yii' in method 'attributeLabels'.
      Open

                  'time' => \Yii::t('cron', 'Time expression'),
      Severity: Minor
      Found in src/models/Task.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 '\Yii' in method 'attributeLabels'.
      Open

                  'comments' => \Yii::t('cron', 'Comment'),
      Severity: Minor
      Found in src/models/Task.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 '\Yii' in method 'attributeLabels'.
      Open

                  'status' => \Yii::t('cron', 'Status'),
      Severity: Minor
      Found in src/models/Task.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 '\Yii' in method 'acquireLock'.
      Open

                      \Yii::error('Tried to look up the lock status of the task with ID ' . $this->id
                          . ', but a value other than 0/1 or no value was returned: "' . $locked . '"');
      Severity: Minor
      Found in src/models/Task.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 variables with short names like $db. Configured minimum length is 3.
      Open

              $db = \Yii::$app->getDb();
      Severity: Minor
      Found in src/models/Task.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

      There are no issues that match your filters.

      Category
      Status