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

MessageTrait::alert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 12
rs 9.9666
cc 1
nc 1
nop 3
1
<?php
2
3
/**
4
 * MessageTrait.php - Show alert messages.
5
 *
6
 * @package jaxon-core
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
7
 * @author Thierry Feuzeu <[email protected]>
8
 * @copyright 2024 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...
12
13
namespace Jaxon\App\Dialog\Library;
14
15
use Jaxon\App\Dialog\MessageInterface;
16
use Jaxon\Request\Call\Parameter;
17
18
use function array_map;
19
20
trait MessageTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait MessageTrait
Loading history...
21
{
22
    /**
23
     * The next message title
24
     *
25
     * @var string
26
     */
27
    private $sTitle = '';
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
28
29
    /**
30
     * Set the title of the next message.
31
     *
32
     * @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...
33
     *
34
     * @return MessageInterface
35
     */
36
    public function title(string $sTitle): MessageInterface
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
37
    {
38
        $this->sTitle = $sTitle;
39
40
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Jaxon\App\Dialog\Library\MessageTrait which is incompatible with the type-hinted return Jaxon\App\Dialog\MessageInterface.
Loading history...
41
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
42
43
    /**
44
     * Print an alert message.
45
     *
46
     * @param string $sType     The type of the message
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces after parameter name; 5 found
Loading history...
47
     * @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...
48
     * @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...
49
     *
50
     * @return array
51
     */
52
    private function alert(string $sType, string $sMessage, array $aArgs): array
53
    {
54
        $sTitle = $this->sTitle;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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...
55
        $this->sTitle = '';
56
57
        return [
58
            'type' => $sType,
59
            'message' => [
60
                'title' => $sTitle,
61
                'phrase' => [
62
                    'str' => $sMessage,
63
                    'args' => array_map(fn($xArg) => Parameter::make($xArg), $aArgs),
64
                ],
65
            ],
66
        ];
67
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
68
69
    /**
70
     * Show a success 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; 2 found
Loading history...
73
     * @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...
74
     *
75
     * @return array
76
     */
77
    public function success(string $sMessage, array $aArgs = []): array
78
    {
79
        return $this->alert('success', $sMessage, $aArgs);
80
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
81
82
    /**
83
     * Show an information 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; 2 found
Loading history...
86
     * @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...
87
     *
88
     * @return array
89
     */
90
    public function info(string $sMessage, array $aArgs = []): array
91
    {
92
        return $this->alert('info', $sMessage, $aArgs);
93
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
94
95
    /**
96
     * Show a warning 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; 2 found
Loading history...
99
     * @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...
100
     *
101
     * @return array
102
     */
103
    public function warning(string $sMessage, array $aArgs = []): array
104
    {
105
        return $this->alert('warning', $sMessage, $aArgs);
106
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
107
108
    /**
109
     * Show an error message.
110
     *
111
     * @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...
112
     * @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...
113
     *
114
     * @return array
115
     */
116
    public function error(string $sMessage, array $aArgs = []): array
117
    {
118
        return $this->alert('error', $sMessage, $aArgs);
119
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
120
}
121