BaseConvention   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 5
c 1
b 0
f 1
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A oneLevelUp() 0 7 2
A getNamespace() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Contains the BaseConvention class.
7
 *
8
 * @copyright   Copyright (c) 2017 Attila Fulop
9
 * @author      Attila Fulop
10
 * @license     MIT
11
 * @since       2017-04-14
12
 *
13
 */
14
15
namespace Konekt\Concord\Conventions;
16
17
/**
18
 * Contains some utility classes to be used by concrete convention classes
19
 */
20
abstract class BaseConvention
21
{
22
    /**
23
     * Returns the namespace part of a class
24
     *
25
     * @param string $class
26
     *
27
     * @return string
28
     */
29
    protected function getNamespace(string $class)
30
    {
31
        return $this->oneLevelUp($class);
32
    }
33
34
    /**
35
     * Chops the last part of the namespace eg \a\b\c => \a\b
36
     *
37
     * @param string $namespace
38
     *
39
     * @return bool|string
40
     */
41
    protected function oneLevelUp(string $namespace)
42
    {
43
        if ($pos = strrpos($namespace, '\\')) {
44
            return substr($namespace, 0, $pos);
45
        }
46
47
        return '';
48
    }
49
}
50