YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/PublicHoliday/models/Module.php

Summary

Maintainability
A
0 mins
Test Coverage
F
0%

Missing class import via use statement (line '55', column '17').
Open

        $query = (new \App\Db\Query())->select($this->getBaseIndex())->from($this->getBaseTable());

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

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

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

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

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

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

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

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

    public $nameFields = ['holidayname'];

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

     * @return Settings_PublicHoliday_Record_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

        $holidays = [];

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

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

        $query = (new \App\Db\Query())->select($this->getBaseIndex())->from($this->getBaseTable());

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

        $dataReader = $query->createCommand()->query();

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

        $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Module', $name);

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

        return false;

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

    public function getHolidaysByRange(array $range, int $sorting = SORT_ASC)

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

        if ($range) {

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

     * @param int   $sorting SORT_ASC|SORT_DESC

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

    public $listFields = [

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

        'holidayname' => '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

        return $holidays;

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

    public $baseIndex = 'publicholidayid';

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

     * Return info about module paging feature.

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

            $id = $row[$this->getBaseIndex()];

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 new $modelClassName();

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

    /**

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

        $query->orderBy(['holidaydate' => $sorting]);

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

     * @return bool - true: pageable, false: not pageable

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

    public function isPagingSupported()

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

        'holidaydate' => 'Date',

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

        'holidaytype' => 'Type',

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

     * @param string $name

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

     * Returns holidays into date range.

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

    public static function getInstance($name = 'Settings:PublicHoliday')

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

            $holidays[$id] = Settings_PublicHoliday_Record_Model::getInstanceById($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

    public $baseTable = 'vtiger_publicholiday';

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

    public $name = 'PublicHoliday';

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

     * Returns instance of Settings module 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

     * @param array $range

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

            $query->where(['between', 'holidaydate', $range[0], $range[1]]);

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

class Settings_PublicHoliday_Module_Model extends Settings_Vtiger_Module_Model

There are no issues that match your filters.

Category
Status