Missing class import via use statement (line '65', column '15'). Open
$val = (new \App\Db\Query())->select(['value'])->from(self::TABLE_NAME)->where(['key' => $this->key])->scalar();
- Read upRead up
- Exclude checks
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
The method setValue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$result = $dbCommand->update(self::TABLE_NAME, ['value' => $value], ['key' => $this->key])->execute();
}
- 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
Remove this unused "TABLE_NAME" private field. Open
private const TABLE_NAME = 's_#__pauser';
- Read upRead up
- Exclude checks
If a private
field is declared but not used in the program, it can be considered dead code and should therefore be removed. This will
improve maintainability because developers will not wonder what the variable is used for.
Noncompliant Code Example
class MyClass { private $foo = 4; //foo is unused public function compute($a) { return $a * 4; } }
Compliant Solution
class MyClass { public function compute($a) { return $a * 4; } }
See
- CERT, MSC12-CPP. - Detect and remove code that has no effect
Define a constant instead of duplicating this literal "value" 3 times. Open
$val = (new \App\Db\Query())->select(['value'])->from(self::TABLE_NAME)->where(['key' => $this->key])->scalar();
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Assigning null
to property but \App\Pauser->value
is string
Open
$this->value = null;
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
return (bool) \App\Db::getInstance()->createCommand()->delete(self::TABLE_NAME, ['key' => $this->key])->execute();
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$val = (new \App\Db\Query())->select(['value'])->from(self::TABLE_NAME)->where(['key' => $this->key])->scalar();
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$dbCommand = \App\Db::getInstance()->createCommand();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** Table name. */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var string Entry name */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set value.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($result) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string|null
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getValue(): ?string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->value;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Return object instance.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set key name.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $instance;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return self
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
return (bool) \App\Db::getInstance()->createCommand()->delete(self::TABLE_NAME, ['key' => $this->key])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->key = $key;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function destroy(): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return (bool) \App\Db::getInstance()->createCommand()->delete(self::TABLE_NAME, ['key' => $this->key])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return self
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null === $this->value) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private $key;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $key
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = $dbCommand->insert(self::TABLE_NAME, ['value' => $value, 'key' => $this->key])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return (bool) $result;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get value.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance->setKey($key)->load();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Load data from database.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return self
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setValue(string $value): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var string Value */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $value
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private const TABLE_NAME = 's_#__pauser';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private $value;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getInstance(string $key): self
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = $dbCommand->update(self::TABLE_NAME, ['value' => $value], ['key' => $this->key])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Remove key from database.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$val = (new \App\Db\Query())->select(['value'])->from(self::TABLE_NAME)->where(['key' => $this->key])->scalar();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dbCommand = \App\Db::getInstance()->createCommand();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $key
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->value = false === $val ? null : $val;
- Exclude checks
Line exceeds 120 characters; contains 136 characters Open
* It stores data about the last executed element of a given process in order to resume it at a later time while maintaining continuity.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance = new self();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->value = $value;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private function setKey(string $key): self
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private function load(): self
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->value = null;
- Exclude checks