YetiForceCompany/YetiForceCRM

View on GitHub
modules/Project/models/Module.php

Summary

Maintainability
A
0 mins
Test Coverage
D
68%

Missing class import via use statement (line '42', column '15').
Open

        return (new \App\Db\Query())
Severity: Minor
Found in modules/Project/models/Module.php by phpmd

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())
Severity: Minor
Found in modules/Project/models/Module.php by phpmd

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',
Severity: Minor
Found in modules/Project/models/Module.php by phpmd

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);
Severity: Minor
Found in modules/Project/models/Module.php by phpmd

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']);
Severity: Minor
Found in modules/Project/models/Module.php by phpmd

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) {
Severity: Critical
Found in modules/Project/models/Module.php by sonar-php

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);
Severity: Minor
Found in modules/Project/models/Module.php by phan

Suspicious array access to int
Open

                $childEstimatedWorkTime = static::calculateEstimatedWorkTime($child['id']);
Severity: Minor
Found in modules/Project/models/Module.php by phan

Call to undeclared method \App\Db\Query::select
Open

        $dataReader = (new \App\Db\Query())
Severity: Critical
Found in modules/Project/models/Module.php by phan

Suspicious array access to int
Open

            $estimatedWorkTime += static::calculateEstimatedWorkTime($child['id']);
Severity: Minor
Found in modules/Project/models/Module.php by phan

Call to undeclared method \App\Db\Query::select
Open

        return (new \App\Db\Query())
Severity: Critical
Found in modules/Project/models/Module.php by phan

Suspicious array access to int
Open

            if ($callerId !== $child['id']) {
Severity: Minor
Found in modules/Project/models/Module.php by phan

Avoid excessively long variable names like $milestoneEstimatedWorkTime. Keep variable name length under 20.
Open

            $milestoneEstimatedWorkTime = ProjectMilestone_Module_Model::calculateEstimatedWorkTime($row['id']);
Severity: Minor
Found in modules/Project/models/Module.php by phpmd

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']);
Severity: Minor
Found in modules/Project/models/Module.php by phpmd

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

Avoid variables with short names like $id. Configured minimum length is 3.
Open

    protected static function getChildren(int $id): array
Severity: Minor
Found in modules/Project/models/Module.php by phpmd

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
Severity: Minor
Found in modules/Project/models/Module.php by phpmd

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.
     *
Severity: Minor
Found in modules/Project/models/Module.php by phpmd

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)
Severity: Minor
Found in modules/Project/models/Module.php by phpmd

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
Severity: Minor
Found in modules/Project/models/Module.php by phpmd

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

    }

Spaces must be used to indent lines; tabs are not allowed
Open

        $dataReader = (new \App\Db\Query())

Spaces must be used to indent lines; tabs are not allowed
Open

            ->from('vtiger_projectmilestone')

Spaces must be used to indent lines; tabs are not allowed
Open

            ->innerJoin('vtiger_crmentity', 'vtiger_projectmilestone.projectmilestoneid = vtiger_crmentity.crmid')

Spaces must be used to indent lines; tabs are not allowed
Open

        $links = parent::getSideBarLinks($linkParams);

Spaces must be used to indent lines; tabs are not allowed
Open

        $links['SIDEBARLINK'][] = Vtiger_Link_Model::getInstanceFromValues([

Spaces must be used to indent lines; tabs are not allowed
Open

            'linkurl' => 'index.php?module=Project&view=Gantt',

Spaces must be used to indent lines; tabs are not allowed
Open

        ]);

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param float    $estimatedWorkTime

Spaces must be used to indent lines; tabs are not allowed
Open

                $estimatedWorkTime += $childEstimatedWorkTime;

Spaces must be used to indent lines; tabs are not allowed
Open

    public static function calculateEstimatedWorkTime(int $id, float $estimatedWorkTime = 0): float

Spaces must be used to indent lines; tabs are not allowed
Open

        foreach (static::getChildren($id) as $child) {

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param int $id

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param float $estimatedWorkTime

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     * Update progress in project.

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

            }

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

                'projectmilestonename' => 'vtiger_projectmilestone.projectmilestonename',

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        $progressInHours = 0;

Spaces must be used to indent lines; tabs are not allowed
Open

            ->where(['vtiger_crmentity.deleted' => [0, 2]])

Spaces must be used to indent lines; tabs are not allowed
Open

            ])

Spaces must be used to indent lines; tabs are not allowed
Open

        return $links;

Spaces must be used to indent lines; tabs are not allowed
Open

    }

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

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return int[]

Spaces must be used to indent lines; tabs are not allowed
Open

            ->from('vtiger_project')

Spaces must be used to indent lines; tabs are not allowed
Open

            ->andWhere(['vtiger_project.parentid' => $id])->all();

Spaces must be used to indent lines; tabs are not allowed
Open

            ->where(['vtiger_crmentity.deleted' => [0, 2]])

Spaces must be used to indent lines; tabs are not allowed
Open

            $progressInHours += ($milestoneEstimatedWorkTime * (float) $row['projectmilestone_progress']) / 100;

Spaces must be used to indent lines; tabs are not allowed
Open

            'linktype' => 'SIDEBARLINK',

Spaces must be used to indent lines; tabs are not allowed
Open

            'linklabel' => 'LBL_VIEW_GANTT',

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

            $milestoneEstimatedWorkTime = ProjectMilestone_Module_Model::calculateEstimatedWorkTime($row['id']);

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getSideBarLinks($linkParams)

Spaces must be used to indent lines; tabs are not allowed
Open

     * @throws \App\Exceptions\AppException

Spaces must be used to indent lines; tabs are not allowed
Open

                $progressInHours += ($childEstimatedWorkTime * $child['progress'] / 100);

Spaces must be used to indent lines; tabs are not allowed
Open

    protected static function getChildren(int $id): array

Spaces must be used to indent lines; tabs are not allowed
Open

    protected static function calculateProgressOfMilestones(int $id, float &$estimatedWorkTime, float &$progressInHours)

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

            ->createCommand()->query();

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param int|null $callerId

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return array

Spaces must be used to indent lines; tabs are not allowed
Open

        $recordModel->set('progress', $projectProgress);

Spaces must be used to indent lines; tabs are not allowed
Open

            'estimatedWorkTime' => $estimatedWorkTime,

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param int   $id

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

            ->innerJoin('vtiger_crmentity', 'vtiger_project.projectid = vtiger_crmentity.crmid')

Spaces must be used to indent lines; tabs are not allowed
Open

                'id' => 'vtiger_projectmilestone.projectmilestoneid',

Spaces must be used to indent lines; tabs are not allowed
Open

        $dataReader->close();

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

            'linkicon' => 'fas fa-briefcase',

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

        $projectProgress = $estimatedWorkTime ? round((100 * $progressInHours) / $estimatedWorkTime) : 0;

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

        static::calculateProgressOfMilestones($id, $estimatedWorkTime, $progressInHours);

Spaces must be used to indent lines; tabs are not allowed
Open

     * Calculate the progress of milestones.

Spaces must be used to indent lines; tabs are not allowed
Open

            $estimatedWorkTime += $milestoneEstimatedWorkTime;

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param int      $id

Spaces must be used to indent lines; tabs are not allowed
Open

            if ($callerId !== $child['id']) {

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

            );

Spaces must be used to indent lines; tabs are not allowed
Open

        return $estimatedWorkTime;

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

        foreach (static::getChildren($id) as $child) {

Spaces must be used to indent lines; tabs are not allowed
Open

                $childEstimatedWorkTime = static::calculateEstimatedWorkTime($child['id']);

Spaces must be used to indent lines; tabs are not allowed
Open

        static::calculateProgressOfMilestones($id, $estimatedWorkTime, $progressInHours);

Spaces must be used to indent lines; tabs are not allowed
Open

     * Calculate estimated work time.

Spaces must be used to indent lines; tabs are not allowed
Open

            $estimatedWorkTime += static::calculateEstimatedWorkTime($child['id']);

Spaces must be used to indent lines; tabs are not allowed
Open

            ->select(['id' => 'vtiger_project.projectid', 'vtiger_project.progress'])

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param float    $progressInHours

Spaces must be used to indent lines; tabs are not allowed
Open

        $recordModel = Vtiger_Record_Model::getInstanceById($id);

Spaces must be used to indent lines; tabs are not allowed
Open

        $recordModel->save();

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     * @throws \App\Exceptions\AppException

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

        return (new \App\Db\Query())

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param int   $id

Line exceeds 120 characters; contains 138 characters
Open

    public static function updateProgress(int $id, float $estimatedWorkTime = 0, float $progressInHours = 0, ?int $callerId = null): array

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param float $estimatedWorkTime

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return float

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     * @throws \App\Exceptions\AppException

Spaces must be used to indent lines; tabs are not allowed
Open

            ->select([

Spaces must be used to indent lines; tabs are not allowed
Open

            ->andWhere(['vtiger_projectmilestone.projectid' => $id])

Spaces must be used to indent lines; tabs are not allowed
Open

        while ($row = $dataReader->read()) {

Spaces must be used to indent lines; tabs are not allowed
Open

        if (!$recordModel->isEmpty('parentid') && $recordModel->get('parentid') !== $callerId) {

Spaces must be used to indent lines; tabs are not allowed
Open

        return [

Spaces must be used to indent lines; tabs are not allowed
Open

        ];

Spaces must be used to indent lines; tabs are not allowed
Open

     * Get children by parent ID.

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param float $progressInHours

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

            static::updateProgress(

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

                'projectmilestone_progress' => 'vtiger_projectmilestone.projectmilestone_progress',

Spaces must be used to indent lines; tabs are not allowed
Open

            ->andWhere(['or', ['vtiger_projectmilestone.parentid' => 0], ['vtiger_projectmilestone.parentid' => null]])

Spaces must be used to indent lines; tabs are not allowed
Open

    /** {@inheritdoc} */

Spaces must be used to indent lines; tabs are not allowed
Open

                $id

Spaces must be used to indent lines; tabs are not allowed
Open

            'projectProgress' => $projectProgress

Spaces must be used to indent lines; tabs are not allowed
Open

        $recordModel->set('estimated_work_time', $estimatedWorkTime);

Spaces must be used to indent lines; tabs are not allowed
Open

                $progressInHours,

Spaces must be used to indent lines; tabs are not allowed
Open

                $recordModel->get('parentid'),

Spaces must be used to indent lines; tabs are not allowed
Open

                $estimatedWorkTime,

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Class name "Project_Module_Model" is not in camel caps format
Open

class Project_Module_Model extends Vtiger_Module_Model

There are no issues that match your filters.

Category
Status