Gateway   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 25 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 12
loc 48
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A curl() 0 13 2
A testExists() 12 12 3

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 Simplario\Checker\Checker;
4
5
use Simplario\Checker\ResultException\FailException;
6
use Simplario\Checker\ResultException\SuccessException;
7
8
/**
9
 * Class Gateway
10
 *
11
 * @package Simplario\Checker\Checker
12
 */
13 2
class Gateway extends AbstractChecker
14
{
15 2
    /**
16 2
     * @var string
17 2
     */
18 2
    protected $target = 'url';
19 2
20
    /**
21
     * @param string $target
22 2
     * @param array  $options
23
     *
24 2
     * @return boolean
25
     */
26
    protected function curl($target, array $options = [])
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
27 2
    {
28
        $success = true;
29 2
        $ch = curl_init();
30
        curl_setopt($ch, CURLOPT_URL, $target);
31 2
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
32 1
        if (!curl_exec($ch)) {
33
            $success = false;
34
        }
35 1
        curl_close($ch);
36
37 1
        return $success;
38
    }
39
40
    /**
41
     * @param string  $target
42
     * @param boolean $expectExists
43
     * @param array   $task
44
     *
45
     * @throws FailException
46
     * @throws SuccessException
47
     */
48 View Code Duplication
    protected function testExists($target, $expectExists, array $task)
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...
49
    {
50
        $success = $this->curl($target, []);
51
52
        if ($success === $expectExists) {
53
            throw new SuccessException('Ok', $task);
54
        }
55
56
        $msg = $expectExists ? "Target '{$target}' is not available'" : "Target '{$target}' is available";
57
58
        throw new FailException($msg, $task);
59
    }
60
}
61