Email   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 4
cbo 2
dl 0
loc 90
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A initByTemplate() 0 4 1
A getTemplate() 0 8 2
A getPlain() 0 4 1
A getSubject() 0 4 1
A getCc() 0 4 2
A getBcc() 0 4 2
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
use Distilleries\MailerSaver\Contracts\MailModelContract;
8
9
/**
10
 * @property integer $id
11
 * @property string $libelle
12
 * @property string $body_type
13
 * @property string $action
14
 * @property string $cc
15
 * @property string $bcc
16
 * @property string $content
17
 * @property boolean $status
18
 * @property \Carbon\Carbon $created_at
19
 * @property \Carbon\Carbon $updated_at
20
 * @property \Carbon\Carbon $deleted_at
21
 */
22
class Email extends Model implements MailModelContract
23
{
24
    use SoftDeletes;
25
26
    /**
27
     * The attributes that are mass assignable.
28
     *
29
     * @var array
30
     */
31
    protected $fillable = [
32
        'libelle',
33
        'body_type',
34
        'action',
35
        'cc',
36
        'bcc',
37
        'content',
38
        'status',
39
    ];
40
41
    /**
42
     * The attributes that should be cast to native types.
43
     *
44
     * @var array
45
     */
46
    protected $casts = [
47
        'id' => 'integer',
48
        'status' => 'boolean',
49
    ];
50
51
    /**
52
     * The attributes that should be mutated to dates.
53
     *
54
     * @var array
55
     */
56
    protected $dates = [
57
        'deleted_at',
58
    ];
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function initByTemplate($view)
64
    {
65
        return $this->where('action', '=', $view);
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Email>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getTemplate($view)
72
    {
73
        if (! empty($this->action)){
74
            return $this->content;
75
        }
76
77
        return '';
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function getPlain()
84
    {
85
        return mb_strtolower($this->body_type);
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function getSubject()
92
    {
93
        return $this->libelle;
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99
    public function getCc()
100
    {
101
        return ! empty($this->cc) ? explode(',', $this->cc) : [];
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107
    public function getBcc()
108
    {
109
        return ! empty($this->bcc) ? explode(',', $this->bcc) : [];
110
    }
111
}
112