Passed
Push — feature/code_improvement ( ee2f22...15c17b )
by Thierry
03:25 queued 42s
created

Dialog::getDefaultQuestion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
cc 1
nc 1
nop 0
rs 10
1
<?php
2
3
/**
4
 * Dialog.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
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
11
12
namespace Jaxon\Utils\Dialogs;
13
14
use Jaxon\Contracts\Dialogs\Message as MessageContract;
15
use Jaxon\Contracts\Dialogs\Question as QuestionContract;
16
17
class Dialog
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Dialog
Loading history...
18
{
19
    /**
20
     * Javascript confirm function
21
     *
22
     * @var QuestionContract
23
     */
24
    private $xQuestion;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
25
26
    /**
27
     * Default javascript confirm function
28
     *
29
     * @var QuestionContract
30
     */
31
    private $xDefaultQuestion;
32
33
    /**
34
     * Javascript alert function
35
     *
36
     * @var MessageContract
37
     */
38
    private $xMessage;
39
40
    /**
41
     * Default javascript alert function
42
     *
43
     * @var MessageContract
44
     */
45
    private $xDefaultMessage;
46
47
    /**
48
     * The constructor
49
     */
50
    public function __construct()
51
    {
52
        // Javascript confirm function
53
        $this->xQuestion = null;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
54
        $this->xDefaultQuestion = new Question();
55
56
        // Javascript alert function
57
        $this->xMessage = null;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
58
        $this->xDefaultMessage = new Message();
59
    }
60
61
    /**
62
     * Set the javascript confirm function
63
     *
64
     * @param QuestionContract         $xQuestion     The javascript confirm function
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 9 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 5 found
Loading history...
65
     *
66
     * @return void
67
     */
68
    public function setQuestion(QuestionContract $xQuestion)
69
    {
70
        $this->xQuestion = $xQuestion;
71
    }
72
73
    /**
74
     * Get the javascript question function
75
     *
76
     * @return QuestionContract
77
     */
78
    public function getQuestion()
79
    {
80
        return (($this->xQuestion) ? $this->xQuestion : $this->xDefaultQuestion);
81
    }
82
83
    /**
84
     * Get the default javascript confirm function
85
     *
86
     * @return QuestionContract
87
     */
88
    public function getDefaultQuestion()
89
    {
90
        return $this->xDefaultQuestion;
91
    }
92
93
    /**
94
     * Set the javascript alert function
95
     *
96
     * @param MessageContract           $xMessage       The javascript alert function
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 11 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 7 found
Loading history...
97
     *
98
     * @return void
99
     */
100
    public function setMessage(MessageContract $xMessage)
101
    {
102
        $this->xMessage = $xMessage;
103
    }
104
105
    /**
106
     * Get the javascript alert function
107
     *
108
     * @return MessageContract
109
     */
110
    public function getMessage()
111
    {
112
        return (($this->xMessage) ? $this->xMessage : $this->xDefaultMessage);
113
    }
114
115
    /**
116
     * Get the default javascript alert function
117
     *
118
     * @return Message
119
     */
120
    public function getDefaultMessage()
121
    {
122
        return $this->xDefaultMessage;
123
    }
124
125
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $question should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $yesScript should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $noScript should have a doc-comment as per coding-style.
Loading history...
126
     * Get the script which makes a call only if the user answers yes to the given question
127
     *
128
     * It is a function of the Question interface.
129
     *
130
     * @return string
131
     */
132
    public function confirm($question, $yesScript, $noScript)
133
    {
134
        return $this->getQuestion()->confirm($question, $yesScript, $noScript);
135
    }
136
137
    /**
138
     * Print a success message.
139
     *
140
     * It is a function of the Message interface.
141
     *
142
     * @param string              $message              The text of the message
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 14 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 14 found
Loading history...
143
     * @param string|null         $title                The title of the message
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 9 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 16 found
Loading history...
144
     *
145
     * @return string|void
146
     */
147
    public function success($message, $title = null)
148
    {
149
        return $this->getMessage()->success($message, $title);
150
    }
151
152
    /**
153
     * Print an information message.
154
     *
155
     * It is a function of the Message interface.
156
     *
157
     * @param string              $message              The text of the message
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 14 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 14 found
Loading history...
158
     * @param string|null         $title                The title of the message
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 9 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 16 found
Loading history...
159
     *
160
     * @return string|void
161
     */
162
    public function info($message, $title = null)
163
    {
164
        return $this->getMessage()->info($message, $title);
165
    }
166
167
    /**
168
     * Print a warning message.
169
     *
170
     * It is a function of the Message interface.
171
     *
172
     * @param string              $message              The text of the message
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 14 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 14 found
Loading history...
173
     * @param string|null         $title                The title of the message
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 9 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 16 found
Loading history...
174
     *
175
     * @return string|void
176
     */
177
    public function warning($message, $title = null)
178
    {
179
        return $this->getMessage()->warning($message, $title);
180
    }
181
182
    /**
183
     * Print an error message.
184
     *
185
     * It is a function of the Message interface.
186
     *
187
     * @param string              $message              The text of the message
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 14 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 14 found
Loading history...
188
     * @param string|null         $title                The title of the message
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 9 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 16 found
Loading history...
189
     *
190
     * @return string|void
191
     */
192
    public function error($message, $title = null)
193
    {
194
        return $this->getMessage()->error($message, $title);
195
    }
196
}
197