mambax7/extgallery

View on GitHub
class/pear/Image/Transform/Driver/Imagick3.php

Summary

Maintainability
A
1 hr
Test Coverage

The class Image_Transform_Driver_Imagick3 has 15 public methods. Consider refactoring Image_Transform_Driver_Imagick3 to keep number of public methods under 10.
Open

class Image_Transform_Driver_Imagick3 extends Image_Transform
{
    /**
     * Instance of imagick
     * @var Imagick

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

Function save has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function save($filename, $type = '', $quality = null)
    {
        $options = is_array($quality) ? $quality : [];
        if (is_numeric($quality)) {
            $options['quality'] = $quality;
Severity: Minor
Found in class/pear/Image/Transform/Driver/Imagick3.php - About 35 mins to fix

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 display has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function display($type = '', $quality = null)
    {
        $options = is_array($quality) ? $quality : [];
        if (is_numeric($quality)) {
            $options['quality'] = $quality;
Severity: Minor
Found in class/pear/Image/Transform/Driver/Imagick3.php - About 25 mins to fix

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 addText has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function addText($params)
    {
        $this->oldImage = clone $this->imagick;
        $params         = array_merge($this->_get_default_text_params(), $params);

Severity: Minor
Found in class/pear/Image/Transform/Driver/Imagick3.php - About 25 mins to fix

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

Missing class import via use statement (line '89', column '30').
Open

        $this->imagick = new Imagick();

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Missing class import via use statement (line '160', column '22').
Open

        $pixel = new ImagickPixel($color);

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Avoid using static access to class 'PEAR' in method '__construct'.
Open

            $this->isError(PEAR::raiseError('Could not find the imagick extension.', IMAGE_TRANSFORM_ERROR_UNSUPPORTED));

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 'PEAR' in method 'load'.
Open

        if (PEAR::isError($result)) {

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 __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $this->isError(PEAR::raiseError('Could not find the imagick extension.', IMAGE_TRANSFORM_ERROR_UNSUPPORTED));
        }

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 using static access to class 'PEAR' in method '__construct'.
Open

        if (PEAR::loadExtension('imagick')) {

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 'PEAR' in method 'raiseError'.
Open

        return PEAR::raiseError($message, $code);

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 addText uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $params['color'] = mb_strtolower($params['color']);
        }

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 using static access to class 'PEAR' in method 'crop'.
Open

            return PEAR::raiseError('Nothing to crop', IMAGE_TRANSFORM_ERROR_OUTOFBOUND);

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

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class Image_Transform_Driver_Imagick3 extends Image_Transform

The class Image_Transform_Driver_Imagick3 is not named in CamelCase.
Open

class Image_Transform_Driver_Imagick3 extends Image_Transform
{
    /**
     * Instance of imagick
     * @var Imagick

CamelCaseClassName

Since: 0.2

It is considered best practice to use the CamelCase notation to name classes.

Example

class class_name {
}

Source

The parameter $new_x is not named in camelCase.
Open

    public function _resize($new_x, $new_y, $options = null)
    {
        try {
            $scaleMethod = $this->_getOption('scaleMethod', $options, 'smooth');
            $blur        = ('pixel' == $scaleMethod) ? 0 : 1;

CamelCaseParameterName

Since: 0.2

It is considered best practice to use the camelCase notation to name parameters.

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

The parameter $new_y is not named in camelCase.
Open

    public function _resize($new_x, $new_y, $options = null)
    {
        try {
            $scaleMethod = $this->_getOption('scaleMethod', $options, 'smooth');
            $blur        = ('pixel' == $scaleMethod) ? 0 : 1;

CamelCaseParameterName

Since: 0.2

It is considered best practice to use the camelCase notation to name parameters.

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

Avoid variables with short names like $x. Configured minimum length is 3.
Open

    public function crop($width, $height, $x = 0, $y = 0)

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

Avoid variables with short names like $y. Configured minimum length is 3.
Open

    public function crop($width, $height, $x = 0, $y = 0)

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

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 44 and the first side effect is on line 24.
Open

<?php

Method name "_resize" should not be prefixed with an underscore to indicate visibility
Open

    public function _resize($new_x, $new_y, $options = null)

Method name "Image_Transform_Driver_Imagick3::Image_Transform_Driver_Imagick3" is not in camel caps format
Open

    public function Image_Transform_Driver_Imagick3()

Line exceeds 120 characters; contains 142 characters
Open

            return $this->raiseError('Cannot create a new imagick image for the rotation: ' . $e->getMessage(), IMAGE_TRANSFORM_ERROR_FAILED);

Line exceeds 120 characters; contains 124 characters
Open

                return $this->raiseError('Could not save image to file (conversion failed).', IMAGE_TRANSFORM_ERROR_FAILED);

Line exceeds 120 characters; contains 121 characters
Open

                return $this->raiseError("Problem with adding Text::{$v} = {$params[$v]}", IMAGE_TRANSFORM_ERROR_FAILED);

Line exceeds 120 characters; contains 124 characters
Open

                return $this->raiseError('Could not save image to file (conversion failed).', IMAGE_TRANSFORM_ERROR_FAILED);

Line exceeds 120 characters; contains 121 characters
Open

            $this->isError(PEAR::raiseError('Could not find the imagick extension.', IMAGE_TRANSFORM_ERROR_UNSUPPORTED));

Class name "Image_Transform_Driver_Imagick3" is not in camel caps format
Open

class Image_Transform_Driver_Imagick3 extends Image_Transform

The variable $new_x is not named in camelCase.
Open

    public function _resize($new_x, $new_y, $options = null)
    {
        try {
            $scaleMethod = $this->_getOption('scaleMethod', $options, 'smooth');
            $blur        = ('pixel' == $scaleMethod) ? 0 : 1;

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $new_y is not named in camelCase.
Open

    public function _resize($new_x, $new_y, $options = null)
    {
        try {
            $scaleMethod = $this->_getOption('scaleMethod', $options, 'smooth');
            $blur        = ('pixel' == $scaleMethod) ? 0 : 1;

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $new_x is not named in camelCase.
Open

    public function _resize($new_x, $new_y, $options = null)
    {
        try {
            $scaleMethod = $this->_getOption('scaleMethod', $options, 'smooth');
            $blur        = ('pixel' == $scaleMethod) ? 0 : 1;

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $new_y is not named in camelCase.
Open

    public function _resize($new_x, $new_y, $options = null)
    {
        try {
            $scaleMethod = $this->_getOption('scaleMethod', $options, 'smooth');
            $blur        = ('pixel' == $scaleMethod) ? 0 : 1;

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The method Image_Transform_Driver_Imagick3 is not named in camelCase.
Open

    public function Image_Transform_Driver_Imagick3()
    {
        $this->__construct();
    }

CamelCaseMethodName

Since: 0.2

It is considered best practice to use the camelCase notation to name methods.

Example

class ClassName {
    public function get_name() {
    }
}

Source

The method _resize is not named in camelCase.
Open

    public function _resize($new_x, $new_y, $options = null)
    {
        try {
            $scaleMethod = $this->_getOption('scaleMethod', $options, 'smooth');
            $blur        = ('pixel' == $scaleMethod) ? 0 : 1;

CamelCaseMethodName

Since: 0.2

It is considered best practice to use the camelCase notation to name methods.

Example

class ClassName {
    public function get_name() {
    }
}

Source

There are no issues that match your filters.

Category
Status