Help::index()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 9.6333
c 0
b 0
f 0
cc 4
nc 2
nop 0
crap 4
1
<?php
2
3
namespace Botonomous\plugin\help;
4
5
use Botonomous\Command;
6
use Botonomous\plugin\AbstractPlugin;
7
use Botonomous\utility\FormattingUtility;
8
9
/**
10
 * Class Help.
11
 */
12
class Help extends AbstractPlugin
13
{
14
    /**
15
     * @throws \Exception
16
     *
17
     * @return string
18
     */
19 2
    public function index(): string
20
    {
21 2
        $allCommands = $this->getSlackbot()->getCommands();
22
23 2
        $response = '';
24 2
        if (!empty($allCommands)) {
25 2
            $formattingUtility = (new FormattingUtility());
26
27 2
            foreach ($allCommands as $commandName => $commandObject) {
28 2
                if (!$commandObject instanceof Command) {
29 1
                    continue;
30
                }
31
32 1
                $response .= "/{$commandName} - ".$commandObject->getDescription().$formattingUtility->newLine();
33
            }
34
        }
35
36 2
        return $response;
37
    }
38
}
39