Passed
Push — master ( 2cd332...0af4da )
by Ross
02:35
created

CurlResource::curlError()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
/**
3
 *
4
 * Copyright (C) 2018  Ross Mitchell
5
 *
6
 * This file is part of RossMitchell/UpdateCloudFlare.
7
 *
8
 * RossMitchell/UpdateCloudFlare is free software: you can redistribute
9
 * it and/or modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
namespace RossMitchell\UpdateCloudFlare\Tests\Fakes;
23
24
use RossMitchell\UpdateCloudFlare\Interfaces\CurlResourceInterface;
25
26
/**
27
 * Class CurlResource - Used to allow testing of the main curl class
28
 * @package RossMitchell\UpdateCloudFlare\Tests\Fakes
29
 */
30
class CurlResource implements CurlResourceInterface
31
{
32
    /**
33
     * @var string
34
     */
35
    private $error;
36
    /**
37
     * @var array
38
     */
39
    private $options = [];
40
41
    /**
42
     * Used To initialise the curl resource
43
     *
44
     * @return bool
45
     */
46
    public function curlInit()
47
    {
48
        return true;
0 ignored issues
show
Bug Best Practice introduced by
The expression return true returns the type true which is incompatible with the return type mandated by RossMitchell\UpdateCloud...ceInterface::curlInit() of resource.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
49
    }
50
51
    /**
52
     * Used to set a curl option
53
     *
54
     * @param resource $curl
55
     * @param int      $option
56
     * @param mixed    $value
57
     *
58
     * @return void
59
     */
60
    public function setOption($curl, int $option, $value): void
61
    {
62
        $this->options[$option] = $value;
63
    }
64
65
    public function getOption($option)
66
    {
67
        if (!isset($this->options[$option])) {
68
            throw new \LogicException("${option} has not been set");
69
        }
70
71
        return $this->options[$option];
72
    }
73
74
    /**
75
     * Used to make the curl request
76
     *
77
     * @param $curl
78
     *
79
     * @return mixed
80
     */
81
    public function curlExec($curl)
82
    {
83
        return 'worked';
84
    }
85
86
    /**
87
     * Used to check if there has been an error with the request
88
     *
89
     * @param $curl
90
     *
91
     * @return mixed
92
     */
93
    public function curlError($curl)
94
    {
95
        if ($this->error !== null) {
96
            return $this->error;
97
        }
98
99
        return false;
100
    }
101
102
    /**
103
     * Used to close the connection
104
     *
105
     * @param $curl
106
     *
107
     * @return void
108
     */
109
    public function curlClose($curl): void
110
    {
111
112
    }
113
114
    public function setError(string $error)
115
    {
116
        $this->error = $error;
117
    }
118
}
119