GetDiscussesRequest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A parseResponse() 0 16 4
1
<?php
2
/*
3
 * This file is part of the slince/smartqq package.
4
 *
5
 * (c) Slince <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Slince\SmartQQ\Request;
12
13
use GuzzleHttp\Psr7\Response;
14
use Slince\SmartQQ\Credential;
15
use Slince\SmartQQ\Entity\Discuss;
16
use Slince\SmartQQ\EntityCollection;
17
use Slince\SmartQQ\EntityFactory;
18
use Slince\SmartQQ\Exception\ResponseException;
19
20
class GetDiscussesRequest extends Request
21
{
22
    protected $uri = 'http://s.web2.qq.com/api/get_discus_list?clientid=53999199&psessionid={psessionid}&vfwebqq={vfwebqq}&t=0.1';
23
24
    protected $referer = 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2';
25
26
    public function __construct(Credential $credential)
27
    {
28
        $this->setTokens([
29
            'psessionid' => $credential->getPSessionId(),
30
            'vfwebqq' => $credential->getVfWebQQ(),
31
        ]);
32
    }
33
34
    /**
35
     * 解析响应数据.
36
     *
37
     * @param Response $response
38
     *
39
     * @return EntityCollection
40
     */
41
    public static function parseResponse(Response $response)
42
    {
43
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
44
        if ($jsonData && 0 == $jsonData['retcode']) {
45
            $discusses = [];
46
            foreach ($jsonData['result']['dnamelist'] as $discussData) {
47
                $discusses[] = EntityFactory::createEntity(Discuss::class, [
48
                     'id' => $discussData['did'],
49
                     'name' => $discussData['name'],
50
                ]);
51
            }
52
53
            return new EntityCollection($discusses);
54
        }
55
        throw new ResponseException($jsonData['retcode'], $response);
56
    }
57
}
58