Passed
Push — master ( b34d93...aea763 )
by Thierry
03:02 queued 24s
created

AlertLibrary::error()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
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-core
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-core" is not valid; consider "Jaxoncore" 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\Dialog\Library;
16
17
use Jaxon\Ui\Dialog\MessageInterface;
18
use Jaxon\Ui\Dialog\QuestionInterface;
19
20
class AlertLibrary implements MessageInterface, QuestionInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class AlertLibrary
Loading history...
21
{
22
    use DialogLibraryTrait;
23
24
    /**
25
     * Get the script which makes a call only if the user answers yes to the given question
26
     *
27
     * @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...
28
     * @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...
29
     * @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...
30
     *
31
     * @return string
32
     */
33
    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...
34
    {
35
        return empty($sNoScript) ? 'if(confirm(' . $sQuestion . ')){' . $sYesScript . ';}' :
0 ignored issues
show
Coding Style introduced by
Expected 1 space after ":"; newline found
Loading history...
36
            'if(confirm(' . $sQuestion . ')){' . $sYesScript . ';}else{' . $sNoScript . ';}';
37
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
38
39
    /**
40
     * Print an alert message.
41
     *
42
     * @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...
43
     *
44
     * @return string
45
     */
46
    private function alert(string $sMessage): string
47
    {
48
        if($this->returnCode())
49
        {
50
            return 'alert(' . $sMessage . ')';
51
        }
52
        $this->xResponse->alert($sMessage);
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