These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | |||
4 | /** |
||
5 | * This file is part of phpDocumentor. |
||
6 | * |
||
7 | * For the full copyright and license information, please view the LICENSE |
||
8 | * file that was distributed with this source code. |
||
9 | * |
||
10 | * @author Mike van Riel <[email protected]> |
||
11 | * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
||
12 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
||
13 | * @link http://phpdoc.org |
||
14 | */ |
||
15 | |||
16 | namespace phpDocumentor\Transformer\Router\UrlGenerator\Standard; |
||
17 | |||
18 | use phpDocumentor\Descriptor; |
||
19 | use phpDocumentor\Transformer\Router\UrlGenerator\UrlGeneratorInterface; |
||
20 | |||
21 | class ConstantDescriptor implements UrlGeneratorInterface |
||
22 | { |
||
23 | /** @var QualifiedNameToUrlConverter */ |
||
24 | private $converter; |
||
25 | |||
26 | /** |
||
27 | * Initializes this generator. |
||
28 | */ |
||
29 | 2 | public function __construct() |
|
30 | { |
||
31 | 2 | $this->converter = new QualifiedNameToUrlConverter(); |
|
32 | 2 | } |
|
33 | |||
34 | /** |
||
35 | * Generates a URL from the given node or returns false if unable. |
||
36 | * |
||
37 | * @param string|Descriptor\ConstantDescriptor $node |
||
38 | * |
||
39 | * @return string|false |
||
40 | */ |
||
41 | 3 | public function __invoke($node) |
|
42 | { |
||
43 | 3 | if (!($node instanceof Descriptor\ConstantDescriptor)) { |
|
44 | return false; |
||
45 | } |
||
46 | |||
47 | 3 | $prefix = ($node->getParent() instanceof Descriptor\FileDescriptor || ! $node->getParent()) |
|
48 | 2 | ? $this->getUrlPathPrefixForGlobalConstants($node) |
|
49 | 3 | : $this->getUrlPathPrefixForClassConstants($node); |
|
50 | |||
51 | 3 | return $prefix . '.html#constant_' . $node->getName(); |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * Returns the first part of the URL path that is specific to global constants. |
||
56 | * |
||
57 | * @param Descriptor\ConstantDescriptor $node |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | 2 | private function getUrlPathPrefixForGlobalConstants($node) |
|
62 | { |
||
63 | 2 | return '/namespaces/' . $this->converter->fromNamespace($node->getNamespace()); |
|
0 ignored issues
–
show
|
|||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Returns the first part of the URL path that is specific to class constants. |
||
68 | * |
||
69 | * @param Descriptor\ConstantDescriptor $node |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | 1 | private function getUrlPathPrefixForClassConstants($node) |
|
74 | { |
||
75 | 1 | return '/classes/' . $this->converter->fromClass($node->getParent()->getFullyQualifiedStructuralElementName()); |
|
76 | } |
||
77 | } |
||
78 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.