Completed
Push — master ( b9f7b1...c05cbd )
by Ariel
09:22
created

Appointment::scopeAffectingInterval()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 16
Ratio 66.67 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 16
loc 24
ccs 15
cts 15
cp 1
rs 8.9713
cc 1
eloc 15
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Timegridio\Concierge\Models;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Model as EloquentModel;
7
use McCool\LaravelAutoPresenter\HasPresenter;
8
use Timegridio\Concierge\Presenters\AppointmentPresenter;
9
10
/**
11
 * An Appointment can be understood as a reservation of a given Service,
12
 * provided by a given Business, targeted to a Contact, which will take place
13
 * on a determined Date and Time, and might have a duration and or comments.
14
 *
15
 * The Appointment can be issued by the Contact's User or by the Business owner.
16
 */
17
class Appointment extends EloquentModel implements HasPresenter
18
{
19
    /**
20
     * The attributes that are mass assignable.
21
     *
22
     * @var array
23
     */
24
    protected $fillable = ['issuer_id', 'contact_id', 'business_id',
25
        'service_id', 'start_at', 'finish_at', 'duration', 'comments', ];
26
27
    /**
28
     * The attributes that aren't mass assignable.
29
     *
30
     * @var array
31
     */
32
    protected $guarded = ['id', 'hash', 'status', 'vacancy_id'];
33
34
    /**
35
     * The attributes that should be mutated to dates.
36
     *
37
     * @var array
38
     */
39
    protected $dates = ['start_at', 'finish_at'];
40
41
    /**
42
     * Appointment Hard Status Constants.
43
     */
44
    const STATUS_RESERVED = 'R';
45
    const STATUS_CONFIRMED = 'C';
46
    const STATUS_ANNULATED = 'A';
47
    const STATUS_SERVED = 'S';
48
49
    ///////////////
50
    // PRESENTER //
51
    ///////////////
52
53
    /**
54
     * Get Presenter Class.
55
     *
56
     * @return App\Presenters\AppointmentPresenter
57
     */
58 1
    public function getPresenterClass()
59
    {
60 1
        return AppointmentPresenter::class;
61
    }
62
63
    /**
64
     * Generate hash and save the model to the database.
65
     *
66
     * @param array $options
67
     *
68
     * @return bool
69
     */
70 27
    public function save(array $options = [])
71
    {
72 27
        $this->doHash();
73
74 27
        return parent::save($options);
75
    }
76
77
    ///////////////////
78
    // Relationships //
79
    ///////////////////
80
81
    /**
82
     * Get the issuer (the User that generated the Appointment).
83
     *
84
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
85
     */
86 4
    public function issuer()
87
    {
88 4
        return $this->belongsTo(config('auth.providers.users.model'));
89
    }
90
91
    /**
92
     * Get the target Contact (for whom is reserved the Appointment).
93
     *
94
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
95
     */
96 4
    public function contact()
97
    {
98 4
        return $this->belongsTo(Contact::class);
99
    }
100
101
    /**
102
     * Get the holding Business (that has taken the reservation).
103
     *
104
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
105
     */
106 8
    public function business()
107
    {
108 8
        return $this->belongsTo(Business::class);
109
    }
110
111
    /**
112
     * Get the reserved Service.
113
     *
114
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
115
     */
116 8
    public function service()
117
    {
118 8
        return $this->belongsTo(Service::class);
119
    }
120
121
    /**
122
     * Get the Vacancy (that justifies the availability of resources for the
123
     * Appointment generation).
124
     *
125
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
126
     */
127 5
    public function vacancy()
128
    {
129 5
        return $this->belongsTo(Vacancy::class);
130
    }
131
132
    ///////////
133
    // Other //
134
    ///////////
135
136
    /**
137
     * Get the User through Contact.
138
     *
139
     * @return User
140
     */
141 2
    public function user()
142
    {
143 2
        return $this->contact->user;
0 ignored issues
show
Documentation introduced by
The property contact does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
144
    }
145
146
    /**
147
     * Determine if the new Appointment will hash-crash with another existing
148
     * Appointment.
149
     *
150
     * @return bool
151
     */
152 5
    public function duplicates()
153
    {
154 5
        return !self::where('hash', $this->hash)->get()->isEmpty();
0 ignored issues
show
Documentation introduced by
The property hash does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
155
    }
156
157
    ///////////////
158
    // Accessors //
159
    ///////////////
160
161
    /**
162
     * Get Hash.
163
     *
164
     * @return string
165
     */
166 8
    public function getHashAttribute()
167
    {
168 8
        return isset($this->attributes['hash'])
169 8
            ? $this->attributes['hash']
170 8
            : $this->doHash();
171
    }
172
173
    /**
174
     * Get Finish At:
175
     * Calculates the start_at time plus duration in minutes.
176
     *
177
     * @return Carbon
178
     */
179 1
    public function getFinishAtAttribute()
180
    {
181 1
        if (array_get($this->attributes, 'finish_at') !== null) {
182
            return Carbon::parse($this->attributes['finish_at']);
183
        }
184
185 1
        if (is_numeric($this->duration)) {
0 ignored issues
show
Documentation introduced by
The property duration does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
186 1
            return $this->start_at->addMinutes($this->duration);
0 ignored issues
show
Documentation introduced by
The property start_at does not exist on object<Timegridio\Concierge\Models\Appointment>. 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 duration does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
187
        }
188
189
        return $this->start_at;
0 ignored issues
show
Documentation introduced by
The property start_at does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
190
    }
191
192
    /**
193
     * Get annulation deadline (target date).
194
     *
195
     * @return Carbon\Carbon
196
     */
197
    public function getAnnulationDeadlineAttribute()
198
    {
199
        $hours = $this->business->pref('appointment_annulation_pre_hs');
0 ignored issues
show
Documentation introduced by
The property business does not exist on object<Timegridio\Concierge\Models\Appointment>. 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
201
        return $this->start_at
0 ignored issues
show
Documentation introduced by
The property start_at does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
202
                    ->subHours($hours)
203
                    ->timezone($this->business->timezone);
0 ignored issues
show
Documentation introduced by
The property business does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
204
    }
205
206
    /**
207
     * Get the human readable status name.
208
     *
209
     * @return string
210
     */
211
    public function getStatusLabelAttribute()
212
    {
213
        $labels = [
214
            Self::STATUS_RESERVED  => 'reserved',
215
            Self::STATUS_CONFIRMED => 'confirmed',
216
            Self::STATUS_ANNULATED => 'annulated',
217
            Self::STATUS_SERVED    => 'served',
218
            ];
219
220
        return array_key_exists($this->status, $labels)
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
221
            ? $labels[$this->status]
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
222
            : '';
223
    }
224
225
    /**
226
     * Get the date of the Appointment.
227
     *
228
     * @return string
229
     */
230 3
    public function getDateAttribute()
231
    {
232 3
        return $this->start_at
0 ignored issues
show
Documentation introduced by
The property start_at does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
233 3
                    ->timezone($this->business->timezone)
0 ignored issues
show
Documentation introduced by
The property business does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
234 3
                    ->toDateString();
235
    }
236
237
    /**
238
     * Get user-friendly unique identification code.
239
     *
240
     * @return string
241
     */
242
    public function getCodeAttribute()
243
    {
244
        $length = $this->business->pref('appointment_code_length');
0 ignored issues
show
Documentation introduced by
The property business does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
245
246
        return strtoupper(substr($this->hash, 0, $length));
0 ignored issues
show
Documentation introduced by
The property hash does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
247
    }
248
249
    //////////////
250
    // Mutators //
251
    //////////////
252
253
    /**
254
     * Generate Appointment hash.
255
     *
256
     * @return string
257
     */
258 27
    public function doHash()
259
    {
260 27
        return $this->attributes['hash'] = md5(
261 27
            $this->start_at.'/'.
0 ignored issues
show
Documentation introduced by
The property start_at does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
262 27
            $this->contact_id.'/'.
0 ignored issues
show
Documentation introduced by
The property contact_id does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
263 27
            $this->business_id.'/'.
0 ignored issues
show
Documentation introduced by
The property business_id does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
264 27
            $this->service_id
0 ignored issues
show
Documentation introduced by
The property service_id does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
265 27
        );
266
    }
267
268
    /**
269
     * Set start at.
270
     *
271
     * @param Carbon $datetime
272
     */
273 27
    public function setStartAtAttribute(Carbon $datetime)
274
    {
275 27
        $this->attributes['start_at'] = $datetime;
276 27
    }
277
278
    /**
279
     * Set finish_at attribute.
280
     *
281
     * @param Carbon $datetime
282
     */
283 8
    public function setFinishAtAttribute(Carbon $datetime)
284
    {
285 8
        $this->attributes['finish_at'] = $datetime;
286 8
    }
287
288
    /**
289
     * Set Comments.
290
     *
291
     * @param string $comments
292
     */
293 27
    public function setCommentsAttribute($comments)
294
    {
295 27
        $this->attributes['comments'] = trim($comments) ?: null;
296 27
    }
297
298
    /////////////////
299
    // HARD STATUS //
300
    /////////////////
301
302
    /**
303
     * Determine if is Reserved.
304
     *
305
     * @return bool
306
     */
307 1
    public function isReserved()
308
    {
309 1
        return $this->status == Self::STATUS_RESERVED;
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
310
    }
311
312
    ///////////////////////////
313
    // Calculated attributes //
314
    ///////////////////////////
315
316
    /**
317
     * Appointment Status Workflow.
318
     *
319
     * Hard Status: Those concrete values stored in DB
320
     * Soft Status: Those values calculated from stored values in DB
321
     *
322
     * Suggested transitions (Binding is not mandatory)
323
     *     Reserved -> Confirmed -> Served
324
     *     Reserved -> Served
325
     *     Reserved -> Annulated
326
     *     Reserved -> Confirmed -> Annulated
327
     *
328
     * Soft Status
329
     *     (Active)   [ Reserved  | Confirmed ]
330
     *     (InActive) [ Annulated | Served    ]
331
     */
332
333
    /**
334
     * Determine if is Active.
335
     *
336
     * @return bool
337
     */
338 5
    public function isActive()
339
    {
340
        return
341 5
            $this->status == Self::STATUS_CONFIRMED ||
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
342 5
            $this->status == Self::STATUS_RESERVED;
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
343
    }
344
345
    /**
346
     * Determine if is Pending.
347
     *
348
     * @return bool
349
     */
350 3
    public function isPending()
351
    {
352 3
        return $this->isActive() && $this->isFuture();
353
    }
354
355
    /**
356
     * Determine if is Future.
357
     *
358
     * @return bool
359
     */
360 4
    public function isFuture()
361
    {
362 4
        return !$this->isDue();
363
    }
364
365
    /**
366
     * Determine if is due.
367
     *
368
     * @return bool
369
     */
370 5
    public function isDue()
371
    {
372 5
        return $this->start_at->isPast();
0 ignored issues
show
Documentation introduced by
The property start_at does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
373
    }
374
375
    ////////////
376
    // Scopes //
377
    ////////////
378
379
    /////////////////////////
380
    // Hard Status Scoping //
381
    /////////////////////////
382
383
    /**
384
     * Scope to Contacts Collection.
385
     *
386
     * @param Illuminate\Database\Query $query
387
     *
388
     * @return Illuminate\Database\Query
389
     */
390
    public function scopeForContacts($query, $contacts)
391
    {
392
        return $query->whereIn('contact_id', $contacts->pluck('id'));
393
    }
394
395
    /**
396
     * Scope to Unarchived Appointments.
397
     *
398
     * @param Illuminate\Database\Query $query
399
     *
400
     * @return Illuminate\Database\Query
401
     */
402
    public function scopeUnarchived($query)
403
    {
404
        return $query
405
            ->where(function ($query) {
406
                $query->whereIn('status', [Self::STATUS_RESERVED, Self::STATUS_CONFIRMED])
407
                    ->where('start_at', '<=', Carbon::parse('today midnight')->timezone('UTC'))
408
                    ->orWhere(function ($query) {
409
                        $query->where('start_at', '>=', Carbon::parse('today midnight')->timezone('UTC'));
410
                    });
411
            });
412
    }
413
414
    /**
415
     * Scope to Served Appointments.
416
     *
417
     * @param Illuminate\Database\Query $query
418
     *
419
     * @return Illuminate\Database\Query
420
     */
421
    public function scopeServed($query)
422
    {
423
        return $query->where('status', '=', Self::STATUS_SERVED);
424
    }
425
426
    /**
427
     * Scope to Annulated Appointments.
428
     *
429
     * @param Illuminate\Database\Query $query
430
     *
431
     * @return Illuminate\Database\Query
432
     */
433
    public function scopeAnnulated($query)
434
    {
435
        return $query->where('status', '=', Self::STATUS_ANNULATED);
436
    }
437
438
    /////////////////////////
439
    // Soft Status Scoping //
440
    /////////////////////////
441
442
    /**
443
     * Scope to not Served Appointments.
444
     *
445
     * @param Illuminate\Database\Query $query
446
     *
447
     * @return Illuminate\Database\Query
448
     */
449
    public function scopeUnServed($query)
450
    {
451
        return $query->where('status', '<>', Self::STATUS_SERVED);
452
    }
453
454
    /**
455
     * Scope to Active Appointments.
456
     *
457
     * @param Illuminate\Database\Query $query
458
     *
459
     * @return Illuminate\Database\Query
460
     */
461 16
    public function scopeActive($query)
462
    {
463 16
        return $query->whereIn('status', [Self::STATUS_RESERVED, Self::STATUS_CONFIRMED]);
464
    }
465
466
    /**
467
     * Scope of date.
468
     *
469
     * @param Illuminate\Database\Query $query
470
     * @param Carbon                    $date
471
     *
472
     * @return Illuminate\Database\Query
473
     */
474
    public function scopeOfDate($query, Carbon $date)
475
    {
476
        return $query->whereRaw('date(`start_at`) = ?', [$date->timezone('UTC')->toDateString()]);
477
    }
478
479
    /**
480
     * Between Dates.
481
     *
482
     * @param Illuminate\Database\Query $query
483
     * @param Carbon                    $startAt
484
     * @param Carbon                    $finishAt
485
     *
486
     * @return Illuminate\Database\Query
487
     */
488 12
    public function scopeAffectingInterval($query, Carbon $startAt, Carbon $finishAt)
489
    {
490
        return $query
491
            ->where(function ($query) use ($startAt, $finishAt) {
492
493 View Code Duplication
                $query->where(function ($query) use ($startAt, $finishAt) {
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...
494 12
                    $query->where('finish_at', '>=', $finishAt->timezone('UTC'))
495 12
                            ->where('start_at', '<=', $startAt->timezone('UTC'));
496 12
                })
497 View Code Duplication
                ->orWhere(function ($query) use ($startAt, $finishAt) {
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...
498 12
                    $query->where('finish_at', '<', $finishAt->timezone('UTC'))
499 12
                            ->where('finish_at', '>', $startAt->timezone('UTC'));
500 12
                })
501 View Code Duplication
                ->orWhere(function ($query) use ($startAt, $finishAt) {
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...
502 12
                    $query->where('start_at', '>', $startAt->timezone('UTC'))
503 12
                            ->where('start_at', '<', $finishAt->timezone('UTC'));
504 12
                })
505 12 View Code Duplication
                ->orWhere(function ($query) use ($startAt, $finishAt) {
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...
506 12
                    $query->where('start_at', '>', $startAt->timezone('UTC'))
507 12
                            ->where('finish_at', '<', $finishAt->timezone('UTC'));
508 12
                });
509
510 12
            });
511
    }
512
513
    //////////////////////////
514
    // Soft Status Checkers //
515
    //////////////////////////
516
517
    /**
518
     * User is target contact of the appointment.
519
     *
520
     * @param int $userId
521
     *
522
     * @return bool
523
     */
524
    public function isTarget($userId)
525
    {
526
        return $this->contact->isProfileOf($userId);
0 ignored issues
show
Documentation introduced by
The property contact does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
527
    }
528
529
    /**
530
     * User is issuer of the appointment.
531
     *
532
     * @param int $userId
533
     *
534
     * @return bool
535
     */
536
    public function isIssuer($userId)
537
    {
538
        return $this->issuer->id == $userId;
0 ignored issues
show
Documentation introduced by
The property issuer does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
539
    }
540
541
    /**
542
     * User is owner of business.
543
     *
544
     * @param int $userId
545
     *
546
     * @return bool
547
     */
548
    public function isOwner($userId)
549
    {
550
        return $this->business->owners->contains($userId);
0 ignored issues
show
Documentation introduced by
The property business does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
551
    }
552
553
    /**
554
     * can be annulated by user.
555
     *
556
     * @param int $userId
557
     *
558
     * @return bool
559
     */
560
    public function canAnnulate($userId)
561
    {
562
        return $this->isOwner($userId) ||
563
            ($this->isIssuer($userId) && $this->isOnTimeToAnnulate()) ||
564
            ($this->isTarget($userId) && $this->isOnTimeToAnnulate());
565
    }
566
567
    /**
568
     * Determine if it is still possible to annulate according business policy.
569
     *
570
     * @return bool
571
     */
572
    public function isOnTimeToAnnulate()
573
    {
574
        $graceHours = $this->business->pref('appointment_annulation_pre_hs');
0 ignored issues
show
Documentation introduced by
The property business does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
575
576
        $diff = $this->start_at->diffInHours(Carbon::now());
0 ignored issues
show
Documentation introduced by
The property start_at does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
577
578
        return intval($diff) >= intval($graceHours);
579
    }
580
581
    /**
582
     * can Serve.
583
     *
584
     * @param int $userId
585
     *
586
     * @return bool
587
     */
588
    public function canServe($userId)
589
    {
590
        return $this->isOwner($userId);
591
    }
592
593
    /**
594
     * can confirm.
595
     *
596
     * @param int $userId
597
     *
598
     * @return bool
599
     */
600
    public function canConfirm($userId)
601
    {
602
        return $this->isIssuer($userId) || $this->isOwner($userId);
603
    }
604
605
    /**
606
     * is Serveable by user.
607
     *
608
     * @param int $userId
609
     *
610
     * @return bool
611
     */
612
    public function isServeableBy($userId)
613
    {
614
        return $this->isServeable() && $this->canServe($userId);
615
    }
616
617
    /**
618
     * is Confirmable By user.
619
     *
620
     * @param int $userId
621
     *
622
     * @return bool
623
     */
624
    public function isConfirmableBy($userId)
625
    {
626
        return
627
            $this->isConfirmable() &&
628
            $this->shouldConfirmBy($userId) &&
629
            $this->canConfirm($userId);
630
    }
631
632
    /**
633
     * is Annulable By user.
634
     *
635
     * @param int $userId
636
     *
637
     * @return bool
638
     */
639
    public function isAnnulableBy($userId)
640
    {
641
        return $this->isAnnulable() && $this->canAnnulate($userId);
642
    }
643
644
    /**
645
     * Determine if the queried userId may confirm the appointment or not.
646
     *
647
     * @param int $userId
648
     *
649
     * @return bool
650
     */
651
    public function shouldConfirmBy($userId)
652
    {
653
        return ($this->isSelfIssued() && $this->isOwner($userId)) ||
654
               ($this->isOwner($this->issuer->id) && $this->isIssuer($userId));
0 ignored issues
show
Documentation introduced by
The property issuer does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
655
    }
656
657
    /**
658
     * Determine if the target Contact's User is the same of the Appointment
659
     * issuer User.
660
     *
661
     * @return bool
662
     */
663
    public function isSelfIssued()
664
    {
665
        if (!$this->issuer) {
0 ignored issues
show
Documentation introduced by
The property issuer does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
666
            return false;
667
        }
668
        if (!$this->contact) {
0 ignored issues
show
Documentation introduced by
The property contact does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
669
            return false;
670
        }
671
        if (!$this->contact->user) {
0 ignored issues
show
Documentation introduced by
The property contact does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
672
            return false;
673
        }
674
675
        return $this->issuer->id == $this->contact->user->id;
0 ignored issues
show
Documentation introduced by
The property issuer does not exist on object<Timegridio\Concierge\Models\Appointment>. 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 contact does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
676
    }
677
678
    /**
679
     * Determine if the Serve action can be performed.
680
     *
681
     * @return bool
682
     */
683 1
    public function isServeable()
684
    {
685 1
        return $this->isActive() && $this->isDue();
686
    }
687
688
    /**
689
     * Determine if the Confirm action can be performed.
690
     *
691
     * @return bool
692
     */
693 1
    public function isConfirmable()
694
    {
695 1
        return $this->status == self::STATUS_RESERVED && $this->isFuture();
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
696
    }
697
698
    /**
699
     * Determine if the Annulate action can be performed.
700
     *
701
     * @return bool
702
     */
703 1
    public function isAnnulable()
704
    {
705 1
        return $this->isActive();
706
    }
707
708
    /////////////////////////
709
    // Hard Status Actions //
710
    /////////////////////////
711
712
    /**
713
     * Check and perform Confirm action.
714
     *
715
     * @return $this
716
     */
717 5
    public function doReserve()
718
    {
719 5
        if ($this->status === null) {
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
720 5
            $this->status = self::STATUS_RESERVED;
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
721 5
        }
722
723 5
        return $this;
724
    }
725
726
    /**
727
     * Check and perform Confirm action.
728
     *
729
     * @return $this
730
     */
731 2
    public function doConfirm()
732
    {
733 2
        if ($this->isConfirmable()) {
734 2
            $this->status = self::STATUS_CONFIRMED;
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
735
736 2
            $this->save();
737 2
        }
738
739 2
        return $this;
740
    }
741
742
    /**
743
     * Check and perform Annulate action.
744
     *
745
     * @return $this
746
     */
747 2
    public function doAnnulate()
748
    {
749 2
        if ($this->isAnnulable()) {
750 1
            $this->status = self::STATUS_ANNULATED;
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
751
752 1
            $this->save();
753 1
        }
754
755 2
        return $this;
756
    }
757
758
    /**
759
     * Check and perform Serve action.
760
     *
761
     * @return $this
762
     */
763 3
    public function doServe()
764
    {
765 3
        if ($this->isServeable()) {
766 1
            $this->status = self::STATUS_SERVED;
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<Timegridio\Concierge\Models\Appointment>. 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...
767
768 1
            $this->save();
769 1
        }
770
771 3
        return $this;
772
    }
773
}
774