Completed
Push — master ( 566e3d...cbf465 )
by Ariel
06:35
created

TimetableTimeslotStrategy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 3
dl 0
loc 58
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A initTimetable() 0 9 1
A buildTimetable() 0 10 2
A updateTimeslots() 0 18 2
1
<?php
2
3
namespace Timegridio\Concierge\Timetable\Strategies;
4
5
use Timegridio\Concierge\Models\Business;
6
use Timegridio\Concierge\Models\Service;
7
use Timegridio\Concierge\Models\Vacancy;
8
use Timegridio\Concierge\Timetable\Timetable;
9
10
class TimetableTimeslotStrategy extends BaseTimetableStrategy implements TimetableStrategyInterface
11
{
12
    private $interval = 30;
13
14
    public function __construct(Timetable $timetable)
15
    {
16
        $this->timetable = $timetable;
17
    }
18
19
    protected function initTimetable($starting, $days)
20
    {
21
        $this->timetable
22
             ->interval($this->interval)
23
             ->format('date.service.time')
24
             ->from($starting)
25
             ->future($days)
26
             ->init();
27
    }
28
29
    /**
30
     * Build timetable.
31
     *
32
     * @param \Illuminate\Database\Eloquent\Collection $vacancies
33
     * @param string                                  $starting
34
     * @param int                                     $days
35
     *
36
     * @return array
37
     */
38
    public function buildTimetable($vacancies, $starting = 'today', $days = 1)
39
    {
40
        $this->initTimetable($starting, $days);
41
42
        foreach ($vacancies as $vacancy) {
43
            $this->updateTimeslots($vacancy, $this->interval);
44
        }
45
46
        return $this->timetable->get();
47
    }
48
49
    protected function updateTimeslots(Vacancy $vacancy, $step = 30)
50
    {
51
        $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...
52
        $toTime = $fromTime->copy();
53
        $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...
54
55
        while ($fromTime <= $limit) {
56
            $toTime->addMinutes($step);
57
58
            $capacity = $vacancy->getAvailableCapacityBetween($fromTime->timezone('UTC'), $toTime->timezone('UTC'));
59
60
            $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...
61
62
            $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...
63
64
            $fromTime->addMinutes($step);
65
        }
66
    }
67
}
68