Completed
Push — master ( 191869...afc708 )
by Frank
08:08
created

UtilCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 23.08 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 9
loc 39
rs 10
c 2
b 0
f 0
wmc 4
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A processCoin() 0 17 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * T3Bot.
4
 *
5
 * @author Frank Nägler <[email protected]>
6
 *
7
 * @link http://www.t3bot.de
8
 * @link http://wiki.typo3.org/T3Bot
9
 */
10
namespace T3Bot\Commands;
11
12
use Slack\Payload;
13
use Slack\RealTimeClient;
14
15
/**
16
 * Class UtilCommand.
17
 *
18
 * @property string commandName
19
 * @property array helpCommands
20
 */
21
class UtilCommand extends AbstractCommand
22
{
23
    /**
24
     * AbstractCommand constructor.
25
     *
26
     * @param Payload        $payload
27
     * @param RealTimeClient $client
28
     */
29 View Code Duplication
    public function __construct(Payload $payload, RealTimeClient $client)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
    {
31
        $this->commandName = 'util';
32
        $this->helpCommands = [
33
            'help' => 'shows this help',
34
            'coin [options]' => 'coin toss with [options] (separate by comma)',
35
        ];
36
        parent::__construct($payload, $client);
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    protected function processCoin() : string
43
    {
44
        $params = $this->params;
45
        array_shift($params);
46
        $params = implode(' ', $params);
47
        $options = array_map('trim', explode(',', $params));
48
        if (count($options) === 1) {
49
            return '*Botty says:* _A complicated decision ..._';
50
        }
51
        if (count(array_count_values($options)) === 1) {
52
            return '*Botty says:* _it is undecidable ..._';
53
        }
54
55
        $option = $options[random_int(0, count($options) - 1)];
56
57
        return '*Botty says:* _' . $option . '_';
58
    }
59
}
60