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 | * Humbug |
||
4 | * |
||
5 | * @category Humbug |
||
6 | * @package Humbug |
||
7 | * @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com) |
||
8 | * @license https://github.com/padraic/phar-updater/blob/master/LICENSE New BSD License |
||
9 | * |
||
10 | * This class is partially patterned after Composer's version parser. |
||
11 | */ |
||
12 | |||
13 | namespace Humbug\SelfUpdate; |
||
14 | |||
15 | class VersionParser |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | private $versions; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $modifier = '[._-]?(?:(stable|beta|b|RC|alpha|a|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?'; |
||
27 | |||
28 | /** |
||
29 | * @param array $versions |
||
30 | */ |
||
31 | public function __construct(array $versions = array()) |
||
32 | { |
||
33 | $this->versions = $versions; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Get the most recent stable numbered version from versions passed to |
||
38 | * constructor (if any) |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | public function getMostRecentStable() |
||
43 | { |
||
44 | return $this->selectRecentStable(); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Get the most recent unstable numbered version from versions passed to |
||
49 | * constructor (if any) |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | public function getMostRecentUnStable() |
||
54 | { |
||
55 | return $this->selectRecentUnstable(); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Get the most recent stable or unstable numbered version from versions passed to |
||
60 | * constructor (if any) |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | public function getMostRecentAll() |
||
65 | { |
||
66 | return $this->selectRecentAll(); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Checks if given version string represents a stable numbered version |
||
71 | * |
||
72 | * @param string $version |
||
73 | * @return bool |
||
74 | */ |
||
75 | public function isStable($version) |
||
76 | { |
||
77 | return $this->stable($version); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Checks if given version string represents a 'pre-release' version, i.e. |
||
82 | * it's unstable but not development level. |
||
83 | * |
||
84 | * @param string $version |
||
85 | * @return bool |
||
86 | */ |
||
87 | public function isPreRelease($version) |
||
88 | { |
||
89 | return !$this->stable($version) && !$this->development($version); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Checks if given version string represents an unstable or dev-level |
||
94 | * numbered version |
||
95 | * |
||
96 | * @param string $version |
||
97 | * @return bool |
||
98 | */ |
||
99 | public function isUnstable($version) |
||
100 | { |
||
101 | return !$this->stable($version); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Checks if given version string represents a dev-level numbered version |
||
106 | * |
||
107 | * @param string $version |
||
108 | * @return bool |
||
109 | */ |
||
110 | public function isDevelopment($version) |
||
111 | { |
||
112 | return $this->development($version); |
||
113 | } |
||
114 | |||
115 | View Code Duplication | private function selectRecentStable() |
|
0 ignored issues
–
show
|
|||
116 | { |
||
117 | $candidates = array(); |
||
118 | foreach ($this->versions as $version) { |
||
119 | if (!$this->stable($version)) { |
||
120 | continue; |
||
121 | } |
||
122 | $candidates[] = $version; |
||
123 | } |
||
124 | if (empty($candidates)) { |
||
125 | return false; |
||
126 | } |
||
127 | return $this->findMostRecent($candidates); |
||
128 | } |
||
129 | |||
130 | View Code Duplication | private function selectRecentUnstable() |
|
0 ignored issues
–
show
This method seems to be duplicated in 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. ![]() |
|||
131 | { |
||
132 | $candidates = array(); |
||
133 | foreach ($this->versions as $version) { |
||
134 | if ($this->stable($version) || $this->development($version)) { |
||
135 | continue; |
||
136 | } |
||
137 | $candidates[] = $version; |
||
138 | } |
||
139 | if (empty($candidates)) { |
||
140 | return false; |
||
141 | } |
||
142 | return $this->findMostRecent($candidates); |
||
143 | } |
||
144 | |||
145 | View Code Duplication | private function selectRecentAll() |
|
0 ignored issues
–
show
This method seems to be duplicated in 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. ![]() |
|||
146 | { |
||
147 | $candidates = array(); |
||
148 | foreach ($this->versions as $version) { |
||
149 | if ($this->development($version)) { |
||
150 | continue; |
||
151 | } |
||
152 | $candidates[] = $version; |
||
153 | } |
||
154 | if (empty($candidates)) { |
||
155 | return false; |
||
156 | } |
||
157 | return $this->findMostRecent($candidates); |
||
158 | } |
||
159 | |||
160 | private function findMostRecent(array $candidates) |
||
161 | { |
||
162 | $candidate = null; |
||
163 | $tracker = null; |
||
0 ignored issues
–
show
$tracker 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 ![]() |
|||
164 | foreach ($candidates as $version) { |
||
165 | if (version_compare($candidate, $version, '<')) { |
||
166 | $candidate = $version; |
||
167 | } |
||
168 | } |
||
169 | return $candidate; |
||
170 | } |
||
171 | |||
172 | private function stable($version) |
||
173 | { |
||
174 | $version = preg_replace('{#.+$}i', '', $version); |
||
175 | if ($this->development($version)) { |
||
176 | return false; |
||
177 | } |
||
178 | preg_match('{'.$this->modifier.'$}i', strtolower($version), $match); |
||
179 | if (!empty($match[3])) { |
||
180 | return false; |
||
181 | } |
||
182 | if (!empty($match[1])) { |
||
183 | if ('beta' === $match[1] || 'b' === $match[1] |
||
184 | || 'alpha' === $match[1] || 'a' === $match[1] |
||
185 | || 'rc' === $match[1]) { |
||
186 | return false; |
||
187 | } |
||
188 | } |
||
189 | return true; |
||
190 | } |
||
191 | |||
192 | private function development($version) |
||
193 | { |
||
194 | if ('dev-' === substr($version, 0, 4) || '-dev' === substr($version, -4)) { |
||
195 | return true; |
||
196 | } |
||
197 | if (1 == preg_match("/-\d+-[a-z0-9]{8,}$/", $version)) { |
||
198 | return true; |
||
199 | } |
||
200 | return false; |
||
201 | } |
||
202 | } |
||
203 |
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.