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

BootboxLibrary::warning()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * BootboxLibrary.php
5
 *
6
 * Adapter for the Bootbox library.
7
 *
8
 * @package jaxon-dialogs
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-dialogs
13
 */
14
15
namespace Jaxon\Dialogs\Bootbox;
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 BootboxLibrary 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 = 'bootbox';
34
35
    /**
36
     * @inheritDoc
37
     */
38
    public function getName(): string
39
    {
40
        return self::NAME;
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46
    public function getSubdir(): string
47
    {
48
        return 'bootbox';
49
    }
50
51
    /**
52
     * @inheritDoc
53
     */
54
    public function getVersion(): string
55
    {
56
        return '4.3.0';
57
    }
58
59
    /**
60
     * The id of the HTML container block
61
     *
62
     * @return string
63
     */
64
    protected function getContainer(): string
65
    {
66
        return $this->helper()->getOption('dom.container', 'bootbox-container');
67
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72
    public function getJs(): string
73
    {
74
        return $this->helper()->getJsCode('bootbox.min.js');
75
    }
76
77
    /**
78
     * @inheritDoc
79
     */
80
    public function getScript(): string
81
    {
82
        return $this->helper()->render('bootbox/alert.js');
83
    }
84
85
    /**
86
     * @inheritDoc
87
     */
88
    public function getReadyScript(): string
89
    {
90
        return $this->helper()->render('bootbox/ready.js.php', ['container' => $this->getContainer()]);
91
    }
92
93
    /**
94
     * @inheritDoc
95
     */
96
    public function show(string $sTitle, string $sContent, array $aButtons, array $aOptions = [])
97
    {
98
        // ModalInterface container
99
        $sContainer = $this->getContainer();
100
        $html = $this->helper()->render('bootbox/dialog.html',
101
            ['title' => $sTitle, 'content' => $sContent, 'buttons' => $aButtons]);
102
103
        // Assign dialog content
104
        $this->response()->assign($sContainer, 'innerHTML', $html);
105
        $this->response()->jq('#styledModal')->modal('show');
106
        if(isset($aOptions['width']))
107
        {
108
            // Set the value of the dialog width
109
            $width = $aOptions['width'];
110
            $this->response()->jq('.modal-dialog')->css('width', "{$width}px");
111
        }
112
    }
113
114
    /**
115
     * @inheritDoc
116
     */
117
    public function hide()
118
    {
119
        $this->response()->jq('#styledModal')->modal('hide');
120
    }
121
122
    /**
123
     * @inheritDoc
124
     */
125
    protected function alert(string $sMessage, string $sTitle, string $sStdType)
126
    {
127
        $aTypes = [
128
            'error' => 'danger',
129
        ];
130
        $sType = $aTypes[$sStdType] ?? $sStdType;
131
        $this->addCommand('bootbox', ['type' => $sType, 'content' => $sMessage, 'title' => $sTitle]);
0 ignored issues
show
Bug introduced by
'bootbox' of type string is incompatible with the type array expected by parameter $aAttributes of Jaxon\Dialogs\Bootbox\BootboxLibrary::addCommand(). ( Ignorable by Annotation )

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

131
        $this->addCommand(/** @scrutinizer ignore-type */ 'bootbox', ['type' => $sType, 'content' => $sMessage, 'title' => $sTitle]);
Loading history...
132
    }
133
}
134