Passed
Push — task/add-applicants-and-applic... ( 514472...36c932 )
by Yonathan
10:54 queued 12s
created

ApiMailable   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 14
dl 0
loc 23
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPlainText() 0 5 1
A toArray() 0 13 1
1
<?php
2
3
namespace App\Traits;
4
5
use Illuminate\Container\Container;
6
7
/**
8
 * This trait can be used on a Mailable class to get the mailable's plain text,
9
 * or for converting to an array that might be returned in an API request.
10
 */
11
trait ApiMailable
12
{
13
    public function getPlainText()
14
    {
15
        return $this->withLocale($this->locale, function () {
0 ignored issues
show
Bug introduced by
It seems like withLocale() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
        return $this->/** @scrutinizer ignore-call */ withLocale($this->locale, function () {
Loading history...
16
            Container::getInstance()->call([$this, 'build']);
17
            return $this->buildView()['text']->toHtml();
0 ignored issues
show
Bug introduced by
It seems like buildView() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
            return $this->/** @scrutinizer ignore-call */ buildView()['text']->toHtml();
Loading history...
18
        });
19
    }
20
21
    public function toArray()
22
    {
23
        return $this->withLocale($this->locale, function () {
24
            Container::getInstance()->call([$this, 'build']);
25
26
            $mail = $this;
27
            return [
28
                'from' => $mail->from,
29
                'to' => $mail->to,
30
                'cc' => $mail->cc,
31
                'bcc' => $mail->bcc,
32
                'subject' => $mail->subject,
33
                'body' => $mail->getPlainText(),
34
            ];
35
        });
36
    }
37
}
38