1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpDocumentor. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright 2010-2015 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpDocumentor\Reflection\Php\Factory; |
14
|
|
|
|
15
|
|
|
use InvalidArgumentException; |
16
|
|
|
use phpDocumentor\Reflection\Fqsen; |
17
|
|
|
use phpDocumentor\Reflection\Php\Factory; |
18
|
|
|
use phpDocumentor\Reflection\Php\Function_ as FunctionDescriptor; |
19
|
|
|
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy; |
20
|
|
|
use phpDocumentor\Reflection\Php\StrategyContainer; |
21
|
|
|
use phpDocumentor\Reflection\Types\Context; |
22
|
|
|
use PhpParser\Comment\Doc; |
23
|
|
|
use PhpParser\Node\Stmt\Function_ as FunctionNode; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Strategy to convert Function_ to FunctionDescriptor |
27
|
|
|
* |
28
|
|
|
* @see FunctionDescriptor |
29
|
|
|
* @see \PhpParser\Node\ |
30
|
|
|
*/ |
31
|
|
|
final class Function_ extends AbstractFactory implements ProjectFactoryStrategy |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Returns true when the strategy is able to handle the object. |
36
|
|
|
* |
37
|
|
|
* @param FunctionNode $object object to check. |
38
|
|
|
* @return boolean |
39
|
|
|
*/ |
40
|
1 |
|
public function matches($object) |
41
|
|
|
{ |
42
|
1 |
|
return $object instanceof FunctionNode; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Creates an FunctionDescriptor out of the given object including its child elements. |
47
|
|
|
* |
48
|
|
|
* @param \PhpParser\Node\Stmt\Function_ $object object to convert to an Element |
49
|
|
|
* @param StrategyContainer $strategies used to convert nested objects. |
50
|
|
|
* @param Context $context of the created object |
51
|
|
|
* @return FunctionDescriptor |
52
|
|
|
*/ |
53
|
3 |
|
protected function doCreate($object, StrategyContainer $strategies, Context $context = null) |
54
|
|
|
{ |
55
|
3 |
|
$docBlock = $this->createDocBlock($object->getDocComment(), $strategies, $context); |
56
|
|
|
|
57
|
3 |
|
$function = new FunctionDescriptor($object->fqsen, $docBlock); |
|
|
|
|
58
|
|
|
|
59
|
3 |
|
foreach ($object->params as $param) { |
60
|
1 |
|
$strategy = $strategies->findMatching($param); |
61
|
1 |
|
$function->addArgument($strategy->create($param, $strategies, $context)); |
|
|
|
|
62
|
3 |
|
} |
63
|
|
|
|
64
|
3 |
|
return $function; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider
.