@@ -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 { |
@@ -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 { |
@@ -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 { |
@@ -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 | } |
@@ -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; |
@@ -36,7 +36,7 @@ |
||
36 | 36 | * @return null|int |
37 | 37 | */ |
38 | 38 | final public function getErrorCode() { |
39 | - if(false === $this->isSuccess()) { |
|
39 | + if (false === $this->isSuccess()) { |
|
40 | 40 | return $this->httpCode; |
41 | 41 | } |
42 | 42 | return null; |
@@ -34,7 +34,7 @@ |
||
34 | 34 | * @return string |
35 | 35 | */ |
36 | 36 | protected function getErrorMessageByErrorCode($httpCode) { |
37 | - switch($httpCode) { |
|
37 | + switch ($httpCode) { |
|
38 | 38 | case 401: |
39 | 39 | return 'API identity or secret incorrect or file is empty'; |
40 | 40 | case 402: |
@@ -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); |