app/RecordCollector.php
Function getAllByType
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
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'))) {
- Read upRead up
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
Open
foreach ((new \DirectoryIterator(__DIR__ . '/RecordCollectors')) as $fileinfo) {
- Read upRead up
- Exclude checks
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
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'))) {
- Read upRead up
- Exclude checks
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
Open
public static function getAllByType(string $displayType, string $moduleName): array
- Exclude checks
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
Open
if ($instance->isActive() && $instance->displayType === $displayType) {
- Exclude checks
Reference to instance property displayType
from undeclared class \App\RecordCollectors\Base
Open
Open
if ($instance->isActive() && $instance->displayType === $displayType) {
- Exclude checks
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
Open
public static function getInstance(string $className, string $moduleName): ?RecordCollectors\Base
- Exclude checks
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
Open
public static function getInstance(string $className, string $moduleName): ?RecordCollectors\Base
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $displayType
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $moduleName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function getInstance(string $className, string $moduleName): ?RecordCollectors\Base
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$instance = new $className();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$recordCollector = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$instance = null;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return RecordCollectors\Base[]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Get record collector instance.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $moduleName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return RecordCollectors\Base|null
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$instance->moduleName = $moduleName;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return $instance;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Get active record collector by type.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function getAllByType(string $displayType, string $moduleName): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $className
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (class_exists($className) && is_subclass_of($className, 'App\RecordCollectors\Base')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if ($instance->isActive() && $instance->displayType === $displayType) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$instance = self::getInstance('App\RecordCollectors\\' . $fileName, $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$recordCollector[$fileName] = $instance;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
foreach ((new \DirectoryIterator(__DIR__ . '/RecordCollectors')) as $fileinfo) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if ('php' === $fileinfo->getExtension() && 'Base' !== ($fileName = $fileinfo->getBasename('.php'))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return $recordCollector;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks