Method _fileCheck
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function _fileCheck($filename, &$ownFixtures = [], $debug = false)
{
if (\is_array($filename)) {
if (\array_key_exists('width', $filename)) {
$__width = $filename['width'];
Method _normalizeTestGroup
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function _normalizeTestGroup($filename, &$ownFixtures = [], $example_title = 'file_iterator', $debug = false, $attributes = [])
{
$filename_meaningful = \explode('ex', $filename)[0];
if ('file_iterator' === $example_title) {
Function _fileCheck
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private function _fileCheck($filename, &$ownFixtures = [], $debug = false)
{
if (\is_array($filename)) {
if (\array_key_exists('width', $filename)) {
$__width = $filename['width'];
- 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
Method _normalizeTestGroup
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private function _normalizeTestGroup($filename, &$ownFixtures = [], $example_title = 'file_iterator', $debug = false, $attributes = [])
Method renameIfDimensionsDontMatch
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function renameIfDimensionsDontMatch($exampleRoot, $filename, $__width, $__height, $size)
Function tearDownAfterClass
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function tearDownAfterClass(): void
{
$arr = \explode('\\', static::class);
$className = \array_pop($arr);
- 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
The method _fileCheck has a boolean flag argument $debug, which is a certain sign of a Single Responsibility Principle violation. Open
private function _fileCheck($filename, &$ownFixtures = [], $debug = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method _normalizeTestGroup has a boolean flag argument $debug, which is a certain sign of a Single Responsibility Principle violation. Open
private function _normalizeTestGroup($filename, &$ownFixtures = [], $example_title = 'file_iterator', $debug = false, $attributes = [])
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Avoid using static access to class '\Symfony\Component\Yaml\Yaml' in method 'setUpBeforeClass'. Open
self::$fixTures = Yaml::parseFile(\sprintf('%s/_support/%s.yml', __DIR__, $className));
- Read upRead up
- Exclude checks
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 '\Codeception\Util\Debug' in method 'setUpBeforeClass'. Open
Debug::debug(__CLASS__ . ' has ' . \count(self::$files) . ' ungrouped files. knownFixtures are:');
- Read upRead up
- Exclude checks
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 '\Codeception\Util\Debug' in method '_fileCheck'. Open
Debug::debug(
'testing ' . $filename .
' for image/jpeg headers '
);
- Read upRead up
- Exclude checks
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
The method setUpBeforeClass uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
self::$fixTures = ['testFileIterator' => self::$files];
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method _fileCheck uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
Debug::debug(
'testing ' . $filename .
' for image/jpeg headers '
);
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\Codeception\Util\Debug' in method 'tearDownAfterClass'. Open
Debug::debug(self::$genericFixtures['testFileIterator']);
- Read upRead up
- Exclude checks
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 '\Codeception\Util\Debug' in method 'tearDownAfterClass'. Open
Debug::debug('non grouped fixtures:');
- Read upRead up
- Exclude checks
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 '\Codeception\Util\Debug' in method 'setUpBeforeClass'. Open
Debug::debug($knownFixtures);
- Read upRead up
- Exclude checks
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 '\Symfony\Component\Yaml\Yaml' in method 'tearDownAfterClass'. Open
$yaml = Yaml::dump(self::$genericFixtures);
- Read upRead up
- Exclude checks
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 '\Codeception\Util\Debug' in method '_normalizeTestGroup'. Open
Debug::debug([
'withoutSuffix' => $withoutSuffix,
'example_title' => 'file_iterator' === $example_title ? 'No Title' : $example_title,
'camelCased' => $camelCased,
'filename' => $filename,
- Read upRead up
- Exclude checks
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
The method getFiles() contains an exit expression. Open
exit("PANIC: Apache/PHP does not have enough permission to read the scripts in directory: {$folder}");
- Read upRead up
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
Source https://phpmd.org/rules/design.html#exitexpression
Avoid unused parameters such as '$class'. Open
public static function getFiles($class = '')
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid variables with short names like $a. Configured minimum length is 3. Open
$a = [];
- Read upRead up
- Exclude checks
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
Avoid variables with short names like $d. Configured minimum length is 3. Open
$d = \dir($folder);
- Read upRead up
- Exclude checks
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
Line exceeds 120 characters; contains 139 characters Open
private function _normalizeTestGroup($filename, &$ownFixtures = [], $example_title = 'file_iterator', $debug = false, $attributes = [])
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
$ownFixtures[$methodName][$filename] = \array_merge($dims, ['title' => $example_title, 'filename' => $filename]);
- Exclude checks
Line exceeds 120 characters; contains 139 characters Open
if (isset(self::$debugFileGroups) && self::$debugFileGroups && \array_key_exists('testFileIterator', self::$genericFixtures)) {
- Exclude checks
Line exceeds 120 characters; contains 131 characters Open
self::$exampleRoot = UNIT_TEST_FOLDER . '/Examples/examples_' . \str_replace('test', '', \mb_strtolower($class)) . '/';
- Exclude checks
Expected 0 spaces after opening bracket; newline found Open
if (
- Exclude checks