Wrapper::getShortLink()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 7
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 10
ccs 7
cts 7
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: aless
5
 * Date: 14/03/2019
6
 * Time: 10:24
7
 */
8
9
namespace Bitlywrap\Wrapper;
10
11
use Bitlywrap\Adapter\Adapter;
12
use Bitlywrap\Interfaces\WrapperInterface;
13
14
class Wrapper implements WrapperInterface
15
{
16
    /**
17
     * @var \BitlyWrap\Adapter\Adapter
18
     */
19
    private $adapter;
20
21
    /**
22
     * Wrapper constructor.
23
     * @param Adapter $adapter
24
     */
25 2
    public function __construct(Adapter $adapter)
26
    {
27 2
        $this->setAdapter($adapter);
28 2
    }
29
30
    /**
31
     * @param string $long_url
32
     * @return string
33
     */
34 1
    public function getShortLink($long_url)
35
    {
36 1
        $adapter = $this->getAdapter();
37
        $data = [
38 1
            'long_url' => $long_url
39
        ];
40 1
        $response = $adapter->post('shorten', $data);
41 1
        $content = $response->getBody()->getContents();
42 1
        $array = json_decode($content, 1);
43 1
        return $array['link'];
44
    }
45
46
    /**
47
     * @return Adapter
48
     */
49 1
    private function getAdapter()
50
    {
51 1
        return $this->adapter;
52
    }
53
54
    /**
55
     * @param Adapter $adapter
56
     */
57 2
    private function setAdapter(Adapter $adapter)
58
    {
59 2
        $this->adapter = $adapter;
60 2
    }
61
}
62