sovereignbot/citadel

View on GitHub

Showing 284 of 284 total issues

The class Sovereign has 17 fields. Consider redesigning Sovereign to keep the number of fields under 15.
Open

class Sovereign
{
    /**
     * @var WebSocket
     */
Severity: Minor
Found in src/Sovereign.php by phpmd

TooManyFields

Since: 0.1

Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

Example

class Person {
   protected $one;
   private $two;
   private $three;
   [... many more fields ...]
}

Source https://phpmd.org/rules/codesize.html#toomanyfields

Method run has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function run()
    {
        $memes = array(
            'dank meme',
            '>mfw no gf',
Severity: Minor
Found in src/Plugins/onMessage/meme.php - About 1 hr to fix

Function run has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    public function run()
    {
        // Most EVE players on Discord use their ingame name, so lets support @highlights
        $explode = explode(" ", $this->message->content);
        unset($explode[0]);
Severity: Minor
Found in src/Plugins/onMessage/char.php - About 1 hr 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

Method __construct has 10 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function __construct($discord, $log, $config, $db, $curl, $settings, $permissions, $serverConfig, $users, $extras)
Severity: Major
Found in src/Plugins/onTimer/kills.php - About 1 hr to fix

Method __construct has 10 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function __construct($message, $discord, $log, $config, $db, $curl, $settings, $permissions, $serverConfig, $users)
Severity: Major
Found in src/Plugins/onMessage/cleverbot.php - About 1 hr to fix

Method __construct has 10 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function __construct($discord, $log, $config, $db, $curl, $settings, $permissions, $serverConfig, $users, $extras)
Severity: Major
Found in src/Plugins/onTimer/memory.php - About 1 hr to fix

Method __construct has 10 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function __construct($discord, $log, $config, $db, $curl, $settings, $permissions, $serverConfig, $users, $extras)
Severity: Major
Found in src/Plugins/onTimer/jabberPingsTheCulture.php - About 1 hr to fix

Method run has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function run()
    {
        $explode = explode(" ", $this->message->content);
        $authString = isset($explode[1]) ? $explode[1] : "";

Severity: Minor
Found in src/Plugins/onMessage/auth.php - About 1 hr to fix

Method run has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function run()
    {
        $choices = array(
            'It is certain',
            'It is decidedly so',
Severity: Minor
Found in src/Plugins/onMessage/eightball.php - About 1 hr to fix

Method run has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function run()
    {
        $handle = fopen("/tmp/discord.db", "r+");
        flock($handle, LOCK_EX);

Severity: Minor
Found in src/Plugins/onTimer/jabberPingsTheCulture.php - About 1 hr to fix

Identical blocks of code found in 2 locations. Consider refactoring.
Open

            foreach ($this->discord->getClient()->getGuildsAttribute()->all() as $guild) {
                $this->extras['memberCount'] += $guild->member_count;
                $this->extras['guildCount']++;
                $this->extras['guild']['memberCount']["id{$guild->id}"] = $guild->member_count;
                $this->extras['onMessagePlugins'] = $this->onMessage;
Severity: Major
Found in src/Sovereign.php and 1 other location - About 1 hr to fix
src/Sovereign.php on lines 202..208

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 101.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

                foreach ($this->discord->getClient()->getGuildsAttribute()->all() as $guild) {
                    $this->extras['memberCount'] += $guild->member_count;
                    $this->extras['guildCount']++;
                    $this->extras['guild']['memberCount']["id{$guild->id}"] = $guild->member_count;
                    $this->extras['onMessagePlugins'] = $this->onMessage;
Severity: Major
Found in src/Sovereign.php and 1 other location - About 1 hr to fix
src/Sovereign.php on lines 175..181

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 101.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function run has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    public function run()
    {
        $handle = fopen("/tmp/discord.db", "r+");
        flock($handle, LOCK_EX);

Severity: Minor
Found in src/Plugins/onTimer/jabberPingsTheCulture.php - About 55 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

Method run has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function run(Message $message, Discord $discord, WebSocket $webSocket, Logger $log, &$audioStreams, Channel $channel, cURL $curl)
Severity: Major
Found in src/Plugins/onVoice/horn.php - About 50 mins to fix

Method set has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function set($userID, $name, $lastStatus, $game, $lastSeen, $lastSpoke, $lastWritten)
Severity: Major
Found in src/Lib/Users.php - About 50 mins to fix

Method run has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function run(Message $message, Discord $discord, WebSocket $webSocket, Logger $log, &$audioStreams, Channel $channel, cURL $curl)
Severity: Major
Found in src/Plugins/onVoice/reapers.php - About 50 mins to fix

Method addPlugin has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function addPlugin($type, $command, $class, $perms, $description, $usage, $timer)
Severity: Major
Found in src/Sovereign.php - About 50 mins to fix

Method run has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function run(Message $message, Discord $discord, WebSocket $webSocket, Logger $log, &$audioStreams, Channel $channel, cURL $curl)
Severity: Major
Found in src/Plugins/onVoice/warnings.php - About 50 mins to fix

Avoid variables with short names like $db. Configured minimum length is 3.
Open

    public function __construct($message, $discord, $log, $config, $db, $curl, $settings, $permissions, $serverConfig, $users)
Severity: Minor
Found in src/Plugins/onMessage/cleverbot.php by phpmd

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

Avoid classes with short names like Db. Configured minimum length is 3.
Open

class Db
{
    /**
     * @var Config
     */
Severity: Minor
Found in src/Lib/Db.php by phpmd

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

Severity
Category
Status
Source
Language