vistart/yii2-models

View on GitHub
traits/TimestampTrait.php

Summary

Maintainability
A
25 mins
Test Coverage

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

    public function removeIfExpired()
    {
        if ($this->getIsExpired() && !$this->getIsNewRecord()) {
            if (($this->expiredRemovingCallback instanceof Closure || is_array($this->expiredRemovingCallback)) && is_callable($this->expiredRemovingCallback)) {
                $result = call_user_func($this->expiredRemovingCallback, $this);
Severity: Minor
Found in traits/TimestampTrait.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

Avoid using static access to class '\yii\behaviors\TimestampBehavior' in method 'getTimestampBehaviors'.
Open

                'class' => TimestampBehavior::className(),
Severity: Minor
Found in traits/TimestampTrait.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 'getIsExpired()' method which returns a boolean should be named 'is...()' or 'has...()'
Open

    public function getIsExpired()
    {
        $createdAt = $this->getCreatedAt();
        if ($this->expiredAt === false || $createdAt === null) {
            return false;
Severity: Minor
Found in traits/TimestampTrait.php by phpmd

BooleanGetMethodName

Since: 0.2

Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.

Example

class Foo {
    /**
     * @return boolean
     */
    public function getFoo() {} // bad
    /**
     * @return bool
     */
    public function isFoo(); // ok
    /**
     * @return boolean
     */
    public function getFoo($bar); // ok, unless checkParameterizedMethods=true
}

Source https://phpmd.org/rules/naming.html#booleangetmethodname

Line exceeds 120 characters; contains 161 characters
Open

            if (($this->expiredRemovingCallback instanceof Closure || is_array($this->expiredRemovingCallback)) && is_callable($this->expiredRemovingCallback)) {
Severity: Minor
Found in traits/TimestampTrait.php by phpcodesniffer

Line exceeds 120 characters; contains 174 characters
Open

            return date('Y-m-d H:i:s', strtotime(($offset >= 0 ? "+$offset" : $offset) . " seconds", is_string($time) ? strtotime($time) : (is_int($time) ? $time : time())));
Severity: Minor
Found in traits/TimestampTrait.php by phpcodesniffer

There are no issues that match your filters.

Category
Status