nopolabs/yabot

View on GitHub
src/Plugin/PluginTrait.php

Summary

Maintainability
A
25 mins
Test Coverage

Function methodMatch has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function methodMatch(Message $message)
    {
        foreach ($this->getMethodMatchers() as $methodMatcher) {
            /** @var MethodMatcher $methodMatcher */
            if ($matches = $methodMatcher->matches($message)) {
Severity: Minor
Found in src/Plugin/PluginTrait.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 '89', column '17').
Open

    protected function methodMatch(Message $message)
    {
        foreach ($this->getMethodMatchers() as $methodMatcher) {
            /** @var MethodMatcher $methodMatcher */
            if ($matches = $methodMatcher->matches($message)) {
Severity: Minor
Found in src/Plugin/PluginTrait.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 Exception (\Exception)
Open

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

Argument #1 of this call to \preg_match is typically a literal or constant but isn't, but argument #2 (which is typically a variable) is a literal or constant. The arguments may be in the wrong order.
Open

            preg_match($pattern, '');
Severity: Minor
Found in src/Plugin/PluginTrait.php by phan

Blank line found at end of control structure
Open


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

Blank line found at start of control structure
Open

        try {
Severity: Minor
Found in src/Plugin/PluginTrait.php by phpcodesniffer

Expected 1 space after FUNCTION keyword; 0 found
Open

            $params['patterns'] = array_map(function($pattern) use ($search, $replace) {
Severity: Minor
Found in src/Plugin/PluginTrait.php by phpcodesniffer

Line exceeds 120 characters; contains 137 characters
Open

        $this->pluginMatcher = new PluginMatcher($pluginId, $this->getIsBot(), $this->getChannels(), $this->getUsers(), $this->getLog());
Severity: Minor
Found in src/Plugin/PluginTrait.php by phpcodesniffer

Expected 1 newline at end of file; 0 found
Open

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

There are no issues that match your filters.

Category
Status