source/Parser/DirectiveProcessors/SitemapProcessor.php
The method process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
Open
} else {
$this->log(strtr('{directive} with value {faulty} skipped as already exists for {useragent}', [
'{directive}' => Directive::SITEMAP,
'{faulty}' => $entry,
'{useragent}' => $currentUserAgent,
- 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
Avoid unused parameters such as '$prevLine'. Open
Open
public function process(string $line, array & $root, string & $currentUserAgent = '*', string $prevLine = '') {
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Opening brace of a class must be on the line after the definition Open
Open
class SitemapProcessor extends AbstractDirectiveProcessor implements DirectiveProcessorInterface {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return Directive::SITEMAP;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (!isset($root[$currentUserAgent][Directive::SITEMAP])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$parts = explode(':', $line);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$entry = implode(':', $trimmed);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$root[$currentUserAgent][Directive::SITEMAP][] = $entry;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
]));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public function getDirectiveName(): string {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'{directive}' => Directive::SITEMAP,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'{useragent}' => $currentUserAgent,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'{faulty}' => $entry,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public function process(string $line, array & $root, string & $currentUserAgent = '*', string $prevLine = '') {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$root[$currentUserAgent][Directive::SITEMAP] = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
array_shift($parts);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$trimmed = array_map('trim', $parts);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (!in_array($entry, $root[$currentUserAgent][Directive::SITEMAP])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$this->log(strtr('{directive} with value {faulty} skipped as already exists for {useragent}', [
- Exclude checks
Opening brace should be on a new line Open
Open
public function process(string $line, array & $root, string & $currentUserAgent = '*', string $prevLine = '') {
- Exclude checks
Opening brace should be on a new line Open
Open
public function getDirectiveName(): string {
- Exclude checks