guruMeditationError accesses the super-global variable $_GET. Open
public function guruMeditationError($error = '', $fix = '')
{
echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">'
.'<meta name="viewport" content="width=device-width, initial-scale=1">'
.'<title>Guru Meditation Error</title>'
- 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
The class GuruMeditationLoader has 12 public methods. Consider refactoring GuruMeditationLoader to keep number of public methods under 10. Open
class GuruMeditationLoader
{
/** @var array List of debug messages */
public $debugLog;
- 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
The class GuruMeditationLoader has an overall complexity of 67 which is very high. The configured complexity threshold is 50. Open
class GuruMeditationLoader
{
/** @var array List of debug messages */
public $debugLog;
- Exclude checks
File index.php
has 294 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
// Attogram Framework - Guru Meditation Loader - v0.6.0
namespace Attogram;
Method guruMeditationErrorHandler
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function guruMeditationErrorHandler(
$level,
$message,
$file = '',
$line = '',
Method tranquility
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function tranquility()
{
// Speed things up! gz compession
//if (ob_start('ob_gzhandler')) {
// $this->debug('tranquility: ob_gzhandler active');
Method meditate
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function meditate()
{
// Set default configuration
$this->config = array();
$this->config['attogramDirectory'] = '..'.DIRECTORY_SEPARATOR;
Function tranquility
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function tranquility()
{
// Speed things up! gz compession
//if (ob_start('ob_gzhandler')) {
// $this->debug('tranquility: ob_gzhandler active');
- 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 ((isset($this->config['debug']) // debug is true...
&& is_bool($this->config['debug'])
&& $this->config['debug'])
||
($request->query->has('debug') // admin debug url override ?debug
Method guruMeditationErrorHandler
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
$level,
$message,
$file = '',
$line = '',
$context = array()
Function guruMeditationErrorHandler
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function guruMeditationErrorHandler(
$level,
$message,
$file = '',
$line = '',
- 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;
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return;
Function meditate
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function meditate()
{
// Set default configuration
$this->config = array();
$this->config['attogramDirectory'] = '..'.DIRECTORY_SEPARATOR;
- 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 guruMeditationErrorHandler() has an NPath complexity of 306. The configured NPath complexity threshold is 200. Open
public function guruMeditationErrorHandler(
$level,
$message,
$file = '',
$line = '',
- 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 guruMeditationErrorHandler() has a Cyclomatic Complexity of 22. The configured cyclomatic complexity threshold is 10. Open
public function guruMeditationErrorHandler(
$level,
$message,
$file = '',
$line = '',
- 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 tranquility() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
public function tranquility()
{
// Speed things up! gz compession
//if (ob_start('ob_gzhandler')) {
// $this->debug('tranquility: ob_gzhandler active');
- 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
Missing class import via use statement (line '210', column '24'). Open
$log = new \Psr\Log\NullLogger();
- 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 '203', column '34'). Open
$streamHandler = new \Monolog\Handler\StreamHandler('php://output');
- 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 '202', column '24'). Open
$log = new \Monolog\Logger('debug');
- 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 '227', column '37'). Open
$event->pushHandler(new \Attogram\EventLogger($database));
- 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 '226', column '26'). Open
$event = new \Monolog\Logger('event'); // Setup the Event Logger
- 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 '231', column '26'). Open
$event = new \Psr\Log\NullLogger();
- 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 '206', column '46'). Open
$streamHandler->setFormatter(new \Monolog\Formatter\LineFormatter($format, $dateformat));
- 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 '207', column '35'). Open
$log->pushHandler(new \Monolog\Handler\BufferHandler($streamHandler));
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid using static access to class 'Attogram\Attogram' in method 'meditateDeeper'. Open
$configDirs = Attogram::getAllSubdirectories(
$this->config['modulesDirectory'],
'configs'
);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'Attogram\Attogram' in method 'focusInnerEye'. Open
$counts = Attogram::loadModuleSubdirectories(
$this->config['modulesDirectory'],
'includes'
);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'Attogram\Attogram' in method 'meditateDeeper'. Open
Attogram::includeAllPhpFilesInDirectory($dir);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Symfony\Component\HttpFoundation\Request' in method 'tranquility'. Open
$request = Request::createFromGlobals();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method tranquility uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$log = new \Psr\Log\NullLogger();
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method guruMeditationError() contains an exit expression. Open
exit; // Exit everything
- 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
Call to method __construct
from undeclared class \Psr\Log\NullLogger
Open
$event = new \Psr\Log\NullLogger();
- Exclude checks
Reference to undeclared property \Attogram\GuruMeditationLoader->configLog
Open
if (isset($_GET['debug']) && isset($this->configLog)) {
- Exclude checks
Reference to undeclared property \Attogram\GuruMeditationLoader->configLog
Open
if (isset($this->configLog) && is_array($this->configLog)) {
- Exclude checks
Reference to undeclared property \Attogram\GuruMeditationLoader->configLog
Open
foreach ($this->configLog as $message) {
- Exclude checks
Call to method __construct
from undeclared class \Monolog\Handler\StreamHandler
Open
$streamHandler = new \Monolog\Handler\StreamHandler('php://output');
- Exclude checks
Call to method setFormatter
from undeclared class \Monolog\Handler\StreamHandler
Open
$streamHandler->setFormatter(new \Monolog\Formatter\LineFormatter($format, $dateformat));
- Exclude checks
Call to method createFromGlobals
from undeclared class \Symfony\Component\HttpFoundation\Request
Open
$request = Request::createFromGlobals();
- Exclude checks
Call to method pushHandler
from undeclared class \Monolog\Logger
Open
$log->pushHandler(new \Monolog\Handler\BufferHandler($streamHandler));
- Exclude checks
Call to method __construct
from undeclared class \Monolog\Logger
Open
$event = new \Monolog\Logger('event'); // Setup the Event Logger
- Exclude checks
Argument 1 (log)
is \Monolog\Logger|\Psr\Log\NullLogger
but \Attogram\Attogram::__construct()
takes \Psr\Log\LoggerInterface
defined at /code/Attogram/Attogram.php:52
Open
$log, // The Debug Logger Object
- Exclude checks
Call to method __construct
from undeclared class \Psr\Log\NullLogger
Open
$log = new \Psr\Log\NullLogger();
- Exclude checks
Call to method __construct
from undeclared class \Monolog\Handler\BufferHandler
Open
$log->pushHandler(new \Monolog\Handler\BufferHandler($streamHandler));
- Exclude checks
Call to method __construct
from undeclared class \Monolog\Formatter\LineFormatter
Open
$streamHandler->setFormatter(new \Monolog\Formatter\LineFormatter($format, $dateformat));
- Exclude checks
Call to method debug
from undeclared class \Monolog\Logger
Open
$log->debug($message);
- Exclude checks
Call to method __construct
from undeclared class \Attogram\SqliteDatabase
Open
$database = new SqliteDatabase( // init the database, sans-connection
- Exclude checks
Call to method pushHandler
from undeclared class \Monolog\Logger
Open
$event->pushHandler(new \Attogram\EventLogger($database));
- Exclude checks
Reference to undeclared property \Attogram\GuruMeditationLoader->configLog
Open
$this->configLog[] = $msg;
- Exclude checks
Argument 2 (event)
is ?\Monolog\Logger|?\Psr\Log\NullLogger
but \Attogram\Attogram::__construct()
takes \Psr\Log\LoggerInterface
defined at /code/Attogram/Attogram.php:52
Open
$event, // The Event Logger Object
- Exclude checks
Reference to undeclared property \Attogram\GuruMeditationLoader->configLog
Open
echo implode('<br />💠', $this->configLog);
- Exclude checks
Call to method __construct
from undeclared class \Monolog\Logger
Open
$log = new \Monolog\Logger('debug');
- Exclude checks
Argument 2 (newvalue)
is 32767
but \ini_set()
takes string
Open
ini_set('display_errors', E_ALL); // display all errors
- Exclude checks
A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 14 and the first side effect is on line 8. Open
<?php
- Exclude checks
Function closing brace must go on the next line following the body; found 1 blank lines before brace Open
} // end function __construct()
- Exclude checks
Function closing brace must go on the next line following the body; found 1 blank lines before brace Open
} // end function tranquility()
- Exclude checks