Completed
Push — master ( ef29db...6cb927 )
by Ariel
06:10
created

VacancyCalendar::forDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Timegridio\Concierge\Calendar;
4
5
use Carbon\Carbon;
6
7
abstract class VacancyCalendar
8
{
9
    protected $vacancies = [];
10
11
    protected $service = null;
12
13
    protected $duration = null;
14
15
    protected $date = null;
16
17
    protected $time = null;
18
19
    protected $timezone = 'UTC';
20
21
    public function __construct($vacancies, $timezone = 'UTC')
22
    {
23
        $this->vacancies = $vacancies;
24
25
        $this->timezone = $timezone;
26
    }
27
28
    public function timezone($timezone = null)
29
    {
30
        if ($timezone === null) {
31
            return $this->timezone;
32
        }
33
34
        return $this;
35
    }
36
37
    public function forService($service = null)
38
    {
39
        $this->service = $service;
40
41
        return $this;
42
    }
43
44
    public function forDate($date)
45
    {
46
        $this->date = $date;
47
48
        return $this;
49
    }
50
51
    public function atTime($time, $timezone = null)
52
    {
53
        $this->time = $time;
54
55
        if ($timezone !== null) {
56
            $this->timezone = $timezone;
57
        }
58
59
        return $this;
60
    }
61
62
    public function withDuration($duration)
63
    {
64
        $this->duration = $duration;
65
66
        return $this;
67
    }
68
69
    public function getUTCDateTime()
70
    {
71
        return Carbon::parse("{$this->date} {$this->time} {$this->timezone}")->timezone('UTC');
72
    }
73
74
    final protected function date()
75
    {
76
        return Carbon::parse($this->date);
77
    }
78
79
//    protected function find()
0 ignored issues
show
Unused Code Comprehensibility introduced by
51% 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...
80
//    {
81
//        $this->prepare();
82
//
83
//        $results = $this->vacancies->get();
84
//
85
//        $fromDatetime = $this->getUTCDateTime();
86
//
87
//        if ($this->duration !== null) {
88
//            $toDatetime = $fromDatetime->addMinutes($this->duration);
89
//
90
//            $results = $results->reject(function ($vacancy) use ($fromDatetime, $toDatetime) {
91
//                return !$vacancy->hasRoomBetween($fromDatetime, $toDatetime);
92
//            });
93
//        }
94
//
95
//        return $results;
96
//    }
97
//
98
//    protected function prepare()
99
//    {
100
//        if ($this->service !== null) {
101
//            $this->vacancies->forService($this->service);
102
//        }
103
//
104
//        if ($this->date !== null &&  $this->time !== null) {
105
//            $this->vacancies->forDateTime($this->getUTCDateTime());
106
//        }
107
//
108
//        return $this;
109
//    }
110
}
111