YetiForceCompany/YetiForceCRM

View on GitHub
modules/OSSTimeControl/models/TimeCounting.php

Summary

Maintainability
A
0 mins
Test Coverage
B
84%

Missing class import via use statement (line '222', column '23').
Open

        return (float) (new \App\QueryGenerator($this->moduleName))

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 '165', column '17').
Open

            (float) (new \App\QueryGenerator('OSSTimeControl'))

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_Module_Model' in method '__construct'.
Open

        $moduleModel = Vtiger_Module_Model::getInstance($moduleName);

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 'calculate'.
Open

        $recordModel = \Vtiger_Record_Model::getInstanceById($recordId, $this->moduleName);

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\Field' in method '__construct'.
Open

}

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

Call to undeclared method \App\Db::createCommand
Open

            \App\Db::getInstance()

Call to undeclared method \App\Db::createCommand
Open

        \App\Db::getInstance()

Call to method __construct from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

            (float) (new \App\QueryGenerator('OSSTimeControl'))

Call to method __construct from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

        return (float) (new \App\QueryGenerator($this->moduleName))

Reference to undeclared property \CRMEntity->table_index
Open

            $this->primaryKey = $moduleModel->getEntityInstance()->table_index;

Call to method createQuery from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

            (float) (new \App\QueryGenerator('OSSTimeControl'))

Call to method createQuery from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

        return (float) (new \App\QueryGenerator($this->moduleName))

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

    private $fieldModelSumTimeSubordinate;

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 $isActiveSumTimeSubordinate. Keep variable name length under 20.
Open

    private $isActiveSumTimeSubordinate = false;

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 OSSTimeControl_TimeCounting_Model

The class OSSTimeControl_TimeCounting_Model is not named in CamelCase.
Open

class OSSTimeControl_TimeCounting_Model
{
    /**
     * Recalculate status.
     */

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

    /**

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

     * Recalculate status.

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

    private $isActiveSumTimeSubordinate = false;

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

     * @var bool

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

    private $isActiveSumTime = false;

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

    /**

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

                $this->isActiveSumTimeSubordinate = $this->fieldModelSumTimeSubordinate && $this->fieldModelSumTimeSubordinate->isActiveField();

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

     * @param string $relationField

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

     * Recalculate time control.

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

     */

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

            2

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

     * @param int   $recordId

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

    /**

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

     * @var bool

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

     * @param string $relationField

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

     */

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

            $this->primaryKey = $moduleModel->getEntityInstance()->table_index;

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 $initialValue

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

    const COLUMN_SUM_TIME = 'sum_time';

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

     * Field name 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

    }

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 sum of time.

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

                ->createQuery()

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

                ->andWhere(['osstimecontrol_status' => static::RECALCULATE_STATUS, $this->relationField => $this->recordId])

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

    /**

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

    private $relationField;

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

                    $this->fieldModelSumTime->getTableName(),

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

     * Field model name sum of time.

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

     * @param string $moduleName

Line exceeds 120 characters; contains 122 characters
Open

                $this->fieldModelSumTimeSubordinate = $moduleModel->getFieldByColumn(static::COLUMN_SUM_TIME_SUBORDINATE);

Line exceeds 120 characters; contains 144 characters
Open

                $this->isActiveSumTimeSubordinate = $this->fieldModelSumTimeSubordinate && $this->fieldModelSumTimeSubordinate->isActiveField();

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 void

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

     * @return void

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

     */

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

     * Field model name sum of time subordinate.

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

    private $columnNameParentId;

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

            $this->columnNameParentId = \App\Field::getRelatedFieldForModule($moduleName, $moduleName)['columnname'] ?? null;

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

     * @var \Vtiger_Field_Model

Line exceeds 120 characters; contains 125 characters
Open

            $this->columnNameParentId = \App\Field::getRelatedFieldForModule($moduleName, $moduleName)['columnname'] ?? null;

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

                ->update(

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::COLUMN_SUM_TIME => $this->getSumTime()],

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

    }

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

    const RECALCULATE_STATUS = 'Accepted';

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

            (float) (new \App\QueryGenerator('OSSTimeControl'))

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

     * @var string

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

     * Is active total execution time.

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

        $moduleModel = Vtiger_Module_Model::getInstance($moduleName);

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 function recalculateTimeControl()

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

            \App\Db::getInstance()

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

        return round(

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

                ->sum($this->fieldModelSumTime->getColumnName()),

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

     *

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

     * Column sum time subordinate.

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

    private $fieldModelSumTimeSubordinate;

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

     *

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

    private $moduleName;

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

     * @param int    $recordId

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

    {

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

        (new self($moduleName, $recordId, $relationField))->recalculateTimeControl();

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

                $this->calculate($this->recordId);

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

    private function getSumTime(): 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

     */

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

     * @var string

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

     * @var int

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

     * @var string

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

        $this->relationField = $relationField;

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

        $this->moduleName = $moduleName;

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

        $this->isActiveSumTime = $this->fieldModelSumTime && $this->fieldModelSumTime->isActiveField();

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

     * @param int    $recordId

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

     * Column sum time.

Line exceeds 120 characters; contains 124 characters
Open

                ->andWhere(['osstimecontrol_status' => static::RECALCULATE_STATUS, $this->relationField => $this->recordId])

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

     * Calculate.

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

     *

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

     * Is active sum of time.

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

    private $recordId;

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

        if ($this->isActiveSumTime) {

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

     * Recalculate time control by record.

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

     */

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

     * Module name.

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

     */

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

        $this->recordId = $recordId;

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

                )->execute();

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

            if ($this->isActiveSumTimeSubordinate) {

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

     * Record 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

                $this->fieldModelSumTimeSubordinate = $moduleModel->getFieldByColumn(static::COLUMN_SUM_TIME_SUBORDINATE);

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()

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

    const COLUMN_SUM_TIME_SUBORDINATE = 'sum_time_subordinate';

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

    private $fieldModelSumTime;

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

     * @var \Vtiger_Field_Model

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

     */

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

        $this->fieldModelSumTime = $moduleModel->getFieldByColumn(static::COLUMN_SUM_TIME);

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

        if ($this->isActiveSumTime) {

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

                    [$this->primaryKey => $this->recordId]

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

    {

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

     * @var string

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

     */

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

    private $primaryKey;

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

     *

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

     * Relation field.

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

     * @param string $moduleName

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

     * @return void

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

        );

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

    private function calculate(int $recordId, float $initialValue = 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

     * Primary key of table.

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

     * Construct.

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

    public function __construct(string $moduleName, int $recordId, string $relationField)

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

            if ($this->columnNameParentId) {

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

    public static function recalculate(string $moduleName, int $recordId, string $relationField): void

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

    /**

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

            round(($initialValue + (float) $recordModel->get(static::COLUMN_SUM_TIME)), 2)

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

        if (!empty($parentId)) {

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

            ->createCommand()

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

    private function getSumTimeOfChildren(int $recordId): float

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

        $this->update(

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

        \App\Db::getInstance()

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

        )->execute();

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

            ->sum($this->fieldModelSumTimeSubordinate->getColumnName());

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 $sumTime

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

            ->createQuery()

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

        $recordModel = \Vtiger_Record_Model::getInstanceById($recordId, $this->moduleName);

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

     * Update.

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

    private function update(int $recordId, float $sumTime)

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

            $this->calculate($parentId, $this->getSumTimeOfChildren($parentId));

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

            [$this->primaryKey => $recordId]

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

     * @param int $recordId

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

     * @param int   $recordId

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

            ->update(

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 void

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

     */

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

                $this->fieldModelSumTimeSubordinate->getTableName(),

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

    }

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

            ->andWhere([$this->columnNameParentId => $recordId])

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

        return (float) (new \App\QueryGenerator($this->moduleName))

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

        $parentId = $recordModel->get($this->columnNameParentId);

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

            [$this->fieldModelSumTimeSubordinate->getColumnName() => $sumTime],

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

            $recordId,

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 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

     *

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

     * Get sum time of children.

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

class OSSTimeControl_TimeCounting_Model

Multi-line function call not indented correctly; expected 16 spaces but found 12
Open

            [$this->primaryKey => $recordId]

Multi-line function call not indented correctly; expected 12 spaces but found 8
Open

        )->execute();

Multi-line function call not indented correctly; expected 16 spaces but found 12
Open

            [$this->fieldModelSumTimeSubordinate->getColumnName() => $sumTime],

There are no issues that match your filters.

Category
Status