Method handle
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function handle(EventMessage $event)
{
if ($event instanceof \PAMI\Message\Event\AsyncAGIEvent) {
if ($event->getSubEvent() == 'Start') {
switch($pid = pcntl_fork())
Function handle
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function handle(EventMessage $event)
{
if ($event instanceof \PAMI\Message\Event\AsyncAGIEvent) {
if ($event->getSubEvent() == 'Start') {
switch($pid = pcntl_fork())
- 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
Missing class import via use statement (line '73', column '36'). Open
$agi = new \PAMI\AsyncAgi\AsyncClientImpl(array(
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '77', column '36'). Open
$app = new MyPAGIApplication(array(
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid using static access to class '\Logger' in method 'handle'. Open
$logger = \Logger::getLogger(__CLASS__);
- 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 unused local variables such as '$logger'. Open
$logger = \Logger::getLogger(__CLASS__);
- 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 '$pid'. Open
switch($pid = pcntl_fork())
- 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 '$status'. Open
pcntl_wait($status);
- 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
The method handle() contains an exit expression. Open
exit(0);
- 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
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class ListenerTest implements IEventListener
- 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 57 and the first side effect is on line 30. Open
<?php
- Exclude checks
The property $_pamiOptions is not named in camelCase. Open
class ListenerTest implements IEventListener
{
private $_client;
private $_id;
private $_pamiOptions;
- Read upRead up
- 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 $_client is not named in camelCase. Open
class ListenerTest implements IEventListener
{
private $_client;
private $_id;
private $_pamiOptions;
- Read upRead up
- 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 $_id is not named in camelCase. Open
class ListenerTest implements IEventListener
{
private $_client;
private $_id;
private $_pamiOptions;
- Read upRead up
- 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
Property name "$_id" should not be prefixed with an underscore to indicate visibility Open
private $_id;
- Exclude checks
Property name "$_client" should not be prefixed with an underscore to indicate visibility Open
private $_client;
- Exclude checks
Property name "$_pamiOptions" should not be prefixed with an underscore to indicate visibility Open
private $_pamiOptions;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->_client->close();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$listener = new ListenerTest($options);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo $e->getMessage() . "\n";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
usleep(1000);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->_client->process();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while(true)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$listener->run();
- Exclude checks
Expected 1 space after closing parenthesis; found 17 Open
switch($pid = pcntl_fork())
- Exclude checks
Expected 1 space after TRY keyword; newline found Open
try
- Exclude checks
Space before opening parenthesis of function call prohibited Open
exit (254);
- Exclude checks
Expected 1 space after SWITCH keyword; 0 found Open
switch($pid = pcntl_fork())
- Exclude checks
Expected 1 space after WHILE keyword; 0 found Open
while(true)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
while(true)
- Exclude checks