PackageParser   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 80.95%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 47
ccs 17
cts 21
cp 0.8095
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A parse() 0 6 1
A toDirectoryName() 0 4 1
A toPsr4() 0 4 1
A toPackageName() 0 4 1
A setPackageName() 0 4 1
A toHuman() 0 5 1
1
<?php namespace Packedge\Workbench\Parsers;
2
3
class PackageParser implements ParserInterface
4
{
5
    protected $packageName;
6
7 18
    public function __construct($packageName = null)
8
    {
9
        if($packageName)
10 18
        {
11
            $this->setPackageName($packageName);
12
        }
13 18
    }
14
15 9
    public function parse($packageName)
16
    {
17 9
        $parser = new static;
18 9
        $parser->setPackageName($packageName);
19 9
        return $parser;
20
    }
21
22 3
    public function toDirectoryName()
23
    {
24 3
        return str_replace('/', '-', $this->packageName);
25
    }
26
27 3
    public function toPsr4()
28
    {
29 3
        return str_replace(' ', '\\\\', ucwords(str_replace('/', ' ', $this->packageName)));
30
    }
31
32
    public function toPackageName()
33
    {
34
        return $this->packageName;
35
    }
36
    /**
37
     * @param mixed $packageName
38
     */
39 9
    public function setPackageName($packageName)
40
    {
41 9
        $this->packageName = trim(strtolower($packageName));
42 9
    }
43
44 3
    public function toHuman()
45
    {
46 3
        $name = explode('/', $this->packageName)[1];
47 3
        return ucwords(str_replace('-', ' ', $name));
48
    }
49
}
50