Passed
Push — feature/micro-ref-email ( 897999 )
by Tristan
05:32
created

ApiMailable::getPlainText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Traits;
4
5
/**
6
 * This trait can be used on a Mailable class to get the mailable's plain text,
7
 * or for converting to an array that might be returned in an API request.
8
 */
9
trait ApiMailable
10
{
11
    public function getPlainText()
12
    {
13
        $this->build();
0 ignored issues
show
Bug introduced by
It seems like build() 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

13
        $this->/** @scrutinizer ignore-call */ 
14
               build();
Loading history...
14
        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

14
        return $this->/** @scrutinizer ignore-call */ buildView()['text']->toHtml();
Loading history...
15
    }
16
17
    public function toArray()
18
    {
19
        $this->build();
20
        $mail = $this;
21
        return [
22
            'from' => $mail->from,
23
            'to' => $mail->to,
24
            'cc' => $mail->cc,
25
            'bcc' => $mail->bcc,
26
            'subject' => $mail->subject,
27
            'body' => $mail->getPlainText(),
28
        ];
29
    }
30
}
31