Annotation.php
1.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Lackoxygen\TiktokShop\Mock;
use Lackoxygen\TiktokShop\Util\Preg;
class Annotation
{
/**
* @param $class
* @param $method
* @return array
* @throws \ReflectionException
*/
public function method($class, $method): array
{
$ref = new \ReflectionClass($class);
$interfaces = $ref->getInterfaces();
/**
* @var \ReflectionClass $interface
*/
$interface = array_shift($interfaces);
if (is_null($interface)) {
return [];
}
$method = $interface->getMethod($method);
$docs = $method->getDocComment();
$docsItems = Preg::annotation($docs);
if (!$docsItems) {
return [];
}
$docsArray = [];
foreach ($docsItems as $item) {
$line = Preg::mergeSpaces($item);
$lineParts = explode(' ', $line);
$key = array_shift($lineParts);
$docsArray[$key] = $lineParts;
}
return $docsArray;
}
}