HasViewTrait::initView()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace ByTIC\Notifications\Messages\Builder\Traits;
4
5
use Default_View as DefaultView;
0 ignored issues
show
Bug introduced by
The type Default_View was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Nip\View\ViewInterface;
0 ignored issues
show
Bug introduced by
The type Nip\View\ViewInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
/**
9
 * Class HasViewTrait
10
 * @package ByTIC\Common\Records\Emails\Builder
11
 */
12
trait HasViewTrait
13
{
14
    /**
15
     * @var null|ViewInterface
16
     */
17
    protected $view = null;
18
19
    protected $layout = '/layouts/email';
20
21
    /**
22
     * @return string
23
     */
24
    public function getLayout()
25
    {
26
        return $this->layout;
27
    }
28
29
    /**
30
     * @param string $layout
31
     */
32
    public function setLayout($layout)
33
    {
34
        $this->layout = $layout;
35
    }
36
37
    /**
38
     * @return null|string
39
     */
40
    protected function generateEmailBody()
41
    {
42
        $this->compileView();
43
        return $this->getView()->load($this->layout, [], true);
44
    }
45
46
    protected function compileView()
47
    {
48
//        $this->getView()->title = $this->getEmail()->subject;
49
//        $this->getView()->content = $this->getEmail()->body;
50
        $this->getView()->setBlock('content', '/emails/notifications');
51
        $this->getView()->set('content', $this->generateEmailContent());
52
        $this->getView()->set('title', $this->getEmail()->subject);
0 ignored issues
show
Bug introduced by
It seems like getEmail() 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

52
        $this->getView()->set('title', $this->/** @scrutinizer ignore-call */ getEmail()->subject);
Loading history...
53
    }
54
55
    /**
56
     * @return ViewInterface
57
     */
58
    public function getView()
59
    {
60
        if ($this->view === null) {
61
            $this->initView();
62
        }
63
64
        return $this->view;
65
    }
66
67
    public function initView()
68
    {
69
        $this->view = $this->newView();
70
    }
71
72
    /**
73
     * @param ViewInterface $view
74
     */
75
    public function setView($view)
76
    {
77
        $this->view = $view;
78
    }
79
80
    /**
81
     * @return DefaultView
82
     */
83
    public function newView()
84
    {
85
        return new DefaultView();
86
    }
87
88
    /**
89
     * @return null|string
90
     */
91
    abstract protected function generateEmailContent();
92
}
93