Google   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 26
loc 26
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 16 16 3
A shorten() 3 3 1

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\Drivers;
4
5
use LeadThread\GoogleShortener\Google as GoogleDriver;
6
use LeadThread\Shortener\Interfaces\UrlShortener;
7
use LeadThread\Shortener\Rotators\Account\Google as GoogleRotator;
8
9 View Code Duplication
class Google implements UrlShortener
0 ignored issues
show
Duplication introduced by
This class 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...
10
{
11
    protected $config;
12
    protected $rotator;
13
14 24
    public function __construct(GoogleRotator $rotator = null)
15
    {
16 24
        $this->config = config('shortener.accounts.google');
17
18 24
        if(!$rotator instanceof GoogleRotator){
19 6
            $drivers = [];
20
21 6
            foreach ($this->config as $c) {
22 6
                $drivers[] = new GoogleDriver($c['token']);
23 6
            }
24
25 6
            $rotator = new GoogleRotator($drivers);
26 6
        }
27
        
28 24
        $this->rotator = $rotator;
29 24
    }
30
31 18
    public function shorten($url, $encode = true){
32 18
        return $this->rotator->shorten($url, $encode);
33
    }
34
}