Rotator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 55.17 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 16
loc 29
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
handle() 0 1 ?
A shorten() 16 16 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}