89% of 148OPs |
100% of 23Lines |
81% of 26Branches |
57% of 14Paths |
Method | OPs | OPs % | Lines | Line % | Branches | Branches % | Paths | Path % |
---|---|---|---|---|---|---|---|---|
mageekguy\atoum\asserter\resolver::__construct() | 24 | 100% | 4 | 100% | 1 | 0% | 1 | 100% |
mageekguy\atoum\asserter\resolver::setBaseClass() | 15 | 100% | 2 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\asserter\resolver::getBaseClass() | 6 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\asserter\resolver::addNamespace() | 16 | 100% | 2 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\asserter\resolver::getNamespaces() | 6 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\asserter\resolver::resolve() | 50 | 68% | 12 | 100% | 13 | 69% | 5 | 20% |
mageekguy\atoum\asserter\resolver::checkClass() | 31 | 100% | 1 | 100% | 8 | 100% | 4 | 50% |
# | |
---|---|
1 |
<?php |
2 |
|
3 |
namespace mageekguy\atoum\asserter; |
4 |
|
5 |
class resolver |
6 |
{ |
7 |
const defaultBaseClass = 'mageekguy\atoum\asserter'; |
8 |
const defaultNamespace = 'mageekguy\atoum\asserters'; |
9 |
|
10 |
protected $baseClass = ''; |
11 |
protected $namespaces = array(); |
12 |
|
13 |
public function __construct($baseClass = null, $namespace = null)100% |
14 |
{ |
15 |
$this |
16 |
->setBaseClass($baseClass ?: static::defaultBaseClass) |
17 |
->addNamespace($namespace ?: static::defaultNamespace) |
18 |
; |
19 |
} |
20 |
|
21 |
public function setBaseClass($baseClass)100% |
22 |
{ |
23 |
$this->baseClass = trim($baseClass, '\\'); |
24 |
|
25 |
return $this; |
26 |
} |
27 |
|
28 |
public function getBaseClass()100% |
29 |
{ |
30 |
return $this->baseClass; |
31 |
} |
32 |
|
33 |
public function addNamespace($namespace)100% |
34 |
{ |
35 |
$this->namespaces[] = trim($namespace, '\\'); |
36 |
|
37 |
return $this; |
38 |
} |
39 |
|
40 |
public function getNamespaces()100% |
41 |
{ |
42 |
return $this->namespaces; |
43 |
} |
44 |
|
45 |
public function resolve($asserter)100% |
46 |
{ |
47 |
$class = null; |
48 |
|
49 |
if (strpos($asserter, '\\') !== false) |
50 |
{ |
51 |
$class = $this->checkClass($asserter); |
52 |
} |
53 |
else foreach ($this->namespaces as $namespace) |
54 |
{ |
55 |
$class = $this->checkClass($namespace . '\\' . $asserter); |
56 |
|
57 |
if ($class !== null) |
58 |
{ |
59 |
break; |
60 |
} |
61 |
} |
62 |
|
63 |
return $class; |
64 |
} |
65 |
|
66 |
private function checkClass($class)100% |
67 |
{ |
68 |
return (class_exists($class, true) === false || is_subclass_of($class, $this->baseClass) === false ? null : $class); |
69 |
} |
70 |
} |