Completed
Push — master ( b0bc39...c39dfb )
by Emily
10s
created

ClassName   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 47
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 2
A __toString() 0 6 2
1
<?php
2
/**
3
 * This file is part of the Composite Utils package.
4
 *
5
 * (c) Emily Shepherd <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the
8
 * LICENSE.md file that was distributed with this source code.
9
 *
10
 * @package spaark/composite-utils
11
 * @author Emily Shepherd <[email protected]>
12
 * @license MIT
13
 */
14
15
namespace Spaark\CompositeUtils\Model;
16
17
use Spaark\CompositeUtils\Traits\AllReadableTrait;
18
19
/**
20
 * Models a classname which has both a namespace and a classname
21
 */
22
class ClassName
23
{
24
    use AllReadableTrait;
25
26
    /**
27
     * @var string
28
     */
29
    protected $namespace = '';
30
31
    /**
32
     * @var string
33
     */
34
    protected $classname;
35
36
    /**
37
     * Constructs the ClassName by taking a fully qualified classname
38
     * and splitting it into its namespace and classname sections
39
     *
40
     * @param string $classname
41
     */
42 32
    public function __construct(string $classname)
43
    {
44 32
        preg_match('/(.+)\\\\([a-z_A-Z0-9]+)/', $classname, $matches);
45
46 32
        if (!$matches)
0 ignored issues
show
Bug Best Practice introduced by
The expression $matches of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
47
        {
48 7
            $this->classname = $classname;
49
        }
50
        else
51
        {
52 27
            $this->classname = $matches[2];
53 27
            $this->namespace = $matches[1];
54
        }
55 32
    }
56
57
    /**
58
     * Returns the fully qualified classname
59
     *
60
     * @return string
61
     */
62 14
    public function __toString()
63
    {
64
        return
65 14
              ($this->namespace ? $this->namespace . '\\' : '')
66 14
            . $this->classname;
67
    }
68
}
69