Issues (2884)

src/App/View/Store.php (23 issues)

1
<?php
2
0 ignored issues
show
Missing file doc comment
Loading history...
3
namespace Jaxon\App\View;
4
5
use JsonSerializable;
6
7
use function array_merge;
8
9
class Store implements JsonSerializable
0 ignored issues
show
Missing doc comment for class Store
Loading history...
10
{
11
    /**
12
     * The view renderer
13
     *
14
     * @var ViewInterface
15
     */
16
    protected $xRenderer;
0 ignored issues
show
Expected 1 blank line(s) before first member var; 0 found
Loading history...
17
18
    /**
19
     * The view namespace
20
     *
21
     * @var string
22
     */
23
    protected $sNamespace;
24
25
    /**
26
     * The view name
27
     *
28
     * @var string
29
     */
30
    protected $sViewName;
31
32
    /**
33
     * The view data
34
     *
35
     * @var array
36
     */
37
    protected $aViewData = [];
38
39
    /**
40
     * Make a piece of data available for the rendered view
41
     *
42
     * @param string $sName    The data name
0 ignored issues
show
Expected 2 spaces after parameter name; 4 found
Loading history...
43
     * @param mixed $xValue    The data value
0 ignored issues
show
Expected 2 spaces after parameter type; 1 found
Loading history...
Expected 1 spaces after parameter name; 4 found
Loading history...
44
     *
45
     * @return Store
46
     */
47
    public function with(string $sName, $xValue): Store
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
48
    {
49
        $this->aViewData[$sName] = $xValue;
50
        return $this;
51
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
52
53
    /**
54
     * Set the data to be rendered
55
     *
56
     * @param array $aViewData    The view data
0 ignored issues
show
Expected 1 spaces after parameter name; 4 found
Loading history...
57
     *
58
     * @return Store
59
     */
60
    public function setData(array $aViewData): Store
61
    {
62
        $this->aViewData = array_merge($this->aViewData, $aViewData);
63
        return $this;
64
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
65
66
    /**
67
     * Set the view to be rendered, with optional data
68
     *
69
     * @param ViewInterface $xRenderer    The view renderer
0 ignored issues
show
Expected 2 spaces after parameter name; 4 found
Loading history...
70
     * @param string $sNamespace    The view namespace
0 ignored issues
show
Expected 8 spaces after parameter type; 1 found
Loading history...
Expected 1 spaces after parameter name; 4 found
Loading history...
71
     * @param string $sViewName    The view name
0 ignored issues
show
Expected 8 spaces after parameter type; 1 found
Loading history...
Expected 2 spaces after parameter name; 4 found
Loading history...
72
     * @param array $aViewData    The view data
0 ignored issues
show
Expected 9 spaces after parameter type; 1 found
Loading history...
Expected 2 spaces after parameter name; 4 found
Loading history...
73
     *
74
     * @return Store
75
     */
76
    public function setView(ViewInterface $xRenderer, string $sNamespace, string $sViewName, array $aViewData = []): Store
77
    {
78
        $this->xRenderer = $xRenderer;
79
        $this->sNamespace = trim($sNamespace);
80
        $this->sViewName = trim($sViewName);
81
        $this->aViewData = array_merge($this->aViewData, $aViewData);
82
        return $this;
83
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
84
85
    /**
86
     * Get the view namespace
87
     *
88
     * @return string        The view namespace
89
     */
90
    public function getNamespace(): string
91
    {
92
        return $this->sNamespace;
93
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
94
95
    /**
96
     * Get the view name
97
     *
98
     * @return string        The view name
99
     */
100
    public function getViewName(): string
101
    {
102
        return $this->sViewName;
103
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
104
105
    /**
106
     * Get the view data
107
     *
108
     * @return array         The view data
109
     */
110
    public function getViewData(): array
111
    {
112
        return $this->aViewData;
113
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
114
115
    /**
116
     * Render a view using third party view system
117
     *
118
     * @return string        The string representation of the view
119
     */
120
    public function __toString()
121
    {
122
        return ($this->xRenderer) ? $this->xRenderer->render($this) : '';
123
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
124
125
    /**
126
     * Convert this object to string for json.
127
     *
128
     * This is a method of the JsonSerializable interface.
129
     *
130
     * @return string
131
     */
132
    public function jsonSerialize(): string
133
    {
134
        return $this->__toString();
135
    }
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
136
}
137