modules/Settings/Mail/models/Config.php
Missing class import via use statement (line '22', column '22'). Open
Open
$dataReader = (new \App\Db\Query())->select(['name', 'value'])
- 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
Define a constant instead of duplicating this literal "value" 3 times. Open
Open
\App\Db::getInstance()->createCommand()->update('yetiforce_mail_config', ['value' => $val], [
- 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.
Call to undeclared method \App\Db::createCommand
Open
Open
\App\Db::getInstance('admin')->createCommand()->update('s_#__mail_queue', ['status' => 1], [
- Exclude checks
Saw possibly unextractable annotation for a fragment of comment '* @param bool true/false':
after bool,
did not see an element name (will guess based on comment order) Open
Open
* @param bool true/false
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
Open
$dataReader = (new \App\Db\Query())->select(['name', 'value'])
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
Open
\App\Db::getInstance()->createCommand()->update('yetiforce_mail_config', ['value' => $val], [
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
Open
class Settings_Mail_Config_Model
- Exclude checks
Avoid variables with short names like $id. Configured minimum length is 3. Open
Open
public static function acceptanceRecord($id)
- 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
The class Settings_Mail_Config_Model is not named in CamelCase. Open
Open
class Settings_Mail_Config_Model
{
public static function updateConfig($name, $val, $type)
{
\App\Db::getInstance()->createCommand()->update('yetiforce_mail_config', ['value' => $val], [
- 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
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
while ($row = $dataReader->read()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function acceptanceRecord($id)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function getConfig($type)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
->from('yetiforce_mail_config')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Function to get instance.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param bool true/false
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return Settings_Mail_Config_Model
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function getInstance()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'name' => $name,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$config = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
->where(['type' => $type])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$dataReader->close();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
\App\Db::getInstance('admin')->createCommand()->update('s_#__mail_queue', ['status' => 1], [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function updateConfig($name, $val, $type)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return $config;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$dataReader = (new \App\Db\Query())->select(['name', 'value'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'id' => $id,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return new self();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
\App\Db::getInstance()->createCommand()->update('yetiforce_mail_config', ['value' => $val], [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'type' => $type,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$config[$row['name']] = $row['value'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Class name "Settings_Mail_Config_Model" is not in camel caps format Open
Open
class Settings_Mail_Config_Model
- Exclude checks