Passed
Push — master ( 2cb546...9b3a22 )
by Thierry
08:13
created

NotyLibrary   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 122
rs 10
c 0
b 0
f 0
wmc 14

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getJs() 0 3 1
A confirm() 0 9 2
A getScript() 0 3 1
A getReadyScript() 0 3 1
A warning() 0 3 1
A getVersion() 0 3 1
A getSubdir() 0 3 1
A alert() 0 10 2
A error() 0 3 1
A info() 0 3 1
A success() 0 3 1
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\Noty;
14
15
use Jaxon\App\Dialog\Library\DialogLibraryTrait;
16
use Jaxon\App\Dialog\LibraryInterface;
17
use Jaxon\App\Dialog\MessageInterface;
18
use Jaxon\App\Dialog\QuestionInterface;
19
20
class NotyLibrary implements LibraryInterface, MessageInterface, QuestionInterface
21
{
22
    use DialogLibraryTrait;
23
24
    /**
25
     * @const The library name
26
     */
27
    const NAME = 'noty';
28
29
    /**
30
     * @inheritDoc
31
     */
32
    public function getName(): string
33
    {
34
        return self::NAME;
35
    }
36
37
    /**
38
     * @inheritDoc
39
     */
40
    public function getSubdir(): string
41
    {
42
        return 'noty';
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48
    public function getVersion(): string
49
    {
50
        return '2.3.11';
51
    }
52
53
    /**
54
     * @inheritDoc
55
     */
56
    public function getJs(): string
57
    {
58
        return $this->helper()->getJsCode('jquery.noty.packaged.min.js');
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64
    public function getScript(): string
65
    {
66
         return $this->helper()->render('noty/alert.js');
67
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72
    public function getReadyScript(): string
73
    {
74
         return $this->helper()->render('noty/ready.js.php');
75
    }
76
77
    /**
78
     * Print an alert message.
79
     *
80
     * @param string $sMessage The text of the message
81
     * @param string $sTitle The title of the message
82
     * @param string $sType The type of the message
83
     *
84
     * @return string
85
     */
86
    protected function alert(string $sMessage, string $sTitle, string $sType): string
0 ignored issues
show
Unused Code introduced by
The parameter $sTitle is not used and could be removed. ( Ignorable by Annotation )

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

86
    protected function alert(string $sMessage, /** @scrutinizer ignore-unused */ string $sTitle, string $sType): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
87
    {
88
        if($this->returnCode())
89
        {
90
            return "noty({text:" . $sMessage . ", type:'" . $sType . "', layout: 'topCenter'})";
91
        }
92
        $aOptions = array('text' => $sMessage, 'type' => $sType);
93
        // Show the alert
94
        $this->addCommand(array('cmd' => 'noty.alert'), $aOptions);
95
        return '';
96
    }
97
98
    /**
99
     * @inheritDoc
100
     */
101
    public function success(string $sMessage, string $sTitle = ''): string
102
    {
103
        return $this->alert($sMessage, $sTitle, 'success');
104
    }
105
106
    /**
107
     * @inheritDoc
108
     */
109
    public function info(string $sMessage, string $sTitle = ''): string
110
    {
111
        return $this->alert($sMessage, $sTitle, 'information');
112
    }
113
114
    /**
115
     * @inheritDoc
116
     */
117
    public function warning(string $sMessage, string $sTitle = ''): string
118
    {
119
        return $this->alert($sMessage, $sTitle, 'warning');
120
    }
121
122
    /**
123
     * @inheritDoc
124
     */
125
    public function error(string $sMessage, string $sTitle = ''): string
126
    {
127
        return $this->alert($sMessage, $sTitle, 'error');
128
    }
129
130
    /**
131
     * @inheritDoc
132
     */
133
    public function confirm(string $sQuestion, string $sYesScript, string $sNoScript): string
134
    {
135
        // $sTitle = $this->helper()->getQuestionTitle();
136
        if(!$sNoScript)
137
        {
138
            return "jaxon.dialogs.noty.confirm(" . $sQuestion . ",'',function(){" . $sYesScript . ";})";
139
        }
140
        return "jaxon.dialogs.noty.confirm(" . $sQuestion . ",'',function(){" . $sYesScript .
141
            ";},function(){" . $sNoScript . ";})";
142
    }
143
}
144