Passed
Push — master ( fb9395...699f58 )
by Bobby
09:02
created

VfsAdapter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 8
c 2
b 0
f 1
dl 0
loc 48
ccs 9
cts 9
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setDirection() 0 3 1
A write() 0 4 1
A read() 0 6 2
1
<?php
2
namespace Ballen\GPIO\Adapters;
3
4
use Ballen\GPIO\Interfaces\AdapterInterface;
5
6
/**
7
 * GPIO
8
 * A RaspberryPi GPIO library written in PHP.
9
 *
10
 * @author Bobby Allen <[email protected]>
11
 * @license http://www.gnu.org/licenses/gpl-3.0.html
12
 * @link https://github.com/allebb/gpio
13
 * @link http://www.bobbyallen.me
14
 * @package Ballen\GPIO\Adapters
15
 */
16
class VfsAdapter implements AdapterInterface
17
{
18
19
    /**
20
     * In-memory GPIO state storage.
21
     *
22
     * @var array
23
     */
24
    public $storage = [];
25
26
    /**
27
     * Set the direction of the pin (input or output)
28
     *
29
     * @param int $pin The BCM pin number
30
     * @param string $direction The type/direction of the pin - Use GPIO::IN and GPIO::OUT
31
     * @param bool $invert Invert the logic so that high->low and low->high
32
     * @return bool
33
     */
34 14
    public function setDirection(int $pin, string $direction, bool $invert = false): bool
35
    {
36 14
        return true;
37
    }
38
39
    /**
40
     * Write a value to an output pin.
41
     *
42
     * @param int $pin The BCM pin number.
43
     * @param int $value The output value (0,1) - Use GPIO::HIGH and GPIO::LOW
44
     * @return bool
45
     */
46 4
    public function write(int $pin, int $value): bool
47
    {
48 4
        $this->storage[$pin] = $value;
49 4
        return true;
50
    }
51
52
    /**
53
     * Read the value of an input/output pin.
54
     *
55
     * @param int $pin The BCM pin number
56
     * @return int The current value of the pin.
57
     */
58 6
    public function read(int $pin): int
59
    {
60 6
        if (!isset($this->storage[$pin])) {
61 2
            return 0;
62
        }
63 4
        return $this->storage[$pin];
64
    }
65
}