|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpBoot\Controller\Annotations; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use PhpBoot\Annotation\AnnotationBlock; |
|
7
|
|
|
use PhpBoot\Annotation\AnnotationTag; |
|
8
|
|
|
use PhpBoot\Controller\ControllerContainer; |
|
9
|
|
|
use PhpBoot\Entity\ContainerFactory; |
|
10
|
|
|
use PhpBoot\Entity\EntityContainerBuilder; |
|
11
|
|
|
use PhpBoot\Utils\AnnotationParams; |
|
12
|
|
|
use PhpBoot\Utils\Logger; |
|
13
|
|
|
use PhpBoot\Utils\TypeHint; |
|
14
|
|
|
|
|
15
|
|
|
class ReturnAnnotationHandler |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @param ControllerContainer $container |
|
19
|
|
|
* @param AnnotationBlock|AnnotationTag $ann |
|
20
|
|
|
* @param EntityContainerBuilder $entityBuilder |
|
21
|
|
|
*/ |
|
22
|
4 |
|
public function __invoke(ControllerContainer $container, $ann, EntityContainerBuilder $entityBuilder) |
|
23
|
|
|
{ |
|
24
|
4 |
|
if(!$ann->parent){ |
|
25
|
|
|
//Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent route"); |
|
26
|
|
|
return; |
|
27
|
|
|
} |
|
28
|
4 |
|
$target = $ann->parent->name; |
|
29
|
4 |
|
$route = $container->getRoute($target); |
|
30
|
4 |
|
if(!$route){ |
|
31
|
|
|
//Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent route"); |
|
32
|
|
|
return ; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
4 |
|
$params = new AnnotationParams($ann->description, 2); |
|
36
|
4 |
|
$type = $doc = null; |
|
|
|
|
|
|
37
|
4 |
|
if(count($params)>0){ |
|
38
|
4 |
|
$type = TypeHint::normalize($params[0], $container->getClassName()); |
|
39
|
4 |
|
} |
|
40
|
4 |
|
$doc = $params->getRawParam(1, ''); |
|
41
|
|
|
|
|
42
|
|
|
list($_, $meta) = $route |
|
|
|
|
|
|
43
|
4 |
|
->getResponseHandler() |
|
44
|
4 |
|
->getMappingBySource('return'); |
|
45
|
4 |
|
if($meta){ |
|
46
|
4 |
|
$meta->description = $doc; |
|
47
|
4 |
|
$meta->type = $type; |
|
48
|
4 |
|
$meta->container = $type == 'void'?null:ContainerFactory::create($entityBuilder, $type); |
|
49
|
4 |
|
} |
|
50
|
|
|
} |
|
51
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.