Passed
Push — master ( 6eb156...b34d93 )
by Thierry
04:25
created

AlertLibrary::confirm()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * AlertLibrary.php
5
 *
6
 * Implements the dialog message and question features using the js alert and confirm functions.
7
 *
8
 * @package jaxon-dialogs
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-dialogs" is not valid; consider "Jaxondialogs" instead
Loading history...
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2016 Thierry Feuzeu <[email protected]>
11
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
12
 * @link https://github.com/jaxon-php/jaxon-core
13
 */
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...
14
15
namespace Jaxon\Ui\Dialogs;
16
17
class AlertLibrary implements MessageInterface, QuestionInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class AlertLibrary
Loading history...
18
{
19
    use LibraryTrait;
20
21
    /**
22
     * Get the script which makes a call only if the user answers yes to the given question
23
     *
24
     * @param string  $sQuestion
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...
25
     * @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...
26
     * @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...
27
     *
28
     * @return string
29
     */
30
    public function confirm(string $sQuestion, string $sYesScript, string $sNoScript): string
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
31
    {
32
        return empty($sNoScript) ? 'if(confirm(' . $sQuestion . ')){' . $sYesScript . ';}' :
0 ignored issues
show
Coding Style introduced by
Expected 1 space after ":"; newline found
Loading history...
33
            'if(confirm(' . $sQuestion . ')){' . $sYesScript . ';}else{' . $sNoScript . ';}';
34
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
35
36
    /**
37
     * Print an alert message.
38
     *
39
     * @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...
40
     *
41
     * @return string
42
     */
43
    private function alert(string $sMessage): string
44
    {
45
        if($this->getReturn())
46
        {
47
            return 'alert(' . $sMessage . ')';
48
        }
49
        if($this->xResponse !== null)
50
        {
51
            $this->xResponse->alert($sMessage);
52
        }
53
        return '';
54
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
55
56
    /**
57
     * Print a success message.
58
     *
59
     * @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...
60
     * @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...
61
     *
62
     * @return string
63
     */
64
    public function success(string $sMessage, string $sTitle = ''): string
65
    {
66
        return $this->alert($sMessage);
67
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
68
69
    /**
70
     * Print an information message.
71
     *
72
     * @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...
73
     * @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...
74
     *
75
     * @return string
76
     */
77
    public function info(string $sMessage, string $sTitle = ''): string
78
    {
79
        return $this->alert($sMessage);
80
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
81
82
    /**
83
     * Print a warning message.
84
     *
85
     * @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...
86
     * @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...
87
     *
88
     * @return string
89
     */
90
    public function warning(string $sMessage, string $sTitle = ''): string
91
    {
92
        return $this->alert($sMessage);
93
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
94
95
    /**
96
     * Print an error message.
97
     *
98
     * @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...
99
     * @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...
100
     *
101
     * @return string
102
     */
103
    public function error(string $sMessage, string $sTitle = ''): string
104
    {
105
        return $this->alert($sMessage);
106
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
107
}
108