1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpUnitGen\Parser\NodeParser; |
4
|
|
|
|
5
|
|
|
use PhpParser\Node; |
6
|
|
|
use PhpUnitGen\Model\FunctionModel; |
7
|
|
|
use PhpUnitGen\Model\PropertyInterface\ClassLikeInterface; |
8
|
|
|
use PhpUnitGen\Model\PropertyInterface\NodeInterface; |
9
|
|
|
use PhpUnitGen\Parser\NodeParserTrait\DocumentationTrait; |
10
|
|
|
use PhpUnitGen\Parser\NodeParserTrait\ParamTrait; |
11
|
|
|
use PhpUnitGen\Parser\NodeParserTrait\VisibilityTrait; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class FunctionNodeParser. |
15
|
|
|
* |
16
|
|
|
* @author Paul Thébaud <[email protected]>. |
17
|
|
|
* @copyright 2017-2018 Paul Thébaud <[email protected]>. |
18
|
|
|
* @license https://opensource.org/licenses/MIT The MIT license. |
19
|
|
|
* @link https://github.com/paul-thebaud/phpunit-generator |
20
|
|
|
* @since Class available since Release 2.0.0. |
21
|
|
|
*/ |
22
|
|
|
class FunctionNodeParser extends AbstractNodeParser |
23
|
|
|
{ |
24
|
|
|
use VisibilityTrait; |
25
|
|
|
use DocumentationTrait; |
26
|
|
|
use ParamTrait; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function parse(Node $node, NodeInterface $parent): NodeInterface |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Overriding variable types. |
35
|
|
|
* @var Node\Stmt\ClassMethod $node The function node to parse. |
36
|
|
|
* @var ClassLikeInterface $parent The node which contains this namespace. |
37
|
|
|
*/ |
38
|
|
|
$function = new FunctionModel(); |
39
|
|
|
$function->setName($node->name); |
40
|
|
|
$function->setDocumentation($this->parseDocumentation($node)); |
41
|
|
|
$function->setIsFinal($node->isFinal()); |
42
|
|
|
$function->setIsStatic($node->isStatic()); |
43
|
|
|
$function->setIsAbstract($node->isAbstract()); |
44
|
|
|
$function->setVisibility($this->parseVisibility($node)); |
45
|
|
|
|
46
|
|
|
foreach ($node->getParams() as $param) { |
47
|
|
|
$function->addParameter($this->parseParam($param)); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$parent->addFunction($function); |
51
|
|
|
|
52
|
|
|
return $parent; |
|
|
|
|
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|