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

Flaps   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 76.92%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 50
ccs 10
cts 13
cp 0.7692
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setDefaultViolationHandler() 0 4 1
A __get() 0 4 1
A getFlap() 0 8 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