File SpecificationsService.php
has 1897 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace Application\Service;
use Application\ItemNameFormatter;
SpecificationsService
has 64 functions (exceeds 20 allowed). Consider refactoring. Open
class SpecificationsService
{
private const
DEFAULT_ZONE_ID = 1,
ENGINE_ZONE_ID = 5,
Function setUserValue
has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring. Open
public function setUserValue(int $uid, int $attributeId, int $itemId, $value): void
{
$attribute = $this->getAttribute($attributeId);
if (! $attribute) {
throw new Exception("attribute `$attributeId` not found");
- 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 getAttributes
has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring. Open
public function getAttributes(array $options = []): array
{
$defaults = [
'zone' => null,
'parent' => null,
- 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 setUserValue2
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
public function setUserValue2(int $uid, int $attributeId, int $itemId, $value, bool $empty): void
{
$attribute = $this->getAttribute($attributeId);
if (! $attribute) {
throw new Exception("attribute `$attributeId` not found");
- 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 calcInheritedValue
has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring. Open
private function calcInheritedValue($attribute, int $itemId): array
{
$actualValue = [
'empty' => true,
'value' => null,
- 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 refreshConflictFlag
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
public function refreshConflictFlag(int $attributeId, int $itemId): void
{
if (! $attributeId) {
throw new Exception("attributeId not provided");
}
- 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 calcAvgUserValue
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
private function calcAvgUserValue(array $attribute, int $itemId): array
{
$userValuesDataTable = $this->getUserValueDataTable($attribute['typeId']);
$userValueDataRows = $userValuesDataTable->select([
- 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 getZoneItemsActualValues
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
private function getZoneItemsActualValues(int $zoneId, array $itemIds): array
{
if (count($itemIds) <= 0) {
return [];
}
- 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 specifications
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
public function specifications(array $cars, array $options): CarSpecTable
{
$options = array_merge([
'contextCarId' => null,
'language' => 'en',
- 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 getFilterSpec
has 98 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getFilterSpec(int $attributeId): ?array
{
$filters = [];
$validators = [];
Method specifications
has 97 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function specifications(array $cars, array $options): CarSpecTable
{
$options = array_merge([
'contextCarId' => null,
'language' => 'en',
Method refreshConflictFlag
has 96 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function refreshConflictFlag(int $attributeId, int $itemId): void
{
if (! $attributeId) {
throw new Exception("attributeId not provided");
}
Method setUserValue2
has 95 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setUserValue2(int $uid, int $attributeId, int $itemId, $value, bool $empty): void
{
$attribute = $this->getAttribute($attributeId);
if (! $attribute) {
throw new Exception("attribute `$attributeId` not found");
Method setUserValue
has 94 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setUserValue(int $uid, int $attributeId, int $itemId, $value): void
{
$attribute = $this->getAttribute($attributeId);
if (! $attribute) {
throw new Exception("attribute `$attributeId` not found");
The class SpecificationsService has 29 non-getter- and setter-methods. Consider refactoring SpecificationsService to keep number of methods under 25. Open
class SpecificationsService
{
private const
DEFAULT_ZONE_ID = 1,
ENGINE_ZONE_ID = 5,
- Read upRead up
- Exclude checks
TooManyMethods
Since: 0.1
A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
The default was changed from 10 to 25 in PHPMD 2.3.
Example
Source https://phpmd.org/rules/codesize.html#toomanymethods
The class SpecificationsService has an overall complexity of 375 which is very high. The configured complexity threshold is 50. Open
class SpecificationsService
{
private const
DEFAULT_ZONE_ID = 1,
ENGINE_ZONE_ID = 5,
- Exclude checks
The class SpecificationsService has 13 public methods. Consider refactoring SpecificationsService to keep number of public methods under 10. Open
class SpecificationsService
{
private const
DEFAULT_ZONE_ID = 1,
ENGINE_ZONE_ID = 5,
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
Function setActualValue
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
private function setActualValue(array $attribute, int $itemId, array $actualValue): bool
{
$valueDataTable = $this->getValueDataTable($attribute['typeId']);
$somethingChanges = false;
- 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 calcAvgUserValue
has 75 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function calcAvgUserValue(array $attribute, int $itemId): array
{
$userValuesDataTable = $this->getUserValueDataTable($attribute['typeId']);
$userValueDataRows = $userValuesDataTable->select([
Method setActualValue
has 69 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function setActualValue(array $attribute, int $itemId, array $actualValue): bool
{
$valueDataTable = $this->getValueDataTable($attribute['typeId']);
$somethingChanges = false;
Method __construct
has 22 arguments (exceeds 4 allowed). Consider refactoring. Open
TranslatorInterface $translator,
ItemNameFormatter $itemNameFormatter,
Item $itemModel,
ItemParent $itemParent,
Picture $picture,
Function getItemsActualValues
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
private function getItemsActualValues(array $itemIds): array
{
if (count($itemIds) <= 0) {
return [];
}
- 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 getAttributes
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getAttributes(array $options = []): array
{
$defaults = [
'zone' => null,
'parent' => null,
Method calcEngineValue
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function calcEngineValue($attribute, int $itemId): array
{
if (! $this->isEngineAttributeId($attribute['id'])) {
return [
'empty' => true,
Method getConflicts
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getConflicts(int $userId, $filter, int $page, int $perPage): array
{
$userId = (int) $userId;
$select = new Sql\Select($this->valueTable->getTable());
Function valueToText
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
private function valueToText(array $attribute, $value, string $language)
{
if ($value === null) {
return null;
}
- 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 getZoneItemsActualValues
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getZoneItemsActualValues(int $zoneId, array $itemIds): array
{
if (count($itemIds) <= 0) {
return [];
}
Method calcInheritedValue
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function calcInheritedValue($attribute, int $itemId): array
{
$actualValue = [
'empty' => true,
'value' => null,
Function removeEmpty
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private function removeEmpty(array &$attributes, array $cars): void
{
foreach ($attributes as $idx => &$attribute) {
$this->removeEmpty($attribute['childs'], $cars);
- 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 getFilterSpec
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function getFilterSpec(int $attributeId): ?array
{
$filters = [];
$validators = [];
- 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 calcEngineValue
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private function calcEngineValue($attribute, int $itemId): array
{
if (! $this->isEngineAttributeId($attribute['id'])) {
return [
'empty' => true,
- 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 valueToText
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function valueToText(array $attribute, $value, string $language)
{
if ($value === null) {
return null;
}
Method getUserValue2
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getUserValue2(int $attributeId, int $itemId, int $userId): array
{
if (! $itemId) {
throw new Exception("item_id not set");
}
The class SpecificationsService has 32 fields. Consider redesigning SpecificationsService to keep the number of fields under 15. Open
class SpecificationsService
{
private const
DEFAULT_ZONE_ID = 1,
ENGINE_ZONE_ID = 5,
- Read upRead up
- Exclude checks
TooManyFields
Since: 0.1
Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.
Example
class Person {
protected $one;
private $two;
private $three;
[... many more fields ...]
}
Source https://phpmd.org/rules/codesize.html#toomanyfields
Method getItemsActualValues
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getItemsActualValues(array $itemIds): array
{
if (count($itemIds) <= 0) {
return [];
}
Method getUserValueText
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getUserValueText(int $attributeId, int $itemId, int $userId, string $language): ?string
{
if (! $itemId) {
throw new Exception("item_id not set");
}
Method loadAttributes
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function loadAttributes(): self
{
if (! isset($this->attributes)) {
$array = [];
$childs = [];
Method getActualValue
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getActualValue(int $attributeId, int $itemId)
{
if (! $itemId) {
throw new Exception("item_id not set");
}
Function loadListOptions
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function loadListOptions(array $attributeIds): void
{
$ids = array_diff($attributeIds, array_keys($this->listOptions));
if (count($ids)) {
- 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 getActualValue
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function getActualValue(int $attributeId, int $itemId)
{
if (! $itemId) {
throw new Exception("item_id not set");
}
- 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 loadAttributes
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function loadAttributes(): self
{
if (! isset($this->attributes)) {
$array = [];
$childs = [];
- 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 getUserValue
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getUserValue(int $attributeId, int $itemId, int $userId)
{
if (! $itemId) {
throw new Exception("item_id not set");
}
Function getConflicts
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function getConflicts(int $userId, $filter, int $page, int $perPage): array
{
$userId = (int) $userId;
$select = new Sql\Select($this->valueTable->getTable());
- 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 getUserValueText
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function getUserValueText(int $attributeId, int $itemId, int $userId, string $language): ?string
{
if (! $itemId) {
throw new Exception("item_id not set");
}
- 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 setUserValue2
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function setUserValue2(int $uid, int $attributeId, int $itemId, $value, bool $empty): void
Function hasChildSpecs
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function hasChildSpecs($itemId)
{
$select = new Sql\Select($this->valueTable->getTable());
$select->columns([])
- 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 hasSpecs
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function hasSpecs($itemId)
{
$select = new Sql\Select($this->valueTable->getTable());
$select->columns(['item_id']);
if (is_array($itemId)) {
- 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 getActualValueText
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getActualValueText(int $attributeId, int $itemId, string $language): ?string
{
if (! $itemId) {
throw new Exception("item_id not set");
}
- 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 too many return
statements within this method. Open
return $value ? 'да' : 'нет';
Avoid too many return
statements within this method. Open
return $value;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return [
'empty' => false,
'value' => $value,
];
Avoid too many return
statements within this method. Open
return [
'empty' => true,
'value' => null,
];
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return [
'empty' => true,
'value' => null,
];
Avoid too many return
statements within this method. Open
return $value === null ? null : ($value ? 1 : 0);
Avoid too many return
statements within this method. Open
return $nullText ? null : implode(', ', $text);
Avoid too many return
statements within this method. Open
return $value === null ? null : (int) $value;
Avoid too many return
statements within this method. Open
return $this->getListOptionsText($attribute['id'], $value);
Function propagateInheritance
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function propagateInheritance(array $attribute, int $itemId): void
{
$childIds = $this->getChildCarIds($itemId);
foreach ($childIds as $childId) {
- 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 updateInheritedValues
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function updateInheritedValues(int $itemId): void
{
foreach ($this->getAttributes() as $attribute) {
if ($attribute['typeId']) {
$haveValue = $this->haveOwnAttributeValue($attribute['id'], $itemId);
- 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 updateAllActualValues
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function updateAllActualValues(): void
{
$attributes = $this->getAttributes();
$select = $this->userValueTable->getSql()->select();
- 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 getListOptionsArrayRecursive
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function getListOptionsArrayRecursive(int $aid, int $parentId): array
{
$result = [];
if (isset($this->listOptionsChilds[$aid][$parentId])) {
foreach ($this->listOptionsChilds[$aid][$parentId] as $childId) {
- 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 getListOptions
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function getListOptions(int $aid, int $parentId): array
{
$result = [];
if (isset($this->listOptionsChilds[$aid][$parentId])) {
foreach ($this->listOptionsChilds[$aid][$parentId] as $childId) {
- 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 getUserValue2
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getUserValue2(int $attributeId, int $itemId, int $userId): array
{
if (! $itemId) {
throw new Exception("item_id not set");
}
- 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 __construct has 22 parameters. Consider reducing the number of parameters to less than 10. Open
public function __construct(
TranslatorInterface $translator,
ItemNameFormatter $itemNameFormatter,
Item $itemModel,
ItemParent $itemParent,
- Exclude checks
The method setUserValue() has 126 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function setUserValue(int $uid, int $attributeId, int $itemId, $value): void
{
$attribute = $this->getAttribute($attributeId);
if (! $attribute) {
throw new Exception("attribute `$attributeId` not found");
- Exclude checks
The method specifications() has 125 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function specifications(array $cars, array $options): CarSpecTable
{
$options = array_merge([
'contextCarId' => null,
'language' => 'en',
- Exclude checks
The method getZoneItemsActualValues() has an NPath complexity of 224. The configured NPath complexity threshold is 200. Open
private function getZoneItemsActualValues(int $zoneId, array $itemIds): array
{
if (count($itemIds) <= 0) {
return [];
}
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method setUserValue() has an NPath complexity of 256. The configured NPath complexity threshold is 200. Open
public function setUserValue(int $uid, int $attributeId, int $itemId, $value): void
{
$attribute = $this->getAttribute($attributeId);
if (! $attribute) {
throw new Exception("attribute `$attributeId` not found");
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method refreshConflictFlag() has an NPath complexity of 5568. The configured NPath complexity threshold is 200. Open
public function refreshConflictFlag(int $attributeId, int $itemId): void
{
if (! $attributeId) {
throw new Exception("attributeId not provided");
}
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method setUserValue2() has 130 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function setUserValue2(int $uid, int $attributeId, int $itemId, $value, bool $empty): void
{
$attribute = $this->getAttribute($attributeId);
if (! $attribute) {
throw new Exception("attribute `$attributeId` not found");
- Exclude checks
The class SpecificationsService has 2427 lines of code. Current threshold is 1000. Avoid really long classes. Open
class SpecificationsService
{
private const
DEFAULT_ZONE_ID = 1,
ENGINE_ZONE_ID = 5,
- Exclude checks
The method getFilterSpec() has 114 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function getFilterSpec(int $attributeId): ?array
{
$filters = [];
$validators = [];
- Exclude checks
The method refreshConflictFlag() has 117 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function refreshConflictFlag(int $attributeId, int $itemId): void
{
if (! $attributeId) {
throw new Exception("attributeId not provided");
}
- Exclude checks
The method specifications() has an NPath complexity of 10368. The configured NPath complexity threshold is 200. Open
public function specifications(array $cars, array $options): CarSpecTable
{
$options = array_merge([
'contextCarId' => null,
'language' => 'en',
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method calcAvgUserValue() has an NPath complexity of 4632. The configured NPath complexity threshold is 200. Open
private function calcAvgUserValue(array $attribute, int $itemId): array
{
$userValuesDataTable = $this->getUserValueDataTable($attribute['typeId']);
$userValueDataRows = $userValuesDataTable->select([
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method getFilterSpec() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10. Open
public function getFilterSpec(int $attributeId): ?array
{
$filters = [];
$validators = [];
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method refreshConflictFlag() has a Cyclomatic Complexity of 19. The configured cyclomatic complexity threshold is 10. Open
public function refreshConflictFlag(int $attributeId, int $itemId): void
{
if (! $attributeId) {
throw new Exception("attributeId not provided");
}
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method prepareValue() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
private function prepareValue(int $typeId, $value)
{
switch ($typeId) {
case 1: // string
return $value;
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method setUserValue() has a Cyclomatic Complexity of 20. The configured cyclomatic complexity threshold is 10. Open
public function setUserValue(int $uid, int $attributeId, int $itemId, $value): void
{
$attribute = $this->getAttribute($attributeId);
if (! $attribute) {
throw new Exception("attribute `$attributeId` not found");
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method specifications() has a Cyclomatic Complexity of 18. The configured cyclomatic complexity threshold is 10. Open
public function specifications(array $cars, array $options): CarSpecTable
{
$options = array_merge([
'contextCarId' => null,
'language' => 'en',
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method getAttributes() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10. Open
public function getAttributes(array $options = []): array
{
$defaults = [
'zone' => null,
'parent' => null,
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method setUserValue2() has a Cyclomatic Complexity of 17. The configured cyclomatic complexity threshold is 10. Open
public function setUserValue2(int $uid, int $attributeId, int $itemId, $value, bool $empty): void
{
$attribute = $this->getAttribute($attributeId);
if (! $attribute) {
throw new Exception("attribute `$attributeId` not found");
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method calcInheritedValue() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
private function calcInheritedValue($attribute, int $itemId): array
{
$actualValue = [
'empty' => true,
'value' => null,
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method calcAvgUserValue() has a Cyclomatic Complexity of 17. The configured cyclomatic complexity threshold is 10. Open
private function calcAvgUserValue(array $attribute, int $itemId): array
{
$userValuesDataTable = $this->getUserValueDataTable($attribute['typeId']);
$userValueDataRows = $userValuesDataTable->select([
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method valueToText() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10. Open
private function valueToText(array $attribute, $value, string $language)
{
if ($value === null) {
return null;
}
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method getZoneItemsActualValues() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open
private function getZoneItemsActualValues(int $zoneId, array $itemIds): array
{
if (count($itemIds) <= 0) {
return [];
}
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The class SpecificationsService has a coupling between objects value of 22. Consider to reduce the number of dependencies under 13. Open
class SpecificationsService
{
private const
DEFAULT_ZONE_ID = 1,
ENGINE_ZONE_ID = 5,
- 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 specifications uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$keys = array_keys($zoneIds);
$specsZoneId = reset($keys);
}
- 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 getZoneItemsActualValues uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$values[$id][$aid] = $value;
}
- 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 refreshConflictFlag uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$weight = self::WEIGHT_NONE;
}
- 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 getActualValueText uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return $this->valueToText($attribute, $value, $language);
}
- 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 refreshConflictFlag uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$affectedRows = $this->userValueTable->update([
'conflict' => 0,
'weight' => self::WEIGHT_NONE,
], [
- 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 specifications uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$actualValues = $this->getItemsActualValues($carIds);
}
- 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 setUserValue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$valueChanged = true;
}
- 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 setActualValue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$primaryKey = [
'attribute_id' => $attribute['id'],
'item_id' => $itemId,
];
- 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 setUserValue2 uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if (strlen($value) > 0 || $empty) {
// insert/update value descriptor
$userValue = currentFromResultSetInterface($this->userValueTable->select($userValuePrimaryKey));
- 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 specPicture uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$order[] = 'pictures.id desc';
}
- 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 getAttributes uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if ($zone) {
$attributes = [];
if ($parent !== null) {
$ids = [];
- 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 calcEngineValue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$valueDataRows = $valueDataTable->select([
'attribute_id' => $attribute['id'],
'item_id' => $carRow['engine_item_id'],
'value IS NOT NULL',
- 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 calcEngineValue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return [
'empty' => true,
'value' => null,
];
- 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 setUserValue2 uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
// delete value descriptor
$affected = $this->userValueTable->delete($userValuePrimaryKey);
// remove value
$affected += $userValueDataTable->delete($userValuePrimaryKey);
- 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 getAttributes uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$attributes = $this->attributes;
}
- 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 valueToText uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return $this->getListOptionsText($attribute['id'], $value);
}
- 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 setActualValue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$params = [
'value' => $actualValue['value'],
'attribute_id' => $attribute['id'],
'item_id' => $itemId,
- 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 getUserValueText uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return $values[0];
}
- 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 loadAttributes uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$childs[$pid][] = $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
The method getAttributes uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if ($parent !== null) {
foreach ($this->childs[$parent] as $id) {
$attributes[] = $this->attributes[$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
The method setUserValue2 uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$valueChanged = true;
}
- 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 getAttributes uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if (isset($this->childs[$parent])) {
$ids = $this->childs[$parent];
}
}
- 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 getUserValueWeight uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->valueWeights[$userId] = 1;
}
- 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 loadListOptions uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->listOptionsChilds[$aid][$pid][] = $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
The method setUserValue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if (strlen($value) > 0) {
// insert/update value decsriptor
$userValue = currentFromResultSetInterface($this->userValueTable->select($userValuePrimaryKey));
- 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 setUserValue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$userValueDataTable->insert(array_merge($set, $userValuePrimaryKey));
}
- 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 setUserValue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
// delete value descriptor
$affected = $this->userValueTable->delete($userValuePrimaryKey);
// remove value
$affected += $userValueDataTable->delete($userValuePrimaryKey);
- 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 calcEngineValue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return [
'empty' => true,
'value' => null,
];
- 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 getAttributes uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$ids = $this->zoneAttrs[$zone];
}
- 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 calcAvgUserValue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$value = null;
foreach ($valueRows as $valueRow) {
$value = $valueRow['value'];
}
- 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 setUserValue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->userValueTable->update([
'update_date' => new Sql\Expression('NOW()'),
], $userValuePrimaryKey);
}
- 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 refreshConflictFlag uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$weight = self::WEIGHT_WRONG;
}
- 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 getActualValue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$row = currentFromResultSetInterface($valuesTable->selectWith($select));
if ($row) {
return $row['value'];
- 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 removeEmpty uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$id = $attribute['id'];
$haveValue = false;
foreach ($cars as $car) {
if (isset($car['values'][$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
The method getItemsActualValues uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$values[$id][$aid] = $value;
}
- 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 valueToText uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$text[] = $this->getListOptionsText($attribute['id'], $v);
}
- 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
TODO found Open
// TODO: multiple attr inheritance
- Exclude checks
syntax error, unexpected 'TableGateway' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
Open
private TableGateway $attributeTable;
- Exclude checks
Similar blocks of code found in 2 locations. Consider refactoring. Open
public function __construct(
TranslatorInterface $translator,
ItemNameFormatter $itemNameFormatter,
Item $itemModel,
ItemParent $itemParent,
- 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 356.
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
Similar blocks of code found in 3 locations. Consider refactoring. Open
public function getSpecsCount(int $itemId): int
{
$select = new Sql\Select($this->valueTable->getTable());
$select->columns(['count' => new Sql\Expression('count(1)')])
->where(['item_id' => $itemId]);
- 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 98.
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