Passed
Push — master ( 517bd8...f7cc98 )
by Attila
06:55
created

BaseConvention::oneLevelUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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