BaseChatCommand::getName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
c 2
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Chat;
5
6
/**
7
 * Base chat Command
8
 *
9
 * @author Jakub Konečný
10
 * @property string $name
11
 */
12 1
abstract class BaseChatCommand implements IChatCommand
13
{
14
    use \Nette\SmartObject;
15
16
    protected string $name = "";
17
18
    /**
19
     * Defines default name for the chat command
20
     * The class' name has to follow XCommand pattern
21
     */
22
    public function getName(): string
23
    {
24 1
        if ($this->name !== "") {
25 1
            return $this->name;
26
        }
27 1
        $className = join('', array_slice(explode('\\', static::class), -1));
28 1
        return strtolower(str_replace("Command", "", $className));
29
    }
30
31
    public function setName(string $name): void
32
    {
33 1
        $this->name = $name;
34 1
    }
35
}
36