Missing class import via use statement (line '55', column '17'). Open
$query = (new \App\Db\Query())->select($this->getBaseIndex())->from($this->getBaseTable());
- 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 'Vtiger_Loader' in method 'getInstance'. Open
$modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Module', $name);
- 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 'Settings_PublicHoliday_Record_Model' in method 'getHolidaysByRange'. Open
$holidays[$id] = Settings_PublicHoliday_Record_Model::getInstanceById($id);
- 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
Define a constant instead of duplicating this literal "holidaydate" 3 times. Open
'holidaydate' => 'Date',
- 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\Query::select
Open
$query = (new \App\Db\Query())->select($this->getBaseIndex())->from($this->getBaseTable());
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_PublicHoliday_Module_Model extends Settings_Vtiger_Module_Model
- Exclude checks
The class Settings_PublicHoliday_Module_Model is not named in CamelCase. Open
class Settings_PublicHoliday_Module_Model extends Settings_Vtiger_Module_Model
{
public $baseTable = 'vtiger_publicholiday';
public $baseIndex = 'publicholidayid';
public $listFields = [
- 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 $id. Configured minimum length is 3. Open
$id = $row[$this->getBaseIndex()];
- 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
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $nameFields = ['holidayname'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return Settings_PublicHoliday_Record_Model[]
- 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
$holidays = [];
- 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
$dataReader->close();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$query = (new \App\Db\Query())->select($this->getBaseIndex())->from($this->getBaseTable());
- 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
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return Settings_PublicHoliday_Module_Model
- 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
$modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Module', $name);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getHolidaysByRange(array $range, int $sorting = SORT_ASC)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($range) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $sorting SORT_ASC|SORT_DESC
- 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 $listFields = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'holidayname' => '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 $holidays;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $baseIndex = 'publicholidayid';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Return info about module paging feature.
- 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
$id = $row[$this->getBaseIndex()];
- 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 new $modelClassName();
- 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->orderBy(['holidaydate' => $sorting]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return bool - true: pageable, false: not pageable
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function isPagingSupported()
- 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
'holidaydate' => 'Date',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'holidaytype' => 'Type',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $name
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Returns holidays into date range.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getInstance($name = 'Settings:PublicHoliday')
- 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
$holidays[$id] = Settings_PublicHoliday_Record_Model::getInstanceById($id);
- 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 $baseTable = 'vtiger_publicholiday';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $name = 'PublicHoliday';
- 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
* Returns instance of Settings module model.
- 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 array $range
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$query->where(['between', 'holidaydate', $range[0], $range[1]]);
- Exclude checks
Class name "Settings_PublicHoliday_Module_Model" is not in camel caps format Open
class Settings_PublicHoliday_Module_Model extends Settings_Vtiger_Module_Model
- Exclude checks