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

NotyLibrary::getVersion()   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 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * DialogLibraryInterface.php - Adapter for the Noty 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\Noty;
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
use Jaxon\Ui\Dialog\QuestionInterface;
0 ignored issues
show
Bug introduced by
The type Jaxon\Ui\Dialog\QuestionInterface 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...
18
19
class NotyLibrary extends AbstractDialogLibrary implements MessageInterface, QuestionInterface
20
{
21
    /**
22
     * @const The library name
23
     */
24
    const NAME = 'noty';
25
26
    /**
27
     * @inheritDoc
28
     */
29
    public function getName(): string
30
    {
31
        return self::NAME;
32
    }
33
34
    /**
35
     * @inheritDoc
36
     */
37
    public function getSubdir(): string
38
    {
39
        return 'noty';
40
    }
41
42
    /**
43
     * @inheritDoc
44
     */
45
    public function getVersion(): string
46
    {
47
        return '2.3.11';
48
    }
49
50
    /**
51
     * @inheritDoc
52
     */
53
    public function getJs(): string
54
    {
55
        return $this->xHelper->getJsCode('jquery.noty.packaged.min.js');
56
    }
57
58
    /**
59
     * @inheritDoc
60
     */
61
    public function getScript(): string
62
    {
63
         return $this->xHelper->render('noty/alert.js');
64
    }
65
66
    /**
67
     * @inheritDoc
68
     */
69
    public function getReadyScript(): string
70
    {
71
         return $this->xHelper->render('noty/ready.js.php');
72
    }
73
74
    /**
75
     * Print an alert message.
76
     *
77
     * @param string $sMessage The text of the message
78
     * @param string $sTitle The title of the message
79
     * @param string $sType The type of the message
80
     *
81
     * @return string
82
     */
83
    protected function alert(string $sMessage, string $sTitle, string $sType): string
84
    {
85
        if($this->returnCode())
86
        {
87
            return "noty({text:" . $sMessage . ", type:'" . $sType . "', layout: 'topCenter'})";
88
        }
89
        $aOptions = array('text' => $sMessage, 'type' => $sType);
90
        // Show the alert
91
        $this->addCommand(array('cmd' => 'noty.alert'), $aOptions);
92
        return '';
93
    }
94
95
    /**
96
     * @inheritDoc
97
     */
98
    public function success(string $sMessage, string $sTitle = ''): string
99
    {
100
        return $this->alert($sMessage, $sTitle, 'success');
101
    }
102
103
    /**
104
     * @inheritDoc
105
     */
106
    public function info(string $sMessage, string $sTitle = ''): string
107
    {
108
        return $this->alert($sMessage, $sTitle, 'information');
109
    }
110
111
    /**
112
     * @inheritDoc
113
     */
114
    public function warning(string $sMessage, string $sTitle = ''): string
115
    {
116
        return $this->alert($sMessage, $sTitle, 'warning');
117
    }
118
119
    /**
120
     * @inheritDoc
121
     */
122
    public function error(string $sMessage, string $sTitle = ''): string
123
    {
124
        return $this->alert($sMessage, $sTitle, 'error');
125
    }
126
127
    /**
128
     * @inheritDoc
129
     */
130
    public function confirm(string $sQuestion, string $sYesScript, string $sNoScript): string
131
    {
132
        $sTitle = $this->xHelper->getQuestionTitle();
0 ignored issues
show
Unused Code introduced by
The assignment to $sTitle is dead and can be removed.
Loading history...
133
        if(!$sNoScript)
134
        {
135
            return "jaxon.dialogs.noty.confirm(" . $sQuestion . ",'',function(){" . $sYesScript . ";})";
136
        }
137
        else
138
        {
139
            return "jaxon.dialogs.noty.confirm(" . $sQuestion . ",'',function(){" . $sYesScript . ";},function(){" . $sNoScript . ";})";
140
        }
141
    }
142
}
143