sessioning accesses the super-global variable $_SESSION. Open
public function sessioning()
{
session_start();
$this->log->debug('Session started.', $_SESSION);
if ($this->request->query->has('logoff')) {
- 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 Attogram.php
has 680 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
// Attogram Framework - Attogram class v0.5.6
namespace Attogram;
Attogram
has 31 functions (exceeds 20 allowed). Consider refactoring. Open
class Attogram
{
const ATTOGRAM_VERSION = '0.8.2';
public $startTime; // (float) microsecond time of awakening
The class Attogram has an overall complexity of 149 which is very high. The configured complexity threshold is 50. Open
class Attogram
{
const ATTOGRAM_VERSION = '0.8.2';
public $startTime; // (float) microsecond time of awakening
- Exclude checks
The class Attogram has 19 public methods. Consider refactoring Attogram to keep number of public methods under 10. Open
class Attogram
{
const ATTOGRAM_VERSION = '0.8.2';
public $startTime; // (float) microsecond time of awakening
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
Method awaken
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function awaken()
{
// The Site Administrator IP addresses
$this->remember(
'admins',
Function getMimeType
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public static function getMimeType($file)
{
$mimeType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file);
switch (pathinfo($file, PATHINFO_EXTENSION)) { // https://bugs.php.net/bug.php?id=53035
case 'html':
- 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 getMimeType
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getMimeType($file)
{
$mimeType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file);
switch (pathinfo($file, PATHINFO_EXTENSION)) { // https://bugs.php.net/bug.php?id=53035
case 'html':
Method route
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function route()
{
if (is_dir($this->uri[0])) { // requesting a directory?
$this->log->error('ROUTE: 403 Action Forbidden');
$this->error404('No spelunking allowed');
Method defaultHomepage
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function defaultHomepage()
{
$this->log->error('using defaultHomepage');
$this->pageHeader('Home');
echo '<div class="container">'
Function virtualWebDirectory
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function virtualWebDirectory()
{
if (!preg_match('/^\/'.'web'.'\//', $this->request->getPathInfo())) {
return; // not a virtual web directory request
}
- 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 route
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function route()
{
if (is_dir($this->uri[0])) { // requesting a directory?
$this->log->error('ROUTE: 403 Action Forbidden');
$this->error404('No spelunking allowed');
- 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 virtualWebDirectory
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function virtualWebDirectory()
{
if (!preg_match('/^\/'.'web'.'\//', $this->request->getPathInfo())) {
return; // not a virtual web directory request
}
The class Attogram has 20 fields. Consider redesigning Attogram to keep the number of fields under 15. Open
class Attogram
{
const ATTOGRAM_VERSION = '0.8.2';
public $startTime; // (float) microsecond time of awakening
- Read upRead up
- Exclude checks
TooManyFields
Since: 0.1
Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.
Example
class Person {
protected $one;
private $two;
private $three;
[... many more fields ...]
}
Source https://phpmd.org/rules/codesize.html#toomanyfields
Function getActionables
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function getActionables($dir)
{
$result = array();
if (!is_readable($dir)) {
$this->log->error('GET_ACTIONABLES: directory not readable: '.$dir);
- 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 class Attogram has 51 public methods and attributes. Consider reducing the number of public items to less than 45. Open
class Attogram
{
const ATTOGRAM_VERSION = '0.8.2';
public $startTime; // (float) microsecond time of awakening
- Read upRead up
- Exclude checks
ExcessivePublicCount
Since: 0.1
A large number of public methods and attributes declared in a class can indicate the class may need to be broken up as increased effort will be required to thoroughly test it.
Example
public class Foo {
public $value;
public $something;
public $var;
// [... more more public attributes ...]
public function doWork() {}
public function doMoreWork() {}
public function doWorkAgain() {}
// [... more more public methods ...]
}
Source https://phpmd.org/rules/codesize.html#excessivepubliccount
Method endSlash
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function endSlash()
{
if (!is_array($this->noEndSlash)) {
return;
}
Function getAllSubdirectories
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function getAllSubdirectories($dir, $name)
{
if (!isset($dir) || !$dir || !is_string($dir) || !is_readable($dir)) {
return 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 setModuleTemplates
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function setModuleTemplates()
{
$dirs = $this->getAllSubdirectories($this->modulesDirectory, 'templates');
if (!$dirs) {
//$this->log->debug('setModuleTemplates: no module templates found. Using defaults.');
- 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
Consider simplifying this complex logical expression. Open
if (!$file || !$type || $type == '' || !is_string($type) || !is_string($file) || !is_readable($file)) {
return false;
}
Method __construct
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
\Psr\Log\LoggerInterface $log,
\Psr\Log\LoggerInterface $event,
\Attogram\AttogramDatabaseInterface $database,
\Symfony\Component\HttpFoundation\Request $request,
array $config = array()
Function defaultHomepage
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function defaultHomepage()
{
$this->log->error('using defaultHomepage');
$this->pageHeader('Home');
echo '<div class="container">'
- 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 includeAllPhpFilesInDirectory
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function includeAllPhpFilesInDirectory($dir)
{
$included = array();
if (!is_readable($dir)) {
return $included;
- 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
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return $content;
Function isAdmin
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function isAdmin()
{
if (isset($this->isAdmin) && is_bool($this->isAdmin)) {
return $this->isAdmin;
}
- 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 awaken
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function awaken()
{
// The Site Administrator IP addresses
$this->remember(
'admins',
- 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 exceptionFiles
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function exceptionFiles()
{
switch ($this->request->getPathInfo()) {
case '/robots.txt':
header('Content-Type: text/plain; charset=utf-8');
- 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 virtualWebDirectory() has an NPath complexity of 288. The configured NPath complexity threshold is 200. Open
public function virtualWebDirectory()
{
if (!preg_match('/^\/'.'web'.'\//', $this->request->getPathInfo())) {
return; // not a virtual web directory request
}
- Read upRead up
- 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 getMimeType() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10. Open
public static function getMimeType($file)
{
$mimeType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file);
switch (pathinfo($file, PATHINFO_EXTENSION)) { // https://bugs.php.net/bug.php?id=53035
case 'html':
- 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 method virtualWebDirectory() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public function virtualWebDirectory()
{
if (!preg_match('/^\/'.'web'.'\//', $this->request->getPathInfo())) {
return; // not a virtual web directory request
}
- 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 method route() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public function route()
{
if (is_dir($this->uri[0])) { // requesting a directory?
$this->log->error('ROUTE: 403 Action Forbidden');
$this->error404('No spelunking allowed');
- 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
Remove error control operator '@' on line 123. Open
public function awaken()
{
// The Site Administrator IP addresses
$this->remember(
'admins',
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
Missing class import via use statement (line '448', column '23'). Open
$parser = new \ParsedownExtra();
- 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
Remove error control operator '@' on line 592. Open
public function isAdmin()
{
if (isset($this->isAdmin) && is_bool($this->isAdmin)) {
return $this->isAdmin;
}
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
Remove error control operator '@' on line 90. Open
public function awaken()
{
// The Site Administrator IP addresses
$this->remember(
'admins',
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
Remove error control operator '@' on line 128. Open
public function awaken()
{
// The Site Administrator IP addresses
$this->remember(
'admins',
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
Remove error control operator '@' on line 105. Open
public function awaken()
{
// The Site Administrator IP addresses
$this->remember(
'admins',
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
Remove error control operator '@' on line 133. Open
public function awaken()
{
// The Site Administrator IP addresses
$this->remember(
'admins',
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
Remove error control operator '@' on line 388. Open
public function doCacheHeaders($file)
{
if (!$lastmod = filemtime($file)) {
$lastmod = time();
}
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
Remove error control operator '@' on line 95. Open
public function awaken()
{
// The Site Administrator IP addresses
$this->remember(
'admins',
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
Remove error control operator '@' on line 442. Open
public function getMarkdown($file)
{
if (!$this->isReadableFile($file, '.md')) {
$this->log->error('GET_MARKDOWN: can not read file: '
.$this->webDisplay($file));
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
Remove error control operator '@' on line 100. Open
public function awaken()
{
// The Site Administrator IP addresses
$this->remember(
'admins',
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
Avoid assigning values to variables in if clauses and the like (line '383', column '14'). Open
public function doCacheHeaders($file)
{
if (!$lastmod = filemtime($file)) {
$lastmod = time();
}
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
The method shutdown() contains an exit expression. Open
exit; // The Final Exit
- Read upRead up
- 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
Avoid unused local variables such as '$trash'. Open
$trash = array_shift($this->uri); // take off first blank entry
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid unused local variables such as '$trash'. Open
$trash = array_shift($test); // take off top level
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Call to method getPathInfo
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
rtrim($this->request->getPathInfo(), '/'),
- Exclude checks
Doc-block of $log
in __construct
contains phpdoc param type \Attogram\obj
which is incompatible with the param type \Psr\Log\LoggerInterface
declared in the signature Open
* @param obj $log Debug PSR-3 logger object, interface: \Psr\Log\LoggerInterface
- Exclude checks
Doc-block of $database
in __construct
contains phpdoc param type \Attogram\obj
which is incompatible with the param type \Attogram\AttogramDatabaseInterface
declared in the signature Open
* @param obj $database Attogram Database object, interface: \Attogram\AttogramDatabaseInterface
- Exclude checks
Call to method getPathInfo
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
$this->request->getPathInfo().'/',
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('START The Attogram Framework v'.self::ATTOGRAM_VERSION);
- Exclude checks
Call to method getClientIp
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
$this->log->debug('HOST: '.$this->request->getHost().' IP: '.$this->request->getClientIp());
- Exclude checks
Argument 3 (defaultVal)
is array{}
but \Attogram\Attogram::remember()
takes string
defined at /code/Attogram/Attogram.php:178
Open
array()
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('setUri', $this->uri);
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('setUri', $this->uri);
- Exclude checks
Call to method getRequestUri
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
$this->request->getRequestUri()
- Exclude checks
Call to method getRequestUri
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
$this->request->getRequestUri()
- Exclude checks
Call to method getHost
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
$this->log->debug('HOST: '.$this->request->getHost().' IP: '.$this->request->getClientIp());
- Exclude checks
Argument 3 (defaultVal)
is array{0:'127.0.0.1',1:'::1'}
but \Attogram\Attogram::remember()
takes string
defined at /code/Attogram/Attogram.php:178
Open
array('127.0.0.1', '::1')
- Exclude checks
Call to method getPathInfo
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
$this->uri = explode('/', $this->request->getPathInfo());
- Exclude checks
Saw an @param annotation for configuration,
but it was not found in the param list of function __construct(\Psr\Log\LoggerInterface $log, \Psr\Log\LoggerInterface $event, \Attogram\AttogramDatabaseInterface $database, \Symfony\Component\HttpFoundation\Request $request, array $config = null)
Open
* @param array $configuration (optional) List of configuration values
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('CONFIG:', $this->config);
- Exclude checks
Argument 3 (defaultVal)
is array{}
but \Attogram\Attogram::remember()
takes string
defined at /code/Attogram/Attogram.php:178
Open
array()
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('setUri', $this->uri);
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('setModuleTemplates: File not readable: '.$file);
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('SetModuleTemplates: ', $this->templates);
- Exclude checks
Call to method getPathInfo
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
if (!preg_match('/\/$/', $this->request->getPathInfo())) {
- Exclude checks
Doc-block of $request
in __construct
contains phpdoc param type \Attogram\obj
which is incompatible with the param type \Symfony\Component\HttpFoundation\Request
declared in the signature Open
* @param obj $request Request object, \Symfony\Component\HttpFoundation\Request
- Exclude checks
Parameter $request
has undeclared type \Symfony\Component\HttpFoundation\Request
Open
public function __construct(
- Exclude checks
Call to method getBasePath
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
$this->path = $this->request->getBasePath();
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('HOST: '.$this->request->getHost().' IP: '.$this->request->getClientIp());
- Exclude checks
Parameter $log
has undeclared type \Psr\Log\LoggerInterface
Open
public function __construct(
- Exclude checks
Call to method getPathInfo
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
$this->request->getPathInfo(),
- Exclude checks
Doc-block of $event
in __construct
contains phpdoc param type \Attogram\obj
which is incompatible with the param type \Psr\Log\LoggerInterface
declared in the signature Open
* @param obj $event Event PSR-3 logger object, interface: \Psr\Log\LoggerInterface
- Exclude checks
Parameter $event
has undeclared type \Psr\Log\LoggerInterface
Open
public function __construct(
- Exclude checks
Call to method getPathInfo
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
$this->request->getPathInfo(),
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('isAdmin false '.$cip);
- Exclude checks
Call to method getPathInfo
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
if (!preg_match('/^\/'.'web'.'\//', $this->request->getPathInfo())) {
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('virtualWebDirectory: can not include file: '.$this->webDisplay($file));
- Exclude checks
Reference to instance property server
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
$serverIfNone = trim($this->request->server->get('HTTP_IF_NONE_MATCH'));
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('GET_MARKDOWN: can not find parser');
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('missing pageHeader '.$file.' - using default header');
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('pageFooter');
- Exclude checks
Call to method getPathInfo
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
switch ($this->request->getPathInfo()) {
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('getAdminActions: No module admin actions found');
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('isAdmin false - noadmin override');
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('isAdmin true '.$cip);
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('URI Depth ERROR. uri='.sizeof($this->uri).' allowed='.$depth);
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('ROUTE: 403 Action Forbidden');
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('virtualWebDirectory: can not read file: '.$this->webDisplay($file));
- Exclude checks
Reference to instance property server
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
$serverIfMod = @strtotime($this->request->server->get('HTTP_IF_MODIFIED_SINCE'));
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('GET_MARKDOWN: can not get file contents: '
- Exclude checks
Reference to instance property query
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
if ($this->request->query->has('noadmin')) {
- Exclude checks
Call to method getClientIp
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
$cip = $this->request->getClientIp();
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('ROUTE: action: uri[0]: '.$this->uri[0]);
- Exclude checks
Call to method __construct
from undeclared class \ParsedownExtra
Open
$parser = new \ParsedownExtra();
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('Session started.', $_SESSION);
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('ROUTE: No Parser Found');
- Exclude checks
Reference to undeclared constant \FILEINFO_MIME_TYPE
Open
$mimeType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file);
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('DO_MARKDOWN: '.$file);
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('ERROR404: 404 template not found');
- Exclude checks
Call to method text
from undeclared class \ParsedownExtra
Open
$content = $parser->text($page);
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('getAdminActions: ', array_keys($this->adminActions));
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('pageHeader, title: '.$title);
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('ROUTE: Unreadable action');
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('ROUTE: Action not found. uri[0]='.$this->uri[0]);
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('getActions: ', array_keys($this->actions));
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('ERROR404: exit');
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('ROUTE: Missing action');
- Exclude checks
Call to method getPathInfo
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
$test = explode('/', $this->request->getPathInfo());
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('getActions: No module actions found');
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('using defaultHomepage');
- Exclude checks
Call to method info
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->info('User loggged off');
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('ERROR404: exit');
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('GET_ACTIONABLES: directory not readable: '.$dir);
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('isAdmin false - missing $this->admins array');
- Exclude checks
Reference to undeclared constant \ATTOGRAM_VERSION
(Did you mean self::ATTOGRAM_VERSION) Open
.ATTOGRAM_VERSION.'</a></p>'
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('missing pageFooter '.$file.' - using default footer');
- Exclude checks
Reference to instance property query
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
if ($this->request->query->has('logoff')) {
- Exclude checks
Call to method getSchemeAndHttpHost
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
return $this->request->getSchemeAndHttpHost().$this->path;
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug(
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('GET_MARKDOWN: can not read file: '
- Exclude checks
Call to method debug
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->debug('ROUTE: include '.$action);
- Exclude checks
Call to method error
from undeclared class \Psr\Log\LoggerInterface
Open
$this->log->error('GET_MARKDOWN: parse failed on file: '
- Exclude checks
TODO found Open
// TODO dev - $title input, and default to 1st line of file
- Exclude checks
Avoid variables with short names like $md. Configured minimum length is 3. Open
$md = $dir.DIRECTORY_SEPARATOR.$d;
- Read upRead up
- 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
Avoid variables with short names like $ff. Configured minimum length is 3. Open
$ff = $dir.DIRECTORY_SEPARATOR.$f;
- Read upRead up
- 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;
}
}
}