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

Calendar::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.072

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 8
cts 10
cp 0.8
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 3.072
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