Subscriber::getPresenterClass()   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 AltThree\Validator\ValidatingTrait;
15
use Gitamin\Presenters\SubscriberPresenter;
16
use Illuminate\Database\Eloquent\Model;
17
use McCool\LaravelAutoPresenter\HasPresenter;
18
19
class Subscriber extends Model implements HasPresenter
20
{
21
    use ValidatingTrait;
22
23
    /**
24
     * The attributes that should be casted to native types.
25
     *
26
     * @var string[]
27
     */
28
    protected $casts = [
29
        'id' => 'int',
30
        'email' => 'string',
31
        'verify_code' => 'string',
32
        'verified_at' => 'date',
33
    ];
34
35
    /**
36
     * The fillable properties.
37
     *
38
     * @var string[]
39
     */
40
    protected $fillable = ['email'];
41
42
    /**
43
     * The validation rules.
44
     *
45
     * @var string[]
46
     */
47
    public $rules = [
48
        'email' => 'required|email',
49
    ];
50
51
    /**
52
     * Overrides the models boot method.
53
     */
54
    public static function boot()
55
    {
56
        parent::boot();
57
58
        self::creating(function ($user) {
59
            if (! $user->verify_code) {
60
                $user->verify_code = self::generateVerifyCode();
61
            }
62
        });
63
    }
64
65
    /**
66
     * Determines if the subscriber is verified.
67
     *
68
     * @return bool
69
     */
70
    public function verified()
71
    {
72
        return $this->verified_at !== null;
0 ignored issues
show
Documentation introduced by
The property verified_at does not exist on object<Gitamin\Models\Subscriber>. 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...
73
    }
74
75
    /**
76
     * Returns an new verify code.
77
     *
78
     * @return string
79
     */
80
    public static function generateVerifyCode()
81
    {
82
        return str_random(42);
83
    }
84
85
    /**
86
     * Get the presenter class.
87
     *
88
     * @return string
89
     */
90
    public function getPresenterClass()
91
    {
92
        return SubscriberPresenter::class;
93
    }
94
}
95