@@ -32,17 +32,17 @@ discard block |
||
32 | 32 | parent::__construct($appConfig); |
33 | 33 | } |
34 | 34 | |
35 | - #[\Override] |
|
36 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
35 | + #[\Override ] |
|
36 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
37 | 37 | $this->getProvider()->send($identifier, $message); |
38 | 38 | } |
39 | 39 | |
40 | - #[\Override] |
|
40 | + #[\Override ] |
|
41 | 41 | final public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
42 | 42 | $namespaces = $this->providerFactory->getFqcnList(); |
43 | - $schemas = []; |
|
43 | + $schemas = [ ]; |
|
44 | 44 | foreach ($namespaces as $ns) { |
45 | - $schemas[] = $ns::SCHEMA; |
|
45 | + $schemas[ ] = $ns::SCHEMA; |
|
46 | 46 | } |
47 | 47 | $names = array_column($schemas, 'name'); |
48 | 48 | |
@@ -50,32 +50,32 @@ discard block |
||
50 | 50 | $choiceQuestion = new ChoiceQuestion('Please choose a SMS provider:', $names); |
51 | 51 | $name = $helper->ask($input, $output, $choiceQuestion); |
52 | 52 | $selectedIndex = array_search($name, $names); |
53 | - $schema = $schemas[$selectedIndex]; |
|
53 | + $schema = $schemas[ $selectedIndex ]; |
|
54 | 54 | |
55 | - $provider = $this->getProvider($namespaces[$selectedIndex]::getProviderId()); |
|
55 | + $provider = $this->getProvider($namespaces[ $selectedIndex ]::getProviderId()); |
|
56 | 56 | |
57 | - foreach ($schema['fields'] as $field) { |
|
58 | - $id = $field['field']; |
|
59 | - $prompt = $field['prompt'] . ' '; |
|
60 | - $defaultVal = $field['default'] ?? null; |
|
61 | - $optional = (bool)($field['optional'] ?? false); |
|
57 | + foreach ($schema[ 'fields' ] as $field) { |
|
58 | + $id = $field[ 'field' ]; |
|
59 | + $prompt = $field[ 'prompt' ].' '; |
|
60 | + $defaultVal = $field[ 'default' ] ?? null; |
|
61 | + $optional = (bool)($field[ 'optional' ] ?? false); |
|
62 | 62 | |
63 | 63 | $answer = (string)$helper->ask($input, $output, new Question($prompt, $defaultVal)); |
64 | 64 | |
65 | 65 | if ($optional && $answer === '') { |
66 | - $method = 'delete' . $this->toCamel($id); |
|
66 | + $method = 'delete'.$this->toCamel($id); |
|
67 | 67 | $provider->{$method}(); |
68 | 68 | continue; |
69 | 69 | } |
70 | 70 | |
71 | - $method = 'set' . $this->toCamel($id); |
|
71 | + $method = 'set'.$this->toCamel($id); |
|
72 | 72 | $provider->{$method}($answer); |
73 | 73 | } |
74 | 74 | return 0; |
75 | 75 | } |
76 | 76 | |
77 | - #[\Override] |
|
78 | - public function isComplete(array $schema = []): bool { |
|
77 | + #[\Override ] |
|
78 | + public function isComplete(array $schema = [ ]): bool { |
|
79 | 79 | if (empty($schema)) { |
80 | 80 | try { |
81 | 81 | $provider = $this->getProvider(); |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | return parent::isComplete($schema); |
88 | 88 | } |
89 | 89 | |
90 | - #[\Override] |
|
91 | - public function remove(array $schema = []): void { |
|
90 | + #[\Override ] |
|
91 | + public function remove(array $schema = [ ]): void { |
|
92 | 92 | if (empty($schema)) { |
93 | 93 | $schema = static::SCHEMA; |
94 | 94 | } |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | <p>Enter your JID (XMPP address) to receive your verification code below.</p> |
39 | 39 | HTML, |
40 | 40 | 'fields' => [ |
41 | - ['field' => 'sender', 'prompt' => 'Please enter your sender XMPP-JID:'], |
|
42 | - ['field' => 'password', 'prompt' => 'Please enter your sender XMPP password:'], |
|
43 | - ['field' => 'server', 'prompt' => 'Please enter full path to access REST/HTTP API:'], |
|
44 | - ['field' => 'username'], |
|
45 | - ['field' => 'method', 'prompt' => 'Please enter 1 or 2 for XMPP sending option:'], |
|
41 | + [ 'field' => 'sender', 'prompt' => 'Please enter your sender XMPP-JID:' ], |
|
42 | + [ 'field' => 'password', 'prompt' => 'Please enter your sender XMPP password:' ], |
|
43 | + [ 'field' => 'server', 'prompt' => 'Please enter full path to access REST/HTTP API:' ], |
|
44 | + [ 'field' => 'username' ], |
|
45 | + [ 'field' => 'method', 'prompt' => 'Please enter 1 or 2 for XMPP sending option:' ], |
|
46 | 46 | ], |
47 | 47 | ]; |
48 | 48 | |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | parent::__construct($appConfig); |
54 | 54 | } |
55 | 55 | |
56 | - #[\Override] |
|
57 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
56 | + #[\Override ] |
|
57 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
58 | 58 | $this->logger->debug("sending xmpp message to $identifier, message: $message"); |
59 | 59 | |
60 | 60 | $sender = $this->getSender(); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $server = $this->getServer(); |
63 | 63 | $method = $this->getMethod(); |
64 | 64 | $user = $this->getUsername(); |
65 | - $url = $server . $identifier; |
|
65 | + $url = $server.$identifier; |
|
66 | 66 | |
67 | 67 | if ($method === '1') { |
68 | 68 | $from = $user; |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
79 | 79 | curl_setopt($ch, CURLOPT_POST, 1); |
80 | 80 | curl_setopt($ch, CURLOPT_POSTFIELDS, $message); |
81 | - curl_setopt($ch, CURLOPT_USERPWD, $from . ':' . $password); |
|
82 | - curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: text/plain']); |
|
81 | + curl_setopt($ch, CURLOPT_USERPWD, $from.':'.$password); |
|
82 | + curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: text/plain' ]); |
|
83 | 83 | $result = curl_exec($ch); |
84 | 84 | curl_close($ch); |
85 | 85 | $this->logger->debug("XMPP message to $identifier sent"); |
@@ -88,27 +88,27 @@ discard block |
||
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | - #[\Override] |
|
91 | + #[\Override ] |
|
92 | 92 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
93 | 93 | $helper = new QuestionHelper(); |
94 | - $fields = self::SCHEMA['fields']; |
|
94 | + $fields = self::SCHEMA[ 'fields' ]; |
|
95 | 95 | $fields = array_combine(array_column($fields, 'field'), $fields); |
96 | 96 | $sender = ''; |
97 | 97 | while (empty($sender) or substr_count($sender, '@') !== 1) { |
98 | - $senderQuestion = new Question($fields['sender']['prompt'] . ' '); |
|
98 | + $senderQuestion = new Question($fields[ 'sender' ][ 'prompt' ].' '); |
|
99 | 99 | $sender = $helper->ask($input, $output, $senderQuestion); |
100 | 100 | if (empty($sender)) { |
101 | 101 | $output->writeln('XMPP-JID must not be empty!'); |
102 | 102 | } elseif (substr_count($sender, '@') !== 1) { |
103 | 103 | $output->writeln('XMPP-JID not valid!'); |
104 | 104 | } else { |
105 | - $username = explode('@', $sender)[0]; |
|
105 | + $username = explode('@', $sender)[ 0 ]; |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | $output->writeln("Using $sender as XMPP-JID.\nUsing $username as username."); |
109 | 109 | $password = ''; |
110 | 110 | while (empty($password)) { |
111 | - $passwordQuestion = new Question($fields['password']['prompt'] . ' '); |
|
111 | + $passwordQuestion = new Question($fields[ 'password' ][ 'prompt' ].' '); |
|
112 | 112 | $password = $helper->ask($input, $output, $passwordQuestion); |
113 | 113 | if (empty($password)) { |
114 | 114 | $output->writeln('Password must not be empty!'); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $output->writeln('Password accepted.'); |
118 | 118 | $server = ''; |
119 | 119 | while (empty($server)) { |
120 | - $serverQuestion = new Question($fields['server']['prompt'] . ' '); |
|
120 | + $serverQuestion = new Question($fields[ 'server' ][ 'prompt' ].' '); |
|
121 | 121 | $server = $helper->ask($input, $output, $serverQuestion); |
122 | 122 | if (empty($server)) { |
123 | 123 | $output->writeln('API path must not be empty!'); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $output->writeln("Using $server as full URL to access REST/HTTP API."); |
127 | 127 | $method = 0; |
128 | 128 | while (intval($method) < 1 or intval($method) > 2) { |
129 | - echo $fields['method']['prompt'] . PHP_EOL; |
|
129 | + echo $fields[ 'method' ][ 'prompt' ].PHP_EOL; |
|
130 | 130 | echo "(1) prosody with mod_rest\n"; |
131 | 131 | echo "(2) prosody with mod_post_msg\n"; |
132 | 132 | $methodQuestion = new Question('Your choice: '); |
@@ -23,15 +23,15 @@ |
||
23 | 23 | * |
24 | 24 | * @throws MessageTransmissionException |
25 | 25 | */ |
26 | - public function send(string $identifier, string $message, array $extra = []): void; |
|
26 | + public function send(string $identifier, string $message, array $extra = [ ]): void; |
|
27 | 27 | |
28 | - public function isComplete(array $schema = []): bool; |
|
28 | + public function isComplete(array $schema = [ ]): bool; |
|
29 | 29 | |
30 | 30 | public function getSettings(): array; |
31 | 31 | |
32 | 32 | public function cliConfigure(InputInterface $input, OutputInterface $output): int; |
33 | 33 | |
34 | - public function remove(array $schema = []): void; |
|
34 | + public function remove(array $schema = [ ]): void; |
|
35 | 35 | |
36 | 36 | public static function getProviderId(): string; |
37 | 37 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | |
18 | 18 | abstract class AGateway implements IGateway { |
19 | 19 | use TConfigurable; |
20 | - public const SCHEMA = []; |
|
20 | + public const SCHEMA = [ ]; |
|
21 | 21 | |
22 | 22 | public function __construct( |
23 | 23 | public IAppConfig $appConfig, |
@@ -27,41 +27,41 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * @throws MessageTransmissionException |
29 | 29 | */ |
30 | - #[\Override] |
|
31 | - abstract public function send(string $identifier, string $message, array $extra = []): void; |
|
30 | + #[\Override ] |
|
31 | + abstract public function send(string $identifier, string $message, array $extra = [ ]): void; |
|
32 | 32 | |
33 | - #[\Override] |
|
34 | - public function isComplete(array $schema = []): bool { |
|
33 | + #[\Override ] |
|
34 | + public function isComplete(array $schema = [ ]): bool { |
|
35 | 35 | if (empty($schema)) { |
36 | 36 | $schema = static::SCHEMA; |
37 | 37 | } |
38 | 38 | $set = $this->appConfig->getKeys(Application::APP_ID); |
39 | - $fields = array_column($schema['fields'], 'field'); |
|
40 | - $fields = array_map(fn ($f) => $this->getProviderId() . '_' . $f, $fields); |
|
39 | + $fields = array_column($schema[ 'fields' ], 'field'); |
|
40 | + $fields = array_map(fn ($f) => $this->getProviderId().'_'.$f, $fields); |
|
41 | 41 | $intersect = array_intersect($fields, $set); |
42 | 42 | return count($intersect) === count($fields); |
43 | 43 | } |
44 | 44 | |
45 | - #[\Override] |
|
45 | + #[\Override ] |
|
46 | 46 | public function getSettings(): array { |
47 | - $settings = []; |
|
48 | - if (isset(static::SCHEMA['instructions'])) { |
|
49 | - $settings['instructions'] = static::SCHEMA['instructions']; |
|
47 | + $settings = [ ]; |
|
48 | + if (isset(static::SCHEMA[ 'instructions' ])) { |
|
49 | + $settings[ 'instructions' ] = static::SCHEMA[ 'instructions' ]; |
|
50 | 50 | } |
51 | - $settings['name'] = static::SCHEMA['name']; |
|
51 | + $settings[ 'name' ] = static::SCHEMA[ 'name' ]; |
|
52 | 52 | return $settings; |
53 | 53 | } |
54 | 54 | |
55 | - #[\Override] |
|
55 | + #[\Override ] |
|
56 | 56 | abstract public function cliConfigure(InputInterface $input, OutputInterface $output): int; |
57 | 57 | |
58 | - #[\Override] |
|
59 | - public function remove(array $schema = []): void { |
|
58 | + #[\Override ] |
|
59 | + public function remove(array $schema = [ ]): void { |
|
60 | 60 | if (empty($schema)) { |
61 | 61 | $schema = static::SCHEMA; |
62 | 62 | } |
63 | - foreach ($schema['fields'] as $field) { |
|
64 | - $method = 'delete' . $this->toCamel($field['field']); |
|
63 | + foreach ($schema[ 'fields' ] as $field) { |
|
64 | + $method = 'delete'.$this->toCamel($field[ 'field' ]); |
|
65 | 65 | $this->{$method}(); |
66 | 66 | } |
67 | 67 | } |
@@ -70,11 +70,11 @@ discard block |
||
70 | 70 | return str_replace(' ', '', ucwords(str_replace('_', ' ', $field))); |
71 | 71 | } |
72 | 72 | |
73 | - #[\Override] |
|
73 | + #[\Override ] |
|
74 | 74 | public static function getProviderId(): string { |
75 | 75 | $id = self::deriveIdFromFqcn(static::class); |
76 | 76 | if ($id === null) { |
77 | - throw new \LogicException('Cannot derive gateway id from FQCN: ' . static::class); |
|
77 | + throw new \LogicException('Cannot derive gateway id from FQCN: '.static::class); |
|
78 | 78 | } |
79 | 79 | return $id; |
80 | 80 | } |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | |
14 | 14 | abstract class AFactory { |
15 | 15 | /** @var array<string,AGateway|AProvider|ISMSProvider> */ |
16 | - protected array $instances = []; |
|
16 | + protected array $instances = [ ]; |
|
17 | 17 | /** @var array<string> */ |
18 | - protected array $fqcn = []; |
|
18 | + protected array $fqcn = [ ]; |
|
19 | 19 | |
20 | 20 | abstract protected function getPrefix(): string; |
21 | 21 | abstract protected function getSuffix(): string; |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | /** @return AGateway|AProvider|ISMSProvider */ |
29 | 29 | public function get(string $name): object { |
30 | 30 | $needle = strtolower($name); |
31 | - if (isset($this->instances[$needle])) { |
|
32 | - return $this->instances[$needle]; |
|
31 | + if (isset($this->instances[ $needle ])) { |
|
32 | + return $this->instances[ $needle ]; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | foreach ($this->getFqcnList() as $fqcn) { |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | continue; |
39 | 39 | } |
40 | 40 | $instance = \OCP\Server::get($fqcn); |
41 | - $this->instances[$needle] = $instance; |
|
41 | + $this->instances[ $needle ] = $instance; |
|
42 | 42 | return $instance; |
43 | 43 | } |
44 | 44 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | return $this->fqcn; |
52 | 52 | } |
53 | 53 | |
54 | - $loader = require __DIR__ . '/../../vendor/autoload.php'; |
|
54 | + $loader = require __DIR__.'/../../vendor/autoload.php'; |
|
55 | 55 | foreach ($loader->getClassMap() as $fqcn => $_) { |
56 | 56 | $type = $this->typeFrom($fqcn); |
57 | 57 | if ($type === null) { |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | if (!$this->isValid($fqcn)) { |
64 | 64 | continue; |
65 | 65 | } |
66 | - $this->fqcn[] = $fqcn; |
|
66 | + $this->fqcn[ ] = $fqcn; |
|
67 | 67 | } |
68 | 68 | return $this->fqcn; |
69 | 69 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | return null; |
79 | 79 | } |
80 | 80 | $type = substr($fqcn, strlen($prefix)); |
81 | - $type = substr($type, 0, -strlen('\\' . $suffix)); |
|
81 | + $type = substr($type, 0, -strlen('\\'.$suffix)); |
|
82 | 82 | if (strpos($type, '\\') !== false || $type === '') { |
83 | 83 | return null; |
84 | 84 | } |
@@ -12,17 +12,17 @@ |
||
12 | 12 | use OCA\TwoFactorGateway\Provider\AFactory; |
13 | 13 | |
14 | 14 | class Factory extends AFactory { |
15 | - #[\Override] |
|
15 | + #[\Override ] |
|
16 | 16 | protected function getPrefix(): string { |
17 | 17 | return 'OCA\\TwoFactorGateway\\Provider\\Channel\\'; |
18 | 18 | } |
19 | 19 | |
20 | - #[\Override] |
|
20 | + #[\Override ] |
|
21 | 21 | protected function getSuffix(): string { |
22 | 22 | return 'Gateway'; |
23 | 23 | } |
24 | 24 | |
25 | - #[\Override] |
|
25 | + #[\Override ] |
|
26 | 26 | protected function getBaseClass(): string { |
27 | 27 | return IGateway::class; |
28 | 28 | } |
@@ -15,38 +15,38 @@ |
||
15 | 15 | |
16 | 16 | class Factory extends AFactory { |
17 | 17 | /** @var array<string,IProvider> */ |
18 | - protected array $instances = []; |
|
19 | - #[\Override] |
|
18 | + protected array $instances = [ ]; |
|
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 isValid(string $fqcn): bool { |
36 | 36 | return defined("$fqcn::SCHEMA") |
37 | 37 | && is_array($fqcn::SCHEMA); |
38 | 38 | } |
39 | 39 | |
40 | - #[\Override] |
|
40 | + #[\Override ] |
|
41 | 41 | public function get(string $name): IProvider { |
42 | - if (isset($this->instances[$name])) { |
|
43 | - return $this->instances[$name]; |
|
42 | + if (isset($this->instances[ $name ])) { |
|
43 | + return $this->instances[ $name ]; |
|
44 | 44 | } |
45 | 45 | foreach ($this->getFqcnList() as $fqcn) { |
46 | 46 | if ($fqcn::getProviderId() === $name) { |
47 | 47 | $instance = \OCP\Server::get($fqcn); |
48 | 48 | $instance->setAppConfig(\OCP\Server::get(\OCP\IAppConfig::class)); |
49 | - $this->instances[$name] = $instance; |
|
49 | + $this->instances[ $name ] = $instance; |
|
50 | 50 | return $instance; |
51 | 51 | } |
52 | 52 | } |
@@ -25,16 +25,16 @@ discard block |
||
25 | 25 | ) { |
26 | 26 | parent::__construct('twofactorauth:gateway:test'); |
27 | 27 | |
28 | - $ids = []; |
|
28 | + $ids = [ ]; |
|
29 | 29 | $fqcn = $this->gatewayFactory->getFqcnList(); |
30 | 30 | foreach ($fqcn as $fqcn) { |
31 | - $ids[] = $fqcn::getProviderId(); |
|
31 | + $ids[ ] = $fqcn::getProviderId(); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | $this->addArgument( |
35 | 35 | 'gateway', |
36 | 36 | InputArgument::REQUIRED, |
37 | - 'The name of the gateway: ' . implode(', ', $ids) |
|
37 | + 'The name of the gateway: '.implode(', ', $ids) |
|
38 | 38 | ); |
39 | 39 | $this->addArgument( |
40 | 40 | 'identifier', |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | ); |
44 | 44 | } |
45 | 45 | |
46 | - #[\Override] |
|
46 | + #[\Override ] |
|
47 | 47 | protected function execute(InputInterface $input, OutputInterface $output) { |
48 | 48 | $gatewayName = $input->getArgument('gateway'); |
49 | 49 | $identifier = $input->getArgument('identifier'); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | return 1; |
56 | 56 | } |
57 | 57 | |
58 | - $gateway->send($identifier, 'Test', ['code' => '123456']); |
|
58 | + $gateway->send($identifier, 'Test', [ 'code' => '123456' ]); |
|
59 | 59 | return 0; |
60 | 60 | } |
61 | 61 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | public const SCHEMA = [ |
38 | 38 | 'name' => 'WhatsApp', |
39 | 39 | 'fields' => [ |
40 | - ['field' => 'base_url', 'prompt' => 'Base URL to your WhatsApp API endpoint:'], |
|
40 | + [ 'field' => 'base_url', 'prompt' => 'Base URL to your WhatsApp API endpoint:' ], |
|
41 | 41 | ], |
42 | 42 | ]; |
43 | 43 | private string $instanceId; |
@@ -55,27 +55,27 @@ discard block |
||
55 | 55 | $this->client = $this->clientService->newClient(); |
56 | 56 | } |
57 | 57 | |
58 | - #[\Override] |
|
59 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
58 | + #[\Override ] |
|
59 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
60 | 60 | if (empty($message)) { |
61 | - $message = $this->l10n->t('`%s` is your Nextcloud verification code.', [$extra['code']]); |
|
61 | + $message = $this->l10n->t('`%s` is your Nextcloud verification code.', [ $extra[ 'code' ] ]); |
|
62 | 62 | } |
63 | 63 | $this->logger->debug("sending whatsapp message to $identifier, message: $message"); |
64 | 64 | |
65 | 65 | $response = $this->getSessionStatus(); |
66 | 66 | if ($response !== 'CONNECTED') { |
67 | - throw new MessageTransmissionException('WhatsApp session is not connected. Current status: ' . $response); |
|
67 | + throw new MessageTransmissionException('WhatsApp session is not connected. Current status: '.$response); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | $chatId = $this->getChatIdFromPhoneNumber($identifier); |
71 | 71 | |
72 | 72 | try { |
73 | - $response = $this->client->post($this->getBaseUrl() . '/client/sendMessage/' . $this->instanceId, [ |
|
73 | + $response = $this->client->post($this->getBaseUrl().'/client/sendMessage/'.$this->instanceId, [ |
|
74 | 74 | 'json' => [ |
75 | 75 | 'chatId' => $chatId, |
76 | 76 | 'contentType' => 'string', |
77 | 77 | 'content' => $message, |
78 | - 'options' => [], |
|
78 | + 'options' => [ ], |
|
79 | 79 | ], |
80 | 80 | ]); |
81 | 81 | } catch (\Exception $e) { |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | $this->logger->debug("whatsapp message to chat $identifier sent"); |
90 | 90 | } |
91 | 91 | |
92 | - #[\Override] |
|
92 | + #[\Override ] |
|
93 | 93 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
94 | 94 | $helper = new QuestionHelper(); |
95 | - $baseUrlQuestion = new Question(self::SCHEMA['fields'][0]['prompt'] . ' '); |
|
95 | + $baseUrlQuestion = new Question(self::SCHEMA[ 'fields' ][ 0 ][ 'prompt' ].' '); |
|
96 | 96 | $this->lazyBaseUrl = $helper->ask($input, $output, $baseUrlQuestion); |
97 | 97 | $this->lazyBaseUrl = rtrim($this->lazyBaseUrl, '/'); |
98 | 98 | |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | return 1; |
102 | 102 | } |
103 | 103 | } catch (\Exception $e) { |
104 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
104 | + $output->writeln('<error>'.$e->getMessage().'</error>'); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | $this->setBaseUrl($this->lazyBaseUrl); |
@@ -111,23 +111,23 @@ discard block |
||
111 | 111 | |
112 | 112 | private function getChatIdFromPhoneNumber(string $phoneNumber): string { |
113 | 113 | try { |
114 | - $response = $this->client->post($this->getBaseUrl() . '/client/getNumberId/' . $this->instanceId, [ |
|
114 | + $response = $this->client->post($this->getBaseUrl().'/client/getNumberId/'.$this->instanceId, [ |
|
115 | 115 | 'json' => [ |
116 | 116 | 'number' => preg_replace('/\D/', '', $phoneNumber), |
117 | 117 | ], |
118 | 118 | ]); |
119 | 119 | $json = $response->getBody(); |
120 | 120 | $data = json_decode($json, true); |
121 | - if (empty($data['result'])) { |
|
121 | + if (empty($data[ 'result' ])) { |
|
122 | 122 | throw new MessageTransmissionException('The phone number is not registered on WhatsApp.'); |
123 | 123 | } |
124 | - return $data['result']['_serialized']; |
|
124 | + return $data[ 'result' ][ '_serialized' ]; |
|
125 | 125 | } catch (ServerException $e) { |
126 | 126 | $content = $e->getResponse()?->getBody()?->getContents(); |
127 | 127 | if ($content === null) { |
128 | 128 | throw new MessageTransmissionException('Unknown error'); |
129 | 129 | } |
130 | - $errorMessage = json_decode($content, true)['error'] ?? 'Unknown error'; |
|
130 | + $errorMessage = json_decode($content, true)[ 'error' ] ?? 'Unknown error'; |
|
131 | 131 | throw new MessageTransmissionException($errorMessage); |
132 | 132 | } |
133 | 133 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | } |
142 | 142 | |
143 | 143 | /** @var string */ |
144 | - $this->lazyBaseUrl = $this->__call(__FUNCTION__, []); |
|
144 | + $this->lazyBaseUrl = $this->__call(__FUNCTION__, [ ]); |
|
145 | 145 | return $this->lazyBaseUrl; |
146 | 146 | } |
147 | 147 | |
@@ -157,19 +157,19 @@ discard block |
||
157 | 157 | |
158 | 158 | $last = null; |
159 | 159 | while (true) { |
160 | - $response = $this->client->get($this->getBaseUrl() . '/session/qr/' . $this->instanceId); |
|
160 | + $response = $this->client->get($this->getBaseUrl().'/session/qr/'.$this->instanceId); |
|
161 | 161 | $json = $response->getBody(); |
162 | 162 | $data = json_decode($json, true); |
163 | - if ($data['success'] === false) { |
|
164 | - if ($data['message'] === 'qr code not ready or already scanned') { |
|
163 | + if ($data[ 'success' ] === false) { |
|
164 | + if ($data[ 'message' ] === 'qr code not ready or already scanned') { |
|
165 | 165 | $output->writeln('<error>Session not connected yet, waiting...</error>'); |
166 | 166 | sleep(2); |
167 | 167 | continue; |
168 | 168 | } |
169 | - $output->writeln('<error>' . $data['message'] . '</error>'); |
|
169 | + $output->writeln('<error>'.$data[ 'message' ].'</error>'); |
|
170 | 170 | return 1; |
171 | 171 | } |
172 | - $qrCodeContent = $data['qr']; |
|
172 | + $qrCodeContent = $data[ 'qr' ]; |
|
173 | 173 | |
174 | 174 | if ($qrCodeContent !== $last) { |
175 | 175 | $last = $qrCodeContent; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | } |
192 | 192 | |
193 | 193 | private function getSessionStatus(): string { |
194 | - $endpoint = $this->getBaseUrl() . '/session/status/' . $this->instanceId; |
|
194 | + $endpoint = $this->getBaseUrl().'/session/status/'.$this->instanceId; |
|
195 | 195 | |
196 | 196 | try { |
197 | 197 | $response = $this->client->get($endpoint); |
@@ -202,18 +202,18 @@ discard block |
||
202 | 202 | return 'not_connected'; |
203 | 203 | } |
204 | 204 | |
205 | - if (($responseData['success'] ?? null) === false) { |
|
206 | - $msg = $responseData['message'] ?? ''; |
|
207 | - return in_array($msg, ['session_not_found', 'session_not_connected'], true) |
|
205 | + if (($responseData[ 'success' ] ?? null) === false) { |
|
206 | + $msg = $responseData[ 'message' ] ?? ''; |
|
207 | + return in_array($msg, [ 'session_not_found', 'session_not_connected' ], true) |
|
208 | 208 | ? $msg |
209 | 209 | : 'not_connected'; |
210 | 210 | } |
211 | 211 | |
212 | - return (string)($responseData['state'] ?? 'not_connected'); |
|
212 | + return (string)($responseData[ 'state' ] ?? 'not_connected'); |
|
213 | 213 | } catch (ClientException $e) { |
214 | 214 | return 'not_connected'; |
215 | 215 | } catch (RequestException $e) { |
216 | - $this->logger->info('Could not connect to ' . $endpoint, ['exception' => $e]); |
|
216 | + $this->logger->info('Could not connect to '.$endpoint, [ 'exception' => $e ]); |
|
217 | 217 | throw new \Exception('Could not connect to the WhatsApp API. Please check the URL.', 1); |
218 | 218 | } |
219 | 219 | } |
@@ -232,13 +232,13 @@ discard block |
||
232 | 232 | } |
233 | 233 | |
234 | 234 | private function getSessionStart(): int { |
235 | - $endpoint = $this->getBaseUrl() . '/session/start/' . $this->instanceId; |
|
235 | + $endpoint = $this->getBaseUrl().'/session/start/'.$this->instanceId; |
|
236 | 236 | try { |
237 | 237 | $this->client->get($endpoint); |
238 | 238 | } catch (ClientException $e) { |
239 | 239 | return 1; |
240 | 240 | } catch (RequestException $e) { |
241 | - $this->logger->info('Could not connect to ' . $endpoint, [ |
|
241 | + $this->logger->info('Could not connect to '.$endpoint, [ |
|
242 | 242 | 'exception' => $e, |
243 | 243 | ]); |
244 | 244 | throw new \Exception('Could not connect to the WhatsApp API. Please check the URL.', 1); |