Rotator::shorten()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 16
Code Lines 9

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 16
loc 16
ccs 10
cts 10
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 6
nop 2
crap 4
1
<?php
2
3
namespace LeadThread\Shortener\Rotators\Account;
4
5
use LeadThread\Shortener\Interfaces\UrlShortener;
6
use LeadThread\Shortener\Exceptions\ShortenerException;
7
8
abstract class Rotator implements UrlShortener
9
{
10
    protected $drivers;
11
    protected $error = "Could not shorten url!";
12
13 27
    public function __construct(array $drivers)
14
    {
15 27
        $this->drivers = $drivers;
16 27
    }
17
18
    abstract protected function handle($driver, $url, $encode);
19
20 21 View Code Duplication
    public function shorten($url, $encode = true)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22 21
        $short = false;
23
24 21
        foreach ($this->drivers as $driver) {
25 21
            if(!is_string($short)){
26 21
                $short = $this->handle($driver, $url, $encode);
27 21
            }
28 21
        }
29
30 21
        if(is_string($short)){
31 15
            return $short;
32
        } else {
33 9
            throw new ShortenerException($this->error);
34
        }
35
    }
36
}