Total Complexity | 61 |
Total Lines | 1007 |
Duplicated Lines | 9.04 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Client often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Client, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
32 | class Client implements ClientInterface |
||
33 | { |
||
34 | protected $connector; |
||
35 | |||
36 | protected $query = []; |
||
37 | |||
38 | /** |
||
39 | * Client constructor. |
||
40 | * @param ConnectorInterface $connector |
||
41 | */ |
||
42 | public function __construct(ConnectorInterface $connector) |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @param ConnectorInterface $connector |
||
49 | * |
||
50 | * @return static |
||
51 | */ |
||
52 | public static function factory(ConnectorInterface $connector) |
||
53 | { |
||
54 | $client = new static( |
||
55 | $connector |
||
56 | ); |
||
57 | |||
58 | return $client; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Get query from Client. |
||
63 | * |
||
64 | * @return array |
||
65 | */ |
||
66 | public function getQuery() |
||
67 | { |
||
68 | return $this->query; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Clear query. |
||
73 | */ |
||
74 | public function clearQuery() |
||
75 | { |
||
76 | $this->query = []; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @param string $name |
||
81 | * @param string $value |
||
82 | */ |
||
83 | public function addQuery($name, $value) |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Shows all applications. |
||
90 | * |
||
91 | * @return ApplicationsResponse |
||
92 | */ |
||
93 | public function applications() |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Shows information about an application. |
||
100 | * |
||
101 | * @param string $applicationUuid |
||
102 | * @return ApplicationResponse |
||
103 | */ |
||
104 | public function application($applicationUuid) |
||
105 | { |
||
106 | return new ApplicationResponse( |
||
107 | $this->connector->request( |
||
108 | 'get', |
||
109 | "/applications/${applicationUuid}", |
||
110 | $this->query |
||
111 | ) |
||
112 | ); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Renames an application. |
||
117 | * |
||
118 | * @param string $applicationUuid |
||
119 | * @param string $name |
||
120 | * @return OperationResponse |
||
121 | */ |
||
122 | View Code Duplication | public function renameApplication($applicationUuid, $name) |
|
123 | { |
||
124 | |||
125 | $options = [ |
||
126 | 'form_params' => [ |
||
127 | 'name' => $name, |
||
128 | ], |
||
129 | ]; |
||
130 | |||
131 | return new OperationResponse( |
||
132 | $this->connector->request( |
||
133 | 'put', |
||
134 | "/applications/${applicationUuid}", |
||
135 | $options, |
||
136 | $this->query |
||
137 | ) |
||
138 | ); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Shows all code branches and tags in an application. |
||
143 | * |
||
144 | * @param string $applicationUuid |
||
145 | * @return BranchesResponse |
||
146 | */ |
||
147 | public function code($applicationUuid) |
||
148 | { |
||
149 | return new BranchesResponse( |
||
150 | $this->connector->request( |
||
151 | 'get', |
||
152 | "/applications/${applicationUuid}/code", |
||
153 | $this->query |
||
154 | ) |
||
155 | ); |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * Shows all databases in an application. |
||
160 | * |
||
161 | * @param string $applicationUuid |
||
162 | * @return DatabasesResponse |
||
163 | */ |
||
164 | public function databases($applicationUuid) |
||
165 | { |
||
166 | return new DatabasesResponse( |
||
167 | $this->connector->request( |
||
168 | 'get', |
||
169 | "/applications/${applicationUuid}/databases", |
||
170 | $this->query |
||
171 | ) |
||
172 | ); |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * Shows all databases in an environment. |
||
177 | * |
||
178 | * @param string $environmentUuid |
||
179 | * @return DatabasesResponse |
||
180 | */ |
||
181 | public function environmentDatabases($environmentUuid) |
||
182 | { |
||
183 | return new DatabasesResponse( |
||
184 | $this->connector->request( |
||
185 | 'get', |
||
186 | "/environments/${environmentUuid}/databases", |
||
187 | $this->query |
||
188 | ) |
||
189 | ); |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * Copies a database from an environment to an environment. |
||
194 | * |
||
195 | * @param string $environmentFromUuid |
||
196 | * @param string $dbName |
||
197 | * @param string $environmentToUuid |
||
198 | * @return OperationResponse |
||
199 | */ |
||
200 | View Code Duplication | public function databaseCopy($environmentFromUuid, $dbName, $environmentToUuid) |
|
201 | { |
||
202 | $options = [ |
||
203 | 'form_params' => [ |
||
204 | 'name' => $dbName, |
||
205 | 'source' => $environmentFromUuid, |
||
206 | ], |
||
207 | ]; |
||
208 | |||
209 | return new OperationResponse( |
||
210 | $this->connector->request('post', "/environments/${environmentToUuid}/databases", $this->query, $options) |
||
211 | ); |
||
212 | } |
||
213 | |||
214 | /** |
||
215 | * Create a new database. |
||
216 | * |
||
217 | * @param string $applicationUuid |
||
218 | * @param string $name |
||
219 | * @return OperationResponse |
||
220 | */ |
||
221 | public function databaseCreate($applicationUuid, $name) |
||
222 | { |
||
223 | $options = [ |
||
224 | 'form_params' => [ |
||
225 | 'name' => $name, |
||
226 | ], |
||
227 | ]; |
||
228 | |||
229 | return new OperationResponse( |
||
230 | $this->connector->request('post', "/applications/${applicationUuid}/databases", $this->query, $options) |
||
231 | ); |
||
232 | } |
||
233 | |||
234 | /** |
||
235 | * Delete a database. |
||
236 | * |
||
237 | * @param string $applicationUuid |
||
238 | * @param string $name |
||
239 | * @return OperationResponse |
||
240 | */ |
||
241 | public function databaseDelete($applicationUuid, $name) |
||
242 | { |
||
243 | return new OperationResponse( |
||
244 | $this->connector->request('post', "/applications/${applicationUuid}/databases/${name}", $this->query) |
||
245 | ); |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * Backup a database. |
||
250 | * |
||
251 | * @param string $environmentUuid |
||
252 | * @param string $dbName |
||
253 | * @return OperationResponse |
||
254 | */ |
||
255 | public function createDatabaseBackup($environmentUuid, $dbName) |
||
256 | { |
||
257 | return new OperationResponse( |
||
258 | $this->connector->request( |
||
259 | 'post', |
||
260 | "/environments/${environmentUuid}/databases/${dbName}/backups", |
||
261 | $this->query |
||
262 | ) |
||
263 | ); |
||
264 | } |
||
265 | |||
266 | /** |
||
267 | * Shows all database backups in an environment. |
||
268 | * |
||
269 | * @param string $environmentUuid |
||
270 | * @param string $dbName |
||
271 | * @return BackupsResponse |
||
272 | */ |
||
273 | public function databaseBackups($environmentUuid, $dbName) |
||
274 | { |
||
275 | return new BackupsResponse( |
||
276 | $this->connector->request( |
||
277 | 'get', |
||
278 | "/environments/${environmentUuid}/databases/${dbName}/backups", |
||
279 | $this->query |
||
280 | ) |
||
281 | ); |
||
282 | } |
||
283 | |||
284 | /** |
||
285 | * Gets information about a database backup. |
||
286 | * |
||
287 | * @param string $environmentUuid |
||
288 | * @param int $backupId |
||
289 | * @return BackupResponse |
||
290 | */ |
||
291 | public function databaseBackup($environmentUuid, $backupId) |
||
292 | { |
||
293 | return new BackupResponse( |
||
294 | $this->connector->request( |
||
295 | 'get', |
||
296 | "/environments/${environmentUuid}/database-backups/${backupId}", |
||
297 | $this->query |
||
298 | ) |
||
299 | ); |
||
300 | } |
||
301 | |||
302 | /** |
||
303 | * Restores a database backup to a database in an environment. |
||
304 | * |
||
305 | * @param string $environmentUuid |
||
306 | * @param int $backupId |
||
307 | * @return OperationResponse |
||
308 | */ |
||
309 | public function restoreDatabaseBackup($environmentUuid, $backupId) |
||
310 | { |
||
311 | return new OperationResponse( |
||
312 | $this->connector->request( |
||
313 | 'post', |
||
314 | "/environments/${environmentUuid}/database-backups/${backupId}/actions/restore", |
||
315 | $this->query |
||
316 | ) |
||
317 | ); |
||
318 | } |
||
319 | |||
320 | /** |
||
321 | * Copies files from an environment to another environment. |
||
322 | * |
||
323 | * @param string $environmentUuidFrom |
||
324 | * @param string $environmentUuidTo |
||
325 | * @return OperationResponse |
||
326 | */ |
||
327 | public function copyFiles($environmentUuidFrom, $environmentUuidTo) |
||
328 | { |
||
329 | $options = [ |
||
330 | 'form_params' => [ |
||
331 | 'source' => $environmentUuidFrom, |
||
332 | ], |
||
333 | ]; |
||
334 | |||
335 | return new OperationResponse( |
||
336 | $this->connector->request('post', "/environments/${environmentUuidTo}/files", $this->query, $options) |
||
337 | ); |
||
338 | } |
||
339 | |||
340 | /** |
||
341 | * Deploys a code branch/tag to an environment. |
||
342 | * |
||
343 | * @param string $environmentUuid |
||
344 | * @param string $branch |
||
345 | * @return OperationResponse |
||
346 | */ |
||
347 | public function switchCode($environmentUuid, $branch) |
||
348 | { |
||
349 | |||
350 | $options = [ |
||
351 | 'form_params' => [ |
||
352 | 'branch' => $branch, |
||
353 | ], |
||
354 | ]; |
||
355 | |||
356 | return new OperationResponse( |
||
357 | $this->connector->request( |
||
358 | 'post', |
||
359 | "/environments/${environmentUuid}/code/actions/switch", |
||
360 | $this->query, |
||
361 | $options |
||
362 | ) |
||
363 | ); |
||
364 | } |
||
365 | |||
366 | /** |
||
367 | * Shows all domains on an environment. |
||
368 | * |
||
369 | * @param string $environmentUuid |
||
370 | * @return DomainsResponse |
||
371 | */ |
||
372 | public function domains($environmentUuid) |
||
379 | ) |
||
380 | ); |
||
381 | } |
||
382 | |||
383 | /** |
||
384 | * Adds a domain to an environment. |
||
385 | * |
||
386 | * @param string $environmentUuid |
||
387 | * @param string $hostname |
||
388 | * @return OperationResponse |
||
389 | */ |
||
390 | public function createDomain($environmentUuid, $hostname) |
||
391 | { |
||
392 | |||
393 | $options = [ |
||
394 | 'form_params' => [ |
||
395 | 'hostname' => $hostname, |
||
396 | ], |
||
397 | ]; |
||
398 | |||
399 | return new OperationResponse( |
||
400 | $this->connector->request('post', "/environments/${environmentUuid}/domains", $this->query, $options) |
||
401 | ); |
||
402 | } |
||
403 | |||
404 | /** |
||
405 | * Deletes a domain from an environment. |
||
406 | * |
||
407 | * @param string $environmentUuid |
||
408 | * @param string $domain |
||
409 | * @return OperationResponse |
||
410 | */ |
||
411 | public function deleteDomain($environmentUuid, $domain) |
||
412 | { |
||
413 | return new OperationResponse( |
||
414 | $this->connector->request('delete', "/environments/${environmentUuid}/domains/${domain}", $this->query) |
||
415 | ); |
||
416 | } |
||
417 | |||
418 | /** |
||
419 | * Purges varnish for selected domains in an environment. |
||
420 | * |
||
421 | * @param string $environmentUuid |
||
422 | * @param array $domains |
||
423 | * @return OperationResponse |
||
424 | */ |
||
425 | View Code Duplication | public function purgeVarnishCache($environmentUuid, array $domains) |
|
426 | { |
||
427 | |||
428 | $options = [ |
||
429 | 'form_params' => [ |
||
430 | 'domains' => $domains, |
||
431 | ], |
||
432 | ]; |
||
433 | |||
434 | return new OperationResponse( |
||
435 | $this->connector->request( |
||
436 | 'post', |
||
437 | "/environments/${environmentUuid}/domains/actions/clear-varnish", |
||
438 | $this->query, |
||
439 | $options |
||
440 | ) |
||
441 | ); |
||
442 | } |
||
443 | |||
444 | /** |
||
445 | * Shows all tasks in an application. |
||
446 | * |
||
447 | * @param string $applicationUuid |
||
448 | * @return TasksResponse |
||
449 | */ |
||
450 | public function tasks($applicationUuid) |
||
451 | { |
||
452 | return new TasksResponse( |
||
453 | $this->connector->request( |
||
454 | 'get', |
||
455 | "/applications/${applicationUuid}/tasks", |
||
456 | $this->query |
||
457 | ) |
||
458 | ); |
||
459 | } |
||
460 | |||
461 | /** |
||
462 | * Shows all environments in an application. |
||
463 | * |
||
464 | * @param string $applicationUuid |
||
465 | * @return EnvironmentsResponse |
||
466 | */ |
||
467 | public function environments($applicationUuid) |
||
468 | { |
||
469 | return new EnvironmentsResponse( |
||
470 | $this->connector->request( |
||
471 | 'get', |
||
472 | "/applications/${applicationUuid}/environments", |
||
473 | $this->query |
||
474 | ) |
||
475 | ); |
||
476 | } |
||
477 | |||
478 | /** |
||
479 | * Gets information about an environment. |
||
480 | * |
||
481 | * @param string $environmentUuid |
||
482 | * @return EnvironmentResponse |
||
483 | */ |
||
484 | public function environment($environmentUuid) |
||
485 | { |
||
486 | return new EnvironmentResponse( |
||
487 | $this->connector->request( |
||
488 | 'get', |
||
489 | "/environments/${environmentUuid}", |
||
490 | $this->query |
||
491 | ) |
||
492 | ); |
||
493 | } |
||
494 | |||
495 | /** |
||
496 | * Renames an environment. |
||
497 | * |
||
498 | * @param string $environmentUuid |
||
499 | * @param string $label |
||
500 | * @return OperationResponse |
||
501 | */ |
||
502 | public function renameEnvironment($environmentUuid, $label) |
||
503 | { |
||
504 | |||
505 | $options = [ |
||
506 | 'form_params' => [ |
||
507 | 'label' => $label, |
||
508 | ], |
||
509 | ]; |
||
510 | |||
511 | return new OperationResponse( |
||
512 | $this->connector->request( |
||
513 | 'post', |
||
514 | "/environments/${environmentUuid}/actions/change-label", |
||
515 | $this->query, |
||
516 | $options |
||
517 | ) |
||
518 | ); |
||
519 | } |
||
520 | |||
521 | /** |
||
522 | * Show all servers associated with an environment. |
||
523 | * |
||
524 | * @param string $environmentUuid |
||
525 | * @return ServersResponse |
||
526 | */ |
||
527 | public function servers($environmentUuid) |
||
528 | { |
||
529 | return new ServersResponse( |
||
530 | $this->connector->request( |
||
531 | 'get', |
||
532 | "/environments/${environmentUuid}/servers", |
||
533 | $this->query |
||
534 | ) |
||
535 | ); |
||
536 | } |
||
537 | |||
538 | /** |
||
539 | * Enable livedev mode for an environment. |
||
540 | * |
||
541 | * @param string $environmentUuid |
||
542 | * @return OperationResponse |
||
543 | */ |
||
544 | public function enableLiveDev($environmentUuid) |
||
545 | { |
||
546 | return new OperationResponse( |
||
547 | $this->connector->request('post', "/environments/${environmentUuid}/livedev/actions/enable", $this->query) |
||
548 | ); |
||
549 | } |
||
550 | |||
551 | /** |
||
552 | * Disable livedev mode for an environment. |
||
553 | * |
||
554 | * @param string $environmentUuid |
||
555 | * @return OperationResponse |
||
556 | */ |
||
557 | public function disableLiveDev($environmentUuid) |
||
558 | { |
||
559 | |||
560 | $options = [ |
||
561 | 'form_params' => [ |
||
562 | 'discard' => 1, |
||
563 | ], |
||
564 | ]; |
||
565 | |||
566 | return new OperationResponse( |
||
567 | $this->connector->request( |
||
568 | 'post', |
||
569 | "/environments/${environmentUuid}/livedev/actions/disable", |
||
570 | $this->query, |
||
571 | $options |
||
572 | ) |
||
573 | ); |
||
574 | } |
||
575 | |||
576 | /** |
||
577 | * Enable production mode for an environment. |
||
578 | * |
||
579 | * @param string $environmentUuid |
||
580 | * @return OperationResponse |
||
581 | */ |
||
582 | public function enableProductionMode($environmentUuid) |
||
583 | { |
||
584 | return new OperationResponse( |
||
585 | $this->connector->request( |
||
586 | 'post', |
||
587 | "/environments/${environmentUuid}/production-mode/actions/enable", |
||
588 | $this->query |
||
589 | ) |
||
590 | ); |
||
591 | } |
||
592 | |||
593 | /** |
||
594 | * Disable production mode for an environment. |
||
595 | * |
||
596 | * @param string $environmentUuid |
||
597 | * @return OperationResponse |
||
598 | */ |
||
599 | public function disableProductionMode($environmentUuid) |
||
600 | { |
||
601 | return new OperationResponse( |
||
602 | $this->connector->request( |
||
603 | 'post', |
||
604 | "/environments/${environmentUuid}/production-mode/actions/disable", |
||
605 | $this->query |
||
606 | ) |
||
607 | ); |
||
608 | } |
||
609 | |||
610 | /** |
||
611 | * Show all cron tasks for an environment. |
||
612 | * |
||
613 | * @param string $environmentUuid The environment ID |
||
614 | * @return CronsResponse |
||
615 | */ |
||
616 | public function crons($environmentUuid) |
||
617 | { |
||
618 | return new CronsResponse( |
||
619 | $this->connector->request( |
||
620 | 'get', |
||
621 | "/environments/${environmentUuid}/crons", |
||
622 | $this->query |
||
623 | ) |
||
624 | ); |
||
625 | } |
||
626 | |||
627 | /** |
||
628 | * Get information about a cron task. |
||
629 | * |
||
630 | * @param string $environmentUuid The environment ID |
||
631 | * @param int $cronId |
||
632 | * @return CronResponse |
||
633 | */ |
||
634 | public function cron($environmentUuid, $cronId) |
||
635 | { |
||
636 | return new CronResponse( |
||
637 | $this->connector->request( |
||
638 | 'get', |
||
639 | "/environments/${environmentUuid}/crons/${cronId}", |
||
640 | $this->query |
||
641 | ) |
||
642 | ); |
||
643 | } |
||
644 | |||
645 | /** |
||
646 | * Add a cron task. |
||
647 | * |
||
648 | * @param string $environmentUuid |
||
649 | * @param string $command |
||
650 | * @param string $frequency |
||
651 | * @param string $label |
||
652 | * @return OperationResponse |
||
653 | */ |
||
654 | View Code Duplication | public function createCron($environmentUuid, $command, $frequency, $label) |
|
655 | { |
||
656 | |||
657 | $options = [ |
||
658 | 'form_params' => [ |
||
659 | 'command' => $command, |
||
660 | 'frequency' => $frequency, |
||
661 | 'label' => $label, |
||
662 | ], |
||
663 | ]; |
||
664 | |||
665 | return new OperationResponse( |
||
666 | $this->connector->request('post', "/environments/${environmentUuid}/crons", $this->query, $options) |
||
667 | ); |
||
668 | } |
||
669 | |||
670 | /** |
||
671 | * Delete a cron task. |
||
672 | * |
||
673 | * @param string $environmentUuid |
||
674 | * @param int $cronId |
||
675 | * @return OperationResponse |
||
676 | */ |
||
677 | public function deleteCron($environmentUuid, $cronId) |
||
678 | { |
||
679 | return new OperationResponse( |
||
680 | $this->connector->request('delete', "/environments/${environmentUuid}/crons/${cronId}", $this->query) |
||
681 | ); |
||
682 | } |
||
683 | |||
684 | /** |
||
685 | * Disable a cron task. |
||
686 | * |
||
687 | * @param string $environmentUuid |
||
688 | * @param int $cronId |
||
689 | * @return OperationResponse |
||
690 | */ |
||
691 | public function disableCron($environmentUuid, $cronId) |
||
692 | { |
||
693 | return new OperationResponse( |
||
694 | $this->connector->request( |
||
695 | 'post', |
||
696 | "/environments/${environmentUuid}/crons/${cronId}/actions/disable", |
||
697 | $this->query |
||
698 | ) |
||
699 | ); |
||
700 | } |
||
701 | |||
702 | /** |
||
703 | * Enable a cron task. |
||
704 | * |
||
705 | * @param string $environmentUuid |
||
706 | * @param int $cronId |
||
707 | * @return OperationResponse |
||
708 | */ |
||
709 | public function enableCron($environmentUuid, $cronId) |
||
710 | { |
||
711 | return new OperationResponse( |
||
712 | $this->connector->request( |
||
713 | 'post', |
||
714 | "/environments/${environmentUuid}/crons/${cronId}/actions/enable", |
||
715 | $this->query |
||
716 | ) |
||
717 | ); |
||
718 | } |
||
719 | |||
720 | /** |
||
721 | * @return StreamInterface |
||
722 | */ |
||
723 | public function drushAliases() |
||
724 | { |
||
725 | return $this->connector->request('get', '/account/drush-aliases/download', $this->query); |
||
726 | } |
||
727 | |||
728 | /** |
||
729 | * Show insights data from an application. |
||
730 | * |
||
731 | * @param string $applicationUuid |
||
732 | * @return InsightsResponse |
||
733 | */ |
||
734 | public function applicationInsights($applicationUuid) |
||
735 | { |
||
736 | return new InsightsResponse( |
||
737 | $this->connector->request('get', "/applications/${applicationUuid}/insight", $this->query) |
||
738 | ); |
||
739 | } |
||
740 | |||
741 | /** |
||
742 | * Show insights data from a specific environment. |
||
743 | * |
||
744 | * @param string $environmentUuid |
||
745 | * @return InsightsResponse |
||
746 | */ |
||
747 | public function environmentInsights($environmentUuid) |
||
748 | { |
||
749 | return new InsightsResponse( |
||
750 | $this->connector->request('get', "/environments/${environmentUuid}/insight", $this->query) |
||
751 | ); |
||
752 | } |
||
753 | |||
754 | /** |
||
755 | * Show all organizations. |
||
756 | * |
||
757 | * @return OrganizationsResponse |
||
758 | */ |
||
759 | public function organizations() |
||
760 | { |
||
761 | return new OrganizationsResponse($this->connector->request('get', '/organizations', $this->query)); |
||
762 | } |
||
763 | |||
764 | /** |
||
765 | * Show all applications in an organisation. |
||
766 | * |
||
767 | * @param string $organizationUuid |
||
768 | * |
||
769 | * @return ApplicationsResponse |
||
770 | */ |
||
771 | public function organizationApplications($organizationUuid) |
||
772 | { |
||
773 | return new ApplicationsResponse( |
||
774 | $this->connector->request('get', "/organizations/${organizationUuid}/applications", $this->query) |
||
775 | ); |
||
776 | } |
||
777 | |||
778 | /** |
||
779 | * Show all roles in an organization. |
||
780 | * |
||
781 | * @param string $organizationUuid |
||
782 | * @return RolesResponse |
||
783 | */ |
||
784 | public function organizationRoles($organizationUuid) |
||
785 | { |
||
786 | return new RolesResponse( |
||
787 | $this->connector->request('get', "/organizations/${organizationUuid}/roles", $this->query) |
||
788 | ); |
||
789 | } |
||
790 | |||
791 | /** |
||
792 | * @param string $roleUuid |
||
793 | * @param array $permissions |
||
794 | * @return OperationResponse |
||
795 | */ |
||
796 | public function updateRole($roleUuid, array $permissions) |
||
797 | { |
||
798 | $options = [ |
||
799 | 'form_params' => [ |
||
800 | 'permissions' => $permissions, |
||
801 | ], |
||
802 | ]; |
||
803 | |||
804 | return new OperationResponse( |
||
805 | $this->connector->request('put', "/roles/${roleUuid}", $this->query, $options) |
||
806 | ); |
||
807 | } |
||
808 | |||
809 | /** |
||
810 | * @param string $organizationUuid |
||
811 | * @param string $name |
||
812 | * @param array $permissions |
||
813 | * @param null|string $description |
||
814 | * @return OperationResponse |
||
815 | */ |
||
816 | View Code Duplication | public function createRole($organizationUuid, $name, array $permissions, $description = null) |
|
817 | { |
||
818 | $options = [ |
||
819 | 'form_params' => [ |
||
820 | 'name' => $name, |
||
821 | 'permissions' => $permissions, |
||
822 | 'description' => $description, |
||
823 | ], |
||
824 | ]; |
||
825 | |||
826 | return new OperationResponse( |
||
827 | $this->connector->request('post', "/organizations/${organizationUuid}/roles", $this->query, $options) |
||
828 | ); |
||
829 | } |
||
830 | |||
831 | /** |
||
832 | * @param string $roleUuid |
||
833 | * @return OperationResponse |
||
834 | */ |
||
835 | public function deleteRole($roleUuid) |
||
836 | { |
||
837 | return new OperationResponse($this->connector->request('delete', "/roles/${roleUuid}", $this->query)); |
||
838 | } |
||
839 | |||
840 | /** |
||
841 | * Show all teams in an organization. |
||
842 | * |
||
843 | * @param string $organizationUuid |
||
844 | * @return TeamsResponse |
||
845 | */ |
||
846 | public function organizationTeams($organizationUuid) |
||
847 | { |
||
848 | return new TeamsResponse( |
||
849 | $this->connector->request('get', "/organizations/${organizationUuid}/teams", $this->query) |
||
850 | ); |
||
851 | } |
||
852 | |||
853 | /** |
||
854 | * Show all teams. |
||
855 | * |
||
856 | * @return TeamsResponse |
||
857 | */ |
||
858 | public function teams() |
||
859 | { |
||
860 | return new TeamsResponse( |
||
861 | $this->connector->request('get', '/teams', $this->query) |
||
862 | ); |
||
863 | } |
||
864 | |||
865 | /** |
||
866 | * @param string $teamUuid |
||
867 | * @param string $name |
||
868 | * @return OperationResponse |
||
869 | */ |
||
870 | public function renameTeam($teamUuid, $name) |
||
871 | { |
||
872 | $options = [ |
||
873 | 'form_params' => [ |
||
874 | 'name' => $name, |
||
875 | ], |
||
876 | ]; |
||
877 | |||
878 | return new OperationResponse( |
||
879 | $this->connector->request('put', "/teams/${teamUuid}", $options) |
||
880 | ); |
||
881 | } |
||
882 | |||
883 | /** |
||
884 | * Create a new team. |
||
885 | * |
||
886 | * @param string $organizationUuid |
||
887 | * @param string $name |
||
888 | * @return OperationResponse |
||
889 | */ |
||
890 | public function createTeam($organizationUuid, $name) |
||
891 | { |
||
892 | $options = [ |
||
893 | 'form_params' => [ |
||
894 | 'name' => $name, |
||
895 | ], |
||
896 | ]; |
||
897 | |||
898 | return new OperationResponse( |
||
899 | $this->connector->request('post', "/organizations/${organizationUuid}/teams", $this->query, $options) |
||
900 | ); |
||
901 | } |
||
902 | |||
903 | /** |
||
904 | * @param string $teamUuid |
||
905 | * @return OperationResponse |
||
906 | */ |
||
907 | public function deleteTeam($teamUuid) |
||
908 | { |
||
909 | return new OperationResponse( |
||
910 | $this->connector->request('delete', "/teams/${teamUuid}", $this->query) |
||
911 | ); |
||
912 | } |
||
913 | |||
914 | /** |
||
915 | * @param string $teamUuid |
||
916 | * @param string $applicationUuid |
||
917 | * @return OperationResponse |
||
918 | */ |
||
919 | public function addApplicationToTeam($teamUuid, $applicationUuid) |
||
929 | ); |
||
930 | } |
||
931 | |||
932 | /** |
||
933 | * Invites a user to join a team. |
||
934 | * |
||
935 | * @param string $teamUuid |
||
936 | * @param string $email |
||
937 | * @param array $roles |
||
938 | * @return OperationResponse |
||
939 | */ |
||
940 | View Code Duplication | public function createTeamInvite($teamUuid, $email, $roles) |
|
941 | { |
||
942 | $options = [ |
||
943 | 'form_params' => [ |
||
944 | 'email' => $email, |
||
945 | 'roles' => $roles |
||
946 | ], |
||
947 | ]; |
||
948 | |||
949 | return new OperationResponse( |
||
950 | $this->connector->request('post', "/teams/${teamUuid}/invites", $options) |
||
951 | ); |
||
952 | } |
||
953 | |||
954 | /** |
||
955 | * Invites a user to become admin of an organization. |
||
956 | * |
||
957 | * @param string $organizationUuid |
||
958 | * @param string $email |
||
959 | * @return OperationResponse |
||
960 | */ |
||
961 | public function createOrganizationAdminInvite($organizationUuid, $email) |
||
962 | { |
||
963 | $options = [ |
||
964 | 'form_params' => [ |
||
965 | 'email' => $email, |
||
966 | ], |
||
967 | ]; |
||
968 | |||
969 | return new OperationResponse( |
||
970 | $this->connector->request('post', "/teams/${organizationUuid}/invites", $this->query, $options) |
||
971 | ); |
||
972 | } |
||
973 | |||
974 | /** |
||
975 | * Show all applications associated with a team. |
||
976 | * |
||
977 | * @param string $teamUuid |
||
978 | * @return ApplicationsResponse |
||
979 | */ |
||
980 | public function teamApplications($teamUuid) |
||
981 | { |
||
982 | return new ApplicationsResponse( |
||
983 | $this->connector->request('get', "/teams/${teamUuid}/applications", $this->query) |
||
984 | ); |
||
985 | } |
||
986 | |||
987 | /** |
||
988 | * Show all members of an organisation. |
||
989 | * |
||
990 | * @param string $organizationUuid |
||
991 | * @return MembersResponse |
||
992 | */ |
||
993 | public function members($organizationUuid) |
||
994 | { |
||
995 | return new MembersResponse( |
||
996 | $this->connector->request('get', "/organizations/${organizationUuid}/members", $this->query) |
||
997 | ); |
||
998 | } |
||
999 | |||
1000 | /** |
||
1001 | * Show all members invited to an organisation. |
||
1002 | * |
||
1003 | * @param string $organizationUuid |
||
1004 | * @return InvitationsResponse |
||
1005 | */ |
||
1006 | public function invitees($organizationUuid) |
||
1010 | ); |
||
1011 | } |
||
1012 | |||
1013 | /** |
||
1014 | * Delete a member from an organisation. |
||
1015 | * |
||
1016 | * @param string $organizationUuid |
||
1017 | * @param string $memberUuid |
||
1018 | * @return OperationResponse |
||
1019 | */ |
||
1020 | public function deleteMember($organizationUuid, $memberUuid) |
||
1021 | { |
||
1022 | return new OperationResponse( |
||
1023 | $this->connector->request( |
||
1024 | 'delete', |
||
1025 | "/organizations/${organizationUuid}/members/${memberUuid}", |
||
1026 | $this->query |
||
1027 | ) |
||
1028 | ); |
||
1029 | } |
||
1030 | |||
1031 | /** |
||
1032 | * Show all available permissions. |
||
1033 | * |
||
1034 | * @return PermissionsResponse |
||
1035 | */ |
||
1036 | public function permissions() |
||
1039 | } |
||
1040 | } |
||
1041 |