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(
- Read upRead up
- Exclude checks
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();
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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();
- Read upRead up
- Exclude checks
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
- Exclude checks
Multi-line function declarations must define one parameter per line Open
public function __construct($connection, array $attributes = [],
- Exclude checks
Multi-line function declarations must define one parameter per line Open
array $properties = [], array $map = [])
- Exclude checks
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line Open
{
- Exclude checks
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 = [],
- Exclude checks
Multi-line function declaration not indented correctly; expected 8 spaces but found 32 Open
array $properties = [], array $map = [])
- Exclude checks
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,
- Exclude checks
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,
- Exclude checks
The closing parenthesis of a multi-line function declaration must be on a new line Open
array $properties = [], array $map = [])
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
$builder->generate(), $builder->getParams())
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
$builder->generate(), $builder->getParams()))) {
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
$builder->generate(), $builder->getParams())
- Exclude checks
Line exceeds 120 characters; contains 131 characters Open
abstract class DBModel extends \pwf\components\activerecord\Model implements \pwf\components\querybuilder\interfaces\SelectBuilder,
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
$this->getConditionBuilder()->getParams());
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
$builder->getParams());
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
$builder->getParams());
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
$this->getConnection()->insertId($this->getSequenceName()));
- Exclude checks
Opening parenthesis of a multi-line function call must be the last content on the line Open
$result = $this->getConnection()->exec($builder->generate(),
- Exclude checks
Multi-line function call not indented correctly; expected 12 spaces but found 16 Open
$builder->generate(), $builder->getParams()))) {
- Exclude checks
Expected 1 newline at end of file; 0 found Open
}
- Exclude checks
Whitespace found at end of line Open
*
- Exclude checks
Opening parenthesis of a multi-line function call must be the last content on the line Open
return $this->getConnection()->exec($builder->generate(),
- Exclude checks
Opening parenthesis of a multi-line function call must be the last content on the line Open
$this->setAttribute($this->getPK(),
- Exclude checks
Multi-line function call not indented correctly; expected 8 spaces but found 24 Open
$builder->generate(), $builder->getParams())
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
$builder->generate(), $builder->getParams()))) {
- Exclude checks
Whitespace found at end of line Open
*
- Exclude checks
Multi-line function call not indented correctly; expected 12 spaces but found 16 Open
$builder->getParams());
- Exclude checks
Multi-line function call not indented correctly; expected 8 spaces but found 16 Open
$builder->getParams());
- Exclude checks
Multi-line function call not indented correctly; expected 8 spaces but found 24 Open
$builder->generate(), $builder->getParams())
- Exclude checks
Multi-line function call not indented correctly; expected 16 spaces but found 20 Open
$this->getConnection()->insertId($this->getSequenceName()));
- Exclude checks
Multi-line function call not indented correctly; expected 8 spaces but found 12 Open
$this->getConditionBuilder()->getParams());
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
$builder->generate(), $builder->getParams())
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
$builder->generate(), $builder->getParams())
- Exclude checks
Opening parenthesis of a multi-line function call must be the last content on the line Open
return array_merge($this->parentGetParams(),
- Exclude checks