Function dispatchToPrefixes
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function dispatchToPrefixes(array $prefixMap, Message $message, string $text)
{
foreach ($prefixMap as $prefix => $plugins) {
if ($matches = $this->matchesPrefix($prefix, $text)) {
$this->debug("Dispatching prefix '$prefix'");
- 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 updatePrefixes
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function updatePrefixes($authedUsername)
{
$updatedPriorityMap = [];
foreach ($this->getPriorityMap() as $priority => $prefixMap) {
$updatedPrefixMap = [];
- 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 assigning values to variables in if clauses and the like (line '124', column '17'). Open
protected function dispatchToPrefixes(array $prefixMap, Message $message, string $text)
{
foreach ($prefixMap as $prefix => $plugins) {
if ($matches = $this->matchesPrefix($prefix, $text)) {
$this->debug("Dispatching prefix '$prefix'");
- 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
Possibly zero references to use statement for classlike/namespace Yabot
(\Nopolabs\Yabot\Yabot)
Open
use Nopolabs\Yabot\Yabot;
- Exclude checks
Call to method getUsername
from undeclared class \Slack\User
Open
$this->updatePrefixes($authedUser->getUsername());
- Exclude checks
Call to method getName
from undeclared class \Slack\Channel
Open
'channel' => $message->getChannel()->getName(),
- Exclude checks
Call to method getUsername
from undeclared class \Slack\User
Open
return '@'.$this->getAuthedUser()->getUsername().' ';
- Exclude checks
Possibly zero references to use statement for classlike/namespace Exception
(\Exception)
Open
use Exception;
- Exclude checks
Parameter $logger
has undeclared type \Psr\Log\LoggerInterface
Open
public function __construct(LoggerInterface $logger)
- Exclude checks
Parameter $authedUser
has undeclared type \Slack\User
Open
public function setAuthedUser(User $authedUser)
- Exclude checks
Property \Nopolabs\Yabot\Plugin\PluginManager->authedUser
has undeclared type \Slack\User
Open
protected $authedUser;
- Exclude checks
Blank line found at end of control structure Open
- Exclude checks
There must be one blank line after the namespace declaration Open
namespace Nopolabs\Yabot\Plugin;
- Exclude checks
Expected 1 newline at end of file; 0 found Open
}
- Exclude checks