Completed
Push — master ( c91fb3...77e88f )
by Ariel
05:48
created

Concierge   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 11
c 3
b 0
f 0
lcom 1
cbo 3
dl 0
loc 74
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A business() 0 6 1
A strategy() 0 8 2
A vacancyManager() 0 11 2
B takeReservation() 0 27 4
A makeDateTimeUTC() 0 9 2
1
<?php
2
3
namespace Timegridio\Concierge;
4
5
use Carbon\Carbon;
6
use Timegridio\Concierge\Booking\Strategies\BookingStrategy;
7
use Timegridio\Concierge\Models\Business;
8
use Timegridio\Concierge\Models\Service;
9
use Timegridio\Concierge\VacancyManager;
10
11
/*******************************************************************************
12
 * Concierge Service Layer
13
 *     High level booking manager
14
 ******************************************************************************/
15
class Concierge
16
{
17
    protected $business = null;
18
19
    protected $strategy = null;
20
21
    protected $vacancyManager = null;
22
23
    public function business($business)
24
    {
25
        $this->business = $business;
26
27
        return $this;
28
    }
29
30
    protected function strategy()
31
    {
32
        if ($this->strategy === null) {
33
            $this->strategy = new BookingStrategy($this->business->strategy);
34
        }
35
36
        return $this->strategy;
37
    }
38
39
    protected function vacancyManager()
40
    {
41
        if($this->vacancyManager === null)
42
        {
43
            $this->vacancyManager = new VacancyManager();
44
        }
45
46
        $this->vacancyManager->setBusiness($this->business);
47
48
        return $this->vacancyManager;
49
    }
50
51
    public function takeReservation($request)
52
    {
53
        $datetime = $this->makeDateTimeUTC($request['date'], $request['time'], $request['timezone']);
54
55
        $appointment = $this->strategy()->generateAppointment(
56
            $request['issuer'],
57
            $this->business,
58
            $request['contact'],
59
            $request['service'],
60
            $datetime,
61
            $request['comments']
62
        );
63
64
        if ($appointment->duplicates()) {
65
            return $appointment;
66
            // throw new \Exception('Duplicated Appointment Attempted');
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
67
        }
68
69
        $vacancy = $this->vacancyManager()->getSlotFor($appointment->start_at, $appointment->service->id);
70
71
        if ($vacancy != null && $this->strategy()->hasRoom($appointment, $vacancy)) {
72
            $appointment->vacancy()->associate($vacancy);
73
            $appointment->save();
74
            return $appointment;
75
        }
76
        return false;
77
    }
78
79
    protected function makeDateTimeUTC($date, $time, $timezone = null)
80
    {
81
        if($timezone === null)
82
        {
83
            $timezone = $this->business->timezone;
84
        }
85
86
        return Carbon::parse("{$date} {$time} {$timezone}")->timezone('UTC');
87
    }
88
}
89