Showing 211 of 211 total issues
File Parser.php
has 439 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* This file is part of the LongitudeOne WKB-Parser project.
*
Parser
has 30 functions (exceeds 20 allowed). Consider refactoring. Open
class Parser
{
public const TYPE_CIRCULARSTRING = 'CircularString';
public const TYPE_COMPOUNDCURVE = 'CompoundCurve';
public const TYPE_CURVEPOLYGON = 'CurvePolygon';
The class Parser has an overall complexity of 68 which is very high. The configured complexity threshold is 50. Open
class Parser
{
public const TYPE_CIRCULARSTRING = 'CircularString';
public const TYPE_COMPOUNDCURVE = 'CompoundCurve';
public const TYPE_CURVEPOLYGON = 'CurvePolygon';
- Exclude checks
Method readGeometry
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function readGeometry(): array
{
$srid = null;
try {
Method geometryCollection
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function geometryCollection(): array
{
$values = [];
$count = $this->readCount();
Similar blocks of code found in 2 locations. Consider refactoring. Open
for ($i = 0; $i < $count; ++$i) {
$this->readByteOrder();
$type = $this->readType();
- 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 102.
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
for ($i = 0; $i < $count; ++$i) {
$this->readByteOrder();
$type = $this->readType();
- 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 102.
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
A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 16 and the first side effect is on line 14. Open
<?php
- Exclude checks
A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 75 and the first side effect is on line 21. Open
<?php
- Exclude checks
Possible parse error: class missing opening or closing brace Open
class Parser
- Exclude checks
Possible parse error: class missing opening or closing brace Open
class Parser
- Exclude checks
Function getBadTypeInTypeMessage
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function getBadTypeInTypeMessage(int $childType, int $parentType, array $expectedTypes)
{
if ($this->type !== $parentType) {
$parentType = $this->type;
}
- 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 getBadTypeInTypeMessage uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$message = 'Bad'.$message;
}
- 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 getBadTypeInTypeMessage uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$last = $this->getTypeName(array_pop($expectedTypes));
$message .= implode(', ', array_map([$this, 'getTypeName'], $expectedTypes)).' or '.$last;
}
- 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 private methods such as 'onWarning'. Open
private function onWarning(int $errorNumber, string $errorMessage): void
{
throw $this->getInvalidArgumentException($errorNumber, $errorMessage);
}
- Read upRead up
- Exclude checks
UnusedPrivateMethod
Since: 0.2
Unused Private Method detects when a private method is declared but is unused.
Example
class Something
{
private function foo() {} // unused
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod
Line exceeds 120 characters; contains 213 characters Open
throw new UnexpectedValueException($this->getBadTypeInTypeMessage($type, self::WKB_TYPE_CURVEPOLYGON, [self::WKB_TYPE_LINESTRING, self::WKB_TYPE_CIRCULARSTRING, self::WKB_TYPE_COMPOUNDCURVE]));
- Exclude checks
Line exceeds 120 characters; contains 149 characters Open
* This value can be point|line-string|multiPoint|polygon|multiLineString|multiPolygon|compoundCurve||multiCurve|multiSurface| polyhedralSurface,
- Exclude checks
Line exceeds 120 characters; contains 191 characters Open
default => throw new UnexpectedValueException($this->getBadTypeInTypeMessage($type, self::WKB_TYPE_COMPOUNDCURVE, [self::WKB_TYPE_LINESTRING, self::WKB_TYPE_CIRCULARSTRING])),
- Exclude checks
Line exceeds 120 characters; contains 919 characters Open
* @return array{type:string, srid: ?int, value: (float|int)[]|(float|int)[][]|(float|int)[][][]|(float|int)[][][][]|(float|int)[][][][][]|array{type: string, value:(float|int)[][]}[]|array{type: string, value:(float|int)[][]|array{type: string, value:(float|int)[][]}[]}[]|array{type: string, value:(float|int)[][][]|array{type: string, value:(float|int)[][]|array{type: string, value:(float|int)[][]}[]}[]}[]|array{type: string, value:(float|int)[][][]}[]|array{type:string, value:(float|int)[]|(float|int)[][]|(float|int)[][][]|(float|int)[][][][]|(float|int)[][][][][]|array{type: string, value:(float|int)[][]}[]|array{type: string, value:(float|int)[][]|array{type: string, value:(float|int)[][]}[]}[]|array{type: string, value:(float|int)[][][]|array{type: string, value:(float|int)[][]|array{type: string, value:(float|int)[][]}[]}[]}[]|array{type: string, value:(float|int)[][][]}[]}[], dimension: ?string}
- Exclude checks
Line exceeds 120 characters; contains 151 characters Open
throw new UnexpectedValueException($this->getBadTypeInTypeMessage($type, self::WKB_TYPE_MULTILINESTRING, [self::WKB_TYPE_LINESTRING]));
- Exclude checks