| Conditions | 5 |
| Paths | 5 |
| Total Lines | 83 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 38 | public function handle() |
||
| 39 | { |
||
| 40 | // generate the key with sha512sum of time() |
||
| 41 | |||
| 42 | $this->info("read https://docs.ovh.com/gb/en/public-cloud/share_an_object_via_a_temporary_url/#generate-the-key for explanation of what we're doing here"); |
||
| 43 | |||
| 44 | $temp_url_key = hash('sha512', time()); |
||
| 45 | $client = new \GuzzleHttp\Client(); |
||
| 46 | |||
| 47 | // ( https://docs.ovh.com/gb/en/public-cloud/managing_tokens/ ) |
||
| 48 | // Request token creation |
||
| 49 | // curl -X POST ${OS_AUTH_URL}auth/tokens -H "Content-Type: application/json" -d ' { "auth": { "identity": { "methods": ["password"], "password": { "user": { "name": "'$OS_USERNAME'", "domain": { "id": "default" }, "password": "'$OS_PASSWORD'" } } }, "scope": { "project": { "name": "'$OS_TENANT_NAME'", "domain": { "id": "default" } } } } }' | python -mjson.tool |
||
| 50 | |||
| 51 | $payload = [ |
||
| 52 | "auth" => [ |
||
| 53 | "identity" => [ |
||
| 54 | "methods" => [ |
||
| 55 | "password" |
||
| 56 | ], |
||
| 57 | "password" => [ |
||
| 58 | "user" => [ |
||
| 59 | "name" => config('filesystems.disks.ovh.user'), |
||
| 60 | "domain" => [ |
||
| 61 | "id" => "default" |
||
| 62 | ], |
||
| 63 | "password" => config('filesystems.disks.ovh.pass') |
||
| 64 | ] |
||
| 65 | ] |
||
| 66 | ], |
||
| 67 | "scope" => [ |
||
| 68 | "project" => [ |
||
| 69 | "name" => config('filesystems.disks.ovh.tenantName'), |
||
| 70 | "domain" => [ |
||
| 71 | "id" => "default" |
||
| 72 | ] |
||
| 73 | ] |
||
| 74 | ] |
||
| 75 | ], |
||
| 76 | ]; |
||
| 77 | |||
| 78 | $this->info("getting auth token from ".config('filesystems.disks.ovh.server').'auth/tokens'); |
||
| 79 | |||
| 80 | $response = $client->request('POST', config('filesystems.disks.ovh.server').'auth/tokens', [ |
||
| 81 | 'json' => $payload |
||
| 82 | ]); |
||
| 83 | |||
| 84 | $data = json_decode($response->getBody()); |
||
| 85 | |||
| 86 | // Retrieve the token ID variables and publicURL endpoint |
||
| 87 | foreach($data->token->catalog as $catalog): |
||
| 88 | if ( $catalog->type == 'object-store' ): |
||
| 89 | foreach($catalog->endpoints as $endpoint): |
||
| 90 | if ( $endpoint->region == config('filesystems.disks.ovh.region') ): |
||
| 91 | // $auth_token = $endpoint->id; |
||
| 92 | $endpoint = $endpoint->url; |
||
| 93 | break(2); |
||
| 94 | endif; |
||
| 95 | endforeach; |
||
| 96 | endif; |
||
| 97 | endforeach; |
||
| 98 | |||
| 99 | // export token=$(curl -is -X POST ${OS_AUTH_URL}auth/tokens -H "Content-Type: application/json" -d ' { "auth": { "identity": { "methods": ["password"], "password": { "user": { "name": "'$OS_USERNAME'", "domain": { "id": "default" }, "password": "'$OS_PASSWORD'" } } }, "scope": { "project": { "name": "'$OS_TENANT_NAME'", "domain": { "id": "default" } } } } }' | grep '^X-Subject-Token' | cut -d" " -f2) |
||
| 100 | $headers = $response->getHeaders(); |
||
| 101 | $auth_token = $headers["X-Subject-Token"][0]; |
||
| 102 | |||
| 103 | |||
| 104 | // then define the temp-url-key header ( https://docs.ovh.com/gb/en/public-cloud/share_an_object_via_a_temporary_url/#generate-the-key ) |
||
| 105 | // curl -i -X POST \ -H "X-Account-Meta-Temp-URL-Key: 12345" \ -H "X-Auth-Token: abcdef12345" \ https://storage.sbg1.cloud.ovh.net/v1/AUTH_ProjectID |
||
| 106 | |||
| 107 | $payload = [ |
||
| 108 | 'headers' => [ |
||
| 109 | 'X-Account-Meta-Temp-URL-Key' => $temp_url_key, |
||
| 110 | 'X-Auth-Token' => $auth_token |
||
| 111 | ] |
||
| 112 | ]; |
||
| 113 | $this->info("posting to ".$endpoint); |
||
| 114 | |||
| 115 | $response = $client->request('POST', $endpoint, $payload); |
||
| 116 | |||
| 117 | $this->alert("add this line to your .env file"); |
||
| 118 | $this->info("OVH_URL_KEY=".$temp_url_key.PHP_EOL); |
||
| 119 | |||
| 120 | } |
||
| 121 | |||
| 125 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.