File Sampler.php
has 558 lines of code (exceeds 250 allowed). Consider refactoring.
<?php
declare(strict_types=1);
namespace Autowp\Image;
Function convertImagick
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
public function convertImagick(Imagick $imagick, ?array $crop, $format): Imagick
{
if (! $format instanceof Sampler\Format) {
if (! is_array($format)) {
throw new Sampler\Exception("Unexpected type of format");
Method convertImagick
has 84 lines of code (exceeds 25 allowed). Consider refactoring.
public function convertImagick(Imagick $imagick, ?array $crop, $format): Imagick
{
if (! $format instanceof Sampler\Format) {
if (! is_array($format)) {
throw new Sampler\Exception("Unexpected type of format");
The class Sampler has an overall complexity of 128 which is very high. The configured complexity threshold is 50.
class Sampler
{
* @throws ImagickException
*/
Function cropImage
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
private function cropImage(Imagick $imagick, array $crop, Sampler\Format $format): Imagick
{
$cropSet = isset($crop['width'], $crop['height'], $crop['left'], $crop['top']);
if (! $cropSet) {
throw new Sampler\Exception('Crop parameters not properly set');
Method cropImage
has 67 lines of code (exceeds 25 allowed). Consider refactoring.
private function cropImage(Imagick $imagick, array $crop, Sampler\Format $format): Imagick
{
$cropSet = isset($crop['width'], $crop['height'], $crop['left'], $crop['top']);
if (! $cropSet) {
throw new Sampler\Exception('Crop parameters not properly set');
Method extendHorizontal
has 50 lines of code (exceeds 25 allowed). Consider refactoring.
private function extendHorizontal(Imagick $imagick, Sampler\Format $format): void
{
$fRatio = (int) $format->getWidth() / (int) $format->getHeight();
$srcWidth = $imagick->getImageWidth();
Method extendVertical
has 50 lines of code (exceeds 25 allowed). Consider refactoring.
private function extendVertical(Imagick $imagick, Sampler\Format $format): void
{
$fRatio = (int) $format->getWidth() / (int) $format->getHeight();
$srcWidth = $imagick->getImageWidth();
Method convertByOuterFit
has 38 lines of code (exceeds 25 allowed). Consider refactoring.
private function convertByOuterFit(Imagick $imagick, Sampler\Format $format): Imagick
{
$srcWidth = $imagick->getImageWidth();
$srcHeight = $imagick->getImageHeight();
$srcRatio = $srcWidth / $srcHeight;
Function convertByInnerFit
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
private function convertByInnerFit(Imagick $imagick, Sampler\Format $format): Imagick
{
$srcWidth = $imagick->getImageWidth();
$srcHeight = $imagick->getImageHeight();
$srcRatio = $srcWidth / $srcHeight;
Method convertByInnerFit
has 35 lines of code (exceeds 25 allowed). Consider refactoring.
private function convertByInnerFit(Imagick $imagick, Sampler\Format $format): Imagick
{
$srcWidth = $imagick->getImageWidth();
$srcHeight = $imagick->getImageHeight();
$srcRatio = $srcWidth / $srcHeight;
Function convertByOuterFit
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
private function convertByOuterFit(Imagick $imagick, Sampler\Format $format): Imagick
{
$srcWidth = $imagick->getImageWidth();
$srcHeight = $imagick->getImageHeight();
$srcRatio = $srcWidth / $srcHeight;
Function extendHorizontal
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
private function extendHorizontal(Imagick $imagick, Sampler\Format $format): void
{
$fRatio = (int) $format->getWidth() / (int) $format->getHeight();
$srcWidth = $imagick->getImageWidth();
Function convertByMaximumFit
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
private function convertByMaximumFit(Imagick $imagick, Sampler\Format $format): Imagick
{
$srcWidth = $imagick->getImageWidth();
$srcHeight = $imagick->getImageHeight();
$srcRatio = $srcWidth / $srcHeight;
Function extendVertical
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
private function extendVertical(Imagick $imagick, Sampler\Format $format): void
{
$fRatio = (int) $format->getWidth() / (int) $format->getHeight();
$srcWidth = $imagick->getImageWidth();
Method convertByMaximumFit
has 30 lines of code (exceeds 25 allowed). Consider refactoring.
private function convertByMaximumFit(Imagick $imagick, Sampler\Format $format): Imagick
{
$srcWidth = $imagick->getImageWidth();
$srcHeight = $imagick->getImageHeight();
$srcRatio = $srcWidth / $srcHeight;
Method extendEdgeColor
has 29 lines of code (exceeds 25 allowed). Consider refactoring.
private function extendEdgeColor(ImagickPixelIterator $iterator): ?ImagickPixel
{
$sum = [
'r' => [],
'g' => [],
Method crop
has 5 arguments (exceeds 4 allowed). Consider refactoring.
private function crop(Imagick $imagick, int $width, int $height, int $left, int $top): Imagick
Function convertToFile
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
public function convertToFile($source, string $destFile, $format): void
{
if ($source instanceof Imagick) {
$imagick = clone $source;
} else {
The method convertImagick() has an NPath complexity of 110592. The configured NPath complexity threshold is 200.
public function convertImagick(Imagick $imagick, ?array $crop, $format): Imagick
{
if (! $format instanceof Sampler\Format) {
if (! is_array($format)) {
throw new Sampler\Exception("Unexpected type of format");
The method convertImagick() has 107 lines of code. Current threshold is set to 100. Avoid really long methods.
public function convertImagick(Imagick $imagick, ?array $crop, $format): Imagick
{
if (! $format instanceof Sampler\Format) {
if (! is_array($format)) {
throw new Sampler\Exception("Unexpected type of format");
The method cropImage() has an NPath complexity of 1056. The configured NPath complexity threshold is 200.
private function cropImage(Imagick $imagick, array $crop, Sampler\Format $format): Imagick
{
$cropSet = isset($crop['width'], $crop['height'], $crop['left'], $crop['top']);
if (! $cropSet) {
throw new Sampler\Exception('Crop parameters not properly set');
The method cropImage() has a Cyclomatic Complexity of 20. The configured cyclomatic complexity threshold is 10.
private function cropImage(Imagick $imagick, array $crop, Sampler\Format $format): Imagick
{
$cropSet = isset($crop['width'], $crop['height'], $crop['left'], $crop['top']);
if (! $cropSet) {
throw new Sampler\Exception('Crop parameters not properly set');
The method convertImagick() has a Cyclomatic Complexity of 25. The configured cyclomatic complexity threshold is 10.
public function convertImagick(Imagick $imagick, ?array $crop, $format): Imagick
{
if (! $format instanceof Sampler\Format) {
if (! is_array($format)) {
throw new Sampler\Exception("Unexpected type of format");
The method standardDeviation has a boolean flag argument $sample, which is a certain sign of a Single Responsibility Principle violation.
private function standardDeviation(array $values, bool $sample = false): float
The method scaleImage uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
$imagick->scaleImage($width, $height, false);
}
The method convertByHeight uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
$scaleHeight = (int) $format->getHeight();
}
The method convertByInnerFit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
$cropWidth = $srcWidth;
$cropHeight = (int) round($srcWidth / $ratio);
$cropLeft = 0;
The method cropImage uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
$targetWidth = (int) round($cropHeight * $fRatio);
if ($targetWidth > $width) {
$targetWidth = $width;
The method convertImagick uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
$decomposited = $imagick;
}
The method convertByOuterFit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
$scaleWidth = (int) round($formatHeight * $srcRatio);
$scaleHeight = $formatHeight;
}
The method convertImagick uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
if ($fWidth) {
$decomposited = $this->convertByWidth($decomposited, $format);
} elseif ($fHeight) {
$decomposited = $this->convertByHeight($decomposited, $format);
The method convertImagick uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
$imagick = $decomposited;
}
The method convertToFile uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
$imagick = new Imagick();
if (! $imagick->readImage($source)) {
throw new Sampler\Exception("Error read image from `$source`");
}
The method convertByInnerFit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
if ($ratio < $srcRatio) {
$cropWidth = (int) round($srcHeight * $ratio);
The method convertImagick uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
$this->extendHorizontal($decomposited, $format);
}
The method convertByMaximumFit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
$scaleWidth = (int) round($formatHeight * $srcRatio);
$scaleHeight = $formatHeight;
}
The method convertByOuterFit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
if ($ratio < $srcRatio) {
$scaleWidth = $formatWidth;
$scaleHeight = (int) round($formatWidth / $srcRatio);
The method convertByWidth uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
$scaleWidth = (int) $format->getWidth();
}
The method crop uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
$imagick->setImagePage(0, 0, 0, 0);
$imagick->cropImage($width, $height, $left, $top);
}
The method convertByMaximumFit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
if ($ratio < $srcRatio) {
$scaleWidth = $formatWidth;
$scaleHeight = (int) round($formatWidth / $srcRatio);
Identical blocks of code found in 2 locations. Consider refactoring.
if ($format->isReduceOnly() && $sizeLess) {
if (! $heightLess) {
$scaleHeight = $formatHeight;
Identical blocks of code found in 2 locations. Consider refactoring.
if ($format->isReduceOnly() && $sizeLess) {
if (! $heightLess) {
$scaleHeight = $formatHeight;
$scaleWidth = (int) round($scaleHeight * $srcRatio);
There are no issues that match your filters.