YetiForceCompany/YetiForceCRM

View on GitHub
app/RecordCollector.php

Summary

Maintainability
A
35 mins
Test Coverage
F
42%

Function getAllByType has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public static function getAllByType(string $displayType, string $moduleName): array
    {
        $recordCollector = [];
        foreach ((new \DirectoryIterator(__DIR__ . '/RecordCollectors')) as $fileinfo) {
            if ('php' === $fileinfo->getExtension() && 'Base' !== ($fileName = $fileinfo->getBasename('.php'))) {
Severity: Minor
Found in app/RecordCollector.php - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

        foreach ((new \DirectoryIterator(__DIR__ . '/RecordCollectors')) as $fileinfo) {
Severity: Minor
Found in app/RecordCollector.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 assigning values to variables in if clauses and the like (line '49', column '59').
Open

    public static function getAllByType(string $displayType, string $moduleName): array
    {
        $recordCollector = [];
        foreach ((new \DirectoryIterator(__DIR__ . '/RecordCollectors')) as $fileinfo) {
            if ('php' === $fileinfo->getExtension() && 'Base' !== ($fileName = $fileinfo->getBasename('.php'))) {
Severity: Minor
Found in app/RecordCollector.php by phpmd

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

Return type of getAllByType() is undeclared type \App\RecordCollectors\Base[] (Did you mean class \App\Base or class \App\Cache\Base or class \App\Cli\Base or class \App\Controller\Base or class \App\Controller\View\Base or class \App\Db\Importers\Base or class \Tests\Base)
Open

    public static function getAllByType(string $displayType, string $moduleName): array
Severity: Minor
Found in app/RecordCollector.php by phan

Call to method isActive from undeclared class \App\RecordCollectors\Base (Did you mean class \App\Base or class \App\Cache\Base or class \App\Cli\Base or class \App\Controller\Base or class \App\Controller\View\Base or class \App\Db\Importers\Base or class \Tests\Base)
Open

                if ($instance->isActive() && $instance->displayType === $displayType) {
Severity: Critical
Found in app/RecordCollector.php by phan

Reference to instance property displayType from undeclared class \App\RecordCollectors\Base
Open

                if ($instance->isActive() && $instance->displayType === $displayType) {
Severity: Minor
Found in app/RecordCollector.php by phan

Return type of getInstance() is undeclared type ?\App\RecordCollectors\Base (Did you mean class \App\Base or class \App\Cache\Base or class \App\Cli\Base or class \App\Controller\Base or class \App\Controller\View\Base or class \App\Db\Importers\Base or class \Tests\Base)
Open

    public static function getInstance(string $className, string $moduleName): ?RecordCollectors\Base
Severity: Minor
Found in app/RecordCollector.php by phan

Return type of getInstance() is undeclared type \App\RecordCollectors\Base (Did you mean class \App\Base or class \App\Cache\Base or class \App\Cli\Base or class \App\Controller\Base or class \App\Controller\View\Base or class \App\Db\Importers\Base or class \Tests\Base)
Open

    public static function getInstance(string $className, string $moduleName): ?RecordCollectors\Base
Severity: Minor
Found in app/RecordCollector.php by phan

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

    {
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

     * @param string $displayType
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

     * @param string $moduleName
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

    public static function getInstance(string $className, string $moduleName): ?RecordCollectors\Base
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

            $instance = new $className();
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

        $recordCollector = [];
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

        $instance = null;
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

     * @return RecordCollectors\Base[]
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

     * Get record collector instance.
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

     * @param string $moduleName
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

     * @return RecordCollectors\Base|null
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

            $instance->moduleName = $moduleName;
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

        return $instance;
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

     * Get active record collector by type.
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

    public static function getAllByType(string $displayType, string $moduleName): array
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

     * @param string $className
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

        if (class_exists($className) && is_subclass_of($className, 'App\RecordCollectors\Base')) {
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

                if ($instance->isActive() && $instance->displayType === $displayType) {
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

                $instance = self::getInstance('App\RecordCollectors\\' . $fileName, $moduleName);
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

            }
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

                    $recordCollector[$fileName] = $instance;
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

        foreach ((new \DirectoryIterator(__DIR__ . '/RecordCollectors')) as $fileinfo) {
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

            if ('php' === $fileinfo->getExtension() && 'Base' !== ($fileName = $fileinfo->getBasename('.php'))) {
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

                }
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

        return $recordCollector;
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/RecordCollector.php by phpcodesniffer

There are no issues that match your filters.

Category
Status