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 | * Represents a git repository for interaction with git. |
||
4 | */ |
||
5 | |||
6 | namespace markmarco16\git\components; |
||
7 | |||
8 | use yii\base\Component; |
||
9 | use yii\web\NotFoundHttpException; |
||
10 | use yii\helpers\Html; |
||
11 | use Yii; |
||
12 | |||
13 | class Repository extends Component { |
||
14 | |||
15 | public $repository; |
||
16 | |||
17 | protected $cotainerPath; |
||
18 | |||
19 | protected $repositoryPath; |
||
20 | |||
21 | //The list of project in cotainerPath |
||
22 | protected $repositoriesList = array(); |
||
23 | |||
24 | //Longitud maxima de mensaje resumen |
||
25 | protected $subjectMaxLength; |
||
26 | |||
27 | //Formato de la fecha corta |
||
28 | protected $datetimeFormat; |
||
29 | |||
30 | //Prefijo de ejecutable GIT |
||
31 | protected $gitPath = "git"; |
||
32 | |||
33 | /** |
||
34 | * Construct |
||
35 | */ |
||
36 | public function __construct($repository = null) { |
||
37 | $this->cotainerPath = Yii::$app->getModule('git')->gitDir; |
||
38 | $this->datetimeFormat = Yii::$app->getModule('git')->datetimeFormat; |
||
39 | $this->subjectMaxLength = Yii::$app->getModule('git')->subjectMaxLength; |
||
40 | if ($repository == null) { |
||
41 | $this->setRepositoryList(); |
||
42 | } else { |
||
43 | $this->setRepositoryPath($repository); |
||
44 | } |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Search repositories on the specified path |
||
49 | */ |
||
50 | public function setRepositoryList() { |
||
51 | if (is_dir($this->cotainerPath) && ($dir = opendir($this->cotainerPath))) { |
||
52 | while (($file = readdir($dir)) !== false) { |
||
53 | if (filetype($this->cotainerPath . $file) == "dir") { |
||
54 | if (file_exists($this->cotainerPath.$file."/HEAD")) { |
||
55 | $this->repositoriesList[] = array_merge( |
||
56 | array( |
||
57 | 'dir'=> $file, |
||
58 | 'name' => substr($file, 0,-4), |
||
59 | 'description'=> file_get_contents($this->cotainerPath.$file.'/description') |
||
60 | ), |
||
61 | $this->getRevListHashDetail("--all",$file) |
||
62 | ); |
||
63 | } elseif (file_exists($this->cotainerPath.$file."/.git/HEAD")) { |
||
64 | $this->repositoriesList[] = array_merge( |
||
65 | array( |
||
66 | 'dir'=> $file, |
||
67 | 'name' => $file, |
||
68 | 'description'=> file_get_contents($this->cotainerPath.$file.'/.git/description') |
||
69 | ), |
||
70 | $this->getRevListHashDetail("--all",$file."/.git") |
||
71 | ); |
||
72 | } else { |
||
73 | continue; |
||
74 | } |
||
75 | } |
||
76 | } |
||
77 | closedir($dir); |
||
78 | } else { |
||
79 | throw new NotFoundHttpException("La ruta base para repositorios GIT: $this->cotainerPath, no es un directorio o no posee repositorios."); |
||
80 | } |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * return project list |
||
85 | */ |
||
86 | public function getRepositoriesList() { |
||
87 | return $this->repositoriesList; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Sets the path to the git repository folder. |
||
92 | */ |
||
93 | public function setRepositoryPath($repository) { |
||
94 | $realPath = realpath($this->cotainerPath.$repository); |
||
95 | if ((file_exists($realPath."/HEAD")) || (file_exists($realPath."/.git/HEAD"))) { |
||
96 | if (file_exists($realPath."/.git/HEAD")) |
||
97 | $realPath .= "/.git"; |
||
98 | $this->repository=$repository; |
||
99 | $this->repositoryPath = $realPath; |
||
100 | } else { |
||
101 | throw new NotFoundHttpException("La ruta especificada no existe o no es un repositorio git."); |
||
102 | } |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Lists commit objects in reverse chronological order |
||
107 | */ |
||
108 | public function getRevList($start = 'HEAD', $skip = 0, $max_count = null) { |
||
109 | $cmd = "rev-list "; |
||
110 | if ($skip != 0) { |
||
111 | $cmd .= "--skip=$skip "; |
||
112 | } |
||
113 | if (!is_null($max_count)) { |
||
114 | $cmd .= "--max-count=$max_count "; |
||
115 | } |
||
116 | $cmd .= $start; |
||
117 | $result = array(); |
||
0 ignored issues
–
show
|
|||
118 | $result = $this->run_git($cmd); |
||
119 | $commitsList = array(); |
||
120 | foreach ($result as &$hash) { |
||
0 ignored issues
–
show
The expression
$result of type null|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
121 | $commitsList[] = $this->getRevListHashDetail($hash); |
||
122 | } |
||
123 | return $commitsList; |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Obtiene la informacion detallada de un commit |
||
128 | */ |
||
129 | public function getRevListHashDetail($hash = 'HEAD', $repository = null) { |
||
130 | $pattern = '/^(author|committer) ([^<]+) <([^>]*)> ([0-9]+) (.*)$/'; |
||
131 | $info = array(); |
||
132 | $info['h'] = $hash; |
||
133 | $info['subject'] = '(No Message)'; |
||
134 | $info['message'] = ''; |
||
135 | $info['author_datetime'] = null; |
||
136 | $info['parents'] = array(); |
||
137 | $info['rev'] = $this->getNameRev($hash); |
||
138 | $output = $this->run_git("rev-list --date=raw --pretty=format:'tree %T %nparent %P %nauthor %an <%ae> %ad %ncommitter %cn <%ce> %cd %nsubject %s %n%B ' --max-count=1 $hash", $repository); |
||
139 | foreach ($output as $line) { |
||
0 ignored issues
–
show
The expression
$output of type null|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
140 | if (substr($line, 0, 7)=='commit ') { |
||
141 | $info['h'] = substr($line, 7); |
||
142 | View Code Duplication | } elseif (substr($line, 0, 4) === 'tree') { |
|
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. ![]() |
|||
143 | $info['tree'] = substr($line, 5); |
||
144 | } elseif (substr($line, 0, 6) === 'parent') { |
||
145 | foreach (explode(" ", substr($line, 7)) as $item) { |
||
146 | $info['parents'][] = Html::a('<span class="">'.$item.'</span>', |
||
147 | ["commitview", 'id' => $this->repository, 'hash' => $item], |
||
148 | ['title' => Yii::t('app', 'Detail')] |
||
149 | ); |
||
150 | } |
||
151 | } elseif (preg_match($pattern, $line, $matches) > 0) { |
||
152 | $info[$matches[1] .'_name'] = $matches[2]; |
||
153 | $info[$matches[1] .'_mail'] = $matches[3]; |
||
154 | $info[$matches[1] .'_stamp'] = $matches[4] + ((intval($matches[5]) / 100.0) * 3600); |
||
155 | $info[$matches[1] .'_timezone'] = $matches[5]; |
||
156 | $info[$matches[1] .'_utcstamp'] = $matches[4]; |
||
157 | if (isset($conf['mail_filter'])) { |
||
158 | $info[$matches[1] .'_mail'] = $conf['mail_filter']($info[$matches[1] .'_mail']); |
||
159 | } |
||
160 | } elseif (substr($line, 0, 7) == 'subject') { |
||
161 | strlen($line)>=$this->subjectMaxLength?$info['subject'] = substr($line, 8, $this->subjectMaxLength).'...':$info['subject'] = substr($line, 8); |
||
162 | } else { |
||
163 | $info['message'] .= $line.' <br>'; |
||
164 | } |
||
165 | } |
||
166 | if (array_key_exists('author_stamp', $info)) { |
||
167 | $info['author_datetime'] = strftime($this->datetimeFormat, $info['author_utcstamp']); |
||
168 | $info['author_datetime_local'] = strftime($this->datetimeFormat, $info['author_stamp']); |
||
169 | } |
||
170 | if (array_key_exists('committer_stamp', $info)) { |
||
171 | $info['committer_datetime'] = strftime($this->datetimeFormat, $info['committer_utcstamp']); |
||
172 | $info['committer_datetime_local'] = strftime($this->datetimeFormat, $info['committer_stamp']); |
||
173 | } |
||
174 | return $info; |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * Obtiene los archivos modificados segun el hash ingresado |
||
179 | */ |
||
180 | public function getChangedPaths($hash) { |
||
181 | $result = array(); |
||
182 | $affected_files = $this->run_git("diff --name-only $hash^ $hash"); |
||
183 | if (empty($affected_files)) { |
||
184 | $affected_files = $this->run_git("show --pretty='format:' --name-only $hash"); |
||
185 | } |
||
186 | foreach ($affected_files as $file) { |
||
0 ignored issues
–
show
The expression
$affected_files of type null|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
187 | if ($file == '') { |
||
188 | continue; |
||
189 | } |
||
190 | $output = $this->run_git("ls-tree -l --full-tree $hash '$file'"); |
||
191 | if (empty($output)) { |
||
192 | $output = $this->run_git("ls-tree -l --full-tree -r $hash^ '$file'"); |
||
193 | } |
||
194 | foreach ($output as $line) { |
||
0 ignored issues
–
show
The expression
$output of type null|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
195 | $parts = preg_split('/\s+/', $line, 5); |
||
196 | $result[] = array( |
||
197 | 'name' => $parts[4], |
||
198 | 'mode' => $parts[0], |
||
199 | 'type' => $parts[1], |
||
200 | 'hash_file' => $parts[2], |
||
201 | 'size'=>$parts[3], |
||
202 | 'link'=> array( |
||
203 | Html::a('<span class="">View</span>', |
||
204 | [$parts[1], 'id' => $this->repository, 'hash' => $hash, "hash_file"=>$parts[2]], |
||
205 | ['title' => Yii::t('app', 'Detail')] |
||
206 | ), |
||
207 | Html::a('<span class="">Compare</span>', |
||
208 | ["commitview", 'id' => $this->repository, 'hash' => $hash, "hash_file"=>$parts[2]], |
||
209 | ['title' => Yii::t('app', 'Detail')] |
||
210 | ), |
||
211 | ), |
||
212 | ); |
||
213 | } |
||
214 | } |
||
215 | return $result; |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * |
||
220 | */ |
||
221 | public function getTree($treeish,$hash) { |
||
222 | $command = "ls-tree -l --full-tree $treeish "; |
||
223 | foreach ($this->run_git($command) as $list) |
||
0 ignored issues
–
show
The expression
$this->run_git($command) of type null|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
224 | { |
||
225 | $parts = preg_split('/\s+/', $list, 5); |
||
226 | $result[] = array( |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
227 | 'name' => $parts[4], |
||
228 | 'mode' => $parts[0], |
||
229 | 'type' => $parts[1], |
||
230 | 'hash_file' => $parts[2], |
||
231 | 'size'=>$parts[3], |
||
232 | 'link'=> array( |
||
233 | Html::a('<span class="">View</span>', |
||
234 | [$parts[1], 'id' => $this->repository, 'hash' => $hash, $parts[1]=="tree"?"tree":"hash_file"=>$parts[2]], |
||
235 | ['title' => Yii::t('app', 'Detail')] |
||
236 | ), |
||
237 | //'<a href="'.Yii::app()->createUrl("repositorio/".$parts[1],array("id"=>$this->repositoryPath, "hash"=>$hash, $parts[1]=="tree"?"tree":"hash_file"=>$parts[2])).'">Ver</a>', |
||
238 | ), |
||
239 | |||
240 | ); |
||
241 | } |
||
242 | return $result; |
||
0 ignored issues
–
show
The variable
$result does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
243 | } |
||
244 | |||
245 | /** |
||
246 | * Funcion para mostrar todas las referencias de los commits |
||
247 | */ |
||
248 | public function getShowRef($project = null, $tags = true, $heads = true, $remotes = true) { |
||
249 | $cmd = "show-ref --dereference"; |
||
250 | if (!$remotes) { |
||
251 | if ($tags) |
||
252 | $cmd .= " --tags"; |
||
253 | if ($heads) |
||
254 | $cmd .= " --heads"; |
||
255 | } |
||
256 | $result = array(); |
||
257 | $output = $this->run_git($cmd,$project); |
||
258 | foreach ($output as $line) { |
||
0 ignored issues
–
show
The expression
$output of type null|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
259 | // <hash> <ref> |
||
260 | $parts = explode(' ', $line, 2); |
||
261 | $name = str_replace(array('refs/', '^{}'), array('', ''), $parts[1]); |
||
262 | $result[]= array('h'=>$parts[0], 'ref' => $name); |
||
263 | } |
||
264 | return $result; |
||
265 | } |
||
266 | |||
267 | /** |
||
268 | * Obtiene las referencias a partir de un hash en formato html |
||
269 | */ |
||
270 | public function getNameRev($hash) { |
||
271 | $output = $this->run_git("show-ref -d | grep $hash"); |
||
272 | $items=array(); |
||
273 | $result = ''; |
||
274 | $type=''; |
||
0 ignored issues
–
show
$type 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 ![]() |
|||
275 | foreach ($output as $line) { |
||
0 ignored issues
–
show
The expression
$output of type null|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
276 | // <hash> <ref> |
||
277 | $part = explode(' ', $line, 2); |
||
278 | if ($part[0]==$hash) { |
||
279 | $name = str_replace(array('refs/', '^{}'), array('', ''), $part[1]); |
||
280 | if (substr($name, 0, 4)=="tags") { |
||
281 | $type = "tags"; |
||
282 | $name = str_replace("/","",substr($name,4)); |
||
283 | } elseif (substr($name, 0, 7)=="remotes") { |
||
284 | $type = "remote"; |
||
285 | $name = str_replace("/",": ",substr($name,8)); |
||
286 | } |
||
287 | else { |
||
288 | $type = "branch"; |
||
289 | $name = str_replace("/","",substr($name,5)); |
||
290 | } |
||
291 | $items[]= array('h'=>$part[0], 'type' => $type, 'name'=>$name); |
||
292 | } |
||
293 | } |
||
294 | foreach ($items as $item) { |
||
295 | if (!empty($item['type'])) { |
||
296 | $result .= "<span class='git-".$item['type']."'>".$item['name']."</span>"; |
||
297 | } |
||
298 | } |
||
299 | return $result; |
||
300 | } |
||
301 | |||
302 | /** |
||
303 | * |
||
304 | */ |
||
305 | public function showDiffPath($hash,$hash_file) { |
||
306 | $path = $this->showNameHashFile($hash_file); |
||
307 | $output = $this->run_git("diff $hash^..$hash -- '$path'"); |
||
308 | if (empty($output)) { |
||
309 | throw new NotFoundHttpException("No se puede mostrar los detalles del archivo: '$path' ($hash_file), en la versión: $hash."); |
||
310 | } else { |
||
311 | return $this->formatDiff($output); |
||
312 | } |
||
313 | } |
||
314 | |||
315 | /** |
||
316 | * |
||
317 | */ |
||
318 | public function showDiffCommit($hash_from,$hash_to) { |
||
0 ignored issues
–
show
|
|||
319 | $output = $this->run_git("diff \"hash_from..$hash_to\""); |
||
320 | return $this->formatDiff($output); |
||
321 | } |
||
322 | |||
323 | /** |
||
324 | * |
||
325 | */ |
||
326 | public function formatDiff($text) { |
||
327 | $output = array(); |
||
328 | $output['info'] = ''; |
||
329 | /* |
||
330 | old mode <mode> |
||
331 | new mode <mode> |
||
332 | new file mode <mode> |
||
333 | deleted file mode <mode> |
||
334 | copy from <path> |
||
335 | copy to <path> |
||
336 | rename from <path> |
||
337 | rename to <path> |
||
338 | similarity index <number> |
||
339 | dissimilarity index <number> |
||
340 | index <hash>..<hash> <mode> |
||
341 | */ |
||
342 | foreach ($text as $item) { |
||
343 | if ('diff' === substr($item, 0, 4)) { |
||
344 | preg_match('#^diff --git a/(.*) b/(.*)$#', $item, $matches); |
||
345 | $output['name'] = $matches[1]; |
||
346 | $output['info'] .= "<pre>".$item."</pre>"; |
||
347 | } elseif (('new file'===substr($item,0,8)) || ('old mode'===substr($item,0,8)) || |
||
348 | ('new mode'===substr($item,0,8)) || ('deleted file'===substr($item,0,12)) || |
||
349 | ('index' === substr($item, 0, 5))) { |
||
350 | $output['info'] .= "<pre>".$item."</pre>"; |
||
351 | View Code Duplication | } elseif ('Binary files'===substr($item,0,12)) { |
|
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. ![]() |
|||
352 | $output['contents'][] = array('lineNumOld'=> "-", 'lineNumNew'=> "-", 'lineCode' => "<pre class='chunk'>".$item."</pre>",); |
||
353 | } elseif ('@@' === substr($item, 0, 2)) { |
||
354 | preg_match('/@@ -([0-9]+)/', $item, $matches); |
||
355 | $lineNumOld = $matches[1] - 1; |
||
356 | $lineNumNew = $matches[1] - 1; |
||
357 | $output['contents'][] = array('lineNumOld'=> "-", 'lineNumNew'=> "-", 'lineCode' => "<pre class='chunk'>".$item."</pre>",); |
||
358 | View Code Duplication | } elseif ('---' === substr($item, 0, 3)) { |
|
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. ![]() |
|||
359 | $output['info'] .= "<pre class='old'>".$item."</pre>"; |
||
360 | } elseif ('+++' === substr($item, 0, 3)) { |
||
361 | $output['info'] .= "<pre class='new'>".$item."</pre>"; |
||
362 | View Code Duplication | } elseif ('\ ' === substr($item, 0, 2)) { |
|
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. ![]() |
|||
363 | $output['contents'][] = array('lineNumOld'=> "-", 'lineNumNew'=> "-", 'lineCode'=> "<pre>".htmlspecialchars($item)."</pre>",); |
||
364 | } elseif ('-' === substr($item, 0, 1)) { |
||
365 | $lineNumOld++; |
||
0 ignored issues
–
show
The variable
$lineNumOld does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
366 | $output['contents'][] = array('lineNumOld'=> $lineNumOld, 'lineNumNew'=> "-", 'lineCode'=> "<pre class='old'>".htmlspecialchars($item)."</pre>",); |
||
367 | View Code Duplication | } elseif ('+' === substr($item, 0, 1)) { |
|
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. ![]() |
|||
368 | $lineNumNew++; |
||
0 ignored issues
–
show
The variable
$lineNumNew does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
369 | $output['contents'][] = array('lineNumOld'=> "-", 'lineNumNew'=> $lineNumNew, 'lineCode'=> "<pre class='new'>".htmlspecialchars($item)."</pre>",); |
||
370 | } else { |
||
371 | $lineNumNew++; |
||
372 | $lineNumOld++; |
||
373 | $output['contents'][] = array('lineNumOld'=> $lineNumOld, 'lineNumNew'=> $lineNumNew, 'lineCode'=> "<pre>".htmlspecialchars($item)."</pre>",); |
||
374 | } |
||
375 | } |
||
376 | return $output; |
||
377 | } |
||
378 | |||
379 | /** |
||
380 | * Show blob file |
||
381 | */ |
||
382 | public function showBlobFile($hash_file) { |
||
383 | $output = array(); |
||
384 | $output['name'] = $this->showNameHashFile($hash_file); |
||
385 | $command = "cat-file blob $hash_file"; |
||
386 | $output['contents'] = $this->run_git($command); |
||
387 | return $output; |
||
388 | } |
||
389 | |||
390 | /** |
||
391 | * Show name of hash file |
||
392 | */ |
||
393 | public function showNameHashFile($hash_file) { |
||
394 | $command = "rev-list --objects --all | grep $hash_file"; |
||
395 | $name = ''; |
||
396 | foreach (($this->run_git($command)) as $item) { |
||
0 ignored issues
–
show
The expression
$this->run_git($command) of type null|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
397 | $output = explode(' ', $item,2); |
||
398 | if ($output['0']==$hash_file) { |
||
399 | $name = $output['1']; |
||
400 | } |
||
401 | } |
||
402 | return $name; |
||
403 | } |
||
404 | |||
405 | /** |
||
406 | * Get blade file, opon para los view tree |
||
407 | */ |
||
408 | //public function getBlame($file) { |
||
409 | // $blame = array(); |
||
410 | // $logs = $this->getClient()->run($this, "blame -s $file"); |
||
411 | // $logs = explode("\n", $logs); |
||
412 | // |
||
413 | // $i = 0; |
||
414 | // $previousCommit = ''; |
||
415 | // foreach ($logs as $log) { |
||
416 | // if ($log == '') { |
||
417 | // continue; |
||
418 | // } |
||
419 | // |
||
420 | // preg_match_all("/([a-zA-Z0-9^]{8})\s+.*?([0-9]+)\)(.+)/", $log, $match); |
||
421 | // |
||
422 | // $currentCommit = $match[1][0]; |
||
423 | // if ($currentCommit != $previousCommit) { |
||
424 | // ++$i; |
||
425 | // $blame[$i] = array('line' => '', 'commit' => $currentCommit); |
||
426 | // } |
||
427 | // |
||
428 | // $blame[$i]['line'] .= PHP_EOL . $match[3][0]; |
||
429 | // $previousCommit = $currentCommit; |
||
430 | // } |
||
431 | // |
||
432 | // return $blame; |
||
433 | //} |
||
434 | |||
435 | /** |
||
436 | * Gets a list of tags in this branch |
||
437 | */ |
||
438 | public function getTags() { |
||
439 | $tag = array(); |
||
440 | foreach($this->run_git("tag -l") as $item) { |
||
0 ignored issues
–
show
The expression
$this->run_git('tag -l') of type null|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
441 | $tag[]= $this->showtag($item); |
||
442 | } |
||
443 | return $tag; |
||
444 | } |
||
445 | |||
446 | /** |
||
447 | * Verificar un Tag |
||
448 | */ |
||
449 | public function showtag($tag) { |
||
450 | $tags = array(); |
||
451 | $tags['message'] = ''; |
||
452 | $pattern = '/^(tagger) ([^<]+) <([^>]*)> ([0-9]+) (.*)$/'; |
||
453 | foreach($this->run_git("tag -v ".$tag) as $line) { |
||
0 ignored issues
–
show
The expression
$this->run_git('tag -v ' . $tag) of type null|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
454 | if (substr($line, 0, 6) === 'object') { |
||
455 | $tags['h'] = substr($line, 7); |
||
456 | View Code Duplication | } elseif (substr($line, 0, 4) === 'type') { |
|
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. ![]() |
|||
457 | $tags['type'] = substr($line, 5); |
||
458 | } elseif (substr($line, 0, 6) === 'tagger') { |
||
459 | preg_match($pattern, $line, $matches); |
||
460 | $tags['name'] = $matches[2]; |
||
461 | $tags['mail'] = $matches[3]; |
||
462 | $tags['stamp'] = $matches[4] + ((intval($matches[5]) / 100.0) * 3600); |
||
463 | $tags['timezone'] = $matches[5]; |
||
464 | $tags['utcstamp'] = $matches[4]; |
||
465 | $tags['datetime'] = strftime($this->datetimeFormat, $tags['utcstamp']); |
||
466 | $tags['datetime_local'] = strftime($this->datetimeFormat, $tags['stamp']) .' '. $tags['timezone']; |
||
467 | View Code Duplication | } elseif (substr($line, 0, 3) === 'tag') { |
|
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. ![]() |
|||
468 | $tags['tag'] = substr($line, 4); |
||
469 | } elseif (!empty($line)) { |
||
470 | $tags['message'] .= $line.'<br>'; |
||
471 | } |
||
472 | } |
||
473 | $tags['message_short'] = strlen($tags['message'])>=$this->subjectMaxLength?substr($tags['message'],0,$this->subjectMaxLength).'...':$tags['message']; |
||
474 | return $tags; |
||
475 | } |
||
476 | |||
477 | /** |
||
478 | * Verifica si un hash existe en rev list |
||
479 | */ |
||
480 | public function verifyHash($hash) { |
||
481 | $command = "rev-list --all | grep $hash"; |
||
482 | return $this->run_git($command); |
||
483 | } |
||
484 | |||
485 | /** |
||
486 | * Gets a list of git branches |
||
487 | */ |
||
488 | public function getBranches() { |
||
489 | $branches = array(); |
||
490 | foreach($this->run_git("branch") as $branchName) { |
||
0 ignored issues
–
show
The expression
$this->run_git('branch') of type null|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
491 | $branches[] = array('branch' => substr($branchName, 2), 'active' => substr($branchName,0,2)=="* "?true:false); |
||
492 | } |
||
493 | return $branches; |
||
494 | } |
||
495 | |||
496 | /** |
||
497 | * Graficar el log de un repositorio comands git |
||
498 | */ |
||
499 | public function showGraphLog() { |
||
500 | $command = "log --graph --abbrev-commit --decorate --format=format:'<a href=commitview?id=$this->repository&hash=%H><b>%h</b></a> - <font color=blue>%aD (%ar)</font> <span class=git-ref>%d</span>%n'' <i>%s</i> - <b>%an</b>' --all"; |
||
501 | $output = $this->run_git($command); |
||
502 | return implode("\n", $output); |
||
503 | } |
||
504 | |||
505 | /* |
||
506 | * |
||
507 | */ |
||
508 | public function getTotalCommits() { |
||
509 | $command = "rev-list --all $file | wc -l"; |
||
0 ignored issues
–
show
|
|||
510 | return $this->run_git($command); |
||
511 | } |
||
512 | |||
513 | /** |
||
514 | * Obtener los disparadores disponibles en el repsoitorio con su contenido |
||
515 | */ |
||
516 | public function getHooks() { |
||
517 | $Hooks = array(); |
||
518 | if ($dir = opendir($this->cotainerPath.$this->project."/hooks/")) { |
||
0 ignored issues
–
show
The property
project does not exist on object<markmarco16\git\components\Repository> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
519 | while (($file = readdir($dir)) !== false) { |
||
520 | if (($file !=='.') && ($file !=='..')) { |
||
521 | $Hooks[] = array('name' => $file, 'contents'=> file_get_contents($this->cotainerPath.$this->repositoryPath.'/hooks/'.$file)); |
||
522 | } |
||
523 | } |
||
524 | closedir($dir); |
||
525 | } |
||
526 | return $Hooks; |
||
527 | } |
||
528 | |||
529 | /** |
||
530 | * Get all, git configuration variable |
||
531 | */ |
||
532 | public function getConfigAll($global = false) { |
||
533 | $config = array(); |
||
534 | if ($global) { |
||
535 | $output = $this->run_git("config --global -l"); |
||
536 | } else { |
||
537 | $output = $this->run_git("config --local -l"); |
||
538 | } |
||
539 | if (!empty($output)) { |
||
540 | foreach ($output as $item) { |
||
541 | $matches = explode("=", $item); |
||
542 | $config[] = array('key'=>$matches[0], 'value'=>$matches[1], ); |
||
543 | } |
||
544 | } |
||
545 | return $config; |
||
546 | } |
||
547 | |||
548 | /** |
||
549 | * Get a git configuration variable |
||
550 | */ |
||
551 | public function getConfig($key, $global = false) { |
||
552 | if ($global) |
||
553 | $key = $this->run_git("config --global $key"); |
||
554 | else |
||
555 | $key = $this->run_git("config $key"); |
||
556 | return $key; |
||
557 | } |
||
558 | |||
559 | /** |
||
560 | * Execute comands git |
||
561 | */ |
||
562 | protected function run_git($command, $repository = null) { |
||
563 | $output = array(); |
||
564 | if ($repository == null) { |
||
565 | $cmd = $this->gitPath." --git-dir=".escapeshellarg($this->repositoryPath)." $command"; |
||
566 | } else { |
||
567 | $cmd = $this->gitPath." --git-dir=". escapeshellarg($this->cotainerPath . $repository) ." $command"; |
||
568 | } |
||
569 | $ret = 0; |
||
570 | exec($cmd, $output, $ret); |
||
571 | return $output; |
||
572 | } |
||
573 | } |
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.