src/Shop/Form/OrderAttachmentUpdate.php

Summary

Maintainability
A
45 mins
Test Coverage

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

    function save($commit = true)
    {
        $model = parent::save(false);
        // update the content
        if (array_key_exists('file', $this->cleaned_data)) {
Severity: Minor
Found in src/Shop/Form/OrderAttachmentUpdate.php - About 45 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

The method save has a boolean flag argument $commit, which is a certain sign of a Single Responsibility Principle violation.
Open

    function save($commit = true)

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

Missing class import via use statement (line '34', column '37').
Open

        $this->fields['file'] = new Pluf_Form_Field_File(array(

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 'Pluf_FileUtil' in method 'save'.
Open

            $mimeType = Pluf_FileUtil::getMimeType($model->file_name);

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 'Pluf' in method 'initFields'.
Open

            'max_size' => Pluf::f('upload_max_size', 2097152),

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 Shop_Form_OrderAttachmentUpdate extends Pluf_Form_Model

The class Shop_Form_OrderAttachmentUpdate is not named in CamelCase.
Open

class Shop_Form_OrderAttachmentUpdate extends Pluf_Form_Model
{

    public function initFields($extra = array())
    {

CamelCaseClassName

Since: 0.2

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

Example

class class_name {
}

Source

Visibility must be declared on method "save"
Open

    function save($commit = true)

Expected 1 space after closing parenthesis; found 0
Open

            if(is_array($mimeType)){

Whitespace found at end of line
Open

 *        

Expected 1 space after closing parenthesis; found 0
Open

            if(!array_key_exists('mime_type', $this->data)){

Expected 1 space after IF keyword; 0 found
Open

            if(!array_key_exists('media_type', $this->data)){

Expected 1 space after closing parenthesis; found 0
Open

            if(!array_key_exists('media_type', $this->data)){

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

class Shop_Form_OrderAttachmentUpdate extends Pluf_Form_Model

Expected 1 space after IF keyword; 0 found
Open

            if(is_array($mimeType)){

Expected 1 space after IF keyword; 0 found
Open

            if(!array_key_exists('mime_type', $this->data)){

There are no issues that match your filters.

Category
Status