Passed
Push — master ( 0c5836...7e4fb9 )
by Thierry
02:39
created

ToastrLibrary::getReadyScript()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * DialogLibraryInterface.php - Adapter for the Toastr library.
5
 *
6
 * @package jaxon-dialogs
7
 * @author Thierry Feuzeu <[email protected]>
8
 * @copyright 2016 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-dialogs
11
 */
12
13
namespace Jaxon\Dialogs\Library\Toastr;
14
15
use Jaxon\Ui\Dialog\Library\AbstractDialogLibrary;
0 ignored issues
show
Bug introduced by
The type Jaxon\Ui\Dialog\Library\AbstractDialogLibrary 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...
16
use Jaxon\Ui\Dialog\MessageInterface;
0 ignored issues
show
Bug introduced by
The type Jaxon\Ui\Dialog\MessageInterface 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...
17
18
class ToastrLibrary extends AbstractDialogLibrary implements MessageInterface
19
{
20
    /**
21
     * @const The library name
22
     */
23
    const NAME = 'toastr';
24
25
    /**
26
     * @inheritDoc
27
     */
28
    public function getName(): string
29
    {
30
        return self::NAME;
31
    }
32
33
    /**
34
     * @inheritDoc
35
     */
36
    public function getSubdir(): string
37
    {
38
        return 'toastr.js';
39
    }
40
41
    /**
42
     * @inheritDoc
43
     */
44
    public function getVersion(): string
45
    {
46
        return '2.1.3';
47
    }
48
49
    /**
50
     * @inheritDoc
51
     */
52
    public function getJs(): string
53
    {
54
        return $this->xHelper->getJsCode('toastr.min.js');
55
    }
56
57
    /**
58
     * @inheritDoc
59
     */
60
    public function getCss(): string
61
    {
62
        return $this->xHelper->getCssCode('toastr.min.css');
63
    }
64
65
    /**
66
     * @inheritDoc
67
     */
68
    public function getScript(): string
69
    {
70
        return $this->xHelper->render('toastr/alert.js');
71
    }
72
73
    /**
74
     * @inheritDoc
75
     */
76
    public function getReadyScript(): string
77
    {
78
        return $this->xHelper->render('toastr/ready.js.php', [
79
            'options' =>  $this->xHelper->getOptionScript('toastr.options.', 'options.')
80
        ]);
81
    }
82
83
    /**
84
     * Print an alert message.
85
     *
86
     * @param string $sMessage The text of the message
87
     * @param string $sTitle The title of the message
88
     * @param string $sType The type of the message
89
     *
90
     * @return string
91
     */
92
    protected function alert(string $sMessage, string $sTitle, string $sType): string
93
    {
94
        if($this->returnCode())
95
        {
96
            return empty($sTitle) ? "toastr.$sType($sMessage)" : "toastr.$sType($sMessage, '$sTitle')";
97
        }
98
        $aOptions = ['message' => $sMessage, 'title' => $sTitle];
99
        // Show the alert
100
        $this->addCommand(['cmd' => 'toastr.' . $sType], $aOptions);
101
        return '';
102
    }
103
104
    /**
105
     * @inheritDoc
106
     */
107
    public function success(string $sMessage, string $sTitle = ''): string
108
    {
109
        return $this->alert($sMessage, $sTitle, 'success');
110
    }
111
112
    /**
113
     * @inheritDoc
114
     */
115
    public function info(string $sMessage, string $sTitle = ''): string
116
    {
117
        return $this->alert($sMessage, $sTitle, 'info');
118
    }
119
120
    /**
121
     * @inheritDoc
122
     */
123
    public function warning(string $sMessage, string $sTitle = ''): string
124
    {
125
        return $this->alert($sMessage, $sTitle, 'warning');
126
    }
127
128
    /**
129
     * @inheritDoc
130
     */
131
    public function error(string $sMessage, string $sTitle = ''): string
132
    {
133
        return $this->alert($sMessage, $sTitle, 'error');
134
    }
135
136
    public function remove()
137
    {
138
        $this->response()->script('toastr.remove()');
139
    }
140
141
    public function clear()
142
    {
143
        $this->response()->script('toastr.clear()');
144
    }
145
}
146