importAction accesses the super-global variable $_POST. Open
public function importAction()
{
$this->requireAdminPrivileges();
// This is necessary in order to avoid session lock and being able to run two
- 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
importAction accesses the super-global variable $_POST. Open
public function importAction()
{
$this->requireAdminPrivileges();
// This is necessary in order to avoid session lock and being able to run two
- 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
Function _recursiveParseDirectory
has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring. Open
private function _recursiveParseDirectory($path, $currentdir)
{
$it = new DirectoryIterator($path);
foreach ($it as $fileInfo) {
if ($fileInfo->isDot()) {
- 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
Method _recursiveParseDirectory
has 75 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function _recursiveParseDirectory($path, $currentdir)
{
$it = new DirectoryIterator($path);
foreach ($it as $fileInfo) {
if ($fileInfo->isDot()) {
- Create a ticketCreate a ticket
Method importAction
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function importAction()
{
$this->requireAdminPrivileges();
// This is necessary in order to avoid session lock and being able to run two
- Create a ticketCreate a ticket
Function importAction
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function importAction()
{
$this->requireAdminPrivileges();
// This is necessary in order to avoid session lock and being able to run two
- 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
Function _recursiveCountFiles
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function _recursiveCountFiles($path)
{
$initialcount = 0;
$it = new DirectoryIterator($path);
foreach ($it as $fileInfo) {
- 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
Avoid too many return
statements within this method. Open
return false;
- Create a ticketCreate a ticket
The method _recursiveParseDirectory() has an NPath complexity of 289. The configured NPath complexity threshold is 200. Open
private function _recursiveParseDirectory($path, $currentdir)
{
$it = new DirectoryIterator($path);
foreach ($it as $fileInfo) {
if ($fileInfo->isDot()) {
- 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 _recursiveParseDirectory() has 113 lines of code. Current threshold is set to 100. Avoid really long methods. Open
private function _recursiveParseDirectory($path, $currentdir)
{
$it = new DirectoryIterator($path);
foreach ($it as $fileInfo) {
if ($fileInfo->isDot()) {
- Create a ticketCreate a ticket
- Exclude checks
The method _recursiveParseDirectory() has a Cyclomatic Complexity of 17. The configured cyclomatic complexity threshold is 10. Open
private function _recursiveParseDirectory($path, $currentdir)
{
$it = new DirectoryIterator($path);
foreach ($it as $fileInfo) {
if ($fileInfo->isDot()) {
- 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
Avoid using undefined variables such as '$progress' which will lead to PHP notices. Open
$progress['current'] = $progressfile[0];
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$progress' which will lead to PHP notices. Open
$progress['max'] = $progressfile[1];
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$progress' which will lead to PHP notices. Open
$progress['percent'] = round($progress['current'] * 100 / $progress['max']);
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$progress' which will lead to PHP notices. Open
$progress['percent'] = round($progress['current'] * 100 / $progress['max']);
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$progress' which will lead to PHP notices. Open
$progress['max'] = 0;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$progress' which will lead to PHP notices. Open
echo json_encode($progress);
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$progress' which will lead to PHP notices. Open
$progress['current'] = 0;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$progress' which will lead to PHP notices. Open
$progress['percent'] = 'NA';
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$progress' which will lead to PHP notices. Open
$progress['percent'] = round($progress['current'] * 100 / $progress['max']);
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Missing class import via use statement (line '166', column '34'). Open
$child = new FolderDao();
- Read upRead up
- Create a ticketCreate a ticket
- 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 '183', column '33'). Open
$item = new ItemDao();
- Read upRead up
- Create a ticketCreate a ticket
- 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 '81', column '19'). Open
$it = new DirectoryIterator($path);
- Read upRead up
- Create a ticketCreate a ticket
- 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 '128', column '19'). Open
$it = new DirectoryIterator($path);
- Read upRead up
- Create a ticketCreate a ticket
- 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 '218', column '41'). Open
$bitstreamDao = new BitstreamDao();
- Read upRead up
- Create a ticketCreate a ticket
- 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 '300', column '31'). Open
$currentdir = new FolderDao();
- Read upRead up
- Create a ticketCreate a ticket
- 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 '211', column '44'). Open
$itemRevisionDao = new ItemRevisionDao();
- Read upRead up
- Create a ticketCreate a ticket
- 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
The method _recursiveParseDirectory uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else { // We have a file
$this->_incrementFileProcessed();
$newrevision = true;
$item = $this->Folder->getItemByName($currentdir, $fileInfo->getFilename());
if (!$item) {
- 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
The method importAction uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
echo json_encode(
array(
'error' => $this->t(
'Problem occured while importing. '.'Check the log files or contact an '.'administrator.'
- 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 'UtilityComponent' in method 'indexAction'. Open
UtilityComponent::setTimeLimit(0);
- 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 'UtilityComponent' in method '_recursiveParseDirectory'. Open
$curMD5 = UtilityComponent::md5file($fileInfo->getPathName());
- 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 _recursiveCountFiles uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
++$initialcount;
}
- 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 'UtilityComponent' in method 'importAction'. Open
UtilityComponent::safedelete($this->progressfile);
- 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 'UtilityComponent' in method 'importAction'. Open
UtilityComponent::safedelete($this->stopfile);
- 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 excessively long variable names like $importemptydirectories. Keep variable name length under 20. Open
private $importemptydirectories = true;
- Read upRead up
- Create a ticketCreate a ticket
- 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
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class ImportController extends AppController
- Create a ticketCreate a ticket
- Exclude checks
The property $_forms is not named in camelCase. Open
class ImportController extends AppController
{
public $_models = array(
'Item',
'Folder',
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
Avoid variables with short names like $it. Configured minimum length is 3. Open
$it = new DirectoryIterator($path);
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The property $_models is not named in camelCase. Open
class ImportController extends AppController
{
public $_models = array(
'Item',
'Folder',
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $_daos is not named in camelCase. Open
class ImportController extends AppController
{
public $_models = array(
'Item',
'Folder',
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $_components is not named in camelCase. Open
class ImportController extends AppController
{
public $_models = array(
'Item',
'Folder',
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
Avoid variables with short names like $it. Configured minimum length is 3. Open
$it = new DirectoryIterator($path);
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Method name "_recursiveCountFiles" should not be prefixed with an underscore to indicate visibility Open
private function _recursiveCountFiles($path)
- Create a ticketCreate a ticket
- Exclude checks
Method name "_checkStopImport" should not be prefixed with an underscore to indicate visibility Open
private function _checkStopImport()
- Create a ticketCreate a ticket
- Exclude checks
Property name "$_daos" should not be prefixed with an underscore to indicate visibility Open
public $_daos = array('Item', 'Folder', 'ItemRevision', 'Bitstream', 'Assetstore');
- Create a ticketCreate a ticket
- Exclude checks
Property name "$_forms" should not be prefixed with an underscore to indicate visibility Open
public $_forms = array('Import', 'Assetstore');
- Create a ticketCreate a ticket
- Exclude checks
Method name "_incrementFileProcessed" should not be prefixed with an underscore to indicate visibility Open
private function _incrementFileProcessed()
- Create a ticketCreate a ticket
- Exclude checks
Method name "_recursiveParseDirectory" should not be prefixed with an underscore to indicate visibility Open
private function _recursiveParseDirectory($path, $currentdir)
- Create a ticketCreate a ticket
- Exclude checks
Property name "$_models" should not be prefixed with an underscore to indicate visibility Open
public $_models = array(
- Create a ticketCreate a ticket
- Exclude checks
Property name "$_components" should not be prefixed with an underscore to indicate visibility Open
public $_components = array('Upload', 'Utility');
- Create a ticketCreate a ticket
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
'Problem occured while importing. '.'Check the log files or contact an '.'administrator.'
- Create a ticketCreate a ticket
- Exclude checks
The method _checkStopImport is not named in camelCase. Open
private function _checkStopImport()
{
// maybe we should check for the content of the file but not necessary
if (file_exists($this->stopfile)) {
return true;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _recursiveParseDirectory is not named in camelCase. Open
private function _recursiveParseDirectory($path, $currentdir)
{
$it = new DirectoryIterator($path);
foreach ($it as $fileInfo) {
if ($fileInfo->isDot()) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _recursiveCountFiles is not named in camelCase. Open
private function _recursiveCountFiles($path)
{
$initialcount = 0;
$it = new DirectoryIterator($path);
foreach ($it as $fileInfo) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _incrementFileProcessed is not named in camelCase. Open
private function _incrementFileProcessed()
{
++$this->nfilesprocessed;
$percent = ($this->nfilesprocessed / $this->ntotalfiles) * 100;
$count = 2; // every 2%
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}