Test Failed
Pull Request — master (#3)
by
unknown
17:36
created

Calendar   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 51
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 3
A __call() 0 8 2
1
<?php
2
3
namespace Timegridio\Concierge\Calendar;
4
5
use Illuminate\Database\Eloquent\Relations\HasMany;
6
use Timegridio\Concierge\Exceptions\StrategyMethodNotRecognizedException;
7
use Timegridio\Concierge\Exceptions\StrategyNotRecognizedException;
8
9
class Calendar
10
{
11
    /**
12
     * Strategy Calendar.
13
     *
14
     * @var TimeslotCalendar|DateslotCalendar
15
     */
16
    protected $strategy = null;
17
18
    /**
19
     * Construct the class and load the strategy Calendar.
20
     *
21
     * @param string $strategyName
22
     * @param HasMany $vacancies    The entity relationship to Vacancies.
23
     * @param string $timezone
24
     *
25
     * @throws Timegridio\Concierge\Exceptions\StrategyNotRecognizedException
26
     */
27 18
    public function __construct($strategyName, HasMany $vacancies, $timezone = null)
28
    {
29 18
        switch (strtolower($strategyName)) {
30
            case 'timeslot':
31 9
                $this->strategy = new TimeslotCalendar($vacancies, $timezone);
32 9
                break;
33
            case 'dateslot':
34 8
                $this->strategy = new DateslotCalendar($vacancies, $timezone);
35 8
                break;
36
            default:
37 1
                throw new StrategyNotRecognizedException();
38
        }
39 17
    }
40
41
    /**
42
     * Pass method call to the Calendar strategy.
43
     *
44
     * @param  string $name
45
     * @param  mixed $arguments
46
     *
47
     * @throws Timegridio\Concierge\Exceptions\StrategyMethodNotRecognizedException
48
     *
49
     * @return mixed
50
     */
51 17
    public function __call($name, $arguments)
52
    {
53 17
        if (!method_exists($this->strategy, $name)) {
54 1
            throw new StrategyMethodNotRecognizedException();
55
        }
56
57 16
        return $this->strategy->$name($arguments);
58
    }
59
}
60