attogram/justrefs

View on GitHub
src/Mediawiki.php

Summary

Maintainability
A
1 hr
Test Coverage

The method Mediawiki::getApi() calls the typical debug function print_r() which is mostly only used during development.
Open

            $this->error('getApi: invalid url: ' . print_r($url, true));
Severity: Minor
Found in src/Mediawiki.php by phpmd

DevelopmentCodeFragment

Since: 2.3.0

Functions like vardump(), printr() etc. are normally only used during development and therefore such calls in production code are a good indicator that they were just forgotten.

Example

class SuspectCode {

    public function doSomething(array $items)
    {
        foreach ($items as $i => $item) {
            // …

            if ('qafoo' == $item) var_dump($i);

            // …
        }
    }
}

Source https://phpmd.org/rules/design.html#developmentcodefragment

Method links has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function links($query)
    {
        $data = $this->getApi($this->api . $this->apiLinks . urlencode($query));
        if (!$data || !is_array($data)) {
            $this->error('links: decode failed: ' . $query);
Severity: Minor
Found in src/Mediawiki.php - About 1 hr to fix

    Function search has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        public function search($query)
        {
            $data = $this->getApi($this->api . $this->apiSearch . urlencode($query));
            if (!$data || !is_array($data) || empty($data[self::QUERY])
                || empty($data[self::QUERY][self::SEARCH]) || !is_array($data[self::QUERY][self::SEARCH])
    Severity: Minor
    Found in src/Mediawiki.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

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

        private function getApi($url)
    Severity: Major
    Found in src/Mediawiki.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;
    }
    

    Remove error control operator '@' on line 130.
    Open

        private function getApi($url)
        {
            if (empty($url) || !is_string($url)) {
                $this->error('getApi: invalid url: ' . print_r($url, true));
                return false;
    Severity: Minor
    Found in src/Mediawiki.php by phpmd

    ErrorControlOperator

    Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

    Example

    function foo($filePath) {
        $file = @fopen($filPath); // hides exceptions
        $key = @$array[$notExistingKey]; // assigns null to $key
    }

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

    TODO found
    Open

            //$result['cached'] = time();  // @TODO set and use cache time
    Severity: Minor
    Found in src/Mediawiki.php by fixme

    There are no issues that match your filters.

    Category
    Status