Completed
Push — master ( 26ee5a...f9c4ed )
by Tomasz
03:08 queued 16s
created

FixedConfig::getMachine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 4
Bugs 0 Features 3
Metric Value
c 4
b 0
f 3
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Fixed configuration.
4
 * 
5
 * This is designed to be used where each machine **knows** what its machine
6
 * ID is - eg: via some kind of automatically deployed configuration
7
 * (puppet etc.)
8
 * 
9
 * @author @davegardnerisme
10
 */
11
12
namespace Gendoria\CruftFlake\Config;
13
14
use Psr\Log\LoggerAwareInterface;
15
use Psr\Log\LoggerInterface;
16
use Psr\Log\NullLogger;
17
18
class FixedConfig implements ConfigInterface, LoggerAwareInterface
19
{
20
    /**
21
     * Machine ID.
22
     * 
23
     * @var int
24
     */
25
    private $machineId;
26
27
    /**
28
     * Logger.
29
     * 
30
     * @var LoggerInterface
31
     */
32
    private $logger;
33
34
    /**
35
     * Constructor.
36
     * 
37
     * @param int             $machineId Fixed machine ID.
38
     * @param LoggerInterface $logger    Logger class
39
     */
40 4
    public function __construct($machineId, LoggerInterface $logger = null)
41
    {
42 4
        $this->machineId = (int) $machineId;
43 4
        if ($logger) {
44 1
            $this->logger = $logger;
45 1
        } else {
46 3
            $this->logger = new NullLogger();
47
        }
48 4
    }
49
50
    /**
51
     * Get machine identifier.
52
     * 
53
     * @return int Should be a 10-bit int (decimal 0 to 1023)
54
     */
55 4
    public function getMachine()
56
    {
57 4
        $this->logger->debug('Obtained machine ID '.$this->machineId.' through fixed configuration.');
58
59 4
        return $this->machineId;
60
    }
61
62
    /**
63
     * Set logger.
64
     * 
65
     * @param LoggerInterface $logger
66
     */
67 1
    public function setLogger(LoggerInterface $logger)
68
    {
69 1
        $this->logger = $logger;
70 1
    }
71
}
72