Missing class import via use statement (line '26', column '17'). Open
$query = (new \App\Db\Query())->from($this->baseTable);
- 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
Missing class import via use statement (line '52', column '13'). Open
if ((new \App\Db\Query())->select('type', 'name')
- 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
Avoid using static access to class '\App\Cache' in method 'setConfig'. Open
\App\Cache::delete('AddressFinder', 'Config');
- 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 using static access to class '\App\Db' in method 'setConfig'. Open
$db = \App\Db::getInstance();
- 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
The method setConfig uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$result = $db->createCommand()->insert($this->baseTable, ['val' => $val, 'type' => $type, 'name' => $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
Doc-block of $type
in getConfig
is phpdoc param type string
which is not a permitted replacement of the nullable param type ?string
declared in the signature ('?T' should be documented as 'T|null' or '?T') Open
* @param string $type
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
if ((new \App\Db\Query())->select('type', 'name')
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$result = $db->createCommand()->insert($this->baseTable, ['val' => $val, 'type' => $type, 'name' => $key])->execute();
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$result = $db->createCommand()->update($this->baseTable, ['val' => $val], ['type' => $type, 'name' => $key])->execute();
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$query = (new \App\Db\Query())->from($this->baseTable);
- Exclude checks
Doc-block of getConfig
contains declared return type void
which is incompatible with the return type array
declared in the signature Open
* @return void
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_ApiAddress_Module_Model extends Settings_Vtiger_Module_Model
- Exclude checks
The class Settings_ApiAddress_Module_Model is not named in CamelCase. Open
class Settings_ApiAddress_Module_Model extends Settings_Vtiger_Module_Model
{
/** {@inheritdoc} */
public $baseTable = 's_#__address_finder_config';
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
Avoid variables with short names like $db. Configured minimum length is 3. Open
$db = \App\Db::getInstance();
- 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
Spaces must be used to indent lines; tabs are not allowed Open
public function getConfig(string $type = null): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$rawData = [];
- 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 void
- 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
$query = (new \App\Db\Query())->from($this->baseTable);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$query->where(['type' => $type]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $baseTable = 's_#__address_finder_config';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $type
- 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
* Get configuration.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($type) {
- 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
foreach ($data as $value) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = $db->createCommand()->update($this->baseTable, ['val' => $val], ['type' => $type, 'name' => $key])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setConfig(array $data): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from($this->baseTable)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['name' => $key, 'type' => $type])
- Exclude checks
Line exceeds 120 characters; contains 136 characters Open
$result = $db->createCommand()->update($this->baseTable, ['val' => $val], ['type' => $type, 'name' => $key])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Save Configuration.
- Exclude checks
Line exceeds 120 characters; contains 134 characters Open
$result = $db->createCommand()->insert($this->baseTable, ['val' => $val, 'type' => $type, 'name' => $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
return (bool) $result;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $data
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->exists()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = $db->createCommand()->insert($this->baseTable, ['val' => $val, 'type' => $type, 'name' => $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
\App\Cache::delete('AddressFinder', 'Config');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader->close();
- 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 $rawData;
- 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
['name' => $key, 'type' => $type, 'val' => $val] = $value;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$db = \App\Db::getInstance();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = $query->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($row = $dataReader->read()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ((new \App\Db\Query())->select('type', '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
$rawData[$row['type']][$row['name']] = $row['val'];
- 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
}
- 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
Class name "Settings_ApiAddress_Module_Model" is not in camel caps format Open
class Settings_ApiAddress_Module_Model extends Settings_Vtiger_Module_Model
- Exclude checks