Completed
Push — master ( 6ea7ff...8c9744 )
by Ariel
11:07
created

Vacancy::humanresource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Timegridio\Concierge\Models;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Model as EloquentModel;
7
8
/**
9
 * @property Timegridio\Concierge\Models\Business $business
10
 * @property string $date Local timezone date of the published Vacancy
11
 */
12
class Vacancy extends EloquentModel
13
{
14
    /**
15
     * The attributes that are mass assignable.
16
     *
17
     * @var array
18
     */
19
    protected $fillable = [
20
        'business_id',
21
        'service_id',
22
        'humanresource_id',
23
        'date',
24
        'start_at',
25
        'finish_at',
26
        'capacity',
27
    ];
28
29
    /**
30
     * The attributes that aren't mass assignable.
31
     *
32
     * @var array
33
     */
34
    protected $guarded = ['id'];
35
36
    /**
37
     * The attributes that should be mutated to dates.
38
     *
39
     * @var array
40
     */
41
    protected $dates = ['start_at', 'finish_at'];
42
43
    ///////////////////
44
    // Relationships //
45
    ///////////////////
46
47
    /**
48
     * belongs to Business.
49
     *
50
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo Relationship Vacancy belongs to Business query
51
     */
52 16
    public function business()
53
    {
54 16
        return $this->belongsTo(Business::class);
55
    }
56
57
    /**
58
     * for Service.
59
     *
60
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo Relationship Vacancy is for providing Service query
61
     */
62 16
    public function service()
63
    {
64 16
        return $this->belongsTo(Service::class);
65
    }
66
67
    /**
68
     * Humanresource.
69
     *
70
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
71
     */
72 18
    public function humanresource()
73
    {
74 18
        return $this->belongsTo(Humanresource::class);
75
    }
76
77
    /**
78
     * holds many Appointments.
79
     *
80
     * @return \Illuminate\Database\Eloquent\Relations\HasMany Relationship Vacancy belongs to Business query
81
     */
82 10
    public function appointments()
83
    {
84 10
        return $this->hasMany(Appointment::class);
85
    }
86
87
    ////////////
88
    // Scopes //
89
    ////////////
90
91
    /**
92
     * Scope For Date.
93
     *
94
     * @param Illuminate\Database\Query $query
95
     * @param Carbon                    $date  Date of inquiry
96
     *
97
     * @return Illuminate\Database\Query Scoped query
98
     */
99 6
    public function scopeForDate($query, Carbon $date)
100
    {
101 6
        return $query->where('date', '=', $date->toDateString());
102
    }
103
104
    /**
105
     * Scope For DateTime.
106
     *
107
     * @param Illuminate\Database\Query $query
108
     * @param Carbon                    $datetime Date and Time of inquiry
109
     *
110
     * @return Illuminate\Database\Query Scoped query
111
     */
112 6
    public function scopeForDateTime($query, Carbon $datetime)
113
    {
114 6
        return $query->where('start_at', '<=', $datetime->toDateTimeString())
115 6
                        ->where('finish_at', '>=', $datetime->toDateTimeString());
116
    }
117
118
    /**
119
     * Scope only Future.
120
     *
121
     * @param Illuminate\Database\Query $query
122
     *
123
     * @return Illuminate\Database\Query Scoped query
124
     */
125 1
    public function scopeFuture($query)
126
    {
127 1
        return $query->where('date', '>', Carbon::now());
128
    }
129
130
    /**
131
     * Scope For Service.
132
     *
133
     * @param Illuminate\Database\Query $query
134
     * @param int serviceId  $service Inquired Service to filter
135
     *
136
     * @return Illuminate\Database\Query Scoped query
137
     */
138 14
    public function scopeForService($query, $serviceId)
139
    {
140 14
        return $query->where('service_id', '=', $serviceId);
141
    }
142
143
    /////////////////////
144
    // Soft Attributes //
145
    /////////////////////
146
147
    /**
148
     * is Holding Any Appointment for given User.
149
     *
150
     * ToDo: Remove from here as needs knowledge from User
151
     *
152
     * @param int $userId User to check belonging Appointments
153
     *
154
     * @return bool Vacancy holds at least one Appointment of User
155
     */
156 2
    public function isHoldingAnyFor($userId)
157
    {
158 2
        $appointments = $this->appointments()->get();
159
160 2
        foreach ($appointments as $appointment) {
161 2
            $contact = $appointment->contact()->first();
162 2
            if ($contact->isProfileOf($userId)) {
163 1
                return true;
164
            }
165 1
        }
166
167 1
        return false;
168
    }
169
170
    /**
171
     * is Full.
172
     *
173
     * @return bool Vacancy is fully booked
174
     */
175
#    public function isFull()
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% 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...
176
#    {
177
#        return $this->getFreeSlotsCount() <= 0;
178
#    }
179
180
    /**
181
     * get free slots count.
182
     *
183
     * @return int Count Capacity minus Used
184
     */
185
#    public function getFreeSlotsCount()
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% 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...
186
#    {
187
#        $count = $this->appointments()->active()->count();
188
#
189
#        return $this->capacity - $count;
190
#    }
191
192
    /**
193
     * get capacity.
194
     *
195
     * @return int Capacity of the vacancy (in appointment instances)
196
     */
197 17
    public function getCapacityAttribute()
198
    {
199 17
        if ($this->humanresource) {
0 ignored issues
show
Documentation introduced by
The property humanresource 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...
200
            return intval($this->humanresource->capacity);
0 ignored issues
show
Documentation introduced by
The property humanresource 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...
201
        }
202
203 17
        return intval($this->attributes['capacity']);
204
    }
205
206
    /**
207
     * has Room.
208
     *
209
     * @return bool There is more capacity than used
210
     */
211 4
    public function hasRoom()
212
    {
213 4
        return $this->capacity > $this->appointments()->active()->count();
0 ignored issues
show
Documentation introduced by
The property capacity 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...
214
    }
215
216
    /**
217
     * has Room between time.
218
     *
219
     * @return bool There is more capacity than used
220
     */
221 4
    public function hasRoomBetween(Carbon $startAt, Carbon $finishAt)
222
    {
223 4
        return $this->capacity > $this->business
0 ignored issues
show
Documentation introduced by
The property capacity 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...
224 4
                                      ->bookings()
225 4
                                      ->active()
226 4
                                      ->affectingInterval($startAt, $finishAt)
227 4
                                      ->affectingHumanresource($this->humanresource_id)
0 ignored issues
show
Documentation introduced by
The property humanresource_id 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...
228 4
                                      ->count() &&
229 4
            ($this->start_at <= $startAt && $this->finish_at >= $finishAt);
0 ignored issues
show
Documentation introduced by
The property start_at 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 finish_at 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...
230
    }
231
232
    /**
233
     * Get available capacity between time.
234
     *
235
     * @return int Available capacity
236
     */
237 8
    public function getAvailableCapacityBetween(Carbon $startAt, Carbon $finishAt)
238
    {
239 8
        if (!($this->start_at <= $startAt && $this->finish_at >= $finishAt)) {
0 ignored issues
show
Documentation introduced by
The property start_at 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 finish_at 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...
240 7
            return 0;
241
        }
242
243 8
        $count = $this->business
244 8
                      ->bookings()
245 8
                      ->with('humanresource')
246 8
                      ->active()
247 8
                      ->affectingHumanresource($this->humanresource_id)
0 ignored issues
show
Documentation introduced by
The property humanresource_id 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...
248 8
                      ->affectingInterval($startAt, $finishAt)
249 8
                      ->count();
250
251 8
        return $this->capacity - intval($count);
0 ignored issues
show
Documentation introduced by
The property capacity 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...
252
    }
253
}
254