NatLibFi/Skosmos

View on GitHub

Showing 1,049 of 1,049 total issues

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

    protected function arbitrarySort($sortable)
    {
        // sorting the result list to a arbitrary order defined below in mycompare()
        if ($sortable !== null) {
            uksort($sortable, array($this, 'mycompare'));
Severity: Minor
Found in src/model/DataObject.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 getVocabularyByGraph has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function getVocabularyByGraph($graph, $endpoint = null)
    {
        if ($endpoint === null) {
            $endpoint = $this->getConfig()->getDefaultEndpoint();
        }
Severity: Minor
Found in src/model/Model.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 getDefaultSidebarView has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function getDefaultSidebarView()
    {
        $defview = $this->resource->getLiteral('skosmos:defaultSidebarView');
        $sidebarViews = $this->getSidebarViews();
        if ($defview) {
Severity: Minor
Found in src/model/VocabularyConfig.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 getDefaultConceptSidebarView has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function getDefaultConceptSidebarView()
    {
        $defview = $this->resource->getLiteral('skosmos:defaultConceptSidebarView');
        $sidebarViews = $this->getSidebarViews();
        if ($defview) {
Severity: Minor
Found in src/model/VocabularyConfig.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 redirect has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function redirect($request)
    {
        /* determine parameters: URI and (optional) vocabulary */
        $request->setUri($request->getQueryParam('uri'));
        if ($request->getQueryParam('vocab')) {
Severity: Minor
Found in src/controller/EntityController.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 getVocabGraphs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function getVocabGraphs($vocabs)
    {
        if ($vocabs === null || sizeof($vocabs) == 0) {
            // searching from all vocabularies - limit to known graphs
            $vocabs = $this->model->getVocabularies();
Severity: Minor
Found in src/model/sparql/GenericSparql.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 redirectWeb has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    private function redirectWeb($vocab, $uri)
    {
        $baseurl = $this->getBaseHref();
        $vocid = $vocab->getId();
        $localname = $vocab->getLocalName($uri);
Severity: Minor
Found in src/controller/EntityController.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 invokeVocabularySearch has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function invokeVocabularySearch($request)
    {
        $template = $this->twig->load('vocab-search.twig');
        $this->model->setLocale($request->getLang());
        $vocab = $request->getVocab();
Severity: Minor
Found in src/controller/WebController.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 getModifiedDate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function getModifiedDate()
    {
        $modifiedDate = null;

        $conceptSchemeURI = $this->getDefaultConceptScheme();
Severity: Minor
Found in src/model/Vocabulary.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 getTemplates has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function getTemplates($names = null)
    {
        $templateStrings = array();
        $plugins = $this->getPluginsTemplates($names);
        foreach ($plugins as $folder => $templates) {
Severity: Minor
Found in src/model/PluginRegister.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

The method redirectWeb uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {

            if ($localname !== $uri && $localname === urlencode($localname)) {
                // the URI can be shortened
                $url = $baseurl . "$vocid/page/$localname";
Severity: Minor
Found in src/controller/EntityController.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

Avoid unused local variables such as '$lang'.
Open

        $lang = $request->getLang();
Severity: Minor
Found in src/controller/WebController.php by phpmd

UnusedLocalVariable

Since: 0.2

Detects when a local variable is declared and/or assigned, but not used.

Example

class Foo {
    public function doSomething()
    {
        $i = 5; // Unused
    }
}

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

The method linkUrlFilter() has an NPath complexity of 252. The configured NPath complexity threshold is 200.
Open

    public function linkUrlFilter($uri, $vocab, $lang, $type = 'page', $clang = null, $term = null)
    {
        // $vocab can either be null, a vocabulary id (string) or a Vocabulary object
        if ($vocab === null) {
            return $uri;
Severity: Minor
Found in src/controller/LinkUrlExtension.php by phpmd

NPathComplexity

Since: 0.1

The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

Example

class Foo {
    function bar() {
        // lots of complicated code
    }
}

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

The class RestController has 1172 lines of code. Current threshold is 1000. Avoid really long classes.
Open

class RestController extends Controller
{
    /* supported MIME types that can be used to return RDF data */
    public const SUPPORTED_FORMATS = 'application/rdf+xml text/turtle application/ld+json application/json application/marcxml+xml';
    /* context array template */
Severity: Minor
Found in src/controller/RestController.php by phpmd

The method linkUrlFilter uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $vocid = $vocab->getId();
        }
Severity: Minor
Found in src/controller/LinkUrlExtension.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

The method redirectToVocabData uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            header("Location: " . $urls[$format]);
        }
Severity: Minor
Found in src/controller/RestController.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

Avoid unused local variables such as '$lang'.
Open

        $lang = $request->getLang();
Severity: Minor
Found in src/controller/WebController.php by phpmd

UnusedLocalVariable

Since: 0.2

Detects when a local variable is declared and/or assigned, but not used.

Example

class Foo {
    public function doSomething()
    {
        $i = 5; // Unused
    }
}

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

Avoid assigning values to variables in if clauses and the like (line '70', column '13').
Open

    private function isSecure()
    {
        if ($protocol = filter_input(INPUT_SERVER, 'HTTP_X_FORWARDED_PROTO', FILTER_SANITIZE_FULL_SPECIAL_CHARS)) {
            return \in_array(strtolower($protocol), ['https', 'on', 'ssl', '1'], true);
        }
Severity: Minor
Found in src/controller/Controller.php by phpmd

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

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

The method redirectWeb uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                // must use full URI
                $query = http_build_query(array('uri' => $uri));
                $url = $baseurl . "$vocid/page/?" . $query;
            }
Severity: Minor
Found in src/controller/EntityController.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

Avoid using static access to class 'EasyRdf\RdfNamespace' in method 'vocabularyStatistics'.
Open

                'label' => isset($vocabStats[$arrayClass]['label']) ? $vocabStats[$arrayClass]['label'] : $this->model->getText(EasyRdf\RdfNamespace::shorten($arrayClass)),
Severity: Minor
Found in src/controller/RestController.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

Severity
Category
Status
Source
Language