Showing 100 of 100 total issues
Method crop
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private function crop(Imagick $imagick, int $width, int $height, int $left, int $top): Imagick
Method generateLockWrite
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private function generateLockWrite(string $dirName, array $options, int $width, int $height, Closure $callback): int
Method __construct
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
array $options,
TableGateway $imageTable,
TableGateway $formatedImageTable,
TableGateway $dirTable,
Processor\ProcessorPluginManager $processors
Function getImageResolution
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getImageResolution(int $imageId): ?array
{
$imageRow = $this->getImageRow($imageId);
if (! $imageRow) {
- 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
Remove error control operator '@' on line 1115. Open
public function extractEXIF(int $imageId): ?array
{
$imageRow = $this->getImageRow($imageId);
if (! $imageRow) {
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
The method standardDeviation has a boolean flag argument $sample, which is a certain sign of a Single Responsibility Principle violation. Open
private function standardDeviation(array $values, bool $sample = false): float
- 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
Function convertToFile
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function convertToFile($source, string $destFile, $format): void
{
if ($source instanceof Imagick) {
$imagick = clone $source; // to prevent modifying source
} else {
- 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 buildImageResult
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function buildImageResult($imageRow): Storage\Image
{
$dir = $this->getDir($imageRow['dir']);
if (! $dir) {
throw new Storage\Exception("Dir '{$imageRow['dir']}' not defined");
- 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 convertImagick uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if ($fWidth) {
$decomposited = $this->convertByWidth($decomposited, $format);
} elseif ($fHeight) {
$decomposited = $this->convertByHeight($decomposited, $format);
- 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 convertByMaximumFit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
// добавляем поля по бокам
$scaleWidth = (int) round($formatHeight * $srcRatio);
$scaleHeight = $formatHeight;
}
- 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 convertImagick uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$decomposited = $imagick;
}
- 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 scaleImage uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$imagick->scaleImage($width, $height, 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
The method convertToFile uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$imagick = new Imagick();
if (! $imagick->readImage($source)) {
throw new Sampler\Exception("Error read image from `$source`");
}
- 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 setImageCrop() has an NPath complexity of 960. The configured NPath complexity threshold is 200. Open
public function setImageCrop(int $imageId, ?array $crop): void
{
if (! $imageId) {
throw new Storage\Exception("Invalid image id provided `$imageId`");
}
- 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 crop uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$imagick->setImagePage(0, 0, 0, 0);
$imagick->cropImage($width, $height, $left, $top);
}
- 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 doFormatImage() has an NPath complexity of 3564. The configured NPath complexity threshold is 200. Open
private function doFormatImage(int $imageId, string $formatName): int
{
// find source image
/** @var ResultSet $resultSet */
$resultSet = $this->imageTable->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 incDirCounter uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->dirTable->insert([
'dir' => $dirName,
'count' => 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 convertByMaximumFit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
// высчитываем размеры обрезания
if ($ratio < $srcRatio) {
$scaleWidth = $formatWidth;
$scaleHeight = (int) round($formatWidth / $srcRatio);
- 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 class Storage has 1394 lines of code. Current threshold is 1000. Avoid really long classes. Open
class Storage implements StorageInterface
{
private const EXTENSION_DEFAULT = 'jpg';
private const INSERT_MAX_ATTEMPTS = 15;
- Exclude checks
The method convertByInnerFit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
// высокая картинка
$cropWidth = $srcWidth;
$cropHeight = (int) round($srcWidth / $ratio);
$cropLeft = 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
}
}
}