Passed
Push — master ( 37d9b5...bf2aee )
by Thierry
04:39 queued 02:29
created

DialogFacade::confirm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * DialogFacade.php - Shows alert and confirm dialogs
5
 *
6
 * @author Thierry Feuzeu <[email protected]>
7
 * @copyright 2019 Thierry Feuzeu <[email protected]>
8
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
9
 * @link https://github.com/jaxon-php/jaxon-core
10
 */
0 ignored issues
show
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
11
12
namespace Jaxon\Ui\Dialogs;
13
14
use Jaxon\Container\Container;
15
16
class DialogFacade
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class DialogFacade
Loading history...
17
{
18
    /**
19
     * @var Container
20
     */
21
    private $di;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
22
23
    /**
24
     * The QuestionInterface class name (javascript confirm function)
25
     *
26
     * @var string
27
     */
28
    private $sQuestion = '';
29
30
    /**
31
     * Default javascript confirm function
32
     *
33
     * @var QuestionInterface
34
     */
35
    private $xDefaultQuestion;
36
37
    /**
38
     * The MessageInterface class name (javascript alert function)
39
     *
40
     * @var string
41
     */
42
    private $sMessage = '';
43
44
    /**
45
     * Default javascript alert function
46
     *
47
     * @var MessageInterface
48
     */
49
    private $xDefaultMessage;
50
51
    /**
52
     * The constructor
53
     *
54
     * @param Container $di
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
55
     */
56
    public function __construct(Container $di)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
57
    {
58
        $this->di = $di;
59
        // Javascript confirm function
60
        $this->xDefaultQuestion = new Question();
61
        // Javascript alert function
62
        $this->xDefaultMessage = new Message();
63
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
64
65
    /**
66
     * Set the QuestionInterface class name
67
     *
68
     * @param string $sQuestion    The QuestionInterface class name
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
69
     *
70
     * @return void
71
     */
72
    public function setQuestion(string $sQuestion)
73
    {
74
        $this->sQuestion = $sQuestion;
75
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
76
77
    /**
78
     * Get the QuestionInterface class name (javascript question function)
79
     *
80
     * @return QuestionInterface
81
     */
82
    public function getQuestion()
83
    {
84
        return ($this->sQuestion) ? $this->di->get($this->sQuestion) : $this->xDefaultQuestion;
85
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
86
87
    /**
88
     * Get the default QuestionInterface class name (javascript confirm function)
89
     *
90
     * @return QuestionInterface
91
     */
92
    public function getDefaultQuestion(): QuestionInterface
93
    {
94
        return $this->xDefaultQuestion;
95
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
96
97
    /**
98
     * Set MessageInterface class name
99
     *
100
     * @param string $sMessage    The MessageInterface class name
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
101
     *
102
     * @return void
103
     */
104
    public function setMessage(string $sMessage)
105
    {
106
        $this->sMessage = $sMessage;
107
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
108
109
    /**
110
     * Get the MessageInterface class name (javascript alert function)
111
     *
112
     * @return MessageInterface
113
     */
114
    public function getMessage(): MessageInterface
115
    {
116
        return ($this->sMessage) ? $this->di->get($this->sMessage) : $this->xDefaultMessage;
117
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
118
119
    /**
120
     * Get the default MessageInterface class name (javascript alert function)
121
     *
122
     * @return MessageInterface
123
     */
124
    public function getDefaultMessage(): MessageInterface
125
    {
126
        return $this->xDefaultMessage;
127
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
128
129
    /**
130
     * Get the script which makes a call only if the user answers yes to the given question.
131
     * It is a function of the Question interface.
132
     *
133
     * @param string  $sQuestion
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
134
     * @param string  $sYesScript
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
135
     * @param string  $sNoScript
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
136
     *
137
     * @return string
138
     */
139
    public function confirm(string $sQuestion, string $sYesScript, string $sNoScript): string
140
    {
141
        return $this->getQuestion()->confirm($sQuestion, $sYesScript, $sNoScript);
142
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
143
144
    /**
145
     * Print a success message.
146
     *
147
     * It is a function of the Message interface.
148
     *
149
     * @param string $sMessage    The text of the message
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
150
     * @param string $sTitle    The title of the message
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter name; 4 found
Loading history...
151
     *
152
     * @return string
153
     */
154
    public function success(string $sMessage, string $sTitle = ''): string
155
    {
156
        return $this->getMessage()->success($sMessage, $sTitle);
157
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
158
159
    /**
160
     * Print an information message.
161
     *
162
     * It is a function of the Message interface.
163
     *
164
     * @param string $sMessage    The text of the message
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
165
     * @param string $sTitle    The title of the message
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter name; 4 found
Loading history...
166
     *
167
     * @return string
168
     */
169
    public function info(string $sMessage, string $sTitle = ''): string
170
    {
171
        return $this->getMessage()->info($sMessage, $sTitle);
172
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
173
174
    /**
175
     * Print a warning message.
176
     *
177
     * It is a function of the Message interface.
178
     *
179
     * @param string $sMessage    The text of the message
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
180
     * @param string $sTitle    The title of the message
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter name; 4 found
Loading history...
181
     *
182
     * @return string
183
     */
184
    public function warning(string $sMessage, string $sTitle = ''): string
185
    {
186
        return $this->getMessage()->warning($sMessage, $sTitle);
187
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
188
189
    /**
190
     * Print an error message.
191
     *
192
     * It is a function of the Message interface.
193
     *
194
     * @param string $sMessage    The text of the message
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
195
     * @param string $sTitle    The title of the message
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter name; 4 found
Loading history...
196
     *
197
     * @return string
198
     */
199
    public function error(string $sMessage, string $sTitle = ''): string
200
    {
201
        return $this->getMessage()->error($sMessage, $sTitle);
202
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
203
}
204