NatLibFi/Skosmos

View on GitHub
src/model/GlobalConfig.php

Summary

Maintainability
B
5 hrs
Test Coverage
A
96%

GlobalConfig has 33 functions (exceeds 20 allowed). Consider refactoring.
Open

class GlobalConfig extends BaseConfig
{
    /** Cache reference */
    private $cache;
    /** Location of the configuration file. Used for caching. */
Severity: Minor
Found in src/model/GlobalConfig.php - About 4 hrs to fix

    The class GlobalConfig has an overall complexity of 55 which is very high. The configured complexity threshold is 50.
    Open

    class GlobalConfig extends BaseConfig
    {
        /** Cache reference */
        private $cache;
        /** Location of the configuration file. Used for caching. */
    Severity: Minor
    Found in src/model/GlobalConfig.php by phpmd

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

        public function getLanguages()
        {
            $languageResources = $this->getResource()->getResource('skosmos:languages');
            if (!is_null($languageResources) && !empty($languageResources)) {
                $languages = array();
    Severity: Minor
    Found in src/model/GlobalConfig.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

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

        private function initializeConfig(): EasyRdf\Resource
        {
            // retrieve last modified time for config file (filemtime returns int|bool!)
            $configModifiedTime = filemtime($this->filePath);
            if (!is_bool($configModifiedTime)) {
    Severity: Minor
    Found in src/model/GlobalConfig.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

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

                throw new Exception('config.ttl file is missing, please provide one.');
    Severity: Minor
    Found in src/model/GlobalConfig.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 '89', column '23').
    Open

                throw new Exception("config.ttl must have exactly one skosmos:Configuration");
    Severity: Minor
    Found in src/model/GlobalConfig.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 '101', column '28').
    Open

            $this->graph = new EasyRdf\Graph();
    Severity: Minor
    Found in src/model/GlobalConfig.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 '35', column '28').
    Open

            $this->cache = new Cache();
    Severity: Minor
    Found in src/model/GlobalConfig.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 '102', column '23').
    Open

            $parser = new SkosmosTurtleParser();
    Severity: Minor
    Found in src/model/GlobalConfig.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 'EasyRdf\RdfNamespace' in method 'initializeNamespaces'.
    Open

                if ($prefix != '' && EasyRdf\RdfNamespace::get($prefix) === null) { // if not already defined
    Severity: Minor
    Found in src/model/GlobalConfig.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 initializeConfig uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else { // APC not available, parse on every request
                $this->parseConfig($this->filePath);
            }
    Severity: Minor
    Found in src/model/GlobalConfig.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 'initializeNamespaces'.
    Open

                    EasyRdf\RdfNamespace::set($prefix, $fullUri);
    Severity: Minor
    Found in src/model/GlobalConfig.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 getDefaultEndpoint uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                return 'http://localhost:3030/ds/sparql';
            }
    Severity: Minor
    Found in src/model/GlobalConfig.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 getLanguages uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                return array('en' => 'en_GB.utf8');
            }
    Severity: Minor
    Found in src/model/GlobalConfig.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 excessively long variable names like $globalPluginsResource. Keep variable name length under 20.
    Open

            $globalPluginsResource =  $this->getResource()->getResource("skosmos:globalPlugins");
    Severity: Minor
    Found in src/model/GlobalConfig.php by phpmd

    LongVariable

    Since: 0.2

    Detects when a field, formal or local variable is declared with a long name.

    Example

    class Something {
        protected $reallyLongIntName = -3; // VIOLATION - Field
        public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
            $otherReallyLongName = -5; // VIOLATION - Local
            for ($interestingIntIndex = 0; // VIOLATION - For
                 $interestingIntIndex < 10;
                 $interestingIntIndex++ ) {
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#longvariable

    The parameter $config_name is not named in camelCase.
    Open

        public function __construct(Model $model, string $config_name = '../../config.ttl')
        {
            $this->cache = new Cache();
            $this->filePath = realpath(dirname(__FILE__) . "/" . $config_name);
            if (!file_exists($this->filePath)) {
    Severity: Minor
    Found in src/model/GlobalConfig.php by phpmd

    CamelCaseParameterName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name parameters.

    Example

    class ClassName {
        public function doSomething($user_name) {
        }
    }

    Source

    The 'getCollationEnabled()' method which returns a boolean should be named 'is...()' or 'has...()'
    Open

        public function getCollationEnabled()
        {
            return $this->getBoolean('skosmos:sparqlCollationEnabled', false);
        }
    Severity: Minor
    Found in src/model/GlobalConfig.php by phpmd

    BooleanGetMethodName

    Since: 0.2

    Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.

    Example

    class Foo {
        /**
         * @return boolean
         */
        public function getFoo() {} // bad
        /**
         * @return bool
         */
        public function isFoo(); // ok
        /**
         * @return boolean
         */
        public function getFoo($bar); // ok, unless checkParameterizedMethods=true
    }

    Source https://phpmd.org/rules/naming.html#booleangetmethodname

    The 'getUiLanguageDropdown()' method which returns a boolean should be named 'is...()' or 'has...()'
    Open

        public function getUiLanguageDropdown()
        {
            return $this->getBoolean('skosmos:uiLanguageDropdown', false);
        }
    Severity: Minor
    Found in src/model/GlobalConfig.php by phpmd

    BooleanGetMethodName

    Since: 0.2

    Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.

    Example

    class Foo {
        /**
         * @return boolean
         */
        public function getFoo() {} // bad
        /**
         * @return bool
         */
        public function isFoo(); // ok
        /**
         * @return boolean
         */
        public function getFoo($bar); // ok, unless checkParameterizedMethods=true
    }

    Source https://phpmd.org/rules/naming.html#booleangetmethodname

    The 'getLoggingBrowserConsole()' method which returns a boolean should be named 'is...()' or 'has...()'
    Open

        public function getLoggingBrowserConsole()
        {
            return $this->getBoolean('skosmos:logBrowserConsole', false);
        }
    Severity: Minor
    Found in src/model/GlobalConfig.php by phpmd

    BooleanGetMethodName

    Since: 0.2

    Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.

    Example

    class Foo {
        /**
         * @return boolean
         */
        public function getFoo() {} // bad
        /**
         * @return bool
         */
        public function isFoo(); // ok
        /**
         * @return boolean
         */
        public function getFoo($bar); // ok, unless checkParameterizedMethods=true
    }

    Source https://phpmd.org/rules/naming.html#booleangetmethodname

    The 'getLogCaughtExceptions()' method which returns a boolean should be named 'is...()' or 'has...()'
    Open

        public function getLogCaughtExceptions()
        {
            return $this->getBoolean('skosmos:logCaughtExceptions', false);
        }
    Severity: Minor
    Found in src/model/GlobalConfig.php by phpmd

    BooleanGetMethodName

    Since: 0.2

    Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.

    Example

    class Foo {
        /**
         * @return boolean
         */
        public function getFoo() {} // bad
        /**
         * @return bool
         */
        public function isFoo(); // ok
        /**
         * @return boolean
         */
        public function getFoo($bar); // ok, unless checkParameterizedMethods=true
    }

    Source https://phpmd.org/rules/naming.html#booleangetmethodname

    The 'getHoneypotEnabled()' method which returns a boolean should be named 'is...()' or 'has...()'
    Open

        public function getHoneypotEnabled()
        {
            return $this->getBoolean('skosmos:uiHoneypotEnabled', true);
        }
    Severity: Minor
    Found in src/model/GlobalConfig.php by phpmd

    BooleanGetMethodName

    Since: 0.2

    Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.

    Example

    class Foo {
        /**
         * @return boolean
         */
        public function getFoo() {} // bad
        /**
         * @return bool
         */
        public function isFoo(); // ok
        /**
         * @return boolean
         */
        public function getFoo($bar); // ok, unless checkParameterizedMethods=true
    }

    Source https://phpmd.org/rules/naming.html#booleangetmethodname

    The variable $config_name is not named in camelCase.
    Open

        public function __construct(Model $model, string $config_name = '../../config.ttl')
        {
            $this->cache = new Cache();
            $this->filePath = realpath(dirname(__FILE__) . "/" . $config_name);
            if (!file_exists($this->filePath)) {
    Severity: Minor
    Found in src/model/GlobalConfig.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