Skip to content

Commit

Permalink
Merge pull request #1 from hedeqiang/analysis-z9M0E9
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
hedeqiang committed Nov 8, 2019
2 parents df7cab7 + f937a55 commit 322778d
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 17 deletions.
14 changes: 13 additions & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
<?php

/*
* This file is part of the hedeqiang/ten-im.
*
* (c) hedeqiang<[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Hedeqiang\TenIM;

use ArrayAccess;
use InvalidArgumentException;

Expand Down Expand Up @@ -47,6 +57,7 @@ public function get($key, $default = null)
}
$config = $config[$segment];
}

return $config;
}

Expand All @@ -73,6 +84,7 @@ public function set($key, $value)
$config = &$config[$key];
}
$config[array_shift($keys)] = $value;

return $config;
}

Expand Down Expand Up @@ -161,4 +173,4 @@ public function offsetUnset($offset)
{
$this->set($offset, null);
}
}
}
12 changes: 10 additions & 2 deletions src/Exceptions/Exception.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<?php

/*
* This file is part of the hedeqiang/ten-im.
*
* (c) hedeqiang<[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Hedeqiang\TenIM\Exceptions;

class Exception extends \Exception
{

}
}
12 changes: 10 additions & 2 deletions src/Exceptions/HttpException.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<?php

/*
* This file is part of the hedeqiang/ten-im.
*
* (c) hedeqiang<[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Hedeqiang\TenIM\Exceptions;

class HttpException extends Exception
{

}
}
12 changes: 10 additions & 2 deletions src/Exceptions/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<?php

/*
* This file is part of the hedeqiang/ten-im.
*
* (c) hedeqiang<[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Hedeqiang\TenIM\Exceptions;

class InvalidArgumentException extends Exception
{

}
}
34 changes: 26 additions & 8 deletions src/IM.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php

/*
* This file is part of the hedeqiang/ten-im.
*
* (c) hedeqiang<[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Hedeqiang\TenIM;

use Hedeqiang\TenIM\Exceptions\Exception;
Expand Down Expand Up @@ -26,12 +36,14 @@ public function __construct(array $config)
/**
* @param string $servername
* @param string $command
* @param array $params
* @param array $params
*
* @return array
*
* @throws Exception
* @throws HttpException
*/
public function send($servername,$command,array $params = [])
public function send($servername, $command, array $params = [])
{
try {
$result = $this->postJson($this->buildEndpoint($servername, $command), $params);
Expand All @@ -42,15 +54,18 @@ public function send($servername,$command,array $params = [])
if (0 === $result['ErrorCode'] && 'OK' === $result['ActionStatus']) {
return $result;
}
throw new Exception('Tim REST API error: '. json_encode($result));

throw new Exception('Tim REST API error: '.json_encode($result));
}

/**
* Build endpoint url.
*
* @param string $servername
* @param string $command
*
* @return string
*
* @throws \Exception
*/
protected function buildEndpoint(string $servername, string $command): string
Expand All @@ -62,21 +77,24 @@ protected function buildEndpoint(string $servername, string $command): string
'random' => mt_rand(0, 4294967295),
'contenttype' => self::ENDPOINT_FORMAT,
]);
return \sprintf(self::ENDPOINT_TEMPLATE,self::ENDPOINT_VERSION, $servername, $command, $query);

return \sprintf(self::ENDPOINT_TEMPLATE, self::ENDPOINT_VERSION, $servername, $command, $query);
}

/**
* Generate Sign.
*
* @param string $identifier
* @param int $expires
* @param int $expires
*
* @return string
*
* @throws \Exception
*/
protected function generateSign(string $identifier, int $expires = 15552000): string
{
$api = new TLSSigAPIv2($this->config->get('sdk_app_id'), $this->config->get('secret_key'));
return $api->genSig($identifier,$expires);
}

}
return $api->genSig($identifier, $expires);
}
}
15 changes: 13 additions & 2 deletions src/Traits/HasHttpRequest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
<?php

/*
* This file is part of the hedeqiang/ten-im.
*
* (c) hedeqiang<[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Hedeqiang\TenIM\Traits;

use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;

Expand Down Expand Up @@ -85,6 +95,7 @@ protected function getBaseOptions()
'base_uri' => method_exists($this, 'getBaseUri') ? $this->getBaseUri() : '',
'timeout' => method_exists($this, 'getTimeout') ? $this->getTimeout() : 10.0,
];

return $options;
}

Expand Down Expand Up @@ -118,7 +129,7 @@ protected function unwrapResponse(ResponseInterface $response)
} elseif (false !== stripos($contentType, 'xml')) {
return json_decode(json_encode(simplexml_load_string($contents)), true);
}

return $contents;
}

}
}

0 comments on commit 322778d

Please sign in to comment.