|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of PhpUnitGen. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2017-2018 Paul Thébaud <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace PhpUnitGen\Parser\NodeParser; |
|
13
|
|
|
|
|
14
|
|
|
use PhpParser\Node\FunctionLike; |
|
15
|
|
|
use PhpUnitGen\Configuration\ConfigurationInterface\ConfigInterface; |
|
16
|
|
|
use PhpUnitGen\Model\ModelInterface\FunctionModelInterface; |
|
17
|
|
|
use PhpUnitGen\Model\ReturnModel; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class AbstractFunctionNodeParser. |
|
21
|
|
|
* |
|
22
|
|
|
* @author Paul Thébaud <[email protected]>. |
|
23
|
|
|
* @copyright 2017-2018 Paul Thébaud <[email protected]>. |
|
24
|
|
|
* @license https://opensource.org/licenses/MIT The MIT license. |
|
25
|
|
|
* @link https://github.com/paul-thebaud/phpunit-generator |
|
26
|
|
|
* @since Class available since Release 2.0.0. |
|
27
|
|
|
*/ |
|
28
|
|
|
abstract class AbstractFunctionNodeParser extends AbstractNodeParser |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var ConfigInterface $config The configuration. |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $config; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var ParameterNodeParser $parameterNodeParser The parameter node parser. |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $parameterNodeParser; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var TypeNodeParser $typeNodeParser The type node parser. |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $typeNodeParser; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var DocumentationNodeParser $documentationNodeParser The documentation node parser. |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $documentationNodeParser; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* FunctionNodeParser constructor. |
|
52
|
|
|
* |
|
53
|
|
|
* @param ConfigInterface $config The configuration. |
|
54
|
|
|
* @param ParameterNodeParser $parameterNodeParser The parameter node parser. |
|
55
|
|
|
* @param TypeNodeParser $typeNodeParser The type node parser. |
|
56
|
|
|
* @param DocumentationNodeParser $documentationNodeParser The documentation node parser. |
|
57
|
|
|
*/ |
|
58
|
|
|
public function __construct( |
|
59
|
|
|
ConfigInterface $config, |
|
60
|
|
|
ParameterNodeParser $parameterNodeParser, |
|
61
|
|
|
TypeNodeParser $typeNodeParser, |
|
62
|
|
|
DocumentationNodeParser $documentationNodeParser |
|
63
|
|
|
) { |
|
64
|
|
|
$this->config = $config; |
|
65
|
|
|
$this->parameterNodeParser = $parameterNodeParser; |
|
66
|
|
|
$this->typeNodeParser = $typeNodeParser; |
|
67
|
|
|
$this->documentationNodeParser = $documentationNodeParser; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Parse a function like node to update a function model. |
|
72
|
|
|
* |
|
73
|
|
|
* @param FunctionLike $node The node to parse. |
|
74
|
|
|
* @param FunctionModelInterface $function The model to update. |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function parseFunction(FunctionLike $node, FunctionModelInterface $function): void |
|
77
|
|
|
{ |
|
78
|
|
|
foreach ($node->getParams() as $param) { |
|
79
|
|
|
$this->parameterNodeParser->invoke($param, $function); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$return = new ReturnModel(); |
|
83
|
|
|
$return->setParentNode($function); |
|
84
|
|
|
if ($node->getReturnType() !== null) { |
|
85
|
|
|
$this->typeNodeParser->invoke($node->getReturnType(), $return); |
|
86
|
|
|
} |
|
87
|
|
|
$function->setReturn($return); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|