@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | Common::required($threemaId, $from, $secret); |
| 38 | 38 | |
| 39 | - if(strlen($threemaId) != 8) { |
|
| 39 | + if (strlen($threemaId) != 8) { |
|
| 40 | 40 | throw new Exception('invalid threema id'); |
| 41 | 41 | } |
| 42 | 42 | //define connection settings |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | $result = $connector->keyCapability($threemaId); |
| 49 | 49 | Common::required($result); |
| 50 | - if($result->isSuccess()) { |
|
| 50 | + if ($result->isSuccess()) { |
|
| 51 | 51 | Common::l(implode("\n", $result->getCapabilities())); |
| 52 | 52 | } |
| 53 | 53 | else { |
@@ -41,8 +41,7 @@ |
||
| 41 | 41 | $storeHandle = fopen($this->file, 'r'); |
| 42 | 42 | if(false === $storeHandle) { |
| 43 | 43 | throw new Exception('could not open file '.$this->file); |
| 44 | - } |
|
| 45 | - else { |
|
| 44 | + } else { |
|
| 46 | 45 | $threemaId = strtoupper($threemaId); |
| 47 | 46 | $publicKey = null; |
| 48 | 47 | while (!feof($storeHandle)) { |
@@ -43,9 +43,9 @@ |
||
| 43 | 43 | //create a connection |
| 44 | 44 | $connector = new Connection($settings, $this->publicKeyStore); |
| 45 | 45 | |
| 46 | - $result = $connector->keyLookupByEmail($email);; |
|
| 46 | + $result = $connector->keyLookupByEmail($email); ; |
|
| 47 | 47 | Common::required($result); |
| 48 | - if($result->isSuccess()) { |
|
| 48 | + if ($result->isSuccess()) { |
|
| 49 | 49 | Common::l($result->getId()); |
| 50 | 50 | } |
| 51 | 51 | else { |
@@ -41,8 +41,7 @@ |
||
| 41 | 41 | $storeHandle = fopen($this->file, 'r'); |
| 42 | 42 | if(false === $storeHandle) { |
| 43 | 43 | throw new Exception('could not open file '.$this->file); |
| 44 | - } |
|
| 45 | - else { |
|
| 44 | + } else { |
|
| 46 | 45 | $threemaId = strtoupper($threemaId); |
| 47 | 46 | $publicKey = null; |
| 48 | 47 | while (!feof($storeHandle)) { |
@@ -43,9 +43,9 @@ |
||
| 43 | 43 | //create a connection |
| 44 | 44 | $connector = new Connection($settings, $this->publicKeyStore); |
| 45 | 45 | |
| 46 | - $result = $connector->keyLookupByPhoneNumber($phoneNo);; |
|
| 46 | + $result = $connector->keyLookupByPhoneNumber($phoneNo); ; |
|
| 47 | 47 | Common::required($result); |
| 48 | - if($result->isSuccess()) { |
|
| 48 | + if ($result->isSuccess()) { |
|
| 49 | 49 | Common::l($result->getId()); |
| 50 | 50 | } |
| 51 | 51 | else { |
@@ -41,8 +41,7 @@ |
||
| 41 | 41 | $storeHandle = fopen($this->file, 'r'); |
| 42 | 42 | if(false === $storeHandle) { |
| 43 | 43 | throw new Exception('could not open file '.$this->file); |
| 44 | - } |
|
| 45 | - else { |
|
| 44 | + } else { |
|
| 46 | 45 | $threemaId = strtoupper($threemaId); |
| 47 | 46 | $publicKey = null; |
| 48 | 47 | while (!feof($storeHandle)) { |
@@ -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 | } |
@@ -41,8 +41,7 @@ |
||
| 41 | 41 | $storeHandle = fopen($this->file, 'r'); |
| 42 | 42 | if(false === $storeHandle) { |
| 43 | 43 | throw new Exception('could not open file '.$this->file); |
| 44 | - } |
|
| 45 | - else { |
|
| 44 | + } else { |
|
| 46 | 45 | $threemaId = strtoupper($threemaId); |
| 47 | 46 | $publicKey = null; |
| 48 | 47 | while (!feof($storeHandle)) { |
@@ -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 { |
@@ -41,8 +41,7 @@ |
||
| 41 | 41 | $storeHandle = fopen($this->file, 'r'); |
| 42 | 42 | if(false === $storeHandle) { |
| 43 | 43 | throw new Exception('could not open file '.$this->file); |
| 44 | - } |
|
| 45 | - else { |
|
| 44 | + } else { |
|
| 46 | 45 | $threemaId = strtoupper($threemaId); |
| 47 | 46 | $publicKey = null; |
| 48 | 47 | while (!feof($storeHandle)) { |
@@ -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 { |
@@ -41,8 +41,7 @@ |
||
| 41 | 41 | $storeHandle = fopen($this->file, 'r'); |
| 42 | 42 | if(false === $storeHandle) { |
| 43 | 43 | throw new Exception('could not open file '.$this->file); |
| 44 | - } |
|
| 45 | - else { |
|
| 44 | + } else { |
|
| 46 | 45 | $threemaId = strtoupper($threemaId); |
| 47 | 46 | $publicKey = null; |
| 48 | 47 | while (!feof($storeHandle)) { |
@@ -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; |
@@ -86,15 +86,15 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | private function register($argumentKey, Base $command) { |
| 89 | - if(is_scalar($argumentKey)) { |
|
| 89 | + if (is_scalar($argumentKey)) { |
|
| 90 | 90 | $argumentKey = array($argumentKey); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | //check for existing commands with the same arguments |
| 94 | - foreach($this->commands as $commandValues) { |
|
| 94 | + foreach ($this->commands as $commandValues) { |
|
| 95 | 95 | $ex = $commandValues[0]; |
| 96 | - if(null !== $ex && is_array($ex)) { |
|
| 97 | - if(count($ex) == count($argumentKey) |
|
| 96 | + if (null !== $ex && is_array($ex)) { |
|
| 97 | + if (count($ex) == count($argumentKey) |
|
| 98 | 98 | && count(array_diff($ex, $argumentKey)) == 0) { |
| 99 | 99 | throw new Exception('arguments '.implode($argumentKey).' already used'); |
| 100 | 100 | } |
@@ -113,17 +113,17 @@ discard block |
||
| 113 | 113 | $argumentLength = 0; |
| 114 | 114 | |
| 115 | 115 | //find the correct command by arguments and arguments count |
| 116 | - foreach($this->commands as $data) { |
|
| 117 | - if(is_scalar($data)) { |
|
| 116 | + foreach ($this->commands as $data) { |
|
| 117 | + if (is_scalar($data)) { |
|
| 118 | 118 | continue; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | list($keys, $command) = $data; |
| 122 | - if(array_slice($this->arguments, 0, count($keys)) == $keys) { |
|
| 122 | + if (array_slice($this->arguments, 0, count($keys)) == $keys) { |
|
| 123 | 123 | $argCount = count($this->arguments)-count($keys); |
| 124 | 124 | |
| 125 | 125 | /** @noinspection PhpUndefinedMethodInspection */ |
| 126 | - if($argCount >= $command->getRequiredArgumentCount() |
|
| 126 | + if ($argCount >= $command->getRequiredArgumentCount() |
|
| 127 | 127 | && $argCount <= $command->getAllArgumentsCount()) { |
| 128 | 128 | $found = $command; |
| 129 | 129 | $argumentLength = count($keys); |
@@ -132,11 +132,11 @@ discard block |
||
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - if($argumentLength > 0) { |
|
| 135 | + if ($argumentLength > 0) { |
|
| 136 | 136 | array_splice($this->arguments, 0, $argumentLength); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - if(null === $found) { |
|
| 139 | + if (null === $found) { |
|
| 140 | 140 | $this->help(); |
| 141 | 141 | } |
| 142 | 142 | else { |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | try { |
| 146 | 146 | $found->run($this->arguments); |
| 147 | 147 | } |
| 148 | - catch(Exception $x) { |
|
| 148 | + catch (Exception $x) { |
|
| 149 | 149 | Common::l(); |
| 150 | 150 | Common::e('ERROR: '.$x->getMessage()); |
| 151 | 151 | Common::e(get_class($x)); |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | Common::l('CryptTool: '.$defaultCryptTool->getName().' '.$defaultCryptTool->getDescription()); |
| 164 | 164 | Common::l(str_repeat('.', 40)); |
| 165 | 165 | Common::l(); |
| 166 | - foreach($this->commands as $data) { |
|
| 167 | - if(is_scalar($data)) { |
|
| 166 | + foreach ($this->commands as $data) { |
|
| 167 | + if (is_scalar($data)) { |
|
| 168 | 168 | Common::l($data); |
| 169 | 169 | Common::l(str_repeat('-', strlen($data))); |
| 170 | 170 | Common::l(); |
@@ -181,10 +181,10 @@ discard block |
||
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | public function writeHelp(\Closure $writer) { |
| 184 | - if(null !== $writer) { |
|
| 184 | + if (null !== $writer) { |
|
| 185 | 185 | |
| 186 | - foreach($this->commands as $data) { |
|
| 187 | - if(is_scalar($data)) { |
|
| 186 | + foreach ($this->commands as $data) { |
|
| 187 | + if (is_scalar($data)) { |
|
| 188 | 188 | $writer->__invoke($data, null, null, false); |
| 189 | 189 | } |
| 190 | 190 | else { |
@@ -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 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @param string $value |
| 39 | 39 | * @return $this |
| 40 | 40 | */ |
| 41 | - public function setValue($key, $value){ |
|
| 41 | + public function setValue($key, $value) { |
|
| 42 | 42 | $this->values[$key] = $value; |
| 43 | 43 | return $this; |
| 44 | 44 | } |
@@ -50,18 +50,18 @@ discard block |
||
| 50 | 50 | * @return $this |
| 51 | 51 | */ |
| 52 | 52 | public function addPath($path) { |
| 53 | - while(substr($this->path, strlen($this->path)-1) == '/') { |
|
| 53 | + while (substr($this->path, strlen($this->path)-1) == '/') { |
|
| 54 | 54 | $this->path = substr($this->path, 0, strlen($this->path)-1); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | $realPath = ''; |
| 58 | - foreach(explode('/', $path) as $c => $pathPiece) { |
|
| 59 | - if($c > 0) { |
|
| 58 | + foreach (explode('/', $path) as $c => $pathPiece) { |
|
| 59 | + if ($c > 0) { |
|
| 60 | 60 | $realPath .= '/'; |
| 61 | 61 | } |
| 62 | 62 | $realPath .= urlencode($pathPiece); |
| 63 | 63 | } |
| 64 | - while(substr($path, 0, 1) == '/') { |
|
| 64 | + while (substr($path, 0, 1) == '/') { |
|
| 65 | 65 | $path = substr($path, 1); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -74,9 +74,9 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function getPath() { |
| 76 | 76 | $p = $this->path; |
| 77 | - if(count($this->values) > 0) { |
|
| 77 | + if (count($this->values) > 0) { |
|
| 78 | 78 | $s = http_build_query($this->values); |
| 79 | - if(strlen($s) > 0) { |
|
| 79 | + if (strlen($s) > 0) { |
|
| 80 | 80 | $p .= '?'.$s; |
| 81 | 81 | } |
| 82 | 82 | } |
@@ -100,17 +100,17 @@ discard block |
||
| 100 | 100 | { |
| 101 | 101 | $result = array(); |
| 102 | 102 | |
| 103 | - while(strlen($urlParameter) > 0) { |
|
| 103 | + while (strlen($urlParameter) > 0) { |
|
| 104 | 104 | // name |
| 105 | - $keyPosition= strpos($urlParameter,'='); |
|
| 106 | - $keyValue = substr($urlParameter,0,$keyPosition); |
|
| 105 | + $keyPosition = strpos($urlParameter, '='); |
|
| 106 | + $keyValue = substr($urlParameter, 0, $keyPosition); |
|
| 107 | 107 | // value |
| 108 | - $valuePosition = strpos($urlParameter,'&') ? strpos($urlParameter,'&'): strlen($urlParameter); |
|
| 109 | - $valueValue = substr($urlParameter,$keyPosition+1,$valuePosition-$keyPosition-1); |
|
| 108 | + $valuePosition = strpos($urlParameter, '&') ? strpos($urlParameter, '&') : strlen($urlParameter); |
|
| 109 | + $valueValue = substr($urlParameter, $keyPosition+1, $valuePosition-$keyPosition-1); |
|
| 110 | 110 | |
| 111 | 111 | // decoding the response |
| 112 | 112 | $result[$keyValue] = urldecode($valueValue); |
| 113 | - $urlParameter = substr($urlParameter,$valuePosition+1,strlen($urlParameter)); |
|
| 113 | + $urlParameter = substr($urlParameter, $valuePosition+1, strlen($urlParameter)); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | return $result; |