handleRequest accesses the super-global variable $_REQUEST. Open
public function handleRequest()
{
// Check if it is time to add more term. If so, show a warning to admins.
$futureTerms = TermFactory::getFutureTermsAssoc();
if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
- Read upRead up
- Create a ticketCreate a ticket
- 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
handleRequest accesses the super-global variable $_REQUEST. Open
public function handleRequest()
{
// Check if it is time to add more term. If so, show a warning to admins.
$futureTerms = TermFactory::getFutureTermsAssoc();
if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
- Read upRead up
- Create a ticketCreate a ticket
- 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
handleRequest accesses the super-global variable $_REQUEST. Open
public function handleRequest()
{
// Check if it is time to add more term. If so, show a warning to admins.
$futureTerms = TermFactory::getFutureTermsAssoc();
if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
- Read upRead up
- Create a ticketCreate a ticket
- 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
Method handleRequest
has 274 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function handleRequest()
{
// Check if it is time to add more term. If so, show a warning to admins.
$futureTerms = TermFactory::getFutureTermsAssoc();
if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
- Create a ticketCreate a ticket
Function handleRequest
has a Cognitive Complexity of 69 (exceeds 5 allowed). Consider refactoring. Open
public function handleRequest()
{
// Check if it is time to add more term. If so, show a warning to admins.
$futureTerms = TermFactory::getFutureTermsAssoc();
if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
- Read upRead up
- Create a ticketCreate a ticket
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 class InternshipInventory has an overall complexity of 71 which is very high. The configured complexity threshold is 50. Open
class InternshipInventory {
private $content;
public function __construct()
- Create a ticketCreate a ticket
- Exclude checks
File InternshipInventory.php
has 290 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* This file is part of Internship Inventory.
*
* Internship Inventory is free software: you can redistribute it and/or modify
- Create a ticketCreate a ticket
The method handleRequest() has an NPath complexity of 780. The configured NPath complexity threshold is 200. Open
public function handleRequest()
{
// Check if it is time to add more term. If so, show a warning to admins.
$futureTerms = TermFactory::getFutureTermsAssoc();
if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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 method handleRequest() has 289 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function handleRequest()
{
// Check if it is time to add more term. If so, show a warning to admins.
$futureTerms = TermFactory::getFutureTermsAssoc();
if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
- Create a ticketCreate a ticket
- Exclude checks
The method handleRequest() has a Cyclomatic Complexity of 69. The configured cyclomatic complexity threshold is 10. Open
public function handleRequest()
{
// Check if it is time to add more term. If so, show a warning to admins.
$futureTerms = TermFactory::getFutureTermsAssoc();
if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
- Read upRead up
- Create a ticketCreate a ticket
- 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 InternshipInventory has a coupling between objects value of 62. Consider to reduce the number of dependencies under 13. Open
class InternshipInventory {
private $content;
public function __construct()
- Read upRead up
- Create a ticketCreate a ticket
- 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
Avoid using static access to class '\Current_User' in method 'handleRequest'. Open
if (!\Current_User::allow('intern', 'special_host')) {
- Read upRead up
- Create a ticketCreate a ticket
- 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
Avoid using static access to class '\Current_User' in method 'handleRequest'. Open
if (!\Current_User::allow('intern', 'edit_terms')) {
- Read upRead up
- Create a ticketCreate a ticket
- 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
Avoid using static access to class '\NQ' in method 'handleRequest'. Open
\NQ::simple('intern', \Intern\UI\NotifyUI::WARNING, "There are less than three future terms available. It's probably time to add a new term.");
- Read upRead up
- Create a ticketCreate a ticket
- 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 handleRequest uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$req = $_REQUEST['action'];
$transactionName = $req;
}
- Read upRead up
- Create a ticketCreate a ticket
- 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 '\Current_User' in method 'handleRequest'. Open
if (!\Current_User::allow('intern', 'edit_state')) {
- Read upRead up
- Create a ticketCreate a ticket
- 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
Avoid using static access to class 'Intern\TermFactory' in method 'handleRequest'. Open
$futureTerms = TermFactory::getFutureTermsAssoc();
- Read upRead up
- Create a ticketCreate a ticket
- 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
Avoid using static access to class 'Intern\InternshipFactory' in method 'handleRequest'. Open
$i = InternshipFactory::getInternshipById($_REQUEST['internship_id']);
- Read upRead up
- Create a ticketCreate a ticket
- 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
Avoid using static access to class '\Intern\TermFactory' in method 'handleRequest'. Open
$term = \Intern\TermFactory::getTermByTermCode($i->getTerm());
- Read upRead up
- Create a ticketCreate a ticket
- 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
Avoid using static access to class '\Current_User' in method 'handleRequest'. Open
if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
- Read upRead up
- Create a ticketCreate a ticket
- 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
Avoid using static access to class '\Current_User' in method 'handleRequest'. Open
if (!\Current_User::allow('intern', 'edit_courses')) {
- Read upRead up
- Create a ticketCreate a ticket
- 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
Avoid using static access to class '\Current_User' in method 'handleRequest'. Open
if (!\Current_User::allow('intern', 'edit_level')) {
- Read upRead up
- Create a ticketCreate a ticket
- 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
Avoid using static access to class '\Current_User' in method 'handleRequest'. Open
if (!\Current_User::allow('intern', 'edit_terms')) {
- Read upRead up
- Create a ticketCreate a ticket
- 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
Avoid using static access to class 'Intern\EmergencyContactFactory' in method 'handleRequest'. Open
$emgContacts = EmergencyContactFactory::getContactsForInternship($i);
- Read upRead up
- Create a ticketCreate a ticket
- 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 handleRequest() contains an exit expression. Open
exit;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
Source https://phpmd.org/rules/design.html#exitexpression
The method handleRequest() contains an exit expression. Open
exit();
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
Source https://phpmd.org/rules/design.html#exitexpression
Call to method simple
from undeclared class \NQ
Open
\NQ::simple('intern', \Intern\UI\NotifyUI::WARNING, "There are less than three future terms available. It's probably time to add a new term.");
- Create a ticketCreate a ticket
- Exclude checks
Call to undeclared function \disallow()
Open
disallow();
- Create a ticketCreate a ticket
- Exclude checks
Call to undeclared function \disallow()
Open
disallow();
- Create a ticketCreate a ticket
- Exclude checks
Call to undeclared function \disallow()
Open
disallow();
- Create a ticketCreate a ticket
- Exclude checks
Call to method allow
from undeclared class \Current_User
Open
if (!\Current_User::allow('intern', 'edit_terms')) {
- Create a ticketCreate a ticket
- Exclude checks
Call to method output
from undeclared class \Intern\FPDI
Open
$pdf->output();
- Create a ticketCreate a ticket
- Exclude checks
Call to undeclared method \Intern\Command\MajorRest::execute
Open
$ctrl->execute();
- Create a ticketCreate a ticket
- Exclude checks
Reference to undeclared constant \PHPWS_SOURCE_DIR
Open
readfile(\PHPWS_SOURCE_DIR . 'mod/intern/pdf/Internship_Example.pdf');
- Create a ticketCreate a ticket
- Exclude checks
Cannot assign void return value Open
$this->content = $ctrl->execute();
- Create a ticketCreate a ticket
- Exclude checks
Call to undeclared function \disallow()
Open
disallow();
- Create a ticketCreate a ticket
- Exclude checks
Call to undeclared function \disallow()
Open
disallow();
- Create a ticketCreate a ticket
- Exclude checks
Call to method allow
from undeclared class \Current_User
Open
if (!\Current_User::allow('intern', 'edit_terms')) {
- Create a ticketCreate a ticket
- Exclude checks
Possibly zero references to use statement for classlike/namespace NotifyUI
(\Intern\UI\NotifyUI)
Open
use Intern\UI\NotifyUI;
- Create a ticketCreate a ticket
- Exclude checks
Call to method allow
from undeclared class \Current_User
Open
if (!\Current_User::allow('intern', 'edit_courses')) {
- Create a ticketCreate a ticket
- Exclude checks
Call to method allow
from undeclared class \Current_User
Open
if (!\Current_User::allow('intern', 'edit_state')) {
- Create a ticketCreate a ticket
- Exclude checks
Call to undeclared function \disallow()
Open
disallow();
- Create a ticketCreate a ticket
- Exclude checks
Call to method allow
from undeclared class \Current_User
Open
if (!\Current_User::allow('intern', 'special_host')) {
- Create a ticketCreate a ticket
- Exclude checks
Call to method isDeity
from undeclared class \Current_User
Open
if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
- Create a ticketCreate a ticket
- Exclude checks
Argument 1 (termCode)
is int
but \Intern\TermFactory::getTermByTermCode()
takes string
defined at /code/class/TermFactory.php:32
Open
$term = \Intern\TermFactory::getTermByTermCode($i->getTerm());
- Create a ticketCreate a ticket
- Exclude checks
Call to method allow
from undeclared class \Current_User
Open
if (!\Current_User::allow('intern', 'edit_level')) {
- Create a ticketCreate a ticket
- Exclude checks
Avoid variables with short names like $i. Configured minimum length is 3. Open
$i = InternshipFactory::getInternshipById($_REQUEST['internship_id']);
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}