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 | class APIEnvironment extends APINoun { |
||
0 ignored issues
–
show
|
|||
4 | |||
5 | /** |
||
6 | * @var array |
||
7 | */ |
||
8 | private static $allowed_actions = array( |
||
9 | 'ping', |
||
10 | 'deploy' |
||
11 | ); |
||
12 | |||
13 | /** |
||
14 | * @param \SS_HTTPRequest $request |
||
15 | * @return \SS_HTTPResponse |
||
16 | */ |
||
17 | public function index(\SS_HTTPRequest $request) { |
||
18 | if(!$this->record->canView($this->getMember())) { |
||
19 | return $this->message('You are not authorized to view this environment', 403); |
||
20 | } |
||
21 | switch($request->httpMethod()) { |
||
22 | case 'GET': |
||
23 | $href = Director::absoluteURL($this->record->Project()->APILink($this->record->Name)); |
||
24 | return $this->getAPIResponse(array( |
||
25 | "name" => $this->record->Name, |
||
26 | "project" => $this->record->Project()->Name, |
||
27 | "href" => $href, |
||
28 | "created" => $this->record->Created, |
||
29 | "last-edited" => $this->record->LastEdited, |
||
30 | |||
31 | // Stolen from https://github.com/kevinswiber/siren spec |
||
32 | "actions" => array( |
||
33 | array( |
||
34 | "name" => "deploy", |
||
35 | "method" => "POST", |
||
36 | "href" => "$href/deploy", |
||
37 | "type" => "application/json", |
||
38 | "fields" => array( |
||
39 | array("name" => "release", "type" => "text"), |
||
40 | ), |
||
41 | ) |
||
42 | ) |
||
43 | )); |
||
44 | default: |
||
45 | return $this->message('API not found', 404); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param \SS_HTTPRequest $request |
||
51 | * @return \SS_HTTPResponse |
||
52 | */ |
||
53 | View Code Duplication | public function ping(\SS_HTTPRequest $request) { |
|
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. ![]() |
|||
54 | if(!$this->record->canView($this->getMember())) { |
||
55 | return $this->message('You are not authorized to do that on this environment', 403); |
||
56 | } |
||
57 | switch($request->httpMethod()) { |
||
58 | case 'GET': |
||
59 | return $this->getPing($this->getRequest()->param('ID')); |
||
60 | case 'POST': |
||
61 | return $this->createPing(); |
||
62 | default: |
||
63 | return $this->message('API not found', 404); |
||
64 | } |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @deprecated 2.0.0 - moved to DeployDispatcher |
||
69 | * |
||
70 | * @param \SS_HTTPRequest $request |
||
71 | * @return \SS_HTTPResponse |
||
72 | */ |
||
73 | View Code Duplication | public function deploy(\SS_HTTPRequest $request) { |
|
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. ![]() |
|||
74 | if(!$this->record->canView($this->getMember())) { |
||
75 | return $this->message('You are not authorized to do that on this environment', 403); |
||
76 | } |
||
77 | switch($request->httpMethod()) { |
||
78 | case 'GET': |
||
79 | return $this->getDeploy($this->getRequest()->param('ID')); |
||
0 ignored issues
–
show
The method
APIEnvironment::getDeploy() has been deprecated with message: 2.0.0 - moved to DeployDispatcher
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead. ![]() |
|||
80 | case 'POST': |
||
81 | return $this->createDeploy(); |
||
0 ignored issues
–
show
The method
APIEnvironment::createDeploy() has been deprecated with message: 2.0.0 - moved to DeployDispatcher
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead. ![]() |
|||
82 | default: |
||
83 | return $this->message('API not found', 404); |
||
84 | } |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @return string |
||
89 | */ |
||
90 | public function Link() { |
||
91 | return Controller::join_links( |
||
92 | $this->parent->Link(), |
||
93 | $this->record->Project()->Name, |
||
94 | $this->record->Name |
||
95 | ); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @return SS_HTTPResponse |
||
100 | */ |
||
101 | protected function showRecord() { |
||
102 | return $this->getAPIResponse($this->record->toMap()); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @return SS_HTTPResponse |
||
107 | */ |
||
108 | protected function createPing() { |
||
109 | if(!$this->record->canDeploy($this->getMember())) { |
||
110 | return $this->message('You are not authorized to do that on this environment', 403); |
||
111 | } |
||
112 | $ping = DNPing::create(); |
||
113 | $ping->EnvironmentID = $this->record->ID; |
||
114 | $ping->write(); |
||
115 | $ping->start(); |
||
116 | |||
117 | $location = Director::absoluteBaseURL() . $this->Link() . '/ping/' . $ping->ID; |
||
118 | $output = array( |
||
119 | 'message' => 'Ping queued as job ' . $ping->ResqueToken, |
||
120 | 'href' => $location, |
||
121 | ); |
||
122 | |||
123 | $response = $this->getAPIResponse($output); |
||
124 | $response->setStatusCode(201); |
||
125 | $response->addHeader('Location', $location); |
||
126 | return $response; |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * @param int $ID |
||
131 | * @return SS_HTTPResponse |
||
132 | */ |
||
133 | View Code Duplication | protected function getPing($ID) { |
|
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. ![]() |
|||
134 | $ping = DNPing::get()->byID($ID); |
||
135 | if(!$ping) { |
||
136 | return $this->message('Ping not found', 404); |
||
137 | } |
||
138 | $output = array( |
||
139 | 'status' => $ping->ResqueStatus(), |
||
140 | 'message' => $ping->LogContent() |
||
141 | ); |
||
142 | |||
143 | return $this->getAPIResponse($output); |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * @deprecated 2.0.0 - moved to DeployDispatcher |
||
148 | * |
||
149 | * @return SS_HTTPResponse |
||
150 | */ |
||
151 | protected function createDeploy() { |
||
152 | if(!$this->record->canDeploy($this->getMember())) { |
||
153 | return $this->message('You are not authorized to do that on this environment', 403); |
||
154 | } |
||
155 | |||
156 | $reqBody = $this->getRequestBody(); |
||
157 | |||
158 | if($reqBody === null) { |
||
159 | return $this->message('the request body did not contain a valid JSON object.', 400); |
||
160 | } |
||
161 | |||
162 | if(empty($reqBody['release'])) { |
||
163 | return $this->message('deploy requires a {"release": "sha1"} in the body of the request.', 400); |
||
164 | } |
||
165 | |||
166 | $strategy = new DeploymentStrategy($this->record, array( |
||
0 ignored issues
–
show
$this->record of type object<DataObject> is not a sub-type of object<DNEnvironment> . It seems like you assume a child class of the class DataObject to be always present.
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass. Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type. ![]() |
|||
167 | 'sha' => $reqBody['release'] |
||
168 | )); |
||
169 | $deploy = $strategy->createDeployment(); |
||
170 | $deploy->start(); |
||
0 ignored issues
–
show
The method
start does not exist on object<DNDeployment> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
171 | $location = Director::absoluteBaseURL() . $this->Link() . '/deploy/' . $deploy->ID; |
||
172 | $output = array( |
||
173 | 'message' => 'Deploy queued as job ' . $deploy->ResqueToken, |
||
174 | 'href' => $location, |
||
175 | ); |
||
176 | $response = $this->getAPIResponse($output); |
||
177 | $response->setStatusCode(201); |
||
178 | $response->addHeader('Location', $location); |
||
179 | return $response; |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * @deprecated 2.0.0 - moved to DeployDispatcher |
||
184 | * |
||
185 | * @param int $id |
||
186 | * @return SS_HTTPResponse |
||
187 | */ |
||
188 | View Code Duplication | protected function getDeploy($id) { |
|
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. ![]() |
|||
189 | $deploy = DNDeployment::get()->byID($id); |
||
190 | if(!$deploy) { |
||
191 | return $this->message('Deploy not found', 404); |
||
192 | } |
||
193 | $output = array( |
||
194 | 'status' => $deploy->ResqueStatus(), |
||
195 | 'message' => $deploy->LogContent() |
||
196 | ); |
||
197 | |||
198 | return $this->getAPIResponse($output); |
||
199 | } |
||
200 | } |
||
201 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.