Completed
Push — master ( c5510a...18ad07 )
by Byron
02:02
created

Expand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 50
ccs 13
cts 13
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getRequestMethod() 0 4 1
A getRequestOptions() 0 6 1
A processResponse() 0 5 1
1
<?php
2
/**
3
 * This file is part of the badams\GoogleUrl library
4
 *
5
 * @license http://opensource.org/licenses/MIT
6
 * @link https://github.com/badams/google-url
7
 * @package badams/google-url
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace badams\GoogleUrl\Actions;
14
15
use badams\GoogleUrl\Exceptions\GoogleUrlException;
16
use badams\GoogleUrl\UrlResource;
17
use badams\GoogleUrl\ActionInterface;
18
use GuzzleHttp\Message\ResponseInterface;
19
20
/**
21
 * Class Shorten
22
 * @package badams\GoogleUrl\Actions
23
 * @link https://developers.google.com/url-shortener/v1/url/insert
24
 */
25
class Expand implements ActionInterface
26
{
27
    /**
28
     * @var string
29
     */
30
    protected $shortUrl;
31
32
    /**
33
     * Shorten constructor.
34
     * @param $shortUrl
35
     * @throws GoogleUrlException
36
     * @internal param $longUrl
37
     */
38 6
    public function __construct($shortUrl)
39
    {
40 6
        if (empty($shortUrl)) {
41 3
            throw new GoogleUrlException('No URL provided');
42
        }
43
44 3
        $this->shortUrl = $shortUrl;
45 3
    }
46
47
    /**
48
     * @return string
49
     */
50 3
    public function getRequestMethod()
51
    {
52 3
        return 'GET';
53
    }
54
55
    /**
56
     * @return array
57
     */
58 3
    public function getRequestOptions()
59
    {
60
        return [
61 3
            'query' => ['shortUrl' => $this->shortUrl]
62 3
        ];
63
    }
64
65
    /**
66
     * @param ResponseInterface $response
67
     * @return UrlResource
68
     */
69 3
    public function processResponse(ResponseInterface $response)
70
    {
71 3
        $obj = json_decode($response->getBody()->getContents());
72 3
        return UrlResource::createFromJson($obj);
73
    }
74
}
75