Showing 20 of 20 total issues
OptionsOption
has 51 functions (exceeds 20 allowed). Consider refactoring. Open
final class OptionsOption extends ChildOptionAbstract {
const ALLOWED_PAGING_TYPES = [
'numbers',
'simple',
Column
has 30 functions (exceeds 20 allowed). Consider refactoring. Open
final class Column {
const TYPE_DATE = 'date';
const TYPE_NUM = 'num';
const TYPE_NUM_FMT = 'num-fmt';
File OptionsOption.php
has 319 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Copyright (c) Allan Carvalho 2020.
* Under Mit License
* php version 7.2
FeaturesOption
has 24 functions (exceeds 20 allowed). Consider refactoring. Open
final class FeaturesOption extends ChildOptionAbstract {
/**
* @var array
* @inheritDoc
Function setSearchCols
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function setSearchCols(array $searchCols): MainOption {
Validator::getInstance()->checkKeysValueTypesOrFail($searchCols, ['integer'], ['array', 'NULL'], '$searchCols');
foreach ($searchCols as $searchCol) {
if ($searchCol !== null) {
foreach ($searchCol as $key => $item) {
- 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 isInCurrentUrl
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function isInCurrentUrl(array $url = []): bool {
$currentController = Router::getRequest()->getParam('controller');
$currentAction = Router::getRequest()->getParam('action');
$currentQuery = Router::getRequest()->getQuery();
$currentPrefix = Router::getRequest()->getParam('prefix');
- 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 checkKeysValueTypesOrFail
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function checkKeysValueTypesOrFail(?array $array, $allowedKeyTypes = [], $allowedValueTypes = [], string $inString = null): void {
if (empty($array)) {
return;
}
$allowedKeyTypesType = getType($allowedKeyTypes);
- 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 normalizeDataTableField
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private function normalizeDataTableField(string $dataBaseField, ?string $title): Column {
$ormTable = $this->_tables->getOrmTable();
$explodedDataBaseField = explode('.', $dataBaseField);
if (count($explodedDataBaseField) === 2) {
$table = Inflector::camelize($explodedDataBaseField[0]);
- 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 isInCurrentUrl
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function isInCurrentUrl(array $url = []): bool {
$currentController = Router::getRequest()->getParam('controller');
$currentAction = Router::getRequest()->getParam('action');
$currentQuery = Router::getRequest()->getQuery();
$currentPrefix = Router::getRequest()->getParam('prefix');
Method normalizeDataTableField
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function normalizeDataTableField(string $dataBaseField, ?string $title): Column {
$ormTable = $this->_tables->getOrmTable();
$explodedDataBaseField = explode('.', $dataBaseField);
if (count($explodedDataBaseField) === 2) {
$table = Inflector::camelize($explodedDataBaseField[0]);
Method checkKeysValueTypesOrFail
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function checkKeysValueTypesOrFail(?array $array, $allowedKeyTypes = [], $allowedValueTypes = [], string $inString = null): void {
if (empty($array)) {
return;
}
$allowedKeyTypesType = getType($allowedKeyTypes);
Similar blocks of code found in 2 locations. Consider refactoring. Open
public function setType(?string $type): self {
$validTypesString = str_replace(' and ', ' or ', Text::toList(static::VALID_TYPES));
if (!in_array($type, static::VALID_TYPES) && !empty($type)) {
throw new InvalidArgumentException("Type must be $validTypesString. Found: '$type'.");
}
- 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 99.
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 2 locations. Consider refactoring. Open
public function setOrderDataType(?string $orderDataType): self {
$validOrderDataTypeString = str_replace(' and ', ' or ', Text::toList(static::VALID_ORDER_DATA_TYPES));
if (!in_array($orderDataType, static::VALID_ORDER_DATA_TYPES) && !empty($orderDataType)) {
throw new InvalidArgumentException("In \$orderDataType you can use only $validOrderDataTypeString. Found: '$orderDataType'.");
}
- 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 99.
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
Function setDefault
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function setDefault(Column $column): void {
$ignoredMethods = ['setDefault', 'setTitle', 'setDatabase', 'setName'];
$methods = get_class_methods($this);
foreach ($methods as $method) {
if (substr($method, 0, 3) === 'set' && !in_array($method, $ignoredMethods)) {
- 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 getUrlMd5
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private function getUrlMd5(string $controller, string $action, array $query = [], ?string $prefix = null, array $pass = []): string {
Function setRenderer
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function setRenderer($renderer): MainOption {
$rendererType = getType($renderer);
if (!in_array($rendererType, ['string', 'array'])) {
throw new InvalidArgumentException("\$renderer must be a string or array. Found: $rendererType.");
}
- 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 setOrderFixed
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function setOrderFixed(array $orderFixed): MainOption {
if (getType(Functions::getInstance()->arrayKeyFirst($orderFixed)) === 'string') {
foreach ($orderFixed as $key => $objectItem) {
if (!in_array($key, ['pre', 'post'])) {
throw new InvalidArgumentException("You must use only 'pre' or 'post' key for objects type. Found: $key.");
- 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 setOrder
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function setOrder(array $order): MainOption {
Validator::getInstance()->checkKeysValueTypesOrFail($order, 'integer', 'array', '$order');
foreach ($order as $item) {
Validator::getInstance()->checkArraySizeOrFail($item, 2, 'In setOrder($order) you must pass the index and order (asc or desc). Eg.: [0, \'asc\'].');
Validator::getInstance()->checkKeysValueTypesOrFail($item, 'integer', ['integer', 'string'], '$order');
- 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 getConfigBundle
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getConfigBundle(string $tableAndConfig, bool $cache = true): ConfigBundle {
$exploded = explode('::', $tableAndConfig);
if (count($exploded) !== 2) {
throw new InvalidArgumentException('Table param must be a concatenation of Tables class and config. Eg.: Foo::method.');
}
- 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 checkOrderDefault
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function checkOrderDefault(array $orderFixed) {
Validator::getInstance()->checkKeysValueTypesOrFail($orderFixed, ['integer', 'string'], 'array', '$orderFixed');
foreach ($orderFixed as $item) {
Validator::getInstance()->checkArraySizeOrFail($item, 2, "In \$orderFixed you must pass the index and after the order (asc or desc). Eg.: [0, 'asc'].");
$param1 = $item[Functions::getInstance()->arrayKeyFirst($item)];
- 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"