Missing class import via use statement (line '42', column '15'). Open
return (new \App\Db\Query())
- 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 '61', column '22'). Open
$dataReader = (new \App\Db\Query())
- 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_Link_Model' in method 'getSideBarLinks'. Open
$links['SIDEBARLINK'][] = Vtiger_Link_Model::getInstanceFromValues([
'linktype' => 'SIDEBARLINK',
'linklabel' => 'LBL_VIEW_GANTT',
'linkurl' => 'index.php?module=Project&view=Gantt',
'linkicon' => 'fas fa-briefcase',
- 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 'Vtiger_Record_Model' in method 'updateProgress'. Open
$recordModel = Vtiger_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
Avoid using static access to class 'ProjectMilestone_Module_Model' in method 'calculateProgressOfMilestones'. Open
$milestoneEstimatedWorkTime = ProjectMilestone_Module_Model::calculateEstimatedWorkTime($row['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 "parentid" 3 times. Open
if (!$recordModel->isEmpty('parentid') && $recordModel->get('parentid') !== $callerId) {
- 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.
Suspicious array access to int
Open
$progressInHours += ($childEstimatedWorkTime * $child['progress'] / 100);
- Exclude checks
Suspicious array access to int
Open
$childEstimatedWorkTime = static::calculateEstimatedWorkTime($child['id']);
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$dataReader = (new \App\Db\Query())
- Exclude checks
Suspicious array access to int
Open
$estimatedWorkTime += static::calculateEstimatedWorkTime($child['id']);
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
return (new \App\Db\Query())
- Exclude checks
Suspicious array access to int
Open
if ($callerId !== $child['id']) {
- Exclude checks
Avoid excessively long variable names like $milestoneEstimatedWorkTime. Keep variable name length under 20. Open
$milestoneEstimatedWorkTime = ProjectMilestone_Module_Model::calculateEstimatedWorkTime($row['id']);
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $childEstimatedWorkTime. Keep variable name length under 20. Open
$childEstimatedWorkTime = static::calculateEstimatedWorkTime($child['id']);
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Project_Module_Model extends Vtiger_Module_Model
- Exclude checks
Avoid variables with short names like $id. Configured minimum length is 3. Open
protected static function getChildren(int $id): array
- 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
Avoid variables with short names like $id. Configured minimum length is 3. Open
public static function updateProgress(int $id, float $estimatedWorkTime = 0, float $progressInHours = 0, ?int $callerId = null): array
- 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 Project_Module_Model is not named in CamelCase. Open
class Project_Module_Model extends Vtiger_Module_Model
{
/**
* Calculate estimated work time.
*
- 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
protected static function calculateProgressOfMilestones(int $id, float &$estimatedWorkTime, float &$progressInHours)
- 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
Avoid variables with short names like $id. Configured minimum length is 3. Open
public static function calculateEstimatedWorkTime(int $id, float $estimatedWorkTime = 0): float
- 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
$dataReader = (new \App\Db\Query())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('vtiger_projectmilestone')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->innerJoin('vtiger_crmentity', 'vtiger_projectmilestone.projectmilestoneid = vtiger_crmentity.crmid')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$links = parent::getSideBarLinks($linkParams);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$links['SIDEBARLINK'][] = Vtiger_Link_Model::getInstanceFromValues([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'linkurl' => 'index.php?module=Project&view=Gantt',
- 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 float $estimatedWorkTime
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$estimatedWorkTime += $childEstimatedWorkTime;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function calculateEstimatedWorkTime(int $id, float $estimatedWorkTime = 0): float
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (static::getChildren($id) as $child) {
- 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 int $id
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param float $estimatedWorkTime
- 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
* Update progress in project.
- 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
'projectmilestonename' => 'vtiger_projectmilestone.projectmilestonename',
- 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
$progressInHours = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['vtiger_crmentity.deleted' => [0, 2]])
- 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 $links;
- 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 updateProgress(int $id, float $estimatedWorkTime = 0, float $progressInHours = 0, ?int $callerId = null): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return int[]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('vtiger_project')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->andWhere(['vtiger_project.parentid' => $id])->all();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['vtiger_crmentity.deleted' => [0, 2]])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$progressInHours += ($milestoneEstimatedWorkTime * (float) $row['projectmilestone_progress']) / 100;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'linktype' => 'SIDEBARLINK',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'linklabel' => 'LBL_VIEW_GANTT',
- 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
$milestoneEstimatedWorkTime = ProjectMilestone_Module_Model::calculateEstimatedWorkTime($row['id']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getSideBarLinks($linkParams)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @throws \App\Exceptions\AppException
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$progressInHours += ($childEstimatedWorkTime * $child['progress'] / 100);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected static function getChildren(int $id): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected static function calculateProgressOfMilestones(int $id, float &$estimatedWorkTime, float &$progressInHours)
- 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
->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int|null $callerId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('progress', $projectProgress);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'estimatedWorkTime' => $estimatedWorkTime,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $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
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->innerJoin('vtiger_crmentity', 'vtiger_project.projectid = vtiger_crmentity.crmid')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'id' => 'vtiger_projectmilestone.projectmilestoneid',
- 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
'linkicon' => 'fas fa-briefcase',
- 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
$projectProgress = $estimatedWorkTime ? round((100 * $progressInHours) / $estimatedWorkTime) : 0;
- 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
static::calculateProgressOfMilestones($id, $estimatedWorkTime, $progressInHours);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Calculate the progress of milestones.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$estimatedWorkTime += $milestoneEstimatedWorkTime;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $id
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($callerId !== $child['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
);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $estimatedWorkTime;
- 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 (static::getChildren($id) as $child) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$childEstimatedWorkTime = static::calculateEstimatedWorkTime($child['id']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::calculateProgressOfMilestones($id, $estimatedWorkTime, $progressInHours);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Calculate estimated work time.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$estimatedWorkTime += static::calculateEstimatedWorkTime($child['id']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->select(['id' => 'vtiger_project.projectid', 'vtiger_project.progress'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param float $progressInHours
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = Vtiger_Record_Model::getInstanceById($id);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->save();
- 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
* @throws \App\Exceptions\AppException
- 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 \App\Db\Query())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $id
- Exclude checks
Line exceeds 120 characters; contains 138 characters Open
public static function updateProgress(int $id, float $estimatedWorkTime = 0, float $progressInHours = 0, ?int $callerId = null): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param float $estimatedWorkTime
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return float
- 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
* @throws \App\Exceptions\AppException
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->select([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->andWhere(['vtiger_projectmilestone.projectid' => $id])
- 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 (!$recordModel->isEmpty('parentid') && $recordModel->get('parentid') !== $callerId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return [
- 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 children by parent 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
* @param float $progressInHours
- 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
static::updateProgress(
- 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
'projectmilestone_progress' => 'vtiger_projectmilestone.projectmilestone_progress',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->andWhere(['or', ['vtiger_projectmilestone.parentid' => 0], ['vtiger_projectmilestone.parentid' => null]])
- 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
$id
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'projectProgress' => $projectProgress
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('estimated_work_time', $estimatedWorkTime);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$progressInHours,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->get('parentid'),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$estimatedWorkTime,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Class name "Project_Module_Model" is not in camel caps format Open
class Project_Module_Model extends Vtiger_Module_Model
- Exclude checks