@@ -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 | } |
@@ -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 { |
@@ -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 { |
@@ -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 { |
@@ -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; |
@@ -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; |
@@ -78,7 +78,7 @@ |
||
78 | 78 | * @return string |
79 | 79 | */ |
80 | 80 | protected function getErrorMessageByErrorCode($httpCode) { |
81 | - switch($httpCode) { |
|
81 | + switch ($httpCode) { |
|
82 | 82 | case 401: |
83 | 83 | return 'API identity or secret incorrect'; |
84 | 84 | case 404: |