Completed
Branch master (757f21)
by Benedict
03:02 queued 01:09
created

Flaps::getFlap()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
namespace BehEh\Flaps;
3
4
/**
5
 * Acts as a factory for BehEh\Flaps\Flap instances.
6
 * 
7
 * @since 0.1
8
 * @author Benedict Etzel <[email protected]>
9
 */
10
class Flaps
11
{
12
    /**
13
     * @var StorageInterface
14
     */
15
    protected $adapter;
16
17
    public function __construct(StorageInterface $adapter)
18
    {
19
        $this->adapter = $adapter;
20
    }
21
    /**
22
     * @var ViolationHandlerInterface
23
     */
24
    protected $defaultViolationHandler = null;
25
26
    /**
27
     * Sets a default violation handler for flaps created in the future.
28
     * @param \BehEh\Flaps\ViolationHandlerInterface $violationHandler
29
     */
30 1
    public function setDefaultViolationHandler(ViolationHandlerInterface $violationHandler)
31
    {
32 1
        $this->defaultViolationHandler = $violationHandler;
33 1
    }
34
35
    /**
36
     * Creates a new Flap and returns it, setting default violation handler.,
37
     * @param string $name the name of the flap
38
     * @return \BehEh\Flaps\Flap the created flap
39
     */
40 1
    public function getFlap($name)
41
    {
42 1
        $flap = new Flap($this->adapter, $name);
43 1
        if ($this->defaultViolationHandler !== null) {
44 1
            $flap->setViolationHandler($this->defaultViolationHandler);
45
        }
46 1
        return $flap;
47
    }
48
49
    /**
50
     * Creates a new Flap and returns it, setting default violation handler.,
51
     * @param string $name the name of the flap
52
     * @return \BehEh\Flaps\Flap
53
     * @see BehEh\Flaps\Flaps::getFlap
54
     */
55 1
    public function __get($name)
56
    {
57 1
        return $this->getFlap($name);
58
    }
59
}
60