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 | namespace Finder\Spider; |
||
4 | |||
5 | use Symfony\Component\Finder\Finder as FinderBase; |
||
6 | |||
7 | use Finder\Logic\Output\AbstractOutput; |
||
8 | use Finder\Logic\Output\Filter\OutputFilterInterface; |
||
9 | use Finder\Logic\Output\TriggerableInterface; |
||
10 | |||
11 | use League\Flysystem\Adapter\Local; |
||
12 | use League\Flysystem\Filesystem; |
||
13 | |||
14 | /** |
||
15 | * Run all script analysers and outputs their result. |
||
16 | * |
||
17 | * @package qa |
||
18 | */ |
||
19 | class SpiderLinuxCommand |
||
20 | { |
||
21 | const EVENT_STARTING_ANALYSIS = 0; |
||
22 | const EVENT_STARTING_TOOL = 1; |
||
23 | const EVENT_FINISHED_TOOL = 2; |
||
24 | const EVENT_FINISHED_ANALYSIS = 3; |
||
25 | |||
26 | const VERSION = '0.7.1'; |
||
27 | |||
28 | protected $defaultLanguage = 'Php'; |
||
29 | |||
30 | /** |
||
31 | * Composer binaries path. |
||
32 | * |
||
33 | * @var string directory path. |
||
34 | */ |
||
35 | protected $binariesPath; |
||
36 | |||
37 | /** |
||
38 | * Analysis target. |
||
39 | * |
||
40 | * @var string[] file or directory path. |
||
41 | */ |
||
42 | protected $analysedPaths; |
||
43 | |||
44 | /** |
||
45 | * Ignored paths. |
||
46 | * |
||
47 | * @var string[] comma separated list of directories to ignore. |
||
48 | */ |
||
49 | protected $ignoredPaths; |
||
50 | |||
51 | /** |
||
52 | * Output service. |
||
53 | * |
||
54 | * @var AbstractOutput output instance. |
||
55 | */ |
||
56 | protected $output; |
||
57 | |||
58 | /** |
||
59 | * Analysis result filter. |
||
60 | * |
||
61 | * @var OutputFilterInterface filter instance. |
||
62 | */ |
||
63 | protected $resultsFilter; |
||
64 | |||
65 | /** |
||
66 | * Set dependencies and initialize CLI. |
||
67 | * |
||
68 | * @param AbstractOutput $output Output target. |
||
69 | * @param string $binariesPath Composer binaries path. |
||
70 | * @param string[] $analysedPaths target file or directory path. |
||
71 | * @param string[] $ignoredPaths comma separated list of ignored directories. |
||
72 | */ |
||
73 | View Code Duplication | public function __construct(AbstractOutput $output, $binariesPath, $analysedPaths, $ignoredPaths, $project = false) |
|
0 ignored issues
–
show
|
|||
74 | { |
||
75 | $this->output = $output; |
||
76 | $this->binariesPath = $binariesPath; |
||
77 | $this->analysedPaths = $analysedPaths; |
||
78 | $this->ignoredPaths = $ignoredPaths; |
||
79 | |||
80 | if (!$project) { |
||
81 | $this->languageClass = 'Finder\\Actions\\Worker\\Analyser\\Language\\'.$this->defaultLanguage; |
||
0 ignored issues
–
show
The property
languageClass does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
![]() |
|||
82 | } |
||
83 | } |
||
84 | |||
85 | public function getAdapter() |
||
86 | { |
||
87 | |||
88 | $adapter = new Local(__DIR__.'/path/to/root/'); |
||
0 ignored issues
–
show
$adapter is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
89 | } |
||
90 | |||
91 | public function getFilesystem() |
||
92 | { |
||
93 | |||
94 | $filesystem = new Filesystem($adapter); |
||
0 ignored issues
–
show
$filesystem is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
95 | } |
||
96 | |||
97 | /** |
||
98 | * Run each configured PHP analysis tool. |
||
99 | * |
||
100 | * @return boolean true if it didn't find code issues. |
||
101 | */ |
||
102 | public function run() |
||
103 | { |
||
104 | $result = $this->createResult(); |
||
105 | $this->trigger( |
||
106 | self::EVENT_STARTING_ANALYSIS, |
||
107 | ['ignoredPaths' => $this->ignoredPaths] |
||
0 ignored issues
–
show
array('ignoredPaths' => $this->ignoredPaths) is of type array<string,array<integ...rray<integer,string>"}> , but the function expects a string|null .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
108 | ); |
||
109 | |||
110 | $this->runTargetDetectAndCollect(); |
||
0 ignored issues
–
show
The method
runTargetDetectAndCollect() does not seem to exist on object<Finder\Spider\SpiderLinuxCommand> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
111 | $this->runTargetMetrics(); |
||
0 ignored issues
–
show
The method
runTargetMetrics() does not seem to exist on object<Finder\Spider\SpiderLinuxCommand> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
112 | $this->runTargetAnalysis(); |
||
0 ignored issues
–
show
The method
runTargetAnalysis() does not seem to exist on object<Finder\Spider\SpiderLinuxCommand> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
113 | |||
114 | View Code Duplication | foreach ($this->getAnalysisTools() as $tool) { |
|
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. ![]() |
|||
115 | $message = ['description' => $tool->getDescription()]; |
||
116 | $this->trigger(self::EVENT_STARTING_TOOL, $message); |
||
0 ignored issues
–
show
$message is of type array<string,?,{"description":"?"}> , but the function expects a string|null .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
117 | $tool->run($this->getAnalysedPaths()); |
||
118 | $result->mergeWith($tool->getAnalysisResult()); |
||
119 | $this->trigger(self::EVENT_FINISHED_TOOL); |
||
120 | } |
||
121 | |||
122 | if ($this->resultsFilter) { |
||
123 | $result->setResultsFilter($this->resultsFilter); |
||
124 | } |
||
125 | |||
126 | $this->output->result($result); |
||
127 | $this->trigger(self::EVENT_FINISHED_ANALYSIS); |
||
128 | |||
129 | return !$result->hasIssues(); |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * Call an output trigger if supported. |
||
134 | * |
||
135 | * @param int $event occurred event. |
||
136 | * @param string|null $message optional message. |
||
137 | * @return void |
||
138 | */ |
||
139 | protected function trigger($event, $message = null) |
||
140 | { |
||
141 | if ($this->output instanceof TriggerableInterface) { |
||
142 | $this->output->trigger($event, $message); |
||
143 | } |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * Get a list of paths to be ignored by the analysis. |
||
148 | * |
||
149 | * @return string[] a list of file and/or directory paths. |
||
150 | */ |
||
151 | public function getIgnoredPaths() |
||
152 | { |
||
153 | return $this->ignoredPaths; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Analysis target path. |
||
158 | * |
||
159 | * @return string[] target path. |
||
160 | */ |
||
161 | public function getAnalysedPaths() |
||
162 | { |
||
163 | return $this->analysedPaths; |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * Add an output filter to delegate to the analysis result object. |
||
168 | * |
||
169 | * @param OutputFilterInterface $filter filter instance. |
||
170 | */ |
||
171 | public function setResultsFilter(OutputFilterInterface $filter) |
||
172 | { |
||
173 | $this->resultsFilter = $filter; |
||
174 | } |
||
175 | |||
176 | /** |
||
177 | * Set target files and/or directories to be analysed. |
||
178 | * |
||
179 | * @param string[] $paths target paths. |
||
180 | * @return void |
||
181 | */ |
||
182 | public function setAnalysedPaths(array $paths) |
||
183 | { |
||
184 | $this->analysedPaths = $paths; |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * List of PHP analys integration classes. |
||
189 | * |
||
190 | * @return string[] array of class names. |
||
191 | */ |
||
192 | protected function getAnalysisToolsClasses() |
||
193 | { |
||
194 | $this->languageClass::getAnalysisToolsClasses(); |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * Set of PHP analys integration objects. |
||
199 | * |
||
200 | * @return Finder\Logic\Tools\AbstractIntegrationTool[] set of objects. |
||
201 | */ |
||
202 | protected function getAnalysisTools() |
||
203 | { |
||
204 | $objects = []; |
||
205 | |||
206 | foreach ($this->getAnalysisToolsClasses() as $className) { |
||
0 ignored issues
–
show
The expression
$this->getAnalysisToolsClasses() of type array<integer,string>|null is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
207 | $tool = new $className($this->binariesPath, sys_get_temp_dir()); |
||
208 | $tool->setIgnoredPaths($this->getIgnoredPaths()); |
||
209 | $objects[] = $tool; |
||
210 | } |
||
211 | |||
212 | return $objects; |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * Create an empty analysis result. |
||
217 | * |
||
218 | * @return AnalysisResult instance. |
||
219 | */ |
||
220 | protected function createResult() |
||
221 | { |
||
222 | return new AnalysisResult; |
||
223 | } |
||
224 | |||
225 | } |
||
226 |
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.