88% of 273OPs |
96% of 53Lines |
75% of 55Branches |
20% of 44Paths |
Method | OPs | OPs % | Lines | Line % | Branches | Branches % | Paths | Path % |
---|---|---|---|---|---|---|---|---|
mageekguy\atoum\annotations\extractor::extract() | 173 | 82% | 34 | 94% | 35 | 69% | 34 | 3% |
mageekguy\atoum\annotations\extractor::setHandler() | 11 | 100% | 2 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\annotations\extractor::unsetHandler() | 16 | 100% | 5 | 100% | 4 | 100% | 2 | 100% |
mageekguy\atoum\annotations\extractor::getHandlers() | 6 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\annotations\extractor::resetHandlers() | 9 | 100% | 2 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\annotations\extractor::toBoolean() | 36 | 94% | 8 | 100% | 12 | 75% | 4 | 50% |
mageekguy\atoum\annotations\extractor::toArray() | 22 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
# | |
---|---|
1 |
<?php |
2 |
|
3 |
namespace mageekguy\atoum\annotations; |
4 |
|
5 |
class extractor |
6 |
{ |
7 |
protected $handlers = array(); |
8 |
|
9 |
public function extract($comments)94% |
10 |
{ |
11 |
$comments = trim((string) $comments); |
12 |
|
13 |
if (substr($comments, 0, 2) == '/*' && substr($comments, -2) == '*/') |
14 |
{ |
15 |
$comments = preg_replace('#^\/\*+([^*])#', '\1', $comments); |
16 |
$comments = preg_replace('#([^*])\*+/$#', '\1', $comments); |
17 |
$comments = trim($comments); |
18 |
|
19 |
foreach (preg_split("/\r?\n/", $comments) as $comment) |
20 |
{ |
21 |
$cleanComment = ltrim($comment, "*@ \t\r\n\0\x0B"); |
22 |
|
23 |
if ($cleanComment != $comment) |
24 |
{ |
25 |
$comment = preg_split("/\s+/", $cleanComment); |
26 |
|
27 |
if ($comment) |
28 |
{ |
29 |
$annotation = strtolower($comment[0]); |
30 |
|
31 |
switch (sizeof($comment)) |
32 |
{ |
33 |
case 1: |
34 |
$value = true; |
35 |
break; |
36 |
|
37 |
case 2: |
38 |
$value = $comment[1]; |
39 |
break; |
40 |
|
41 |
default: |
42 |
$value = join(' ', array_slice($comment, 1)); |
43 |
} |
44 |
|
45 |
foreach ($this->handlers as $handlerAnnotation => $handlerValue) |
46 |
{ |
47 |
if ($annotation == strtolower($handlerAnnotation)) |
48 |
{ |
49 |
call_user_func_array($handlerValue, array($value)); |
50 |
} |
51 |
} |
52 |
} |
53 |
} |
54 |
} |
55 |
} |
56 |
|
57 |
return $this; |
58 |
} |
59 |
|
60 |
public function setHandler($annotation, \closure $handler)100% |
61 |
{ |
62 |
$this->handlers[$annotation] = $handler; |
63 |
|
64 |
return $this; |
65 |
} |
66 |
|
67 |
public function unsetHandler($annotation)100% |
68 |
{ |
69 |
if (isset($this->handlers[$annotation]) === true) |
70 |
{ |
71 |
unset($this->handlers[$annotation]); |
72 |
} |
73 |
|
74 |
return $this; |
75 |
} |
76 |
|
77 |
public function getHandlers()100% |
78 |
{ |
79 |
return $this->handlers; |
80 |
} |
81 |
|
82 |
public function resetHandlers()100% |
83 |
{ |
84 |
$this->handlers = array(); |
85 |
|
86 |
return $this; |
87 |
} |
88 |
|
89 |
public static function toBoolean($value)100% |
90 |
{ |
91 |
switch (strtolower((string) $value)) |
92 |
{ |
93 |
case 'on': |
94 |
case '1': |
95 |
case 'true': |
96 |
return true; |
97 |
|
98 |
default: |
99 |
return false; |
100 |
} |
101 |
} |
102 |
|
103 |
public static function toArray($value)100% |
104 |
{ |
105 |
return array_values(array_unique(preg_split('/\s+/', $value))); |
106 |
} |
107 |
} |