Invite::generateInviteCode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of Gitamin.
5
 *
6
 * Copyright (C) 2015-2016 The Gitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gitamin\Models;
13
14
use Illuminate\Database\Eloquent\Model;
15
16
class Invite extends Model
17
{
18
    /**
19
     * The attributes that should be casted to native types.
20
     *
21
     * @var string[]
22
     */
23
    protected $casts = [
24
        'email' => 'string',
25
    ];
26
27
    /**
28
     * The fillable properties.
29
     *
30
     * @var string[]
31
     */
32
    protected $fillable = ['email'];
33
34
    /**
35
     * Overrides the models boot method.
36
     */
37
    public static function boot()
38
    {
39
        parent::boot();
40
41
        self::creating(function ($invite) {
42
            if (! $invite->code) {
43
                $invite->code = self::generateInviteCode();
44
            }
45
        });
46
    }
47
48
    /**
49
     * Returns an invite code.
50
     *
51
     * @return string
52
     */
53
    public static function generateInviteCode()
54
    {
55
        return str_random(20);
56
    }
57
58
    /**
59
     * Determines if the invite was claimed.
60
     *
61
     * @return bool
62
     */
63
    public function claimed()
64
    {
65
        return $this->claimed_at !== null;
0 ignored issues
show
Documentation introduced by
The property claimed_at does not exist on object<Gitamin\Models\Invite>. 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...
66
    }
67
}
68