src/ELearn/Part.php

Summary

Maintainability
A
3 hrs
Test Coverage

Method init has 91 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    function init()
    {
        $this->_a['table'] = 'elearn_part';
        $this->_a['verbose'] = 'ELearn_Part';
        $this->_a['cols'] = array(
Severity: Major
Found in src/ELearn/Part.php - About 3 hrs to fix

    The method init() has 111 lines of code. Current threshold is set to 100. Avoid really long methods.
    Open

        function init()
        {
            $this->_a['table'] = 'elearn_part';
            $this->_a['verbose'] = 'ELearn_Part';
            $this->_a['cols'] = array(
    Severity: Minor
    Found in src/ELearn/Part.php by phpmd

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

        function postSave($create = false)
    Severity: Minor
    Found in src/ELearn/Part.php by phpmd

    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

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

        function preSave($create = false)
    Severity: Minor
    Found in src/ELearn/Part.php by phpmd

    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

    Avoid using static access to class 'Pluf_FileUtil' in method 'preSave'.
    Open

            $fileInfo = Pluf_FileUtil::getMimeType($this->file_name);
    Severity: Minor
    Found in src/ELearn/Part.php by phpmd

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

            } else {
                $this->file_size = 0;
            }
    Severity: Minor
    Found in src/ELearn/Part.php by phpmd

    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

    Define a constant instead of duplicating this literal "readable" 8 times.
    Open

                    'readable' => true
    Severity: Critical
    Found in src/ELearn/Part.php by sonar-php

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Define a constant instead of duplicating this literal "Pluf_DB_Field_Varchar" 5 times.
    Open

                    'type' => 'Pluf_DB_Field_Varchar',
    Severity: Critical
    Found in src/ELearn/Part.php by sonar-php

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Define a constant instead of duplicating this literal "editable" 12 times.
    Open

                    'editable' => false,
    Severity: Critical
    Found in src/ELearn/Part.php by sonar-php

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Define a constant instead of duplicating this literal "blank" 10 times.
    Open

                    'blank' => false,
    Severity: Critical
    Found in src/ELearn/Part.php by sonar-php

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Avoid unused parameters such as '$create'.
    Open

        function postSave($create = false)
    Severity: Minor
    Found in src/ELearn/Part.php by phpmd

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    Avoid unused parameters such as '$create'.
    Open

        function preSave($create = false)
    Severity: Minor
    Found in src/ELearn/Part.php by phpmd

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    Reference to undeclared property \ELearn_Part->id
    Open

            return $this->file_path . '/' . $this->id;
    Severity: Minor
    Found in src/ELearn/Part.php by phan

    Reference to undeclared property \ELearn_Part->modif_dtime
    Open

            $this->modif_dtime = gmdate('Y-m-d H:i:s');
    Severity: Minor
    Found in src/ELearn/Part.php by phan

    Reference to undeclared property \ELearn_Part->file_name
    Open

            $fileInfo = Pluf_FileUtil::getMimeType($this->file_name);
    Severity: Minor
    Found in src/ELearn/Part.php by phan

    Reference to undeclared property \ELearn_Part->_a
    Open

            $this->_a['verbose'] = 'ELearn_Part';
    Severity: Minor
    Found in src/ELearn/Part.php by phan

    Reference to undeclared property \ELearn_Part->id
    Open

            unlink($this->file_path . '/' . $this->id);
    Severity: Minor
    Found in src/ELearn/Part.php by phan

    Reference to undeclared property \ELearn_Part->_a
    Open

            $this->_a['cols'] = array(
    Severity: Minor
    Found in src/ELearn/Part.php by phan

    Reference to undeclared property \ELearn_Part->file_path
    Open

            unlink($this->file_path . '/' . $this->id);
    Severity: Minor
    Found in src/ELearn/Part.php by phan

    Reference to undeclared property \ELearn_Part->_a
    Open

            $this->_a['table'] = 'elearn_part';
    Severity: Minor
    Found in src/ELearn/Part.php by phan

    Class extends undeclared class \Pluf_Model
    Open

    class ELearn_Part extends Pluf_Model
    Severity: Critical
    Found in src/ELearn/Part.php by phan

    Reference to undeclared property \ELearn_Part->file_path
    Open

            return $this->file_path . '/' . $this->id;
    Severity: Minor
    Found in src/ELearn/Part.php by phan

    Reference to undeclared property \ELearn_Part->creation_dtime
    Open

                $this->creation_dtime = gmdate('Y-m-d H:i:s');
    Severity: Minor
    Found in src/ELearn/Part.php by phan

    Reference to undeclared property \ELearn_Part->file_size
    Open

                $this->file_size = filesize($path);
    Severity: Minor
    Found in src/ELearn/Part.php by phan

    Reference to undeclared property \ELearn_Part->mime_type
    Open

            $this->mime_type = $fileInfo[0];
    Severity: Minor
    Found in src/ELearn/Part.php by phan

    Reference to undeclared property \ELearn_Part->_a
    Open

            $this->_a['idx'] = array(
    Severity: Minor
    Found in src/ELearn/Part.php by phan

    Reference to undeclared property \ELearn_Part->id
    Open

            if ($this->id == '') {
    Severity: Minor
    Found in src/ELearn/Part.php by phan

    Call to method getMimeType from undeclared class \Pluf_FileUtil
    Open

            $fileInfo = Pluf_FileUtil::getMimeType($this->file_name);
    Severity: Critical
    Found in src/ELearn/Part.php by phan

    Reference to undeclared property \ELearn_Part->file_size
    Open

                $this->file_size = 0;
    Severity: Minor
    Found in src/ELearn/Part.php by phan

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

    class ELearn_Part extends Pluf_Model
    Severity: Minor
    Found in src/ELearn/Part.php by phpcodesniffer

    The class ELearn_Part is not named in CamelCase.
    Open

    class ELearn_Part extends Pluf_Model
    {
    
        /**
         * @brief مدل داده‌ای را بارگذاری می‌کند.
    Severity: Minor
    Found in src/ELearn/Part.php by phpmd

    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 "preDelete"
    Open

        function preDelete()
    Severity: Minor
    Found in src/ELearn/Part.php by phpcodesniffer

    Visibility must be declared on method "postSave"
    Open

        function postSave($create = false)
    Severity: Minor
    Found in src/ELearn/Part.php by phpcodesniffer

    Visibility must be declared on method "preSave"
    Open

        function preSave($create = false)
    Severity: Minor
    Found in src/ELearn/Part.php by phpcodesniffer

    Expected "function abc(...)"; found "function abc (...)"
    Open

        public function getAbsloutPath ()
    Severity: Minor
    Found in src/ELearn/Part.php by phpcodesniffer

    Visibility must be declared on method "init"
    Open

        function init()
    Severity: Minor
    Found in src/ELearn/Part.php by phpcodesniffer

    Expected 0 spaces before opening parenthesis; 1 found
    Open

        public function getAbsloutPath ()
    Severity: Minor
    Found in src/ELearn/Part.php by phpcodesniffer

    Line exceeds 120 characters; contains 128 characters
    Open

         * در این متد فایل مربوط به است حذف می شود. این عملیات قابل بازگشت نیست
    Severity: Minor
    Found in src/ELearn/Part.php by phpcodesniffer

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

    class ELearn_Part extends Pluf_Model
    Severity: Minor
    Found in src/ELearn/Part.php by phpcodesniffer

    There are no issues that match your filters.

    Category
    Status