This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * This file is part of PHP Mess Detector. |
||
4 | * |
||
5 | * Copyright (c) Manuel Pichler <[email protected]>. |
||
6 | * All rights reserved. |
||
7 | * |
||
8 | * Licensed under BSD License |
||
9 | * For full copyright and license information, please see the LICENSE file. |
||
10 | * Redistributions of files must retain the above copyright notice. |
||
11 | * |
||
12 | * @author Manuel Pichler <[email protected]> |
||
13 | * @copyright Manuel Pichler. All rights reserved. |
||
14 | * @license https://opensource.org/licenses/bsd-license.php BSD License |
||
15 | * @link http://phpmd.org/ |
||
16 | */ |
||
17 | |||
18 | namespace PHPMD; |
||
19 | |||
20 | use PDepend\Application; |
||
21 | use PDepend\Engine; |
||
22 | use PDepend\Input\ExcludePathFilter; |
||
23 | use PDepend\Input\ExtensionFilter; |
||
24 | |||
25 | /** |
||
26 | * Simple factory that is used to return a ready to use PDepend instance. |
||
27 | */ |
||
28 | class ParserFactory |
||
29 | { |
||
30 | /** @var string The default config file name */ |
||
31 | const PDEPEND_CONFIG_FILE_NAME = '/pdepend.xml'; |
||
32 | |||
33 | /** @var string The distribution config file name */ |
||
34 | const PDEPEND_CONFIG_FILE_NAME_DIST = '/pdepend.xml.dist'; |
||
35 | |||
36 | /** |
||
37 | * Mapping between phpmd option names and those used by pdepend. |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | private $phpmd2pdepend = array( |
||
42 | 'coverage' => 'coverage-report', |
||
43 | ); |
||
44 | |||
45 | 12 | /** |
|
46 | * Creates the used {@link \PHPMD\Parser} analyzer instance. |
||
47 | 12 | * |
|
48 | 12 | * @param \PHPMD\PHPMD $phpmd |
|
49 | * @return \PHPMD\Parser |
||
50 | 12 | */ |
|
51 | public function create(PHPMD $phpmd) |
||
52 | { |
||
53 | $pdepend = $this->createInstance(); |
||
54 | $pdepend = $this->init($pdepend, $phpmd); |
||
0 ignored issues
–
show
|
|||
55 | |||
56 | return new Parser($pdepend); |
||
57 | } |
||
58 | 12 | ||
59 | /** |
||
60 | 12 | * Creates a clean php depend instance with some base settings. |
|
61 | * |
||
62 | 12 | * @return \PDepend\Engine |
|
63 | */ |
||
64 | 12 | private function createInstance() |
|
65 | 10 | { |
|
66 | $application = new Application(); |
||
67 | |||
68 | 12 | $workingDirectory = getcwd(); |
|
69 | if (file_exists($workingDirectory . self::PDEPEND_CONFIG_FILE_NAME)) { |
||
70 | $application->setConfigurationFile($workingDirectory . self::PDEPEND_CONFIG_FILE_NAME); |
||
71 | } elseif (file_exists($workingDirectory . self::PDEPEND_CONFIG_FILE_NAME_DIST)) { |
||
72 | $application->setConfigurationFile($workingDirectory . self::PDEPEND_CONFIG_FILE_NAME_DIST); |
||
73 | } |
||
74 | |||
75 | return $application->getEngine(); |
||
76 | } |
||
77 | |||
78 | 12 | /** |
|
79 | * Configures the given PDepend\Engine instance based on some user settings. |
||
80 | 12 | * |
|
81 | 12 | * @param \PDepend\Engine $pdepend |
|
82 | 12 | * @param \PHPMD\PHPMD $phpmd |
|
83 | 12 | * @return \PDepend\Engine |
|
84 | */ |
||
85 | 12 | private function init(Engine $pdepend, PHPMD $phpmd) |
|
86 | { |
||
87 | $this->initOptions($pdepend, $phpmd); |
||
88 | $this->initInput($pdepend, $phpmd); |
||
89 | $this->initIgnores($pdepend, $phpmd); |
||
90 | $this->initExtensions($pdepend, $phpmd); |
||
91 | |||
92 | return $pdepend; |
||
93 | } |
||
94 | |||
95 | 12 | /** |
|
96 | * Configures the input source. |
||
97 | 12 | * |
|
98 | 12 | * @param \PDepend\Engine $pdepend |
|
99 | 12 | * @param \PHPMD\PHPMD $phpmd |
|
100 | 3 | * @return void |
|
101 | 3 | */ |
|
102 | private function initInput(Engine $pdepend, PHPMD $phpmd) |
||
103 | 10 | { |
|
104 | foreach (explode(',', $phpmd->getInput()) as $path) { |
||
105 | 12 | $trimmedPath = trim($path); |
|
106 | if (is_dir($trimmedPath)) { |
||
107 | $pdepend->addDirectory($trimmedPath); |
||
108 | continue; |
||
109 | } |
||
110 | $pdepend->addFile($trimmedPath); |
||
111 | } |
||
112 | } |
||
113 | |||
114 | 12 | /** |
|
115 | * Initializes the ignored files and path's. |
||
116 | 12 | * |
|
117 | 12 | * @param \PDepend\Engine $pdepend |
|
118 | 12 | * @param \PHPMD\PHPMD $phpmd |
|
119 | * @return void |
||
120 | */ |
||
121 | 12 | private function initIgnores(Engine $pdepend, PHPMD $phpmd) |
|
122 | { |
||
123 | if (count($phpmd->getIgnorePatterns()) > 0) { |
||
124 | $pdepend->addFileFilter( |
||
125 | new ExcludePathFilter($phpmd->getIgnorePatterns()) |
||
126 | ); |
||
127 | } |
||
128 | } |
||
129 | |||
130 | 12 | /** |
|
131 | * Initializes the accepted php source file extensions. |
||
132 | 12 | * |
|
133 | 12 | * @param \PDepend\Engine $pdepend |
|
134 | 12 | * @param \PHPMD\PHPMD $phpmd |
|
135 | * @return void |
||
136 | */ |
||
137 | 12 | private function initExtensions(Engine $pdepend, PHPMD $phpmd) |
|
138 | { |
||
139 | if (count($phpmd->getFileExtensions()) > 0) { |
||
140 | $pdepend->addFileFilter( |
||
141 | new ExtensionFilter($phpmd->getFileExtensions()) |
||
142 | ); |
||
143 | } |
||
144 | } |
||
145 | |||
146 | 12 | /** |
|
147 | * Initializes additional options for pdepend. |
||
148 | 12 | * |
|
149 | 12 | * @param \PDepend\Engine $pdepend |
|
150 | * @param \PHPMD\PHPMD $phpmd |
||
151 | * @return void |
||
152 | */ |
||
153 | private function initOptions(Engine $pdepend, PHPMD $phpmd) |
||
154 | 12 | { |
|
155 | 12 | $options = array(); |
|
156 | foreach (array_filter($phpmd->getOptions()) as $name => $value) { |
||
157 | if (isset($this->phpmd2pdepend[$name])) { |
||
158 | $options[$this->phpmd2pdepend[$name]] = $value; |
||
159 | } |
||
160 | } |
||
161 | $pdepend->setOptions($options); |
||
162 | } |
||
163 | } |
||
164 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: