YetiForceCompany/YetiForceCRM

View on GitHub
modules/KnowledgeBase/models/KnowledgeBase.php

Summary

Maintainability
C
7 hrs
Test Coverage
F
0%

The class KnowledgeBase_KnowledgeBase_Model has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13.
Open

class KnowledgeBase_KnowledgeBase_Model extends \App\Base
{
    /**
     * Get instance.
     *

CouplingBetweenObjects

Since: 1.1.0

A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

Example

class Foo {
    /**
     * @var \foo\bar\X
     */
    private $x = null;

    /**
     * @var \foo\bar\Y
     */
    private $y = null;

    /**
     * @var \foo\bar\Z
     */
    private $z = null;

    public function setFoo(\Foo $foo) {}
    public function setBar(\Bar $bar) {}
    public function setBaz(\Baz $baz) {}

    /**
     * @return \SplObjectStorage
     * @throws \OutOfRangeException
     * @throws \InvalidArgumentException
     * @throws \ErrorException
     */
    public function process(\Iterator $it) {}

    // ...
}

Source https://phpmd.org/rules/design.html#couplingbetweenobjects

Missing class import via use statement (line '116', column '25').
Open

        $queryGenerator = new App\QueryGenerator('KnowledgeBase');

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 '195', column '39').
Open

        $query->addSelect(['matcher' => new \yii\db\Expression('MATCH(subject,content,introduction) AGAINST(:searchValue IN BOOLEAN MODE)', [':searchValue' => $value])]);

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

        $field = (new \App\Db\Query())->select(['tablename', 'columnname', 'fieldname', 'fieldlabel', 'fieldparams'])->from('vtiger_field')->where(['uitype' => 302, 'tabid' => \App\Module::getModuleId($this->get('moduleName'))])->one();

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 '135', column '25').
Open

        $queryGenerator = new App\QueryGenerator('KnowledgeBase');

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 'App\Fields\DateTime' in method 'parseForDisplay'.
Open

                'full_time' => App\Fields\DateTime::formatToDisplay($row['modifiedtime']),

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\Cache' in method 'getCategoriesByParent'.
Open

        if (App\Cache::has(static::class, 'CategoriesByParent')) {

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\Cache' in method 'getCategoriesByParent'.
Open

        App\Cache::save(static::class, 'CategoriesByParent', $categories);

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\Purifier' in method 'parseForDisplay'.
Open

                'introduction' => $introduction ? nl2br(\App\Utils\Completions::decode(\App\Purifier::purifyHtml($introduction))) : '',

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\Cache' in method 'getTreeField'.
Open

            return App\Cache::get(static::class, 'TreeField');

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\Fields\Tree' in method 'getCategoriesByParent'.
Open

            $parent = App\Fields\Tree::getParentIdx($row);

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\Cache' in method 'getTreeField'.
Open

        App\Cache::save(static::class, 'TreeField', $field);

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\Cache' in method 'getTreeField'.
Open

        if (App\Cache::has(static::class, 'TreeField')) {

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\Cache' in method 'getCategoriesByParent'.
Open

            return App\Cache::get(static::class, 'CategoriesByParent');

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\Utils\Completions' in method 'parseForDisplay'.
Open

                'introduction' => $introduction ? nl2br(\App\Utils\Completions::decode(\App\Purifier::purifyHtml($introduction))) : '',

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\Fields\Tree' in method 'getCategories'.
Open

        return App\Fields\Tree::getValuesById($this->getTemplate());

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\Module' in method 'getTreeField'.
Open

        $field = (new \App\Db\Query())->select(['tablename', 'columnname', 'fieldname', 'fieldlabel', 'fieldparams'])->from('vtiger_field')->where(['uitype' => 302, 'tabid' => \App\Module::getModuleId($this->get('moduleName'))])->one();

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_Util_Helper' in method 'parseForDisplay'.
Open

                'short_time' => \Vtiger_Util_Helper::formatDateDiffInStrings($row['modifiedtime']),

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\Fields\Owner' in method 'parseForDisplay'.
Open

                'assigned_user_id' => App\Fields\Owner::getLabel($row['assigned_user_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 "parentCategory" 5 times.
Open

        $categories = $this->isEmpty('parentCategory') ? $allCategories[0] : $allCategories[$this->get('parentCategory')] ?? [];

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.

Define a constant instead of duplicating this literal "TreeField" 3 times.
Open

        if (App\Cache::has(static::class, 'TreeField')) {

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.

Define a constant instead of duplicating this literal "CategoriesByParent" 3 times.
Open

        if (App\Cache::has(static::class, 'CategoriesByParent')) {

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.

Define a constant instead of duplicating this literal "modifiedtime" 3 times.
Open

        $queryGenerator->setFields(['id', 'assigned_user_id', 'subject', 'introduction', 'modifiedtime', 'category']);

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.

Define a constant instead of duplicating this literal "introduction" 3 times.
Open

        $queryGenerator->setFields(['id', 'assigned_user_id', 'subject', 'introduction', 'modifiedtime', 'category']);

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.

Define a constant instead of duplicating this literal "moduleName" 3 times.
Open

        return new static(['moduleName' => $moduleName]);

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.

Define a constant instead of duplicating this literal "filterValue" 5 times.
Open

        if ($this->has('filterField') && $this->has('filterValue')) {

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.

Define a constant instead of duplicating this literal "assigned_user_id" 3 times.
Open

        $queryGenerator->setFields(['id', 'assigned_user_id', 'subject', 'introduction', 'modifiedtime', 'category']);

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.

Define a constant instead of duplicating this literal "subject" 4 times.
Open

        $queryGenerator->setFields(['id', 'category', 'subject']);

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.

Define a constant instead of duplicating this literal "category" 7 times.
Open

                $featured[$row['category']][] = $row;

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.

Define a constant instead of duplicating this literal "filterField" 5 times.
Open

        if ($this->has('filterField') && $this->has('filterValue')) {

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 method __construct from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

        $queryGenerator = new App\QueryGenerator('KnowledgeBase');

Call to method getLabel from undeclared class \App\Fields\Owner
Open

                'assigned_user_id' => App\Fields\Owner::getLabel($row['assigned_user_id']),

Call to method decode from undeclared class \App\Utils\Completions
Open

                'introduction' => $introduction ? nl2br(\App\Utils\Completions::decode(\App\Purifier::purifyHtml($introduction))) : '',

Argument 1 (templateId) is array but \App\Fields\Tree::getValuesById() takes int defined at /code/app/Fields/Tree.php:27
Open

        return App\Fields\Tree::getValuesById($this->getTemplate());

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

        $queryGenerator->addNativeCondition(['knowledgebase_status' => 'PLL_ACCEPTED']);

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

            $queryGenerator->addNativeCondition(['category' => $this->get('parentCategory')]);

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

            $queryGenerator->addNativeCondition([$this->get('filterField') => $this->get('filterValue')]);

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

        $queryGenerator->addNativeCondition(['featured' => 1]);

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

        $queryGenerator->setLimit(50);

Call to method close from undeclared class \yii\db\DataReader
Open

        $dataReader->close();

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

        $query->andWhere('MATCH(subject,content,introduction) AGAINST(:findvalue IN BOOLEAN MODE)', [':findvalue' => $value]);

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

        $query->addOrderBy(['matcher' => \SORT_DESC]);

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

        $queryGenerator->setFields(['id', 'assigned_user_id', 'subject', 'introduction', 'modifiedtime', 'category']);

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

        $queryGenerator->setFields(['id', 'category', 'subject']);

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

        $queryGenerator->addNativeCondition(['knowledgebase_status' => 'PLL_ACCEPTED']);

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

        $queryGenerator->addNativeCondition(['category' => $categories]);

Parameter $dataReader has undeclared type \yii\db\DataReader
Open

    public function parseForDisplay(yii\db\DataReader $dataReader): array

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

        $query->addSelect(['matcher' => new \yii\db\Expression('MATCH(subject,content,introduction) AGAINST(:searchValue IN BOOLEAN MODE)', [':searchValue' => $value])]);

Reference to static property knowledgeBaseArticleLimit from undeclared class \Config\Modules\KnowledgeBase
Open

        $queryGenerator->setLimit(Config\Modules\KnowledgeBase::$knowledgeBaseArticleLimit);

Call to method __construct from undeclared class \yii\db\Expression
Open

        $query->addSelect(['matcher' => new \yii\db\Expression('MATCH(subject,content,introduction) AGAINST(:searchValue IN BOOLEAN MODE)', [':searchValue' => $value])]);

Declaration of function getData() : void should be compatible with function getData() : array defined in /code/app/Base.php:123
Open

    public function getData()

Suspicious array access to void
Open

        $categories = $this->isEmpty('parentCategory') ? $allCategories[0] : $allCategories[$this->get('parentCategory')] ?? [];

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

            $queryGenerator->addNativeCondition([$this->get('filterField') => $this->get('filterValue')]);

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

        return $queryGenerator->createQuery()->all();

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

        $queryGenerator = new App\QueryGenerator('KnowledgeBase');

Return type of getInstance() is undeclared type \self
Open

    public static function getInstance($moduleName)

Returning type array<string>&gt;|array{0:array{}}</string> but getCategoriesByParent() is declared to return void
Open

        return $categories;

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

        $field = (new \App\Db\Query())->select(['tablename', 'columnname', 'fieldname', 'fieldlabel', 'fieldparams'])->from('vtiger_field')->where(['uitype' => 302, 'tabid' => \App\Module::getModuleId($this->get('moduleName'))])->one();

Returning type array{showAccounts:bool,categories:array{}|mixed,featured:array<int>[]|array<int>[]|array{},records:array}</int></int> but getData() is declared to return void
Open

            'showAccounts' => 'Faq' === $this->get('moduleName'),

Call to method read from undeclared class \yii\db\DataReader
Open

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

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

        return $queryGenerator->createQuery();

Cannot assign void return value
Open

        $allCategories = $this->getCategoriesByParent();

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

        $queryGenerator->setLimit(Config\Modules\KnowledgeBase::$knowledgeBaseArticleLimit);

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    public function getListQuery(): App\Db\Query
    {
        $queryGenerator = new App\QueryGenerator('KnowledgeBase');
        $queryGenerator->setFields(['id', 'assigned_user_id', 'subject', 'introduction', 'modifiedtime', 'category']);
        $queryGenerator->addNativeCondition(['knowledgebase_status' => 'PLL_ACCEPTED']);
Severity: Major
Found in modules/KnowledgeBase/models/KnowledgeBase.php and 1 other location - About 4 hrs to fix
modules/Faq/models/KnowledgeBase.php on lines 43..56

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 162.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    public function getFeaturedRecords(array $categories): array
    {
        $queryGenerator = new App\QueryGenerator('KnowledgeBase');
        $queryGenerator->setFields(['id', 'category', 'subject']);
        $queryGenerator->addNativeCondition(['knowledgebase_status' => 'PLL_ACCEPTED']);
Severity: Major
Found in modules/KnowledgeBase/models/KnowledgeBase.php and 1 other location - About 3 hrs to fix
modules/Faq/models/KnowledgeBase.php on lines 24..36

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 152.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class KnowledgeBase_KnowledgeBase_Model extends \App\Base

The class KnowledgeBase_KnowledgeBase_Model is not named in CamelCase.
Open

class KnowledgeBase_KnowledgeBase_Model extends \App\Base
{
    /**
     * Get instance.
     *

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

     * Get folders.

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

        if (App\Cache::has(static::class, 'CategoriesByParent')) {

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 App\Cache::get(static::class, 'TreeField');

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

        return $field;

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

        $categories = $this->isEmpty('parentCategory') ? $allCategories[0] : $allCategories[$this->get('parentCategory')] ?? [];

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

            foreach ($this->getFeaturedRecords($categories) as $row) {

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

    public static function 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

    {

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 $this->getTreeField()['fieldparams'];

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

        $field = (new \App\Db\Query())->select(['tablename', 'columnname', 'fieldname', 'fieldlabel', 'fieldparams'])->from('vtiger_field')->where(['uitype' => 302, 'tabid' => \App\Module::getModuleId($this->get('moduleName'))])->one();

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 categories by arent.

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

            $parent = App\Fields\Tree::getParentIdx($row);

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 data form ajax.

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

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

     * @return array

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

            'categories' => $categories,

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 array

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

        $categories = [[]];

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

        return $categories;

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

        $featured = [];

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

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

            'showAccounts' => 'Faq' === $this->get('moduleName'),

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

     * Get instance.

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

    {

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

            return App\Cache::get(static::class, 'CategoriesByParent');

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

        App\Cache::save(static::class, 'CategoriesByParent', $categories);

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

        App\Cache::save(static::class, 'TreeField', $field);

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

    public function getData()

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

        $allCategories = $this->getCategoriesByParent();

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

        if ($categories) {

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

    public function getCategories()

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

        foreach ($this->getCategories() as $row) {

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 tree field.

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

        return new static(['moduleName' => $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

     */

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

        if (App\Cache::has(static::class, 'TreeField')) {

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

        $queryGenerator = new App\QueryGenerator('KnowledgeBase');

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

        $queryGenerator->setFields(['id', 'category', 'subject']);

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

        if ($this->has('parentCategory')) {

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

     *

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

        $value = $this->get('value');

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

     * @return \self

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

    }

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

            $categories[$parent][] = $row['tree'];

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

                $featured[$row['category']][] = $row;

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

     * Get featured records.

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 function parseForDisplay(yii\db\DataReader $dataReader): array

Line exceeds 120 characters; contains 135 characters
Open

                'introduction' => $introduction ? nl2br(\App\Utils\Completions::decode(\App\Purifier::purifyHtml($introduction))) : '',

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

    {

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 App\Db\Query

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

        $queryGenerator->setFields(['id', 'assigned_user_id', 'subject', 'introduction', 'modifiedtime', 'category']);

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 array

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 App\Fields\Tree::getValuesById($this->getTemplate());

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

    public function getCategoriesByParent()

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

        }

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

    }

Line exceeds 120 characters; contains 128 characters
Open

        $categories = $this->isEmpty('parentCategory') ? $allCategories[0] : $allCategories[$this->get('parentCategory')] ?? [];

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

        $queryGenerator->setLimit(50);

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

        return $queryGenerator->createQuery()->all();

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

            $queryGenerator->addNativeCondition([$this->get('filterField') => $this->get('filterValue')]);

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

        return $rows;

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

    public function getTemplate()

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

     * @return array

Line exceeds 120 characters; contains 236 characters
Open

        $field = (new \App\Db\Query())->select(['tablename', 'columnname', 'fieldname', 'fieldlabel', 'fieldparams'])->from('vtiger_field')->where(['uitype' => 302, 'tabid' => \App\Module::getModuleId($this->get('moduleName'))])->one();

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[] $categories

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

     * Get record list 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

    public function getRecordsByParentCategory(): array

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

            $queryGenerator->addNativeCondition([$this->get('filterField') => $this->get('filterValue')]);

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 yii\db\DataReader $dataReader

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

            $introduction = $row['introduction'] ?? '';

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 function search(): array

Line exceeds 120 characters; contains 126 characters
Open

        $query->andWhere('MATCH(subject,content,introduction) AGAINST(:findvalue IN BOOLEAN MODE)', [':findvalue' => $value]);

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

                'full_time' => App\Fields\DateTime::formatToDisplay($row['modifiedtime']),

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

            'featured' => $featured,

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

            'records' => $this->getRecordsByParentCategory(),

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

        $queryGenerator->setLimit(Config\Modules\KnowledgeBase::$knowledgeBaseArticleLimit);

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->andWhere('MATCH(subject,content,introduction) AGAINST(:findvalue IN BOOLEAN MODE)', [':findvalue' => $value]);

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

    public function getFeaturedRecords(array $categories): array

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

        $queryGenerator->addNativeCondition(['category' => $categories]);

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

     *

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

                'subject' => $row['subject'],

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

                'category' => $row['category'],

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 [];

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

        $query->addOrderBy(['matcher' => \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

        $queryGenerator->addNativeCondition(['knowledgebase_status' => 'PLL_ACCEPTED']);

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

    public function getListQuery(): App\Db\Query

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

        $queryGenerator = new App\QueryGenerator('KnowledgeBase');

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

        return $queryGenerator->createQuery();

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

                'short_time' => \Vtiger_Util_Helper::formatDateDiffInStrings($row['modifiedtime']),

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

        return $this->parseForDisplay($this->getListQuery()->createCommand()->query());

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

        $query->addSelect(['matcher' => new \yii\db\Expression('MATCH(subject,content,introduction) AGAINST(:searchValue IN BOOLEAN MODE)', [':searchValue' => $value])]);

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

        if ($this->has('filterField') && $this->has('filterValue')) {

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

            $rows[$row['id']] = [

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

        if ($this->isEmpty('parentCategory') && !($this->has('filterField') && $this->has('filterValue'))) {

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 = $this->getListQuery();

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

        $queryGenerator->addNativeCondition(['knowledgebase_status' => 'PLL_ACCEPTED']);

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

     * Parse record list for display.

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

                'introduction' => $introduction ? nl2br(\App\Utils\Completions::decode(\App\Purifier::purifyHtml($introduction))) : '',

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 records by parent category.

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

     * @return array

Line exceeds 120 characters; contains 170 characters
Open

        $query->addSelect(['matcher' => new \yii\db\Expression('MATCH(subject,content,introduction) AGAINST(:searchValue IN BOOLEAN MODE)', [':searchValue' => $value])]);

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

        $queryGenerator->addNativeCondition(['featured' => 1]);

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

        $rows = [];

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

                'assigned_user_id' => App\Fields\Owner::getLabel($row['assigned_user_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

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

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

        return $this->parseForDisplay($dataReader);

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

     *

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

        if ($this->has('filterField') && $this->has('filterValue')) {

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

            $queryGenerator->addNativeCondition(['category' => $this->get('parentCategory')]);

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

     * Article search.

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

class KnowledgeBase_KnowledgeBase_Model extends \App\Base

There are no issues that match your filters.

Category
Status