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. */
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. */
- Exclude checks
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();
- Read upRead up
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)) {
- Read upRead up
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.');
- Read upRead up
- Exclude checks
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");
- Read upRead up
- Exclude checks
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();
- Read upRead up
- Exclude checks
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();
- Read upRead up
- Exclude checks
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();
- Read upRead up
- Exclude checks
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
- Read upRead up
- Exclude checks
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);
}
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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';
}
- Read upRead up
- Exclude checks
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');
}
- Read upRead up
- Exclude checks
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");
- Read upRead up
- Exclude checks
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)) {
- Read upRead up
- Exclude checks
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);
}
- Read upRead up
- Exclude checks
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);
}
- Read upRead up
- Exclude checks
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);
}
- Read upRead up
- Exclude checks
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);
}
- Read upRead up
- Exclude checks
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);
}
- Read upRead up
- Exclude checks
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)) {
- Read upRead up
- Exclude checks
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();
}
}