209821ce91e6ef442fc39ae05124d4cea8657046
[yaffs-website] / vendor / phpspec / prophecy / src / Prophecy / PhpDocumentor / ClassAndInterfaceTagRetriever.php
1 <?php
2
3 /*
4  * This file is part of the Prophecy.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *     Marcello Duarte <marcello.duarte@gmail.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Prophecy\PhpDocumentor;
13
14 use phpDocumentor\Reflection\DocBlock\Tag\MethodTag as LegacyMethodTag;
15 use phpDocumentor\Reflection\DocBlock\Tags\Method;
16
17 /**
18  * @author Théo FIDRY <theo.fidry@gmail.com>
19  *
20  * @internal
21  */
22 final class ClassAndInterfaceTagRetriever implements MethodTagRetrieverInterface
23 {
24     private $classRetriever;
25
26     public function __construct(MethodTagRetrieverInterface $classRetriever = null)
27     {
28         if (null !== $classRetriever) {
29             $this->classRetriever = $classRetriever;
30
31             return;
32         }
33
34         $this->classRetriever = class_exists('phpDocumentor\Reflection\DocBlockFactory') && class_exists('phpDocumentor\Reflection\Types\ContextFactory')
35             ? new ClassTagRetriever()
36             : new LegacyClassTagRetriever()
37         ;
38     }
39
40     /**
41      * @param \ReflectionClass $reflectionClass
42      *
43      * @return LegacyMethodTag[]|Method[]
44      */
45     public function getTagList(\ReflectionClass $reflectionClass)
46     {
47         return array_merge(
48             $this->classRetriever->getTagList($reflectionClass),
49             $this->getInterfacesTagList($reflectionClass)
50         );
51     }
52
53     /**
54      * @param \ReflectionClass $reflectionClass
55      *
56      * @return LegacyMethodTag[]|Method[]
57      */
58     private function getInterfacesTagList(\ReflectionClass $reflectionClass)
59     {
60         $interfaces = $reflectionClass->getInterfaces();
61         $tagList = array();
62
63         foreach($interfaces as $interface) {
64             $tagList = array_merge($tagList, $this->classRetriever->getTagList($interface));
65         }
66
67         return $tagList;
68     }
69 }