Passed
Push — v5.x ( 57c2ac...73bdb8 )
by Thierry
16:58 queued 05:55
created

DialogPlugin::info()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
/**
4
 * DialogPlugin.php - ModalInterface, message and question dialogs for Jaxon.
5
 *
6
 * Show modal, message and question dialogs with various javascript libraries
7
 * based on user settings.
8
 *
9
 * @package jaxon-core
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
10
 * @author Thierry Feuzeu <[email protected]>
11
 * @copyright 2016 Thierry Feuzeu <[email protected]>
12
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
13
 * @link https://github.com/jaxon-php/jaxon-dialogs
14
 */
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...
15
16
namespace Jaxon\Plugin\Response\Dialog;
17
18
use Jaxon\App\Dialog\Library\DialogLibraryManager;
19
use Jaxon\App\Dialog\MessageInterface;
20
use Jaxon\Exception\SetupException;
21
use Jaxon\Plugin\ResponsePlugin;
22
use Jaxon\Response\ResponseInterface;
23
24
use function array_reduce;
25
use function trim;
26
27
class DialogPlugin extends ResponsePlugin
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class DialogPlugin
Loading history...
28
{
29
    use DialogPluginTrait;
30
31
    /**
32
     * @const The plugin name
33
     */
34
    const NAME = 'dialog';
35
36
    /**
37
     * @var DialogLibraryManager
38
     */
39
    protected $xLibraryManager;
40
41
    /**
42
     * @var array
43
     */
44
    protected $aLibraries = null;
45
46
    /**
47
     * The constructor
48
     *
49
     * @param DialogLibraryManager $xLibraryManager
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
50
     */
51
    public function __construct(DialogLibraryManager $xLibraryManager)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
52
    {
53
        $this->xLibraryManager = $xLibraryManager;
54
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
55
56
    /**
57
     * @inheritDoc
58
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
59
    public function getName(): string
60
    {
61
        return self::NAME;
62
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
63
64
    /**
65
     * @inheritDoc
66
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
67
    public function getHash(): string
68
    {
69
        // The version number is used as hash
70
        return '4.0.0';
71
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
72
73
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $xResponse should have a doc-comment as per coding-style.
Loading history...
74
     * @inheritDoc
75
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
76
    public function setResponse(ResponseInterface $xResponse)
77
    {
78
        parent::setResponse($xResponse);
79
80
        // Hack the setResponse() method, to set the default libraries on each access to this plugin.
81
        $this->xLibraryManager->setNextLibrary('');
82
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
83
84
    /**
85
     * Set the library to use for the next call.
86
     *
87
     * @param string $sLibrary The name of the library
88
     *
89
     * @return DialogPlugin
90
     */
91
    public function with(string $sLibrary): DialogPlugin
92
    {
93
        $this->xLibraryManager->setNextLibrary($sLibrary);
94
        return $this;
95
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
96
97
    /**
98
     * @return array
99
     */
100
    private function getLibraries(): array
101
    {
102
        if($this->aLibraries === null)
103
        {
104
            $this->aLibraries = $this->xLibraryManager->getLibraries();
105
        }
106
        return $this->aLibraries;
107
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
108
109
    /**
110
     * @inheritDoc
111
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
112
    public function getJs(): string
113
    {
114
        return array_reduce($this->getLibraries(), function($sCode, $xLibrary) {
115
            return $sCode . $xLibrary->getJs() . "\n\n";
116
        }, '');
117
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
118
119
    /**
120
     * @inheritDoc
121
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
122
    public function getCss(): string
123
    {
124
        return array_reduce($this->getLibraries(), function($sCode, $xLibrary) {
125
            return $sCode . trim($xLibrary->getCss()) . "\n\n";
126
        }, '');
127
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
128
129
    /**
130
     * @inheritDoc
131
     * @throws SetupException
132
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
133
    public function getScript(): string
134
    {
135
        return array_reduce($this->getLibraries(), function($sCode, $xLibrary) {
136
            return $sCode . trim($xLibrary->getScript()) . "\n\n";
137
        }, "jaxon.dialogs = {};\n");
138
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
139
140
    /**
141
     * @inheritDoc
142
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
143
    public function getReadyScript(): string
144
    {
145
        return array_reduce($this->getLibraries(), function($sCode, $xLibrary) {
146
            return $sCode . trim($xLibrary->getReadyScript()) . "\n\n";
147
        }, '');
148
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
149
150
    /**
151
     * Show a modal dialog.
152
     *
153
     * @param string $sTitle The title of the dialog
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter name; 1 found
Loading history...
154
     * @param string $sContent The content of the dialog
155
     * @param array $aButtons The buttons of the dialog
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
156
     * @param array $aOptions The options of the dialog
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
157
     *
158
     * @return void
159
     */
160
    public function show(string $sTitle, string $sContent, array $aButtons = [], array $aOptions = [])
161
    {
162
        // Show the modal dialog
163
        $aResponse = $this->xLibraryManager->show($sTitle, $sContent, $aButtons, $aOptions);
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...
164
        $aResponse['lib'] = $this->xLibraryManager->getModalLibrary()->getName();
165
        $this->addCommand('dialog.modal.show', $aResponse);
166
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
167
168
    /**
169
     * Hide the modal dialog.
170
     *
171
     * @return void
172
     */
173
    public function hide()
174
    {
175
        // Hide the modal dialog
176
        $aResponse = $this->xLibraryManager->hide();
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...
177
        $aResponse['lib'] = $this->xLibraryManager->getModalLibrary()->getName();
178
        $this->addCommand('dialog.modal.hide', $aResponse);
179
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
180
181
    /**
182
     * Set the title of the next message.
183
     *
184
     * @param string $sTitle     The title of the message
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 5 found
Loading history...
185
     *
186
     * @return MessageInterface
187
     */
188
    public function title(string $sTitle): MessageInterface
189
    {
190
        return $this->xLibraryManager->title($sTitle);
191
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
192
193
    /**
194
     * Show a success message.
195
     *
196
     * @param string $sMessage  The text of the message
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 2 found
Loading history...
197
     * @param array $aArgs      The message arguments
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter name; 6 found
Loading history...
198
     *
199
     * @return void
200
     */
201
    public function success(string $sMessage, array $aArgs = [])
202
    {
203
        $aResponse = $this->xLibraryManager->success($sMessage, $aArgs);
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...
204
        $aResponse['lib'] = $this->xLibraryManager->getMessageLibrary()->getName();
205
        $this->addCommand('dialog.message', $aResponse);
206
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
207
208
    /**
209
     * Show an information message.
210
     *
211
     * @param string $sMessage  The text of the message
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 2 found
Loading history...
212
     * @param array $aArgs      The message arguments
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter name; 6 found
Loading history...
213
     *
214
     * @return void
215
     */
216
    public function info(string $sMessage, array $aArgs = [])
217
    {
218
        $aResponse = $this->xLibraryManager->info($sMessage, $aArgs);
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...
219
        $aResponse['lib'] = $this->xLibraryManager->getMessageLibrary()->getName();
220
        $this->addCommand('dialog.message', $aResponse);
221
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
222
223
    /**
224
     * Show a warning message.
225
     *
226
     * @param string $sMessage  The text of the message
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 2 found
Loading history...
227
     * @param array $aArgs      The message arguments
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter name; 6 found
Loading history...
228
     *
229
     * @return void
230
     */
231
    public function warning(string $sMessage, array $aArgs = [])
232
    {
233
        $aResponse = $this->xLibraryManager->warning($sMessage, $aArgs);
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...
234
        $aResponse['lib'] = $this->xLibraryManager->getMessageLibrary()->getName();
235
        $this->addCommand('dialog.message', $aResponse);
236
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
237
238
    /**
239
     * Show an error message.
240
     *
241
     * @param string $sMessage  The text of the message
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 2 found
Loading history...
242
     * @param array $aArgs      The message arguments
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter name; 6 found
Loading history...
243
     *
244
     * @return void
245
     */
246
    public function error(string $sMessage, array $aArgs = [])
247
    {
248
        $aResponse = $this->xLibraryManager->error($sMessage, $aArgs);
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...
249
        $aResponse['lib'] = $this->xLibraryManager->getMessageLibrary()->getName();
250
        $this->addCommand('dialog.message', $aResponse);
251
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
252
}
253