Gateway::curl()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 2
crap 2
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