Completed
Push — master ( 7bfd57...e0f6b9 )
by Alex
02:26
created

AbstractPresenter::getSuccessMessage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Mezon\Application;
3
4
/**
5
 * Interface PresenterInterface
6
 *
7
 * @package Application
8
 * @subpackage PresenterInterface
9
 * @author Dodonov A.A.
10
 * @version v.1.0 (2020/06/23)
11
 * @copyright Copyright (c) 2020, aeon.org
12
 */
13
14
/**
15
 * Base class for all presenters
16
 */
17
abstract class AbstractPresenter implements PresenterInterface
18
{
19
20
    /**
21
     * Presenter's name
22
     *
23
     * @var string
24
     */
25
    private $presenterName = '';
26
27
    /**
28
     * View object
29
     *
30
     * @var ViewInterface
31
     */
32
    private $view = null;
33
34
    /**
35
     * Error code
36
     *
37
     * @var integer
38
     */
39
    private $errorCode = 0;
40
41
    /**
42
     * Error message
43
     *
44
     * @var string
45
     */
46
    private $errorMessage = '';
47
48
    /**
49
     * Method sets success message
50
     *
51
     * @var string
52
     */
53
    private $successMessage = '';
54
55
    /**
56
     * Constructor
57
     *
58
     * @param ?ViewInterface $view
59
     *            view object
60
     */
61
    public function __construct(?ViewInterface $view = null)
62
    {
63
        $this->view = $view;
64
    }
65
66
    /**
67
     * Method returns presenter's name
68
     *
69
     * @return string presenter's name
70
     */
71
    public function getPresenterName(): string
72
    {
73
        return $this->presenterName;
74
    }
75
76
    /**
77
     * Method returns presenter's name
78
     *
79
     * @return string presenter's name
80
     */
81
    public function setPresenterName(string $presenterName): void
82
    {
83
        $this->presenterName = $presenterName;
84
    }
85
86
    /**
87
     * Method returns code of the last error
88
     *
89
     * @return int code of the last error
90
     */
91
    public function getErrorCode(): int
92
    {
93
        return $this->view === null ? $this->errorCode : $this->view->getErrorCode();
94
    }
95
96
    /**
97
     * Method sets code of the last error
98
     *
99
     * @param int $code
100
     *            code of the last error
101
     */
102
    public function setErrorCode(int $errorCode): void
103
    {
104
        if ($this->view === null) {
105
            $this->errorCode = $errorCode;
106
        } else {
107
            $this->view->setErrorCode($errorCode);
108
        }
109
    }
110
111
    /**
112
     * Method return last error description
113
     *
114
     * @return string last error description
115
     */
116
    public function getErrorMessage(): string
117
    {
118
        return $this->view === null ? $this->errorMessage : $this->view->getErrorMessage();
119
    }
120
121
    /**
122
     * Method sets last error description
123
     *
124
     * @param
125
     *            string last error description
126
     */
127
    public function setErrorMessage(string $errorMessage): void
128
    {
129
        if ($this->view === null) {
130
            $this->errorMessage = $errorMessage;
131
        } else {
132
            $this->view->setErrorMessage($errorMessage);
133
        }
134
    }
135
136
    /**
137
     * Method return success message
138
     *
139
     * @return string success message
140
     */
141
    public function getSuccessMessage(): string
142
    {
143
        return $this->view === null ? $this->successMessage : $this->view->getSuccessMessage();
0 ignored issues
show
Bug introduced by
The method getSuccessMessage() does not exist on Mezon\Application\ViewInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Mezon\Application\ViewInterface. ( Ignorable by Annotation )

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

143
        return $this->view === null ? $this->successMessage : $this->view->/** @scrutinizer ignore-call */ getSuccessMessage();
Loading history...
144
    }
145
146
    /**
147
     * Method sets success message
148
     *
149
     * @param $message string
150
     *            message
151
     */
152
    public function setSuccessMessage(string $successMessage): void
153
    {
154
        if ($this->view === null) {
155
            $this->successMessage = $successMessage;
156
        } else {
157
            $this->view->setSuccessMessage($successMessage);
0 ignored issues
show
Bug introduced by
The method setSuccessMessage() does not exist on Mezon\Application\ViewInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Mezon\Application\ViewInterface. ( Ignorable by Annotation )

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

157
            $this->view->/** @scrutinizer ignore-call */ 
158
                         setSuccessMessage($successMessage);
Loading history...
158
        }
159
    }
160
161
    /**
162
     * Method sets view's var
163
     *
164
     * @param string $name
165
     *            var name
166
     * @param mixed $value
167
     *            var value
168
     * @param bool $setTemplateVar
169
     *            do we need to set template parameter
170
     */
171
    public function setViewParameter(string $name, $value, bool $setTemplateVar = true): void
172
    {
173
        if ($this->view !== null) {
174
            $this->view->setViewParameter($name, $value, $setTemplateVar);
175
        }
176
    }
177
178
    /**
179
     * Method gets view's var
180
     *
181
     * @param string $name
182
     *            var name
183
     * @return mixed view's variable
184
     */
185
    public function getViewParameter(string $name)
186
    {
187
        if ($this->view !== null) {
188
            return $this->view->getViewParameter($name);
189
        }
190
191
        return null;
192
    }
193
}
194