BaseCondition::getName()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 8
c 1
b 0
f 1
nc 5
nop 0
dl 0
loc 12
ccs 8
cts 8
cp 1
crap 4
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Menu;
5
6
use Nette\Utils\Strings;
7
8
/**
9
 * BaseCondition
10
 *
11
 * @author Jakub Konečný
12
 * @property-read string $name
13
 */
14 1
abstract class BaseCondition implements IMenuItemCondition {
15
  use \Nette\SmartObject;
16
17
  protected string $name;
18
  
19
  public function getName(): string {
20 1
    $reflection = new \ReflectionClass($this);
21 1
    if($reflection->hasProperty("name")) {
22 1
      if(isset($this->name)) {
23 1
        return $this->name;
24
      }
25
    }
26 1
    $class = (string) Strings::after(static::class, "\\", -1);
27 1
    if(str_starts_with($class, "Condition")) {
28 1
      $class = (string) Strings::after($class, "Condition");
29
    }
30 1
    return Strings::lower($class);
31
  }
32
}
33
?>