Showing 97 of 102 total issues
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return self::TYPE_VARCHAR;
Avoid too many return
statements within this method. Open
return self::TYPE_NUMBER;
Avoid too many return
statements within this method. Open
return !($firstMustBeBigger && isset($parts[1]) && (int) $parts[1] > (int) $parts[0]);
Avoid too many return
statements within this method. Open
return self::TYPE_NVARCHAR;
Avoid too many return
statements within this method. Open
return self::TYPE_DECIMAL;
The method validateNumericLength has a boolean flag argument $firstMustBeBigger, which is a certain sign of a Single Responsibility Principle violation. Open
bool $firstMustBeBigger = true
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Avoid too many return
statements within this method. Open
return self::TYPE_TIMESTAMP;
Function getBasetype
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getBasetype(): string
{
$type = strtolower($this->type);
$baseType = BaseType::STRING;
if (in_array($type, self::DATE_TYPES)) {
- 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 validateLength() has an NPath complexity of 1002. The configured NPath complexity threshold is 200. Open
private function validateLength(string $type, $length = null): void
{
$valid = true;
switch (strtoupper($type)) {
case self::TYPE_NUMBER:
- 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
Avoid unused parameters such as '$basetype'. Open
public static function getTypeByBasetype(string $basetype): string
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
The method validateLength() has an NPath complexity of 986. The configured NPath complexity threshold is 200. Open
private function validateLength(string $type, $length = null): void
{
$valid = true;
switch (strtoupper($type)) {
case 'DECIMAL':
- 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 getSQLDefinition uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$length = $this->getDefaultLength();
if ($length !== null) {
$definition .= sprintf('(%s)', $length);
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid unused parameters such as '$basetype'. Open
public static function getTypeByBasetype(string $basetype): string
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
The method validateNumericLength() has an NPath complexity of 432. The configured NPath complexity threshold is 200. Open
protected function validateNumericLength(
$length,
int $firstMax,
int $secondMax,
bool $firstMustBeBigger = true
- 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
Avoid unused parameters such as '$basetype'. Open
public static function getTypeByBasetype(string $basetype): string
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid using static access to class 'Keboola\Datatype\Definition\BaseType' in method 'getTypeByBasetype'. Open
if (!BaseType::isValid($basetype)) {
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'Keboola\Datatype\Definition\BaseType' in method 'getTypeByBasetype'. Open
if (!BaseType::isValid($basetype)) {
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method validateLength uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$valid = false;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid unused parameters such as '$basetype'. Open
public static function getTypeByBasetype(string $basetype): string
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}