|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* This file is part of phpDocumentor. |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
* @copyright 2010-2018 Mike van Riel<[email protected]> |
|
11
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
|
12
|
|
|
* @link http://phpdoc.org |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace phpDocumentor\Reflection\Php\Factory; |
|
16
|
|
|
|
|
17
|
|
|
use phpDocumentor\Reflection\Fqsen; |
|
18
|
|
|
use phpDocumentor\Reflection\Location; |
|
19
|
|
|
use phpDocumentor\Reflection\Php\Interface_ as InterfaceElement; |
|
20
|
|
|
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy; |
|
21
|
|
|
use phpDocumentor\Reflection\Php\StrategyContainer; |
|
22
|
|
|
use phpDocumentor\Reflection\Types\Context; |
|
23
|
|
|
use PhpParser\Node\Stmt\ClassConst; |
|
24
|
|
|
use PhpParser\Node\Stmt\ClassMethod; |
|
25
|
|
|
use PhpParser\Node\Stmt\Interface_ as InterfaceNode; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Strategy to create a InterfaceElement including all sub elements. |
|
29
|
|
|
*/ |
|
30
|
|
|
// @codingStandardsIgnoreStart |
|
31
|
|
|
final class Interface_ extends AbstractFactory implements ProjectFactoryStrategy |
|
32
|
|
|
// @codingStandardsIgnoreEnd |
|
33
|
|
|
{ |
|
34
|
1 |
|
public function matches($object): bool |
|
35
|
|
|
{ |
|
36
|
1 |
|
return $object instanceof InterfaceNode; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Creates an Interface_ out of the given object. |
|
41
|
|
|
* Since an object might contain other objects that need to be converted the $factory is passed so it can be |
|
42
|
|
|
* used to create nested Elements. |
|
43
|
|
|
* |
|
44
|
|
|
* @param InterfaceNode $object object to convert to an Element |
|
45
|
|
|
* @param StrategyContainer $strategies used to convert nested objects. |
|
46
|
|
|
* @param Context $context of the created object |
|
47
|
|
|
* @return InterfaceElement |
|
48
|
|
|
*/ |
|
49
|
4 |
|
protected function doCreate($object, StrategyContainer $strategies, ?Context $context = null) |
|
50
|
|
|
{ |
|
51
|
4 |
|
$docBlock = $this->createDocBlock($strategies, $object->getDocComment(), $context); |
|
52
|
4 |
|
$parents = []; |
|
53
|
4 |
|
foreach ($object->extends as $extend) { |
|
54
|
|
|
$parents['\\' . (string) $extend] = new Fqsen('\\' . (string) $extend); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
4 |
|
$interface = new InterfaceElement($object->fqsen, $parents, $docBlock, new Location($object->getLine())); |
|
58
|
|
|
|
|
59
|
4 |
|
if (isset($object->stmts)) { |
|
60
|
2 |
|
foreach ($object->stmts as $stmt) { |
|
61
|
2 |
|
switch (get_class($stmt)) { |
|
62
|
2 |
|
case ClassMethod::class: |
|
|
|
|
|
|
63
|
1 |
|
$method = $this->createMember($stmt, $strategies, $context); |
|
64
|
1 |
|
$interface->addMethod($method); |
|
|
|
|
|
|
65
|
1 |
|
break; |
|
66
|
1 |
|
case ClassConst::class: |
|
67
|
1 |
|
$constants = new ClassConstantIterator($stmt); |
|
|
|
|
|
|
68
|
1 |
|
foreach ($constants as $const) { |
|
69
|
1 |
|
$element = $this->createMember($const, $strategies, $context); |
|
70
|
1 |
|
$interface->addConstant($element); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
2 |
|
break; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
4 |
|
return $interface; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next
break.There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.