File BrandsController.php
has 357 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace Application\Controller\Api;
use Application\Model\Brand;
Method otherGroups
has 56 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function otherGroups(
int $brandId,
string $brandCatname,
bool $conceptsSeparately
): array {
Method carSectionGroupsSelect
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function carSectionGroupsSelect(
int $brandId,
int $itemTypeId,
int $carTypeId,
?bool $nullType,
Method carSections
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function carSections(
string $language,
int $brandId,
string $brandCatname,
bool $conceptsSeparatly
Method carSectionGroups
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function carSectionGroups(
string $language,
int $brandId,
string $brandCatname,
array $section,
Method newItemsAction
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function newItemsAction(): ViewModel
{
$brand = $this->itemModel->getRow([
'item_type_id' => Item::BRAND,
'id' => (int) $this->params()->fromRoute('id'),
Method __construct
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
StorageInterface $cache,
Brand $brand,
VehicleType $vehicleType,
Item $itemModel,
Picture $picture,
Method carSectionGroups
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
string $language,
int $brandId,
string $brandCatname,
array $section,
bool $conceptsSeparatly
Method carSectionGroupsSelect
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
int $brandId,
int $itemTypeId,
int $carTypeId,
?bool $nullType,
bool $conceptsSeparately
Function carSectionGroups
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function carSectionGroups(
string $language,
int $brandId,
string $brandCatname,
array $section,
- 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
Function otherGroups
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function otherGroups(
int $brandId,
string $brandCatname,
bool $conceptsSeparately
): array {
- 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
Avoid using undefined variables such as '$success' which will lead to PHP notices. Open
if (! $success) {
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$success' which will lead to PHP notices. Open
$items = $this->cache->getItem($cacheKey, $success);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
The class BrandsController has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13. Open
class BrandsController extends AbstractActionController
{
private StorageInterface $cache;
private Brand $brand;
- Read upRead up
- Exclude checks
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
The method carSectionGroups uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$rows = [];
$select = $this->carSectionGroupsSelect(
$brandId,
$section['item_type_id'],
- 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
syntax error, unexpected 'StorageInterface' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
Open
private StorageInterface $cache;
- Exclude checks
Similar blocks of code found in 2 locations. Consider refactoring. Open
public function __construct(
StorageInterface $cache,
Brand $brand,
VehicleType $vehicleType,
Item $itemModel,
- Read upRead up
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 100.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Avoid excessively long variable names like $unsortedPicturesCount. Keep variable name length under 20. Open
$unsortedPicturesCount = $this->picture->getCount([
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}