1 | <?php |
||
31 | final class Interface_ implements ProjectFactoryStrategy |
||
32 | { |
||
33 | |||
34 | /** |
||
35 | * Returns true when the strategy is able to handle the object. |
||
36 | * |
||
37 | * @param InterfaceNode $object object to check. |
||
38 | * @return boolean |
||
39 | */ |
||
40 | 1 | public function matches($object) |
|
44 | |||
45 | /** |
||
46 | * Creates an Interface_ out of the given object. |
||
47 | * Since an object might contain other objects that need to be converted the $factory is passed so it can be |
||
48 | * used to create nested Elements. |
||
49 | * |
||
50 | * @param InterfaceNode $object object to convert to an Element |
||
51 | * @param StrategyContainer $strategies used to convert nested objects. |
||
52 | * @param Context $context of the created object |
||
53 | * @return InterfaceElement |
||
54 | */ |
||
55 | 5 | public function create($object, StrategyContainer $strategies, Context $context = null) |
|
56 | { |
||
57 | 5 | if (!$this->matches($object)) { |
|
58 | 1 | throw new InvalidArgumentException( |
|
59 | 1 | sprintf('%s cannot handle objects with the type %s', |
|
60 | 1 | __CLASS__, |
|
61 | 1 | is_object($object) ? get_class($object) : gettype($object) |
|
62 | ) |
||
63 | ); |
||
64 | } |
||
65 | |||
66 | 4 | $docBlock = $this->createDocBlock($object->getDocComment(), $strategies, $context); |
|
67 | 4 | $parents = array(); |
|
68 | 4 | foreach ($object->extends as $extend) { |
|
69 | $parents['\\' . (string)$extend] = new Fqsen('\\' . (string)$extend); |
||
70 | } |
||
71 | |||
72 | 4 | $interface = new InterfaceElement($object->fqsen, $parents, $docBlock); |
|
73 | |||
74 | 4 | if (isset($object->stmts)) { |
|
75 | 2 | foreach ($object->stmts as $stmt) { |
|
76 | 2 | switch (get_class($stmt)) { |
|
77 | case ClassMethod::class: |
||
78 | 1 | $method = $this->createMember($stmt, $strategies, $context); |
|
79 | 1 | $interface->addMethod($method); |
|
80 | 1 | break; |
|
81 | case ClassConst::class: |
||
82 | 1 | $constants = new ClassConstantIterator($stmt); |
|
83 | 1 | foreach ($constants as $const) { |
|
84 | 1 | $element = $this->createMember($const, $strategies, $context); |
|
85 | 1 | $interface->addConstant($element); |
|
86 | } |
||
87 | 2 | break; |
|
88 | } |
||
89 | } |
||
90 | } |
||
91 | |||
92 | 4 | return $interface; |
|
93 | } |
||
94 | |||
95 | /** |
||
96 | * @param Node|ClassConstantIterator|Doc $stmt |
||
97 | * @param StrategyContainer $strategies |
||
98 | * @param Context $context |
||
99 | * @return Element |
||
100 | */ |
||
101 | 3 | private function createMember($stmt, StrategyContainer $strategies, Context $context = null) |
|
106 | |||
107 | /** |
||
108 | * @param Doc $docBlock |
||
109 | * @param StrategyContainer $strategies |
||
110 | * @param Context $context |
||
111 | * @return null|\phpDocumentor\Reflection\DocBlock |
||
112 | */ |
||
113 | 4 | private function createDocBlock(Doc $docBlock = null, StrategyContainer $strategies, Context $context = null) |
|
121 | } |
||
122 |