These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace PhpBoot\Controller\Annotations; |
||
4 | |||
5 | use PhpBoot\Annotation\AnnotationBlock; |
||
6 | use PhpBoot\Annotation\AnnotationTag; |
||
7 | use PhpBoot\Controller\ControllerContainer; |
||
8 | use PhpBoot\Exceptions\AnnotationSyntaxException; |
||
9 | use PhpBoot\Utils\AnnotationParams; |
||
10 | use PhpBoot\Utils\Logger; |
||
11 | use PhpBoot\Validator\Validator; |
||
12 | |||
13 | class ValidateAnnotationHandler |
||
14 | { |
||
15 | /** |
||
16 | * @param ControllerContainer $container |
||
17 | * @param AnnotationBlock|AnnotationTag $ann |
||
18 | */ |
||
19 | 3 | public function __invoke(ControllerContainer $container, $ann) |
|
20 | { |
||
21 | 3 | View Code Duplication | if(!$ann->parent || !$ann->parent->parent){ |
0 ignored issues
–
show
|
|||
22 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent parent"); |
||
23 | return; |
||
24 | } |
||
25 | 3 | $target = $ann->parent->parent->name; |
|
26 | 3 | $route = $container->getRoute($target); |
|
27 | 3 | if(!$route){ |
|
28 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent parent"); |
||
29 | return ; |
||
30 | } |
||
31 | 3 | $params = new AnnotationParams($ann->description, 2); |
|
32 | |||
33 | 3 | count($params)>0 or \PhpBoot\abort(new AnnotationSyntaxException("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target require 1 param, {$params->count()} given")); |
|
34 | |||
35 | 3 | if($ann->parent->name == 'param'){ |
|
36 | 3 | list($paramType, $paramName, $paramDoc) = ParamAnnotationHandler::getParamInfo($ann->parent->description); |
|
37 | |||
38 | 3 | $paramMeta = $route->getRequestHandler()->getParamMeta($paramName); |
|
39 | 3 | if($params->count()>1){ |
|
40 | $paramMeta->validation = [$params[0], $params[1]]; |
||
41 | View Code Duplication | }else{ |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
42 | 3 | $paramMeta->validation = $params[0]; |
|
43 | 3 | if($paramMeta->validation) { |
|
44 | 3 | $v = new Validator(); |
|
45 | 3 | $v->rule($paramMeta->validation, $paramMeta->name); |
|
46 | 3 | if ($v->hasRule('optional', $paramMeta->name)) { |
|
47 | $paramMeta->isOptional = true; |
||
48 | } |
||
49 | 3 | } |
|
50 | } |
||
51 | |||
52 | 3 | return; |
|
53 | } |
||
54 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent parent"); |
||
55 | } |
||
56 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.