cosmocode/dokuwiki-plugin-issuelinks

View on GitHub
helper/data.php

Summary

Maintainability
A
3 hrs
Test Coverage

importAllIssues accesses the super-global variable $_SERVER.
Open

    public function importAllIssues($serviceName, $projectKey)
    {
        $lockfileKey = $this->getImportLockID($serviceName, $projectKey);
        if ($this->isImportLocked($lockfileKey)) {
            throw new RuntimeException('Import of Issues is already locked!');
Severity: Minor
Found in helper/data.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

importAllIssues accesses the super-global variable $_SERVER.
Open

    public function importAllIssues($serviceName, $projectKey)
    {
        $lockfileKey = $this->getImportLockID($serviceName, $projectKey);
        if ($this->isImportLocked($lockfileKey)) {
            throw new RuntimeException('Import of Issues is already locked!');
Severity: Minor
Found in helper/data.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

Method importAllIssues has 51 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function importAllIssues($serviceName, $projectKey)
    {
        $lockfileKey = $this->getImportLockID($serviceName, $projectKey);
        if ($this->isImportLocked($lockfileKey)) {
            throw new RuntimeException('Import of Issues is already locked!');
Severity: Major
Found in helper/data.php - About 2 hrs to fix

    Function importAllIssues has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        public function importAllIssues($serviceName, $projectKey)
        {
            $lockfileKey = $this->getImportLockID($serviceName, $projectKey);
            if ($this->isImportLocked($lockfileKey)) {
                throw new RuntimeException('Import of Issues is already locked!');
    Severity: Minor
    Found in helper/data.php - About 1 hr 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

    Reduce the number of returns of this function 4, down to the maximum allowed 3.
    Open

        public function isImportLocked($id)
    Severity: Major
    Found in helper/data.php by sonar-php

    Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

    Noncompliant Code Example

    With the default threshold of 3:

    function myFunction(){ // Noncompliant as there are 4 return statements
      if (condition1) {
        return true;
      } else {
        if (condition2) {
          return false;
        } else {
          return true;
        }
      }
      return false;
    }
    

    Missing class import via use statement (line '39', column '23').
    Open

                throw new RuntimeException('Import of Issues is already locked!');
    Severity: Minor
    Found in helper/data.php by phpmd

    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 '67', column '31').
    Open

                        throw new RuntimeException('Import of Issues aborted because lock removed');
    Severity: Minor
    Found in helper/data.php by phpmd

    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 '321', column '30').
    Open

                $changelog = new PageChangelog($page['page']);
    Severity: Minor
    Found in helper/data.php by phpmd

    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 '\dokuwiki\plugin\issuelinks\classes\ServiceProvider' in method 'importAllIssues'.
    Open

            $serviceProvider = ServiceProvider::getInstance();
    Severity: Minor
    Found in helper/data.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

    Avoid using static access to class '\dokuwiki\plugin\issuelinks\classes\Issue' in method 'getIssue'.
    Open

            $issue = Issue::getInstance($pmServiceName, $project, $issueid, $isMergeRequest);
    Severity: Minor
    Found in helper/data.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

    Avoid using static access to class '\dokuwiki\plugin\issuelinks\classes\Issue' in method 'getMergeRequestsForIssue'.
    Open

                $issue = Issue::getInstance(
                    $issueData['service'],
                    $issueData['project_id'],
                    $issueData['issue_id'],
                    $issueData['is_mergerequest']
    Severity: Minor
    Found in helper/data.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

    Define a constant instead of duplicating this literal ".lock" 6 times.
    Open

            $lockFN = $conf['lockdir'] . '/' . md5('_' . $id) . '.lock';
    Severity: Critical
    Found in helper/data.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 "status" 7 times.
    Open

            $this->lockImport($lockfileKey, json_encode(['user' => $_SERVER['REMOTE_USER'], 'status' => 'started']));
    Severity: Critical
    Found in helper/data.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 and throw a dedicated exception instead of using a generic one.
    Open

                throw new RuntimeException('Import of Issues is already locked!');
    Severity: Major
    Found in helper/data.php by sonar-php

    If you throw a general exception type, such as ErrorException, RuntimeException, or Exception in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle.

    Instead, either throw a subtype that already exists in the Standard PHP Library, or create your own type that derives from Exception.

    Noncompliant Code Example

    throw new Exception();  // Noncompliant
    

    Compliant Solution

    throw new InvalidArgumentException();
    // or
    throw new UnexpectedValueException();
    

    See

    Define and throw a dedicated exception instead of using a generic one.
    Open

                        throw new RuntimeException('Import of Issues aborted because lock removed');
    Severity: Major
    Found in helper/data.php by sonar-php

    If you throw a general exception type, such as ErrorException, RuntimeException, or Exception in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle.

    Instead, either throw a subtype that already exists in the Standard PHP Library, or create your own type that derives from Exception.

    Noncompliant Code Example

    throw new Exception();  // Noncompliant
    

    Compliant Solution

    throw new InvalidArgumentException();
    // or
    throw new UnexpectedValueException();
    

    See

    Define a constant instead of duplicating this literal "REMOTE_USER" 3 times.
    Open

            $this->lockImport($lockfileKey, json_encode(['user' => $_SERVER['REMOTE_USER'], 'status' => 'started']));
    Severity: Critical
    Found in helper/data.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 "lockdir" 6 times.
    Open

            $lockFN = $conf['lockdir'] . '/' . md5('_' . $id) . '.lock';
    Severity: Critical
    Found in helper/data.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.

    Rename "$db" which has the same name as the field declared at line 16.
    Open

            $db = plugin_load('helper', 'issuelinks_db');
    Severity: Major
    Found in helper/data.php by sonar-php

    Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

    Noncompliant Code Example

    class Foo {
      public $myField;
    
      public function doSomething() {
        $myField = 0;
        ...
      }
    }
    

    See

    Call to undeclared function \dbglog()
    Open

            dbglog('lock import: ' . $jsonData, __FILE__ . ': ' . __LINE__);
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \io_readFile()
    Open

            $lockData = json_decode(io_readFile($lockFN), true);
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \io_readFile()
    Open

            $lockData = json_decode(io_readFile($lockFN), true);
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \auth_quickaclcheck()
    Open

                if (auth_quickaclcheck($page['page']) >= AUTH_READ) {
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \dbglog()
    Open

            dbglog('start import. $lockfileKey: ' . $lockfileKey);
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \io_readFile()
    Open

            return json_decode(io_readFile($lockFN), true);
    Severity: Critical
    Found in helper/data.php by phan

    Class extends undeclared class \DokuWiki_Plugin
    Open

    class helper_plugin_issuelinks_data extends DokuWiki_Plugin
    Severity: Critical
    Found in helper/data.php by phan

    Call to method __construct from undeclared class \PageChangelog
    Open

                $changelog = new PageChangelog($page['page']);
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \dbglog()
    Open

                    dbglog($e->getResponseBody());
    Severity: Critical
    Found in helper/data.php by phan

    Call to method getRevisionInfo from undeclared class \PageChangelog
    Open

                $revision = $changelog->getRevisionInfo($page['rev']);
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \dbglog()
    Open

            dbglog($serviceClass);
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \io_readFile()
    Open

            $lockData = json_decode(io_readFile($lockFN), true);
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \io_saveFile()
    Open

            io_saveFile($lock, $jsonData);
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \dbglog()
    Open

            dbglog($services);
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \dbglog()
    Open

            dbglog($serviceName);
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \dbglog()
    Open

                dbglog('issuelinks: stale lock timeout');
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \dbglog()
    Open

                    dbglog($e->getHttpError());
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \dbglog()
    Open

                    dbglog($e->getMessage());
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \dbglog()
    Open

                    dbglog($e->getCode());
    Severity: Critical
    Found in helper/data.php by phan

    Reference to undeclared constant \AUTH_READ
    Open

                if (auth_quickaclcheck($page['page']) >= AUTH_READ) {
    Severity: Minor
    Found in helper/data.php by phan

    Call to undeclared function \dbglog()
    Open

                    dbglog($e->getUrl());
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \plugin_load()
    Open

            $db = plugin_load('helper', 'issuelinks_db');
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared method \helper_plugin_issuelinks_data::loadHelper
    Open

            $this->db = $this->loadHelper('issuelinks_db');
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \io_saveFile()
    Open

            io_saveFile($lockFN, json_encode($lockData));
    Severity: Critical
    Found in helper/data.php by phan

    Call to undeclared function \dbglog()
    Open

                dbglog(
    Severity: Critical
    Found in helper/data.php by phan

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

    class helper_plugin_issuelinks_data extends DokuWiki_Plugin
    Severity: Minor
    Found in helper/data.php by phpcodesniffer

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

        public function isImportLocked($id)
    Severity: Minor
    Found in helper/data.php by phpmd

    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 $db. Configured minimum length is 3.
    Open

        private $db = null;
    Severity: Minor
    Found in helper/data.php by phpmd

    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 $id. Configured minimum length is 3.
    Open

        public function isImportLockedByMe($id)
    Severity: Minor
    Found in helper/data.php by phpmd

    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 $db. Configured minimum length is 3.
    Open

            $db = plugin_load('helper', 'issuelinks_db');
    Severity: Minor
    Found in helper/data.php by phpmd

    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 $id. Configured minimum length is 3.
    Open

        public function unlockImport($id)
    Severity: Minor
    Found in helper/data.php by phpmd

    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 $id. Configured minimum length is 3.
    Open

        public function lockImport($id, $jsonData)
    Severity: Minor
    Found in helper/data.php by phpmd

    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 $id. Configured minimum length is 3.
    Open

        public function getLockContent($id)
    Severity: Minor
    Found in helper/data.php by phpmd

    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

    The class helper_plugin_issuelinks_data is not named in CamelCase.
    Open

    class helper_plugin_issuelinks_data extends DokuWiki_Plugin
    {
    
        /** @var helper_plugin_issuelinks_db */
        private $db = null;
    Severity: Minor
    Found in helper/data.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

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

    class helper_plugin_issuelinks_data extends DokuWiki_Plugin
    Severity: Minor
    Found in helper/data.php by phpcodesniffer

    The variable $INPUT is not named in camelCase.
    Open

        public function isImportLockedByMe($id)
        {
            if (!$this->isImportLocked($id)) {
                return false;
            }
    Severity: Minor
    Found in helper/data.php by phpmd

    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 $INPUT is not named in camelCase.
    Open

        public function isImportLockedByMe($id)
        {
            if (!$this->isImportLocked($id)) {
                return false;
            }
    Severity: Minor
    Found in helper/data.php by phpmd

    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

    There are no issues that match your filters.

    Category
    Status