Passed
Push — v5.x ( 26d105...7911f3 )
by Thierry
03:11
created

ScriptTrait::alert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * ScriptTrait.php
5
 *
6
 * Provides javascript related commands for the Response
7
 *
8
 * @author Thierry Feuzeu <[email protected]>
9
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
10
 * @link https://github.com/jaxon-php/jaxon-core
11
 */
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...
12
13
namespace Jaxon\Response\Traits;
14
15
use Jaxon\Response\ResponseInterface;
16
17
use function func_get_args;
18
use function array_shift;
19
20
trait ScriptTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait ScriptTrait
Loading history...
21
{
22
    /**
23
     * Add a response command to the array of commands that will be sent to the browser
24
     *
25
     * @param array $aAttributes    Associative array of attributes that will describe the command
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
26
     * @param mixed $mData    The data to be associated with this command
0 ignored issues
show
Coding Style introduced by
Expected 7 spaces after parameter name; 4 found
Loading history...
27
     *
28
     * @return ResponseInterface
29
     */
30
    abstract public function addCommand(array $aAttributes, $mData): ResponseInterface;
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
31
32
    /**
33
     * Add a response command to the array of commands that will be sent to the browser
34
     *
35
     * @param string $sName    The command name
0 ignored issues
show
Coding Style introduced by
Expected 8 spaces after parameter name; 4 found
Loading history...
36
     * @param array $aAttributes    Associative array of attributes that will describe the command
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
37
     * @param mixed $mData    The data to be associated with this command
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter name; 4 found
Loading history...
38
     * @param bool $bRemoveEmpty    If true, remove empty attributes
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
39
     *
40
     * @return ResponseInterface
41
     */
42
    abstract protected function _addCommand(string $sName, array $aAttributes,
43
        $mData, bool $bRemoveEmpty = false): ResponseInterface;
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
44
45
    /**
46
     * Response command that prompts user with [ok] [cancel] style message box
47
     *
48
     * If the user clicks cancel, the specified number of response commands
49
     * following this one, will be skipped.
50
     *
51
     * @param integer $nCommandCount    The number of commands to skip upon cancel
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
52
     * @param string $sMessage    The message to display to the user
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter name; 4 found
Loading history...
53
     *
54
     * @return ResponseInterface
55
     */
56
    public function confirmCommands(int $nCommandCount, string $sMessage): ResponseInterface
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
57
    {
58
        $aAttributes = ['count' => $nCommandCount];
59
        return $this->_addCommand('cc', $aAttributes, $sMessage);
60
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
61
62
    /**
63
     * Add a command to call the specified javascript function with the given (optional) parameters
64
     *
65
     * @param string $sFunc    The name of the function to call
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
66
     *
67
     * @return ResponseInterface
68
     */
69
    public function call(string $sFunc): ResponseInterface
70
    {
71
        $aArgs = func_get_args();
72
        array_shift($aArgs);
73
        $aAttributes = ['cmd' => 'jc', 'func' => $sFunc];
74
        return $this->addCommand($aAttributes, $aArgs);
75
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
76
77
    /**
78
     * Add a command to display an alert message to the user
79
     *
80
     * @param string $sMessage    The message to be displayed
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
81
     *
82
     * @return ResponseInterface
83
     */
84
    public function alert(string $sMessage): ResponseInterface
85
    {
86
        return $this->_addCommand('al', [], $sMessage);
87
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
88
89
    /**
90
     * Add a command to display a debug message to the user
91
     *
92
     * @param string $sMessage    The message to be displayed
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
93
     *
94
     * @return ResponseInterface
95
     */
96
    public function debug(string $sMessage): ResponseInterface
97
    {
98
        return $this->_addCommand('dbg', [], $sMessage);
99
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
100
101
    /**
102
     * Add a command to ask the browser to navigate to the specified URL
103
     *
104
     * @param string $sURL    The relative or fully qualified URL
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 4 found
Loading history...
105
     * @param integer $nDelay    Number of seconds to delay before the redirect occurs
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
106
     *
107
     * @return ResponseInterface
108
     */
109
    public function redirect(string $sURL, int $nDelay = 0): ResponseInterface
110
    {
111
        $sURL = $this->xPluginManager->getParameterReader()->parseUrl($sURL);
112
        return $this->_addCommand('rd', ['delay' => $nDelay], $sURL);
113
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
114
115
    /**
116
     * Add a command to make Jaxon to pause execution of the response commands,
117
     * returning control to the browser so it can perform other commands asynchronously.
118
     *
119
     * After the specified delay, Jaxon will continue execution of the response commands.
120
     *
121
     * @param integer $tenths    The number of 1/10ths of a second to sleep
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
122
     *
123
     * @return ResponseInterface
124
     */
125
    public function sleep(int $tenths): ResponseInterface
126
    {
127
        $aAttributes = ['cmd' =>'s', 'prop' => $tenths];
0 ignored issues
show
Coding Style introduced by
Expected 1 space after "=>"; 0 found
Loading history...
128
        return $this->addCommand($aAttributes, '');
129
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
130
}
131