Completed
Push — master ( 3cd0a8...94a3ce )
by Ariel
06:26
created

BookingTimeslotStrategy::generateAppointment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 23
rs 9.0856
c 1
b 0
f 0
cc 1
eloc 19
nc 1
nop 6
1
<?php
2
3
namespace Timegridio\Concierge\Booking\Strategies;
4
5
use Carbon\Carbon;
6
use Illuminate\Support\Collection;
7
use Timegridio\Concierge\Booking\Timetable;
8
use Timegridio\Concierge\Models\Appointment;
9
use Timegridio\Concierge\Models\Business;
10
use Timegridio\Concierge\Models\Contact;
11
use Timegridio\Concierge\Models\Service;
12
use Timegridio\Concierge\Models\Vacancy;
13
14
class BookingTimeslotStrategy implements BookingStrategyInterface
15
{
16
    private $timetable;
17
18
    private $interval = 30;
19
20
    public function __construct(Timetable $timetable)
21
    {
22
        $this->timetable = $timetable;
23
    }
24
25
    /**
26
     * Build timetable.
27
     *
28
     * @param Illuminate\Database\Eloquent\Collection $vacancies
29
     * @param string                                  $starting
30
     * @param int                                     $days
31
     *
32
     * @return array
33
     */
34
    public function buildTimetable($vacancies, $starting = 'today', $days = 1)
35
    {
36
        $this->timetable
37
             ->interval($this->interval)
38
             ->format('date.service.time')
39
             ->from($starting)
40
             ->future($days)
41
             ->init();
42
43
        foreach ($vacancies as $vacancy) {
44
            $this->updateTimeslots($vacancy, $this->interval);
45
        }
46
47
        return $this->timetable->get();
48
    }
49
50
    protected function updateTimeslots(Vacancy $vacancy, $step = 30)
51
    {
52
        $fromTime = $vacancy->start_at;
0 ignored issues
show
Documentation introduced by
The property start_at does not exist on object<Timegridio\Concierge\Models\Vacancy>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
53
        $toTime = $fromTime->copy();
54
        $limit = $vacancy->finish_at;
0 ignored issues
show
Documentation introduced by
The property finish_at does not exist on object<Timegridio\Concierge\Models\Vacancy>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
55
56
        while ($fromTime <= $limit) {
57
            $toTime->addMinutes($step);
58
59
            $capacity = $vacancy->getAvailableCapacityBetween($fromTime->timezone('UTC'), $toTime->timezone('UTC'));
60
61
            $time = $fromTime->timezone($vacancy->business->timezone)->format('H:i:s');
0 ignored issues
show
Documentation introduced by
The property business does not exist on object<Timegridio\Concierge\Models\Vacancy>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
62
63
            $this->timetable->capacity($vacancy->date, $time, $vacancy->service->slug, $capacity);
0 ignored issues
show
Documentation introduced by
The property date does not exist on object<Timegridio\Concierge\Models\Vacancy>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property service does not exist on object<Timegridio\Concierge\Models\Vacancy>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
64
65
            $fromTime->addMinutes($step);
66
        }
67
    }
68
}
69