SergioMadness/pwf

View on GitHub
framework/basic/db/DBModel.php

Summary

Maintainability
A
0 mins
Test Coverage

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

        } else {
            $builder = QueryBuilder::insert()
                ->table($this->getTable())
                ->setParams($attributes);
            if (($result  = $this->getConnection()->exec(
Severity: Minor
Found in framework/basic/db/DBModel.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 assigning values to variables in if clauses and the like (line '158', column '18').
Open

    public function save()
    {
        $result     = null;
        $id         = $this->getId();
        $attributes = $this->getAttributes();
Severity: Minor
Found in framework/basic/db/DBModel.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 'pwf\basic\db\QueryBuilder' in method '__construct'.
Open

        $this->setConditionBuilder(QueryBuilder::getConditionBuilder())->setMap($map);
Severity: Minor
Found in framework/basic/db/DBModel.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 $id. Configured minimum length is 3.
Open

        $id         = $this->getId();
Severity: Minor
Found in framework/basic/db/DBModel.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

Only one interface may be specified per line in a multi-line implements declaration
Open

    \pwf\components\querybuilder\interfaces\DeleteBuilder, \pwf\components\datapaginator\interfaces\Paginatable

Multi-line function declarations must define one parameter per line
Open

    public function __construct($connection, array $attributes = [],

Multi-line function declarations must define one parameter per line
Open

                                array $properties = [], array $map = [])

The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Open

    {

The first parameter of a multi-line function declaration must be on the line after the opening bracket
Open

    public function __construct($connection, array $attributes = [],

Multi-line function declaration not indented correctly; expected 8 spaces but found 32
Open

                                array $properties = [], array $map = [])

The first item in a multi-line implements list must be on the line following the implements keyword
Open

abstract class DBModel extends \pwf\components\activerecord\Model implements \pwf\components\querybuilder\interfaces\SelectBuilder,

Only one interface may be specified per line in a multi-line implements declaration
Open

    \pwf\components\querybuilder\interfaces\InsertBuilder, \pwf\components\querybuilder\interfaces\UpdateBuilder,

The closing parenthesis of a multi-line function declaration must be on a new line
Open

                                array $properties = [], array $map = [])

Only one argument is allowed per line in a multi-line function call
Open

                        $builder->generate(), $builder->getParams())

Only one argument is allowed per line in a multi-line function call
Open

                $builder->generate(), $builder->getParams()))) {

Only one argument is allowed per line in a multi-line function call
Open

                        $builder->generate(), $builder->getParams())

Line exceeds 120 characters; contains 131 characters
Open

abstract class DBModel extends \pwf\components\activerecord\Model implements \pwf\components\querybuilder\interfaces\SelectBuilder,

Closing parenthesis of a multi-line function call must be on a line by itself
Open

            $this->getConditionBuilder()->getParams());

Closing parenthesis of a multi-line function call must be on a line by itself
Open

                $builder->getParams());

Closing parenthesis of a multi-line function call must be on a line by itself
Open

                $builder->getParams());

Closing parenthesis of a multi-line function call must be on a line by itself
Open

                    $this->getConnection()->insertId($this->getSequenceName()));

Opening parenthesis of a multi-line function call must be the last content on the line
Open

            $result = $this->getConnection()->exec($builder->generate(),

Multi-line function call not indented correctly; expected 12 spaces but found 16
Open

                $builder->generate(), $builder->getParams()))) {

Expected 1 newline at end of file; 0 found
Open

}

Whitespace found at end of line
Open

     * 

Opening parenthesis of a multi-line function call must be the last content on the line
Open

        return $this->getConnection()->exec($builder->generate(),

Opening parenthesis of a multi-line function call must be the last content on the line
Open

                $this->setAttribute($this->getPK(),

Multi-line function call not indented correctly; expected 8 spaces but found 24
Open

                        $builder->generate(), $builder->getParams())

Closing parenthesis of a multi-line function call must be on a line by itself
Open

                $builder->generate(), $builder->getParams()))) {

Whitespace found at end of line
Open

     * 

Multi-line function call not indented correctly; expected 12 spaces but found 16
Open

                $builder->getParams());

Multi-line function call not indented correctly; expected 8 spaces but found 16
Open

                $builder->getParams());

Multi-line function call not indented correctly; expected 8 spaces but found 24
Open

                        $builder->generate(), $builder->getParams())

Multi-line function call not indented correctly; expected 16 spaces but found 20
Open

                    $this->getConnection()->insertId($this->getSequenceName()));

Multi-line function call not indented correctly; expected 8 spaces but found 12
Open

            $this->getConditionBuilder()->getParams());

Closing parenthesis of a multi-line function call must be on a line by itself
Open

                        $builder->generate(), $builder->getParams())

Closing parenthesis of a multi-line function call must be on a line by itself
Open

                        $builder->generate(), $builder->getParams())

Opening parenthesis of a multi-line function call must be the last content on the line
Open

        return array_merge($this->parentGetParams(),

There are no issues that match your filters.

Category
Status