@@ -42,7 +42,7 @@ |
||
42 | 42 | $connector = new Connection($settings, $this->publicKeyStore); |
43 | 43 | |
44 | 44 | $result = $connector->fetchPublicKey($id); |
45 | - if($result->isSuccess()) { |
|
45 | + if ($result->isSuccess()) { |
|
46 | 46 | Common::l(Common::convertPublicKey($result->getPublicKey())); |
47 | 47 | } |
48 | 48 | else { |
@@ -44,8 +44,7 @@ |
||
44 | 44 | $result = $connector->fetchPublicKey($id); |
45 | 45 | if($result->isSuccess()) { |
46 | 46 | Common::l(Common::convertPublicKey($result->getPublicKey())); |
47 | - } |
|
48 | - else { |
|
47 | + } else { |
|
49 | 48 | Common::e($result->getErrorMessage()); |
50 | 49 | } |
51 | 50 | } |
@@ -61,14 +61,14 @@ |
||
61 | 61 | $outputFolder |
62 | 62 | ); |
63 | 63 | |
64 | - if(null === $message) { |
|
64 | + if (null === $message) { |
|
65 | 65 | Common::e('invalid message'); |
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
69 | - if($message->isSuccess()) { |
|
69 | + if ($message->isSuccess()) { |
|
70 | 70 | Common::l($message->getMessageId().' - '.$message->getThreemaMessage()); |
71 | - foreach($message->getFiles() as $fileName => $filePath) { |
|
71 | + foreach ($message->getFiles() as $fileName => $filePath) { |
|
72 | 72 | Common::l(' received file '.$fileName.' in '.$filePath); |
73 | 73 | } |
74 | 74 | } |
@@ -71,8 +71,7 @@ |
||
71 | 71 | foreach($message->getFiles() as $fileName => $filePath) { |
72 | 72 | Common::l(' received file '.$fileName.' in '.$filePath); |
73 | 73 | } |
74 | - } |
|
75 | - else { |
|
74 | + } else { |
|
76 | 75 | Common::e('Error: '.implode("\n", $message->getErrors())); |
77 | 76 | } |
78 | 77 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | $helper = new E2EHelper($privateKey, $connector); |
54 | 54 | $result = $helper->sendFileMessage($threemaId, $path, $thumbnailPath); |
55 | 55 | |
56 | - if($result->isSuccess()) { |
|
56 | + if ($result->isSuccess()) { |
|
57 | 57 | Common::l('Message ID: '.$result->getMessageId()); |
58 | 58 | } |
59 | 59 | else { |
@@ -55,8 +55,7 @@ |
||
55 | 55 | |
56 | 56 | if($result->isSuccess()) { |
57 | 57 | Common::l('Message ID: '.$result->getMessageId()); |
58 | - } |
|
59 | - else { |
|
58 | + } else { |
|
60 | 59 | Common::e('Error: '.$result->getErrorMessage()); |
61 | 60 | } |
62 | 61 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | $helper = new E2EHelper($privateKey, $connector); |
52 | 52 | $result = $helper->sendImageMessage($threemaId, $path); |
53 | 53 | |
54 | - if($result->isSuccess()) { |
|
54 | + if ($result->isSuccess()) { |
|
55 | 55 | Common::l('Message ID: '.$result->getMessageId()); |
56 | 56 | } |
57 | 57 | else { |
@@ -55,8 +55,7 @@ |
||
55 | 55 | |
56 | 56 | if($result->isSuccess()) { |
57 | 57 | Common::l('Message ID: '.$result->getMessageId()); |
58 | - } |
|
59 | - else { |
|
58 | + } else { |
|
60 | 59 | Common::e('Error: '.$result->getErrorMessage()); |
61 | 60 | } |
62 | 61 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | Common::required($threemaId, $from, $secret, $privateKey); |
39 | 39 | |
40 | 40 | $message = $this->readStdIn(); |
41 | - if(strlen($message) === 0) { |
|
41 | + if (strlen($message) === 0) { |
|
42 | 42 | throw new \InvalidArgumentException('please define a message'); |
43 | 43 | } |
44 | 44 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | $helper = new E2EHelper($privateKey, $connector); |
53 | 53 | $result = $helper->sendTextMessage($threemaId, $message); |
54 | 54 | |
55 | - if($result->isSuccess()) { |
|
55 | + if ($result->isSuccess()) { |
|
56 | 56 | Common::l('Message ID: '.$result->getMessageId()); |
57 | 57 | } |
58 | 58 | else { |
@@ -55,8 +55,7 @@ |
||
55 | 55 | |
56 | 56 | if($result->isSuccess()) { |
57 | 57 | Common::l('Message ID: '.$result->getMessageId()); |
58 | - } |
|
59 | - else { |
|
58 | + } else { |
|
60 | 59 | Common::e('Error: '.$result->getErrorMessage()); |
61 | 60 | } |
62 | 61 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | Common::required($to, $from, $secret); |
37 | 37 | |
38 | 38 | $message = $this->readStdIn(); |
39 | - if(strlen($message) === 0) { |
|
39 | + if (strlen($message) === 0) { |
|
40 | 40 | throw new \InvalidArgumentException('please define a message'); |
41 | 41 | } |
42 | 42 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $receiver = new Receiver($to, Receiver::TYPE_ID); |
50 | 50 | |
51 | 51 | $result = $connector->sendSimple($receiver, $message); |
52 | - if($result->isSuccess()) { |
|
52 | + if ($result->isSuccess()) { |
|
53 | 53 | Common::l('Message ID: '.$result->getMessageId()); |
54 | 54 | } |
55 | 55 | else { |
@@ -51,8 +51,7 @@ |
||
51 | 51 | $result = $connector->sendSimple($receiver, $message); |
52 | 52 | if($result->isSuccess()) { |
53 | 53 | Common::l('Message ID: '.$result->getMessageId()); |
54 | - } |
|
55 | - else { |
|
54 | + } else { |
|
56 | 55 | Common::l('Error: '.$result->getErrorMessage()); |
57 | 56 | } |
58 | 57 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public static function l($string = '', $indent = 0) { |
21 | 21 | $pad = str_repeat(' ', $indent); |
22 | - echo $pad . wordwrap($string, 100, "\n" . $pad) . "\n"; |
|
22 | + echo $pad.wordwrap($string, 100, "\n".$pad)."\n"; |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param string $string string to output |
29 | 29 | */ |
30 | 30 | public static function ln($string = '') { |
31 | - echo $string . "\n"; |
|
31 | + echo $string."\n"; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public static function required() { |
52 | 52 | $argCount = func_num_args(); |
53 | - for($n = 0; $n < $argCount; $n++) { |
|
53 | + for ($n = 0; $n < $argCount; $n++) { |
|
54 | 54 | $o = func_get_arg($n); |
55 | - if(null === $o || (is_scalar($o) && strlen($o) == 0)) { |
|
55 | + if (null === $o || (is_scalar($o) && strlen($o) == 0)) { |
|
56 | 56 | throw new Exception('invalid data'); |
57 | 57 | } |
58 | 58 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @return null|string |
66 | 66 | */ |
67 | 67 | public static function convertPublicKey($key) { |
68 | - if(null !== $key) { |
|
68 | + if (null !== $key) { |
|
69 | 69 | return Constants::PUBLIC_KEY_PREFIX.$key; |
70 | 70 | } |
71 | 71 | return null; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @return null|string |
79 | 79 | */ |
80 | 80 | public static function getPublicKey($stringWithPrefix = null) { |
81 | - if(null !== $stringWithPrefix && substr($stringWithPrefix, 0, strlen(Constants::PUBLIC_KEY_PREFIX)) == Constants::PUBLIC_KEY_PREFIX) { |
|
81 | + if (null !== $stringWithPrefix && substr($stringWithPrefix, 0, strlen(Constants::PUBLIC_KEY_PREFIX)) == Constants::PUBLIC_KEY_PREFIX) { |
|
82 | 82 | return substr($stringWithPrefix, strlen(Constants::PUBLIC_KEY_PREFIX)); |
83 | 83 | } |
84 | 84 | return null; |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @return null|string |
92 | 92 | */ |
93 | 93 | public static function convertPrivateKey($key) { |
94 | - if(null !== $key) { |
|
94 | + if (null !== $key) { |
|
95 | 95 | return Constants::PRIVATE_KEY_PREFIX.$key; |
96 | 96 | } |
97 | 97 | return null; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @return null|string |
105 | 105 | */ |
106 | 106 | public static function getPrivateKey($stringWithPrefix = null) { |
107 | - if(null !== $stringWithPrefix && substr($stringWithPrefix, 0, strlen(Constants::PRIVATE_KEY_PREFIX)) == Constants::PRIVATE_KEY_PREFIX) { |
|
107 | + if (null !== $stringWithPrefix && substr($stringWithPrefix, 0, strlen(Constants::PRIVATE_KEY_PREFIX)) == Constants::PRIVATE_KEY_PREFIX) { |
|
108 | 108 | return substr($stringWithPrefix, strlen(Constants::PRIVATE_KEY_PREFIX)); |
109 | 109 | } |
110 | 110 | return null; |
@@ -138,14 +138,12 @@ discard block |
||
138 | 138 | |
139 | 139 | if(null === $found) { |
140 | 140 | $this->help(); |
141 | - } |
|
142 | - else { |
|
141 | + } else { |
|
143 | 142 | |
144 | 143 | |
145 | 144 | try { |
146 | 145 | $found->run($this->arguments); |
147 | - } |
|
148 | - catch(Exception $x) { |
|
146 | + } catch(Exception $x) { |
|
149 | 147 | Common::l(); |
150 | 148 | Common::e('ERROR: '.$x->getMessage()); |
151 | 149 | Common::e(get_class($x)); |
@@ -168,8 +166,7 @@ discard block |
||
168 | 166 | Common::l($data); |
169 | 167 | Common::l(str_repeat('-', strlen($data))); |
170 | 168 | Common::l(); |
171 | - } |
|
172 | - else { |
|
169 | + } else { |
|
173 | 170 | list($key, $command) = $data; |
174 | 171 | Common::ln($this->scriptName.' '."\033[1;33m".implode(' ', $key)."\033[0m".' '.$command->help()); |
175 | 172 | Common::l(); |
@@ -186,8 +183,7 @@ discard block |
||
186 | 183 | foreach($this->commands as $data) { |
187 | 184 | if(is_scalar($data)) { |
188 | 185 | $writer->__invoke($data, null, null, false); |
189 | - } |
|
190 | - else { |
|
186 | + } else { |
|
191 | 187 | list($key, $command) = $data; |
192 | 188 | $writer->__invoke($command->subject(false), $this->scriptName.' '.implode(' ', $key).' '.$command->help(false), $command->description(), true); |
193 | 189 | } |
@@ -88,15 +88,15 @@ discard block |
||
88 | 88 | } |
89 | 89 | |
90 | 90 | private function register($argumentKey, Base $command) { |
91 | - if(is_scalar($argumentKey)) { |
|
91 | + if (is_scalar($argumentKey)) { |
|
92 | 92 | $argumentKey = array($argumentKey); |
93 | 93 | } |
94 | 94 | |
95 | 95 | //check for existing commands with the same arguments |
96 | - foreach($this->commands as $commandValues) { |
|
96 | + foreach ($this->commands as $commandValues) { |
|
97 | 97 | $ex = $commandValues[0]; |
98 | - if(null !== $ex && is_array($ex)) { |
|
99 | - if(count($ex) == count($argumentKey) |
|
98 | + if (null !== $ex && is_array($ex)) { |
|
99 | + if (count($ex) == count($argumentKey) |
|
100 | 100 | && count(array_diff($ex, $argumentKey)) == 0) { |
101 | 101 | throw new Exception('arguments '.implode($argumentKey).' already used'); |
102 | 102 | } |
@@ -115,17 +115,17 @@ discard block |
||
115 | 115 | $argumentLength = 0; |
116 | 116 | |
117 | 117 | //find the correct command by arguments and arguments count |
118 | - foreach($this->commands as $data) { |
|
119 | - if(is_scalar($data)) { |
|
118 | + foreach ($this->commands as $data) { |
|
119 | + if (is_scalar($data)) { |
|
120 | 120 | continue; |
121 | 121 | } |
122 | 122 | |
123 | 123 | list($keys, $command) = $data; |
124 | - if(array_slice($this->arguments, 0, count($keys)) == $keys) { |
|
124 | + if (array_slice($this->arguments, 0, count($keys)) == $keys) { |
|
125 | 125 | $argCount = count($this->arguments)-count($keys); |
126 | 126 | |
127 | 127 | /** @noinspection PhpUndefinedMethodInspection */ |
128 | - if($argCount >= $command->getRequiredArgumentCount() |
|
128 | + if ($argCount >= $command->getRequiredArgumentCount() |
|
129 | 129 | && $argCount <= $command->getAllArgumentsCount()) { |
130 | 130 | $found = $command; |
131 | 131 | $argumentLength = count($keys); |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
137 | - if($argumentLength > 0) { |
|
137 | + if ($argumentLength > 0) { |
|
138 | 138 | array_splice($this->arguments, 0, $argumentLength); |
139 | 139 | } |
140 | 140 | |
141 | - if(null === $found) { |
|
141 | + if (null === $found) { |
|
142 | 142 | $this->help(); |
143 | 143 | } |
144 | 144 | else { |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | try { |
148 | 148 | $found->run($this->arguments); |
149 | 149 | } |
150 | - catch(Exception $x) { |
|
150 | + catch (Exception $x) { |
|
151 | 151 | Common::l(); |
152 | 152 | Common::e('ERROR: '.$x->getMessage()); |
153 | 153 | Common::e(get_class($x)); |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | Common::l('CryptTool: '.$defaultCryptTool->getName().' ('.$defaultCryptTool->getDescription().')'); |
167 | 167 | Common::l(str_repeat('.', 40)); |
168 | 168 | Common::l(); |
169 | - foreach($this->commands as $data) { |
|
170 | - if(is_scalar($data)) { |
|
169 | + foreach ($this->commands as $data) { |
|
170 | + if (is_scalar($data)) { |
|
171 | 171 | Common::l($data); |
172 | 172 | Common::l(str_repeat('-', strlen($data))); |
173 | 173 | Common::l(); |
@@ -184,10 +184,10 @@ discard block |
||
184 | 184 | } |
185 | 185 | |
186 | 186 | public function writeHelp(\Closure $writer) { |
187 | - if(null !== $writer) { |
|
187 | + if (null !== $writer) { |
|
188 | 188 | |
189 | - foreach($this->commands as $data) { |
|
190 | - if(is_scalar($data)) { |
|
189 | + foreach ($this->commands as $data) { |
|
190 | + if (is_scalar($data)) { |
|
191 | 191 | $writer->__invoke($data, null, null, false); |
192 | 192 | } |
193 | 193 | else { |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @return mixed|null return the key value or the default value |
29 | 29 | */ |
30 | 30 | public function getValue($key, $defaultValue = null) { |
31 | - if(false === array_key_exists($key, $this->data)) { |
|
31 | + if (false === array_key_exists($key, $this->data)) { |
|
32 | 32 | return $defaultValue; |
33 | 33 | } |
34 | 34 | |
@@ -43,15 +43,15 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public static final function byJsonString($string, array $requiredKeys = null) { |
45 | 45 | $v = json_decode($string, true); |
46 | - if(null === $v || false === $v) { |
|
46 | + if (null === $v || false === $v) { |
|
47 | 47 | throw new Exception('invalid json string'); |
48 | 48 | } |
49 | 49 | |
50 | 50 | //validate first |
51 | - if(null !== $requiredKeys) { |
|
51 | + if (null !== $requiredKeys) { |
|
52 | 52 | //validate array first |
53 | - foreach($requiredKeys as $requiredKey) { |
|
54 | - if(false === array($v)) { |
|
53 | + foreach ($requiredKeys as $requiredKey) { |
|
54 | + if (false === array($v)) { |
|
55 | 55 | throw new Exception('required key '.$requiredKey.' failed'); |
56 | 56 | } |
57 | 57 | } |