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 | |||
4 | namespace Alnutile\Codereview; |
||
5 | |||
6 | use Carbon\Carbon; |
||
7 | use GuzzleHttp\Client; |
||
8 | |||
9 | class GithubClientProvider extends Application |
||
10 | { |
||
11 | |||
12 | |||
13 | protected $github_token = ""; |
||
14 | |||
15 | protected $client; |
||
16 | |||
17 | protected $base_url = "https://api.github.com/search/commits"; |
||
18 | |||
19 | protected $query_string = ""; |
||
20 | |||
21 | |||
22 | /** |
||
23 | * GithubClientProvider constructor. |
||
24 | * @param null|\Silly\Edition\Pimple\Application $app |
||
25 | * @param Client $client |
||
26 | * @codeCoverageIgnore |
||
27 | */ |
||
28 | public function __construct($app, Client $client) |
||
29 | { |
||
30 | parent::__construct($app); |
||
31 | |||
32 | $this->client = $client; |
||
33 | } |
||
34 | |||
35 | |||
36 | public function getLatestCommits($query = []) |
||
37 | { |
||
38 | |||
39 | $this->setQueryString($query); |
||
40 | |||
41 | $url = sprintf( |
||
42 | "%s?%s", |
||
43 | $this->base_url, |
||
44 | $this->getQueryString() |
||
45 | ); |
||
46 | |||
47 | $results = $this->getClient()->get($url); |
||
48 | |||
49 | return $this->returnResults($results); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | * @codeCoverageIgnore |
||
55 | */ |
||
56 | public function getGithubToken() |
||
57 | { |
||
58 | if (!$this->github_token) { |
||
59 | $this->setGithubToken(); |
||
60 | } |
||
61 | return $this->github_token; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @param string $github_token |
||
66 | */ |
||
67 | public function setGithubToken($github_token = null) |
||
68 | { |
||
69 | if (!$github_token) { |
||
0 ignored issues
–
show
|
|||
70 | $github_token = $this->app->getConfigValueByKey('github_token'); |
||
0 ignored issues
–
show
The method
getConfigValueByKey() does not seem to exist on object<Silly\Edition\Pimple\Application> .
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. ![]() |
|||
71 | } |
||
72 | $this->github_token = $github_token; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @return Client |
||
77 | * @codeCoverageIgnore |
||
78 | */ |
||
79 | public function getClient() |
||
80 | { |
||
81 | return $this->client; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param Client $client |
||
86 | * @codeCoverageIgnore |
||
87 | */ |
||
88 | public function setClient($client) |
||
89 | { |
||
90 | $this->client = $client; |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @param $results |
||
95 | * @return array|mixed |
||
96 | * @codeCoverageIgnore |
||
97 | */ |
||
98 | private function returnResults($results) |
||
99 | { |
||
100 | if ($this->isGuzzleResponse($results)) { |
||
101 | $results = json_decode($results->getBody(), true); |
||
102 | } |
||
103 | |||
104 | $results = $this->transformResults($results); |
||
105 | |||
106 | return $results; |
||
107 | } |
||
108 | |||
109 | public function getQueryString() |
||
110 | { |
||
111 | return $this->query_string; |
||
112 | } |
||
113 | |||
114 | |||
115 | |||
116 | /** |
||
117 | * @param string $query_string |
||
0 ignored issues
–
show
There is no parameter named
$query_string . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
118 | */ |
||
119 | public function setQueryString($query = []) |
||
120 | { |
||
121 | if (isset($query['committer'])) { |
||
122 | $items[] = sprintf("committer:%s", $query['committer']); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$items was never initialized. Although not strictly required by PHP, it is generally a good practice to add $items = 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. ![]() |
|||
123 | } |
||
124 | |||
125 | $items[] = 'sort:committer-date-desc'; |
||
0 ignored issues
–
show
The variable
$items 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
![]() |
|||
126 | |||
127 | if (isset($query['org'])) { |
||
128 | $items[] = sprintf("org:%s", $query['org']); |
||
129 | } |
||
130 | |||
131 | $query = sprintf("q=%s", implode("+", $items)); |
||
132 | |||
133 | $query = sprintf('%s&access_token=%s', $query, $this->getGithubToken()); |
||
134 | |||
135 | $this->query_string = $query; |
||
136 | } |
||
137 | |||
138 | private function transformResults($results = []) |
||
139 | { |
||
140 | $items = []; |
||
141 | foreach ($results['items'] as $key => $value) { |
||
142 | $items[] = $this->getResult($value); |
||
143 | } |
||
144 | |||
145 | return $items; |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * @param $value |
||
150 | * @return array |
||
151 | * @codeCoverageIgnore |
||
152 | */ |
||
153 | private function getResult($value) |
||
154 | { |
||
155 | return [ |
||
156 | 'repository' => $value['repository']['html_url'], |
||
157 | 'commit' => $value['html_url'], |
||
158 | 'date' => $this->getDate($value) |
||
159 | ]; |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * @param $results |
||
164 | * @return bool |
||
165 | * @codeCoverageIgnore |
||
166 | */ |
||
167 | private function isGuzzleResponse($results) |
||
168 | { |
||
169 | return is_object($results) && get_class($results) == 'GuzzleHttp\Psr7\Response'; |
||
170 | } |
||
171 | |||
172 | /** |
||
173 | * @param $value |
||
174 | * @return string |
||
175 | * @codeCoverageIgnore |
||
176 | */ |
||
177 | private function getDate($value) |
||
178 | { |
||
179 | return Carbon::parse($value['commit']['committer']['date'])->format('Y/m/d H:i'); |
||
180 | } |
||
181 | } |
||
182 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: