Passed
Push — v5.x ( 0160d0 )
by Thierry
09:10
created

XDialogLibrary::warning()   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
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * XDialogLibrary.php
5
 *
6
 * Adapter for the XDialog library.
7
 *
8
 * @package jaxon-dialogs
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2022 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-dialogs
13
 */
14
15
namespace Jaxon\Dialogs\XDialog;
16
17
use Jaxon\App\Dialog\Library\DialogLibraryTrait;
18
use Jaxon\App\Dialog\Library\MessageTrait;
0 ignored issues
show
Bug introduced by
The type Jaxon\App\Dialog\Library\MessageTrait was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Jaxon\App\Dialog\Library\QuestionTrait;
0 ignored issues
show
Bug introduced by
The type Jaxon\App\Dialog\Library\QuestionTrait was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Jaxon\App\Dialog\ModalInterface;
21
use Jaxon\App\Dialog\MessageInterface;
22
use Jaxon\App\Dialog\QuestionInterface;
23
24
class XDialogLibrary implements ModalInterface, MessageInterface, QuestionInterface
25
{
26
    use DialogLibraryTrait;
27
    use MessageTrait;
28
    use QuestionTrait;
29
30
    /**
31
     * @const The library name
32
     */
33
    const NAME = 'xdialog';
34
35
    /**
36
     * @inheritDoc
37
     */
38
    public function getName(): string
39
    {
40
        return self::NAME;
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46
    public function getUri(): string
47
    {
48
        return 'https://cdn.jsdelivr.net/gh/xxjapp/xdialog@3';
49
    }
50
51
    /**
52
     * @inheritDoc
53
     */
54
    public function getCss(): string
55
    {
56
        return $this->helper()->getCssCode('xdialog.min.css');
57
    }
58
59
    /**
60
     * @inheritDoc
61
     */
62
    public function getJs(): string
63
    {
64
        return $this->helper()->getJsCode('xdialog.min.js');
65
    }
66
67
    /**
68
     * @inheritDoc
69
     */
70
    public function getScript(): string
71
    {
72
        return $this->helper()->render('xdialog/alert.js');
73
    }
74
75
    /**
76
     * @inheritDoc
77
     */
78
    public function getReadyScript(): string
79
    {
80
        return $this->helper()->render('xdialog/ready.js.php');
81
    }
82
83
    /**
84
     * @inheritDoc
85
     */
86
    public function show(string $sTitle, string $sContent, array $aButtons, array $aOptions = [])
87
    {
88
        $aOptions['title'] = $sTitle;
89
        $aOptions['body'] = $sContent;
90
        $aOptions['buttons'] = [];
91
        foreach($aButtons as $aButton)
92
        {
93
            if($aButton['click'] === 'close')
94
            {
95
                $aOptions['buttons']['cancel'] = $aButton['title'];
96
                $aOptions['oncancel'] = 'jaxon.dialogs.xdialog.hide()';
97
            }
98
            else
99
            {
100
                $aOptions['buttons']['ok'] = $aButton['title'];
101
                $aOptions['onok'] = $aButton['click'];
102
            }
103
        }
104
105
        // Assign dialog content
106
        $this->addCommand('xdialog.show', $aOptions);
0 ignored issues
show
Bug introduced by
'xdialog.show' of type string is incompatible with the type array expected by parameter $aAttributes of Jaxon\Dialogs\XDialog\XDialogLibrary::addCommand(). ( Ignorable by Annotation )

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

106
        $this->addCommand(/** @scrutinizer ignore-type */ 'xdialog.show', $aOptions);
Loading history...
107
    }
108
109
    /**
110
     * @inheritDoc
111
     */
112
    public function hide()
113
    {
114
        $this->addCommand('xdialog.hide', []);
0 ignored issues
show
Bug introduced by
'xdialog.hide' of type string is incompatible with the type array expected by parameter $aAttributes of Jaxon\Dialogs\XDialog\XDialogLibrary::addCommand(). ( Ignorable by Annotation )

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

114
        $this->addCommand(/** @scrutinizer ignore-type */ 'xdialog.hide', []);
Loading history...
115
    }
116
117
    /**
118
     * @inheritDoc
119
     */
120
    protected function alert(string $sMessage, string $sTitle, string $sType)
121
    {
122
        $this->addCommand("xdialog.$sType", ['body' => $sMessage, 'title' => $sTitle]);
0 ignored issues
show
Bug introduced by
'xdialog.'.$sType of type string is incompatible with the type array expected by parameter $aAttributes of Jaxon\Dialogs\XDialog\XDialogLibrary::addCommand(). ( Ignorable by Annotation )

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

122
        $this->addCommand(/** @scrutinizer ignore-type */ "xdialog.$sType", ['body' => $sMessage, 'title' => $sTitle]);
Loading history...
123
    }
124
}
125