1 | <?php |
||
17 | class SecurityHelper |
||
18 | { |
||
19 | /** |
||
20 | * Get system resources name. |
||
21 | * |
||
22 | * |
||
23 | * @return array Array of system resources. |
||
24 | 49 | */ |
|
25 | public static function getResourcesNames($path) |
||
26 | 49 | { |
|
27 | 49 | $resources = array(); |
|
28 | $finder = new Finder(); |
||
29 | 49 | try { |
|
30 | 1 | $finder->files()->in($path)->name('*.php'); |
|
31 | 1 | } catch (\InvalidArgumentException $e) { |
|
32 | return $resources; |
||
33 | } |
||
34 | 49 | ||
35 | 49 | $added = 0; |
|
|
|||
36 | 49 | foreach ($finder as $file) { |
|
37 | 49 | $fileContent = file_get_contents($file->getRealPath()); |
|
38 | 49 | if (strpos($fileContent, '@ApiResource') !== false) { |
|
39 | 49 | $resources[] = self::extractName($file->getRealPath(), str_replace('.php', '', $file->getFilename())); |
|
40 | } |
||
41 | } |
||
42 | |||
43 | 49 | return $resources; |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * Extract name from the controller path string. |
||
48 | * |
||
49 | * @param string $resourcePath Path of the controller. |
||
50 | * |
||
51 | * @return string Name. |
||
52 | */ |
||
53 | 49 | public static function extractName($resourcePath, $name) |
|
54 | { |
||
55 | 49 | $resourcePath = str_replace('\\', '/', $resourcePath); |
|
56 | |||
57 | 49 | return self::extract($resourcePath, 'Bundle').' - '.$name; |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * Extract string. |
||
62 | * |
||
63 | * @param string $string String from which will be name extraced. |
||
64 | * @param string $name Extracted string. |
||
65 | * |
||
66 | * @return string Name. |
||
67 | */ |
||
68 | 49 | private static function extract($string, $name) |
|
74 | } |
||
75 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.