Issues (2884)

src/App/Dialog/Library/AlertLibrary.php (30 issues)

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
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
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
14
15
namespace Jaxon\App\Dialog\Library;
16
17
use Jaxon\App\Dialog\LibraryInterface;
18
use Jaxon\App\Dialog\MessageInterface;
19
use Jaxon\App\Dialog\QuestionInterface;
20
21
class AlertLibrary implements LibraryInterface, MessageInterface, QuestionInterface
0 ignored issues
show
Missing doc comment for class AlertLibrary
Loading history...
22
{
23
    use DialogLibraryTrait;
24
25
    /**
26
     * Get the library name
27
     *
28
     * @return string
29
     */
30
    public function getName(): string
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
31
    {
32
        return ''; // No name
33
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
34
35
    /**
36
     * Get the script which makes a call only if the user answers yes to the given question
37
     *
38
     * @param string  $sQuestion
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 1 spaces after parameter type; 2 found
Loading history...
39
     * @param string  $sYesScript
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 1 spaces after parameter type; 2 found
Loading history...
40
     * @param string  $sNoScript
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 1 spaces after parameter type; 2 found
Loading history...
41
     *
42
     * @return string
43
     */
44
    public function confirm(string $sQuestion, string $sYesScript, string $sNoScript): string
45
    {
46
        return empty($sNoScript) ? 'if(confirm(' . $sQuestion . ')){' . $sYesScript . ';}' :
0 ignored issues
show
Expected 1 space after ":"; newline found
Loading history...
47
            'if(confirm(' . $sQuestion . ')){' . $sYesScript . ';}else{' . $sNoScript . ';}';
48
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
49
50
    /**
51
     * Print an alert message.
52
     *
53
     * @param string $sMessage    The text of the message
0 ignored issues
show
Expected 1 spaces after parameter name; 4 found
Loading history...
54
     * @param string $sTitle    The title of the message
0 ignored issues
show
Expected 3 spaces after parameter name; 4 found
Loading history...
55
     *
56
     * @return string
57
     */
58
    private function alert(string $sMessage, string $sTitle): string
59
    {
60
        if(!empty($sTitle))
61
        {
62
            $sMessage = '<b>' . $sTitle . '</b><br/>' . $sMessage;
63
        }
64
        if($this->returnCode())
65
        {
66
            return 'alert(' . $sMessage . ')';
67
        }
68
        $this->xResponse->alert($sMessage, $sTitle);
0 ignored issues
show
The call to Jaxon\Response\Response::alert() has too many arguments starting with $sTitle. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
        $this->xResponse->/** @scrutinizer ignore-call */ 
69
                          alert($sMessage, $sTitle);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
69
        return '';
70
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
71
72
    /**
73
     * Print a success message.
74
     *
75
     * @param string $sMessage    The text of the message
0 ignored issues
show
Expected 1 spaces after parameter name; 4 found
Loading history...
76
     * @param string $sTitle    The title of the message
0 ignored issues
show
Expected 3 spaces after parameter name; 4 found
Loading history...
77
     *
78
     * @return string
79
     */
80
    public function success(string $sMessage, string $sTitle = ''): string
81
    {
82
        return $this->alert($sMessage, $sTitle);
83
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
84
85
    /**
86
     * Print an information message.
87
     *
88
     * @param string $sMessage    The text of the message
0 ignored issues
show
Expected 1 spaces after parameter name; 4 found
Loading history...
89
     * @param string $sTitle    The title of the message
0 ignored issues
show
Expected 3 spaces after parameter name; 4 found
Loading history...
90
     *
91
     * @return string
92
     */
93
    public function info(string $sMessage, string $sTitle = ''): string
94
    {
95
        return $this->alert($sMessage, $sTitle);
96
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
97
98
    /**
99
     * Print a warning message.
100
     *
101
     * @param string $sMessage    The text of the message
0 ignored issues
show
Expected 1 spaces after parameter name; 4 found
Loading history...
102
     * @param string $sTitle    The title of the message
0 ignored issues
show
Expected 3 spaces after parameter name; 4 found
Loading history...
103
     *
104
     * @return string
105
     */
106
    public function warning(string $sMessage, string $sTitle = ''): string
107
    {
108
        return $this->alert($sMessage, $sTitle);
109
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
110
111
    /**
112
     * Print an error message.
113
     *
114
     * @param string $sMessage    The text of the message
0 ignored issues
show
Expected 1 spaces after parameter name; 4 found
Loading history...
115
     * @param string $sTitle    The title of the message
0 ignored issues
show
Expected 3 spaces after parameter name; 4 found
Loading history...
116
     *
117
     * @return string
118
     */
119
    public function error(string $sMessage, string $sTitle = ''): string
120
    {
121
        return $this->alert($sMessage, $sTitle);
122
    }
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
123
}
124