@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @param string $subject |
49 | 49 | * @param string[] $requiredArguments |
50 | 50 | * @param string $description |
51 | - * @param array $optionalArguments |
|
51 | + * @param string[] $optionalArguments |
|
52 | 52 | */ |
53 | 53 | public function __construct($subject, array $requiredArguments, $description, array $optionalArguments = array()) { |
54 | 54 | $this->subject = $subject; |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * return a valid file path |
116 | 116 | * |
117 | 117 | * @param string $pos |
118 | - * @return null|string |
|
118 | + * @return string |
|
119 | 119 | * @throws \Threema\Core\Exception |
120 | 120 | */ |
121 | 121 | public function getArgumentFile($pos) { |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @return int |
69 | 69 | */ |
70 | 70 | public function getAllArgumentsCount() { |
71 | - return $this->getRequiredArgumentCount() + (null !== $this->optionalArguments ? count($this->optionalArguments) : 0); |
|
71 | + return $this->getRequiredArgumentCount()+(null !== $this->optionalArguments ? count($this->optionalArguments) : 0); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,15 +76,15 @@ discard block |
||
76 | 76 | * @return int |
77 | 77 | * @throws \Threema\Core\Exception |
78 | 78 | */ |
79 | - private function getIndexByPos($pos){ |
|
79 | + private function getIndexByPos($pos) { |
|
80 | 80 | $i = array_search($pos, $this->requiredArguments); |
81 | - if(false === $i) { |
|
81 | + if (false === $i) { |
|
82 | 82 | $i = array_search($pos, $this->optionalArguments); |
83 | - if(false !== $i) { |
|
83 | + if (false !== $i) { |
|
84 | 84 | $i += count($this->requiredArguments); |
85 | 85 | } |
86 | 86 | } |
87 | - if(false === $i) { |
|
87 | + if (false === $i) { |
|
88 | 88 | throw new Exception('argument '.$pos.' not found'); |
89 | 89 | } |
90 | 90 | |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | $i = $this->getIndexByPos($pos); |
101 | 101 | $required = $i < count($this->requiredArguments); |
102 | 102 | |
103 | - if(false === array_key_exists($i, $this->arguments)) { |
|
104 | - if(true === $required) { |
|
103 | + if (false === array_key_exists($i, $this->arguments)) { |
|
104 | + if (true === $required) { |
|
105 | 105 | throw new Exception('no argument at position '.$i.' ('.$pos.')'); |
106 | 106 | } |
107 | 107 | else { |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | public function getArgumentFile($pos) { |
122 | 122 | $i = $this->getIndexByPos($pos); |
123 | 123 | |
124 | - if(false === is_file($this->arguments[$i])) { |
|
124 | + if (false === is_file($this->arguments[$i])) { |
|
125 | 125 | throw new Exception('argument '.$i.' is not a file'); |
126 | 126 | } |
127 | 127 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public function getArgumentPrivateKey($pos) { |
136 | 136 | $content = Common::getPrivateKey($this->getArgumentStringOrFileContent($pos)); |
137 | - if(null !== $content) { |
|
137 | + if (null !== $content) { |
|
138 | 138 | return hex2bin($content); |
139 | 139 | } |
140 | 140 | return null; |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public function getArgumentPublicKey($pos) { |
148 | 148 | $content = Common::getPublicKey($this->getArgumentStringOrFileContent($pos)); |
149 | - if(null !== $content) { |
|
149 | + if (null !== $content) { |
|
150 | 150 | return hex2bin($content); |
151 | 151 | } |
152 | 152 | return null; |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | */ |
159 | 159 | private function getArgumentStringOrFileContent($pos) { |
160 | 160 | $content = $this->getArgument($pos); |
161 | - if(file_exists($content)) { |
|
161 | + if (file_exists($content)) { |
|
162 | 162 | $content = trim(file_get_contents($content)); |
163 | 163 | } |
164 | 164 | return $content; |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | */ |
171 | 171 | public function getArgumentThreemaId($pos) { |
172 | 172 | $content = $this->getArgument($pos); |
173 | - if(null !== $content && strlen($content) == 8) { |
|
173 | + if (null !== $content && strlen($content) == 8) { |
|
174 | 174 | return strtoupper($content); |
175 | 175 | } |
176 | 176 | return null; |
@@ -180,12 +180,12 @@ discard block |
||
180 | 180 | * @return string |
181 | 181 | */ |
182 | 182 | protected function readStdIn() { |
183 | - $f = fopen( 'php://stdin', 'r' ); |
|
183 | + $f = fopen('php://stdin', 'r'); |
|
184 | 184 | |
185 | 185 | $lines = array(); |
186 | - while( $line = trim(fgets($f)) ) { |
|
186 | + while ($line = trim(fgets($f))) { |
|
187 | 187 | |
188 | - if(strlen($line) == 0 || $line == "\n") { |
|
188 | + if (strlen($line) == 0 || $line == "\n") { |
|
189 | 189 | continue; |
190 | 190 | } |
191 | 191 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | |
205 | 205 | $argCount = null !== $this->arguments ? count($this->arguments) : 0; |
206 | 206 | |
207 | - if($argCount < count($this->requiredArguments)) { |
|
207 | + if ($argCount < count($this->requiredArguments)) { |
|
208 | 208 | throw new Exception('invalid count of arguments'); |
209 | 209 | } |
210 | 210 | $this->doRun(); |
@@ -217,10 +217,10 @@ discard block |
||
217 | 217 | final public function help($shellColors = true) { |
218 | 218 | $args = array_merge($this->requiredArguments, $this->optionalArguments); |
219 | 219 | |
220 | - if(count($args) > 0) { |
|
220 | + if (count($args) > 0) { |
|
221 | 221 | $colorPrefix = ''; |
222 | 222 | $colorPostfix = ''; |
223 | - if(true === $shellColors) { |
|
223 | + if (true === $shellColors) { |
|
224 | 224 | $colorPrefix = "\033[0;36m\033[40m"; |
225 | 225 | $colorPostfix = "\033[0m"; |
226 | 226 | } |
@@ -103,8 +103,7 @@ |
||
103 | 103 | if(false === array_key_exists($i, $this->arguments)) { |
104 | 104 | if(true === $required) { |
105 | 105 | throw new Exception('no argument at position '.$i.' ('.$pos.')'); |
106 | - } |
|
107 | - else { |
|
106 | + } else { |
|
108 | 107 | return null; |
109 | 108 | } |
110 | 109 | } |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Threema GmbH |
|
4 | - * @copyright Copyright (c) 2015-2016 Threema GmbH |
|
5 | - */ |
|
3 | + * @author Threema GmbH |
|
4 | + * @copyright Copyright (c) 2015-2016 Threema GmbH |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | |
8 | 8 | namespace Threema\Core; |
@@ -36,8 +36,8 @@ |
||
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
39 | - * @param $string |
|
40 | - * @param array|null $requiredKeys |
|
39 | + * @param string $string |
|
40 | + * @param string[] $requiredKeys |
|
41 | 41 | * @return AssocArray |
42 | 42 | * @throws Exception |
43 | 43 | */ |
@@ -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 | } |
@@ -40,7 +40,7 @@ |
||
40 | 40 | /** |
41 | 41 | * @param int $httpCode |
42 | 42 | * @param object $res |
43 | - * @return UploadFileResult |
|
43 | + * @return DownloadFileResult |
|
44 | 44 | */ |
45 | 45 | function parseResult($httpCode, $res){ |
46 | 46 | return new DownloadFileResult($httpCode, $res); |
@@ -48,7 +48,7 @@ |
||
48 | 48 | * @param object $res |
49 | 49 | * @return UploadFileResult |
50 | 50 | */ |
51 | - function parseResult($httpCode, $res){ |
|
51 | + function parseResult($httpCode, $res) { |
|
52 | 52 | return new UploadFileResult($httpCode, $res); |
53 | 53 | } |
54 | 54 | } |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Threema GmbH |
|
4 | - * @copyright Copyright (c) 2015-2016 Threema GmbH |
|
5 | - */ |
|
3 | + * @author Threema GmbH |
|
4 | + * @copyright Copyright (c) 2015-2016 Threema GmbH |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | |
8 | 8 | namespace Threema\Core; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
76 | - * @return \string[] |
|
76 | + * @return string[] |
|
77 | 77 | */ |
78 | 78 | public function getErrors() { |
79 | 79 | return $this->errors; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
90 | - * @return \string[] |
|
90 | + * @return string[] |
|
91 | 91 | */ |
92 | 92 | public function getFiles() { |
93 | 93 | return $this->files; |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Threema GmbH |
|
4 | - * @copyright Copyright (c) 2015-2016 Threema GmbH |
|
5 | - */ |
|
3 | + * @author Threema GmbH |
|
4 | + * @copyright Copyright (c) 2015-2016 Threema GmbH |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | |
8 | 8 | namespace Threema\Core; |
@@ -65,7 +65,7 @@ |
||
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Get the acknowledged message ids |
68 | - * @return array |
|
68 | + * @return string[] |
|
69 | 69 | */ |
70 | 70 | public function getAckedMessageIds() { |
71 | 71 | return $this->ackedMessageIds; |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @return string |
58 | 58 | */ |
59 | 59 | public function getReceiptTypeName() { |
60 | - if(true === array_key_exists($this->receiptType, self::$receiptTypesToNames)) { |
|
60 | + if (true === array_key_exists($this->receiptType, self::$receiptTypesToNames)) { |
|
61 | 61 | return self::$receiptTypesToNames[$this->receiptType]; |
62 | 62 | } |
63 | 63 | return null; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @return string |
78 | 78 | */ |
79 | 79 | function __toString() { |
80 | - $str = "Delivery receipt (" . $this->getReceiptTypeName() . "): "; |
|
80 | + $str = "Delivery receipt (".$this->getReceiptTypeName()."): "; |
|
81 | 81 | $hexMessageIds = array(); |
82 | 82 | foreach ($this->ackedMessageIds as $messageId) { |
83 | 83 | $hexMessageIds[] = bin2hex($messageId); |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Threema GmbH |
|
4 | - * @copyright Copyright (c) 2015-2016 Threema GmbH |
|
5 | - */ |
|
3 | + * @author Threema GmbH |
|
4 | + * @copyright Copyright (c) 2015-2016 Threema GmbH |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | |
8 | 8 | namespace Threema\Core; |
@@ -22,9 +22,9 @@ |
||
22 | 22 | |
23 | 23 | |
24 | 24 | $result = $connector->fetchPublicKey('ECHOECHO'); |
25 | -if($result->isSuccess()) { |
|
26 | - echo 'public key '.$result->getPublicKey() . "\n"; |
|
25 | +if ($result->isSuccess()) { |
|
26 | + echo 'public key '.$result->getPublicKey()."\n"; |
|
27 | 27 | } |
28 | 28 | else { |
29 | - echo 'error '.$result->getErrorMessage() . "\n"; |
|
29 | + echo 'error '.$result->getErrorMessage()."\n"; |
|
30 | 30 | } |
@@ -29,7 +29,6 @@ |
||
29 | 29 | $result = $connector->sendSimple($receiver, "This is a Test Message"); |
30 | 30 | if($result->isSuccess()) { |
31 | 31 | echo 'Message ID: '.$result->getMessageId() . "\n"; |
32 | -} |
|
33 | -else { |
|
32 | +} else { |
|
34 | 33 | echo 'Error: '.$result->getErrorMessage() . "\n"; |
35 | 34 | } |
@@ -21,9 +21,9 @@ |
||
21 | 21 | $connector = new Connection($settings, $publicKeyStore); |
22 | 22 | |
23 | 23 | $result = $connector->keyLookupByPhoneNumber('123456789'); |
24 | -if($result->isSuccess()) { |
|
25 | - echo 'Threema ID found: '.$result->getId() . "\n"; |
|
24 | +if ($result->isSuccess()) { |
|
25 | + echo 'Threema ID found: '.$result->getId()."\n"; |
|
26 | 26 | } |
27 | 27 | else { |
28 | - echo 'Error: '.$result->getErrorMessage() . "\n"; |
|
28 | + echo 'Error: '.$result->getErrorMessage()."\n"; |
|
29 | 29 | } |
@@ -29,7 +29,6 @@ |
||
29 | 29 | $result = $connector->sendSimple($receiver, "This is a Test Message"); |
30 | 30 | if($result->isSuccess()) { |
31 | 31 | echo 'Message ID: '.$result->getMessageId() . "\n"; |
32 | -} |
|
33 | -else { |
|
32 | +} else { |
|
34 | 33 | echo 'Error: '.$result->getErrorMessage() . "\n"; |
35 | 34 | } |
@@ -23,12 +23,12 @@ |
||
23 | 23 | $senderPrivateKey = "MY_PUBLIC_KEY_IN_BIN"; |
24 | 24 | $filePath = "/path/to/my/file.pdf"; |
25 | 25 | |
26 | -$e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper($senderPrivateKey,$connector); |
|
26 | +$e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper($senderPrivateKey, $connector); |
|
27 | 27 | $result = $e2eHelper->sendFileMessage("TEST1234", $filePath); |
28 | 28 | |
29 | -if(true === $result->isSuccess()) { |
|
30 | - echo 'File Message ID: '.$result->getMessageId() . "\n"; |
|
29 | +if (true === $result->isSuccess()) { |
|
30 | + echo 'File Message ID: '.$result->getMessageId()."\n"; |
|
31 | 31 | } |
32 | 32 | else { |
33 | - echo 'Error: '.$result->getErrorMessage() . "\n"; |
|
33 | + echo 'Error: '.$result->getErrorMessage()."\n"; |
|
34 | 34 | } |
@@ -29,7 +29,6 @@ |
||
29 | 29 | $result = $connector->sendSimple($receiver, "This is a Test Message"); |
30 | 30 | if($result->isSuccess()) { |
31 | 31 | echo 'Message ID: '.$result->getMessageId() . "\n"; |
32 | -} |
|
33 | -else { |
|
32 | +} else { |
|
34 | 33 | echo 'Error: '.$result->getErrorMessage() . "\n"; |
35 | 34 | } |
@@ -22,12 +22,12 @@ |
||
22 | 22 | |
23 | 23 | $senderPrivateKey = "MY_PUBLIC_KEY_IN_BIN"; |
24 | 24 | |
25 | -$e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper($senderPrivateKey,$connector); |
|
25 | +$e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper($senderPrivateKey, $connector); |
|
26 | 26 | $result = $e2eHelper->sendTextMessage("TEST1234", "This is an end-to-end encrypted message"); |
27 | 27 | |
28 | -if(true === $result->isSuccess()) { |
|
29 | - echo 'Message ID: '.$result->getMessageId() . "\n"; |
|
28 | +if (true === $result->isSuccess()) { |
|
29 | + echo 'Message ID: '.$result->getMessageId()."\n"; |
|
30 | 30 | } |
31 | 31 | else { |
32 | - echo 'Error: '.$result->getErrorMessage() . "\n"; |
|
32 | + echo 'Error: '.$result->getErrorMessage()."\n"; |
|
33 | 33 | } |
@@ -29,7 +29,6 @@ |
||
29 | 29 | $result = $connector->sendSimple($receiver, "This is a Test Message"); |
30 | 30 | if($result->isSuccess()) { |
31 | 31 | echo 'Message ID: '.$result->getMessageId() . "\n"; |
32 | -} |
|
33 | -else { |
|
32 | +} else { |
|
34 | 33 | echo 'Error: '.$result->getErrorMessage() . "\n"; |
35 | 34 | } |