nopolabs/yabot

View on GitHub
src/Plugin/PluginManager.php

Summary

Maintainability
A
50 mins
Test Coverage

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'");
Severity: Minor
Found in src/Plugin/PluginManager.php - About 25 mins to fix

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 = [];
Severity: Minor
Found in src/Plugin/PluginManager.php - About 25 mins to fix

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'");
Severity: Minor
Found in src/Plugin/PluginManager.php by phpmd

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;
Severity: Minor
Found in src/Plugin/PluginManager.php by phan

Call to method getUsername from undeclared class \Slack\User
Open

        $this->updatePrefixes($authedUser->getUsername());
Severity: Critical
Found in src/Plugin/PluginManager.php by phan

Call to method getName from undeclared class \Slack\Channel
Open

            'channel' => $message->getChannel()->getName(),
Severity: Critical
Found in src/Plugin/PluginManager.php by phan

Call to method getUsername from undeclared class \Slack\User
Open

            return '@'.$this->getAuthedUser()->getUsername().' ';
Severity: Critical
Found in src/Plugin/PluginManager.php by phan

Possibly zero references to use statement for classlike/namespace Exception (\Exception)
Open

use Exception;
Severity: Minor
Found in src/Plugin/PluginManager.php by phan

Parameter $logger has undeclared type \Psr\Log\LoggerInterface
Open

    public function __construct(LoggerInterface $logger)
Severity: Minor
Found in src/Plugin/PluginManager.php by phan

Parameter $authedUser has undeclared type \Slack\User
Open

    public function setAuthedUser(User $authedUser)
Severity: Minor
Found in src/Plugin/PluginManager.php by phan

Property \Nopolabs\Yabot\Plugin\PluginManager->authedUser has undeclared type \Slack\User
Open

    protected $authedUser;
Severity: Minor
Found in src/Plugin/PluginManager.php by phan

Blank line found at end of control structure
Open


Severity: Minor
Found in src/Plugin/PluginManager.php by phpcodesniffer

There must be one blank line after the namespace declaration
Open

namespace Nopolabs\Yabot\Plugin;
Severity: Minor
Found in src/Plugin/PluginManager.php by phpcodesniffer

Expected 1 newline at end of file; 0 found
Open

}
Severity: Minor
Found in src/Plugin/PluginManager.php by phpcodesniffer

There are no issues that match your filters.

Category
Status