doc/examples/sms/example.php
The method handle uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
Open
else{
echo 'Unrecognized encoding - printing message in this encoding : ' ;
$event->getContentEncoding();
echo '\n Message: ' ;
$event->getContent();
- 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
Each class must be in a namespace of at least one level (a top-level vendor name) Open
Open
class A 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 58 and the first side effect is on line 32. Open
Open
<?php
- Exclude checks
Avoid classes with short names like A. Configured minimum length is 3. Open
Open
class A implements IEventListener
{
public function handle(EventMessage $event)
{
//This Handler will print the incoming message.
- Read upRead up
- Exclude checks
ShortClassName
Since: 2.9
Detects when classes or interfaces have a very short name.
Example
class Fo {
}
interface Fo {
}
Source https://phpmd.org/rules/naming.html#shortclassname
Function closing brace must go on the next line following the body; found 3 blank lines before brace Open
Open
}
- Exclude checks
Blank line found at start of control structure Open
Open
if ($event->getContentEncoding()=='base64'){
- Exclude checks
Blank line found at end of control structure Open
Open
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
if ($argc <7 ) {
- Exclude checks
Closing brace indented incorrectly; expected 8 spaces, found 12 Open
Open
}
- Exclude checks
Expected 1 space after WHILE keyword; 0 found Open
Open
while(true)//(time() - $time) < 60) // Wait for events.
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
Open
if ($event->getContentEncoding()=='base64'){
- Exclude checks
Expected 1 space after closing parenthesis; found "//(time() - $time) < 60) // Wait for events.\n " Open
Open
while(true)//(time() - $time) < 60) // Wait for events.
- Exclude checks
Expected 1 space after ELSE keyword; 0 found Open
Open
else{
- Exclude checks
Expected 1 space after TRY keyword; newline found Open
Open
try
- Exclude checks
Space before opening parenthesis of function call prohibited Open
Open
exit (254);
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
Open
}
- Exclude checks
Closing brace indented incorrectly; expected 8 spaces, found 12 Open
Open
}
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
Open
if($argv[7]==1){
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
Open
}
- Exclude checks
Expected 1 space after closing brace; newline found Open
Open
}
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
Open
if($argv[7]==1){
- Exclude checks