Wrapper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 12
c 1
b 0
f 1
dl 0
loc 46
ccs 14
cts 14
cp 1
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setAdapter() 0 3 1
A getAdapter() 0 3 1
A getShortLink() 0 10 1
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