Passed
Push — task/refactor-breadcrumbs ( 91a962...bee80d )
by Yonathan
04:22
created

ApiMailable::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 13
rs 9.9332
c 2
b 0
f 0
cc 1
nc 1
nop 0
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