@@ -29,20 +29,20 @@ discard block |
||
| 29 | 29 | parent::__construct($appConfig); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - #[\Override] |
|
| 33 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
| 32 | + #[\Override ] |
|
| 33 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
| 34 | 34 | $this->getProvider()->send($identifier, $message); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - #[\Override] |
|
| 37 | + #[\Override ] |
|
| 38 | 38 | final public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
| 39 | 39 | $namespaces = $this->telegramProviderFactory->getFqcnList(); |
| 40 | - $names = []; |
|
| 41 | - $providers = []; |
|
| 40 | + $names = [ ]; |
|
| 41 | + $providers = [ ]; |
|
| 42 | 42 | foreach ($namespaces as $ns) { |
| 43 | 43 | $provider = $this->telegramProviderFactory->get($ns); |
| 44 | - $providers[] = $provider; |
|
| 45 | - $names[] = $provider->getSettings()->name; |
|
| 44 | + $providers[ ] = $provider; |
|
| 45 | + $names[ ] = $provider->getSettings()->name; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | $helper = new QuestionHelper(); |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $name = $helper->ask($input, $output, $choiceQuestion); |
| 51 | 51 | $selectedIndex = array_search($name, $names); |
| 52 | 52 | |
| 53 | - $providers[$selectedIndex]->cliConfigure($input, $output); |
|
| 53 | + $providers[ $selectedIndex ]->cliConfigure($input, $output); |
|
| 54 | 54 | return 0; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | return $settings; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - #[\Override] |
|
| 68 | + #[\Override ] |
|
| 69 | 69 | public function isComplete(?Settings $settings = null): bool { |
| 70 | 70 | if ($settings === null) { |
| 71 | 71 | try { |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | return parent::isComplete($settings); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - #[\Override] |
|
| 81 | + #[\Override ] |
|
| 82 | 82 | public function remove(?Settings $settings = null): void { |
| 83 | 83 | if (!is_object($settings)) { |
| 84 | 84 | $settings = $this->getSettings(); |
@@ -16,31 +16,31 @@ |
||
| 16 | 16 | |
| 17 | 17 | /** @extends AFactory<AProvider> */ |
| 18 | 18 | class Factory extends AFactory { |
| 19 | - #[\Override] |
|
| 19 | + #[\Override ] |
|
| 20 | 20 | protected function getPrefix(): string { |
| 21 | 21 | return 'OCA\\TwoFactorGateway\\Provider\\Channel\\SMS\\Provider\\Drivers\\'; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - #[\Override] |
|
| 24 | + #[\Override ] |
|
| 25 | 25 | protected function getSuffix(): string { |
| 26 | 26 | return ''; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - #[\Override] |
|
| 29 | + #[\Override ] |
|
| 30 | 30 | protected function getBaseClass(): string { |
| 31 | 31 | return IProvider::class; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - #[\Override] |
|
| 34 | + #[\Override ] |
|
| 35 | 35 | public function get(string $name): object { |
| 36 | - if (isset($this->instances[$name])) { |
|
| 37 | - return $this->instances[$name]; |
|
| 36 | + if (isset($this->instances[ $name ])) { |
|
| 37 | + return $this->instances[ $name ]; |
|
| 38 | 38 | } |
| 39 | 39 | foreach ($this->getFqcnList() as $fqcn) { |
| 40 | 40 | $instance = \OCP\Server::get($fqcn); |
| 41 | 41 | if ($instance->getSettings()->id === $name) { |
| 42 | 42 | $instance->setAppConfig(\OCP\Server::get(\OCP\IAppConfig::class)); |
| 43 | - $this->instances[$name] = $instance; |
|
| 43 | + $this->instances[ $name ] = $instance; |
|
| 44 | 44 | return $instance; |
| 45 | 45 | } |
| 46 | 46 | } |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | ); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - #[\Override] |
|
| 53 | + #[\Override ] |
|
| 54 | 54 | public function send(string $identifier, string $message) { |
| 55 | 55 | $apiKey = $this->getApiKey(); |
| 56 | 56 | $username = $this->getUser(); |
@@ -55,7 +55,7 @@ |
||
| 55 | 55 | ); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - #[\Override] |
|
| 58 | + #[\Override ] |
|
| 59 | 59 | public function send(string $identifier, string $message) { |
| 60 | 60 | $user = $this->getApiUser(); |
| 61 | 61 | $password = $this->getApiPassword(); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | ); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - #[\Override] |
|
| 64 | + #[\Override ] |
|
| 65 | 65 | public function send(string $identifier, string $message) { |
| 66 | 66 | try { |
| 67 | 67 | $this->client->get( |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | 'query' => [ |
| 71 | 71 | 'username' => $this->getUser(), |
| 72 | 72 | 'password' => $this->getPassword(), |
| 73 | - 'message[0].recipient' => '+' . $identifier, |
|
| 73 | + 'message[0].recipient' => '+'.$identifier, |
|
| 74 | 74 | 'message[0].content' => $message, |
| 75 | 75 | 'serviceId' => $this->getServiceid(), |
| 76 | 76 | ], |
@@ -44,7 +44,7 @@ |
||
| 44 | 44 | ); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - #[\Override] |
|
| 47 | + #[\Override ] |
|
| 48 | 48 | public function send(string $identifier, string $message) { |
| 49 | 49 | $url = $this->getApi(); |
| 50 | 50 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | ); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - #[\Override] |
|
| 58 | + #[\Override ] |
|
| 59 | 59 | public function send(string $identifier, string $message) { |
| 60 | 60 | $login = $this->getLogin(); |
| 61 | 61 | $password = $this->getPassword(); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | $responseData = json_decode((string)$response->getBody(), true); |
| 78 | 78 | |
| 79 | - if ($responseData['success'] !== true) { |
|
| 79 | + if ($responseData[ 'success' ] !== true) { |
|
| 80 | 80 | throw new MessageTransmissionException(); |
| 81 | 81 | } |
| 82 | 82 | } catch (Exception $ex) { |
@@ -99,24 +99,24 @@ discard block |
||
| 99 | 99 | ); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - #[\Override] |
|
| 102 | + #[\Override ] |
|
| 103 | 103 | public function send(string $identifier, string $message) { |
| 104 | 104 | $endpoint = $this->getEndpoint(); |
| 105 | 105 | $sender = $this->getSender(); |
| 106 | 106 | $smsAccount = $this->getAccount(); |
| 107 | 107 | |
| 108 | - $this->attrs['AK'] = $this->getApplicationKey(); |
|
| 109 | - $this->attrs['AS'] = $this->getApplicationSecret(); |
|
| 110 | - $this->attrs['CK'] = $this->getConsumerKey(); |
|
| 111 | - if (!isset($this->endpoints[$endpoint])) { |
|
| 108 | + $this->attrs[ 'AK' ] = $this->getApplicationKey(); |
|
| 109 | + $this->attrs[ 'AS' ] = $this->getApplicationSecret(); |
|
| 110 | + $this->attrs[ 'CK' ] = $this->getConsumerKey(); |
|
| 111 | + if (!isset($this->endpoints[ $endpoint ])) { |
|
| 112 | 112 | throw new InvalidProviderException("Endpoint $endpoint not found"); |
| 113 | 113 | } |
| 114 | - $this->attrs['endpoint'] = $this->endpoints[$endpoint]; |
|
| 114 | + $this->attrs[ 'endpoint' ] = $this->endpoints[ $endpoint ]; |
|
| 115 | 115 | |
| 116 | 116 | $this->getTimeDelta(); |
| 117 | 117 | |
| 118 | - $header = $this->getHeader('GET', $this->attrs['endpoint'] . '/sms'); |
|
| 119 | - $response = $this->client->get($this->attrs['endpoint'] . '/sms', [ |
|
| 118 | + $header = $this->getHeader('GET', $this->attrs[ 'endpoint' ].'/sms'); |
|
| 119 | + $response = $this->client->get($this->attrs[ 'endpoint' ].'/sms', [ |
|
| 120 | 120 | 'headers' => $header, |
| 121 | 121 | ]); |
| 122 | 122 | $body = (string)$response->getBody(); |
@@ -144,15 +144,15 @@ discard block |
||
| 144 | 144 | ]; |
| 145 | 145 | $body = json_encode($content); |
| 146 | 146 | |
| 147 | - $header = $this->getHeader('POST', $this->attrs['endpoint'] . "/sms/$smsAccount/jobs", $body); |
|
| 148 | - $response = $this->client->post($this->attrs['endpoint'] . "/sms/$smsAccount/jobs", [ |
|
| 147 | + $header = $this->getHeader('POST', $this->attrs[ 'endpoint' ]."/sms/$smsAccount/jobs", $body); |
|
| 148 | + $response = $this->client->post($this->attrs[ 'endpoint' ]."/sms/$smsAccount/jobs", [ |
|
| 149 | 149 | 'headers' => $header, |
| 150 | 150 | 'json' => $content, |
| 151 | 151 | ]); |
| 152 | 152 | $body = (string)$response->getBody(); |
| 153 | 153 | $resultPostJob = json_decode($body, true); |
| 154 | 154 | |
| 155 | - if (count($resultPostJob['validReceivers']) === 0) { |
|
| 155 | + if (count($resultPostJob[ 'validReceivers' ]) === 0) { |
|
| 156 | 156 | throw new MessageTransmissionException("Bad receiver $identifier"); |
| 157 | 157 | } |
| 158 | 158 | } |
@@ -163,16 +163,16 @@ discard block |
||
| 163 | 163 | * @throws InvalidProviderException |
| 164 | 164 | */ |
| 165 | 165 | private function getTimeDelta(): void { |
| 166 | - if (!isset($this->attrs['timedelta'])) { |
|
| 167 | - if (!isset($this->attrs['endpoint'])) { |
|
| 166 | + if (!isset($this->attrs[ 'timedelta' ])) { |
|
| 167 | + if (!isset($this->attrs[ 'endpoint' ])) { |
|
| 168 | 168 | throw new InvalidProviderException('Need to set the endpoint'); |
| 169 | 169 | } |
| 170 | 170 | try { |
| 171 | - $response = $this->client->get($this->attrs['endpoint'] . '/auth/time'); |
|
| 171 | + $response = $this->client->get($this->attrs[ 'endpoint' ].'/auth/time'); |
|
| 172 | 172 | $serverTimestamp = (int)$response->getBody(); |
| 173 | - $this->attrs['timedelta'] = $serverTimestamp - time(); |
|
| 173 | + $this->attrs[ 'timedelta' ] = $serverTimestamp - time(); |
|
| 174 | 174 | } catch (Exception $ex) { |
| 175 | - throw new InvalidProviderException('Unable to calculate time delta:' . $ex->getMessage()); |
|
| 175 | + throw new InvalidProviderException('Unable to calculate time delta:'.$ex->getMessage()); |
|
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | } |
@@ -185,14 +185,14 @@ discard block |
||
| 185 | 185 | * @return array $header Contains the data for the request need by OVH |
| 186 | 186 | */ |
| 187 | 187 | private function getHeader($method, $query, $body = '') { |
| 188 | - $timestamp = time() + $this->attrs['timedelta']; |
|
| 189 | - $prehash = $this->attrs['AS'] . '+' . $this->attrs['CK'] . '+' . $method . '+' . $query . '+' . $body . '+' . $timestamp; |
|
| 188 | + $timestamp = time() + $this->attrs[ 'timedelta' ]; |
|
| 189 | + $prehash = $this->attrs[ 'AS' ].'+'.$this->attrs[ 'CK' ].'+'.$method.'+'.$query.'+'.$body.'+'.$timestamp; |
|
| 190 | 190 | $header = [ |
| 191 | 191 | 'Content-Type' => 'application/json; charset=utf-8', |
| 192 | - 'X-Ovh-Application' => $this->attrs['AK'], |
|
| 192 | + 'X-Ovh-Application' => $this->attrs[ 'AK' ], |
|
| 193 | 193 | 'X-Ovh-Timestamp' => $timestamp, |
| 194 | - 'X-Ovh-Signature' => '$1$' . sha1($prehash), |
|
| 195 | - 'X-Ovh-Consumer' => $this->attrs['CK'], |
|
| 194 | + 'X-Ovh-Signature' => '$1$'.sha1($prehash), |
|
| 195 | + 'X-Ovh-Consumer' => $this->attrs[ 'CK' ], |
|
| 196 | 196 | ]; |
| 197 | 197 | return $header; |
| 198 | 198 | } |
@@ -55,7 +55,7 @@ |
||
| 55 | 55 | ); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - #[\Override] |
|
| 58 | + #[\Override ] |
|
| 59 | 59 | public function send(string $identifier, string $message) { |
| 60 | 60 | try { |
| 61 | 61 | $this->client->get( |