1 | <?php |
||
13 | class GithubAPI |
||
14 | { |
||
15 | /** |
||
16 | * Guzzle http client. |
||
17 | * |
||
18 | * @var Client |
||
19 | */ |
||
20 | protected $client; |
||
21 | |||
22 | /** |
||
23 | * Github API URL. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $api_url = "https://api.github.com"; |
||
28 | |||
29 | /** |
||
30 | * Authorization URI in github API. |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $authorizations_uri = "/authorizations"; |
||
35 | |||
36 | /** |
||
37 | * Authorization URI in github API. |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $repos_uri = "/user/repos"; |
||
42 | |||
43 | |||
44 | /** |
||
45 | * Acacha Llum Filesystem. |
||
46 | * |
||
47 | * @var Filesystem |
||
48 | */ |
||
49 | protected $filesystem; |
||
50 | |||
51 | /** |
||
52 | * Token name; |
||
53 | * |
||
54 | * @var |
||
55 | */ |
||
56 | protected $tokenName; |
||
57 | |||
58 | /** |
||
59 | * GithubAPI constructor. |
||
60 | */ |
||
61 | public function __construct(Filesystem $filesystem) |
||
66 | |||
67 | /** |
||
68 | * Path to repo.json stub |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | protected function repo_json_stub() { |
||
75 | |||
76 | /** |
||
77 | * Authorization URL. |
||
78 | * |
||
79 | * @return string |
||
80 | */ |
||
81 | protected function authorization_url() { |
||
84 | |||
85 | /** |
||
86 | * Create repo URL. |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | protected function create_repo_url() { |
||
93 | |||
94 | /** |
||
95 | * Obtain personal token. |
||
96 | * |
||
97 | * @param $username |
||
98 | * @param $password |
||
99 | * @return mixed |
||
100 | */ |
||
101 | public function getPersonalToken($username, $password) |
||
113 | |||
114 | /** |
||
115 | * @return array |
||
116 | */ |
||
117 | protected function authorizationsRequestJson(){ |
||
123 | |||
124 | /** |
||
125 | * Create repo in github. |
||
126 | * |
||
127 | * @param $repo_name |
||
128 | * @param $repo_description |
||
129 | * @return mixed |
||
130 | */ |
||
131 | public function createRepo($repo_name, $repo_description) |
||
140 | |||
141 | /** |
||
142 | * Set github credentials. |
||
143 | * |
||
144 | * @param array $credentials |
||
145 | */ |
||
146 | public function setCredentials(array $credentials) |
||
150 | |||
151 | /** |
||
152 | * Get github credentials. |
||
153 | * |
||
154 | * @return mixed |
||
155 | * @throws CredentialsException |
||
156 | */ |
||
157 | protected function credentials() |
||
163 | |||
164 | /** |
||
165 | * Compile stub. |
||
166 | * |
||
167 | * @param $repo_name |
||
168 | * @param $repo_description |
||
169 | * @return mixed |
||
170 | */ |
||
171 | protected function compileStub($repo_name, $repo_description) |
||
181 | |||
182 | /** |
||
183 | * Compile the template using the given data. |
||
184 | * |
||
185 | * @param $template |
||
186 | * @param $data |
||
187 | * @return mixed |
||
188 | */ |
||
189 | protected function compile($template, $data) |
||
197 | |||
198 | /** |
||
199 | * @return mixed |
||
200 | */ |
||
201 | public function tokenName() |
||
205 | |||
206 | |||
207 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: