passSparqlToARC2AndGetSerializedOutput accesses the super-global variable $_POST. Open
private function passSparqlToARC2AndGetSerializedOutput() {
// Make sure ARC2 returns a PHP serialization, so that we
// can do stuff with it programmatically
$_POST['output'] = 'php_ser';
- Read upRead up
- Exclude checks
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
urisToEquivURIsInQuery accesses the super-global variable $_POST. Open
private function urisToEquivURIsInQuery( $options ) {
$queryInfo = $options->queryInfos;
$patterns = $queryInfo['query']['pattern']['patterns'][0]['patterns'];
$patterns = $this->extendQueryPatternsWithEquivUriLinks( $patterns );
- Read upRead up
- Exclude checks
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
File SpecialSPARQLEndpoint.php
has 390 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
class SPARQLEndpoint extends RDFIOSpecialPage {
protected $sparqlendpoint;
protected $storewrapper;
Method getHTMLForm
has 86 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getHTMLForm( $query = '' ) {
$wRequest = $this->getRequest();
$wUser = $this->getUser();
$uriResolverURI = SpecialPage::getTitleFor( 'URIResolver' )->getFullURL() . '/';
$defaultQuery = "@PREFIX w : <$uriResolverURI> .\n\nSELECT *\nWHERE { ?s ?p ?o }\nLIMIT 25";
The class SPARQLEndpoint has an overall complexity of 63 which is very high. The configured complexity threshold is 50. Open
class SPARQLEndpoint extends RDFIOSpecialPage {
protected $sparqlendpoint;
protected $storewrapper;
public function __construct() {
- Exclude checks
Function toEquivURIsInSparqlResults
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private function toEquivURIsInSparqlResults( $sparqlResult ) {
$rows = $sparqlResult['result']['rows'];
$vars = $sparqlResult['result']['variables'];
foreach ( $rows as $rowid => $row ) {
foreach ( $vars as $var ) {
- 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
Method execute
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function execute( $par ) {
unset( $par ); // Needed to suppress warning about unused variable which we include just for consistency.
// Require rdfio-sparql permission for the current user
if ( !$this->userCanExecute( $this->getUser() ) ) {
Method executeReadOnlyQuery
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function executeReadOnlyQuery( $options ) {
$wikiOut = $this->getOutput();
$outputSer = $this->passSparqlToARC2AndGetSerializedOutput();
Function executeReadOnlyQuery
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
private function executeReadOnlyQuery( $options ) {
$wikiOut = $this->getOutput();
$outputSer = $this->passSparqlToARC2AndGetSerializedOutput();
- 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
Method extendQueryPatternsWithEquivUriLinks
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function extendQueryPatternsWithEquivUriLinks( $patterns ) {
$patternIdx = 0;
foreach ( $patterns as $pattern ) {
$equivUriUris = array(
's' => $this->storewrapper->getEquivURIURI(),
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return;
Function extendQueryPatternsWithEquivUriLinks
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function extendQueryPatternsWithEquivUriLinks( $patterns ) {
$patternIdx = 0;
foreach ( $patterns as $pattern ) {
$equivUriUris = array(
's' => $this->storewrapper->getEquivURIURI(),
- 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 execute
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function execute( $par ) {
unset( $par ); // Needed to suppress warning about unused variable which we include just for consistency.
// Require rdfio-sparql permission for the current user
if ( !$this->userCanExecute( $this->getUser() ) ) {
- 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
The method execute() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function execute( $par ) {
unset( $par ); // Needed to suppress warning about unused variable which we include just for consistency.
// Require rdfio-sparql permission for the current user
if ( !$this->userCanExecute( $this->getUser() ) ) {
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The class SPARQLEndpoint has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13. Open
class SPARQLEndpoint extends RDFIOSpecialPage {
protected $sparqlendpoint;
protected $storewrapper;
public function __construct() {
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
Missing class import via use statement (line '327', column '22'). Open
$rdfImporter = new RDFIOSMWBatchWriter( $triples, 'triples_array' );
- 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 '9', column '31'). Open
$this->sparqlendpoint = new ARC2_StoreEndpoint( $this->getSPARQLEndpointConfig(), $this );
- 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 '157', column '20'). Open
$seOptions = new RDFIOSPARQLEndpointOptions();
- 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 '373', column '14'). Open
$ser = new ARC2_RDFXMLSerializer();
- 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 '312', column '22'). Open
$rdfImporter = new RDFIORDFImporter();
- 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 '120', column '16'). Open
$arc2 = new ARC2_Class( array(), $this );
- 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 '212', column '27'). Open
$sparqlserializer = new ARC2_SPARQLSerializerPlugin( array(), $this );
- 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 '13', column '29'). Open
$this->storewrapper = new RDFIOARC2StoreWrapper();
- 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 '25', column '14'). Open
throw new PermissionsError( 'rdfio-sparql', array( 'rdfio-specialpage-access-permission-missing' ) );
- 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 '188', column '17'). Open
$parser = new ARC2_SPARQLPlusParser( array(), $this );
- 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 excessively long variable names like $rdfiogOutputEquivUris. Keep variable name length under 20. Open
global $rdfiogQueryByEquivURIs, $rdfiogOutputEquivUris;
- 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
Avoid excessively long variable names like $rdfiogQueryByEquivURIs. Keep variable name length under 20. Open
global $rdfiogQueryByEquivURIs, $rdfiogOutputEquivUris;
- 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++ ) {
}
}
}