Completed
Push — master ( b942fe...23de65 )
by Ariel
08:58
created

VacancyManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Timegridio\Concierge\Vacancy;
4
5
use Carbon\Carbon;
6
use Timegridio\Concierge\Models\Business;
7
use Timegridio\Concierge\Models\Vacancy;
8
9
class VacancyManager
10
{
11
    protected $business;
12
13 1
    public function __construct(Business $business)
14
    {
15 1
        $this->business = $business;
16 1
    }
17
18
    /**
19
     * Get a Vacancy for a given DateTime and Service combination.
20
     *
21
     * @param Carbon  $targetDateTime
22
     * @param int $serviceId
23
     *
24
     * @return Timegridio\Concierge\Models\Vacancy
25
     */
26
//    public function getSlotFor(Carbon $targetDateTime, $serviceId)
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
27
//    {
28
//        return $this->business
29
//            ->vacancies()
30
//            ->forDateTime($targetDateTime)
31
//            ->forService($serviceId)
32
//            ->first();
33
//    }
34
35 1
    public function publish($date, Carbon $startAt, Carbon $finishAt, $serviceId, $capacity = 1)
36
    {
37
        $vacancyKeys = [
38 1
            'business_id' => $this->business->id,
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Timegridio\Concierge\Models\Business>. 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...
39 1
            'service_id'  => $serviceId,
40 1
            'date'        => $date,
41 1
            ];
42
        $vacancyValues = [
43 1
            'capacity'    => intval($capacity),
44 1
            'start_at'    => $startAt->timezone('UTC')->toDateTimeString(),
45 1
            'finish_at'   => $finishAt->timezone('UTC')->toDateTimeString(),
46 1
            ];
47
48 1
        return Vacancy::updateOrCreate($vacancyKeys, $vacancyValues);
49
    }
50
51
52
    /**
53
     * [generateAvailability description].
54
     *
55
     * @param Illuminate\Database\Eloquent\Collection $vacancies
56
     * @param string                                  $startDate
57
     * @param int                                     $futureDays
58
     *
59
     * @return array
60
     */
61
    public static function generateAvailability($vacancies, $startDate = 'today', $futureDays = 10)
62
    {
63
        $dates = [];
64 View Code Duplication
        for ($i = 0; $i < $futureDays; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
            $dates[date('Y-m-d', strtotime("$startDate +$i days"))] = [];
66
        }
67
68
        foreach ($vacancies as $vacancy) {
69
            if (array_key_exists($vacancy->date, $dates)) {
70
                $dates[$vacancy->date][$vacancy->service->slug] = $vacancy;
71
            }
72
        }
73
74
        return $dates;
75
    }
76
77
}
78