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

PNotifyLibrary::getName()   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 PNotify 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\PNotify;
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 PNotifyLibrary extends AbstractDialogLibrary implements MessageInterface, QuestionInterface
20
{
21
    /**
22
     * @const The library name
23
     */
24
    const NAME = 'pnotify';
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 'pnotify';
40
    }
41
42
    /**
43
     * @inheritDoc
44
     */
45
    public function getVersion(): string
46
    {
47
        return '3.0.0';
48
    }
49
50
    /**
51
     * @inheritDoc
52
     */
53
    public function getJs(): string
54
    {
55
        return $this->xHelper->getJsCode('pnotify.js') . "\n" . $this->xHelper->getJsCode('pnotify.confirm.js');
56
    }
57
58
    /**
59
     * @inheritDoc
60
     */
61
    public function getCss(): string
62
    {
63
        return $this->xHelper->getCssCode('pnotify.css');
64
    }
65
66
    /**
67
     * @inheritDoc
68
     */
69
    public function getScript(): string
70
    {
71
        return $this->xHelper->render('pnotify/alert.js');
72
    }
73
74
    /**
75
     * @inheritDoc
76
     */
77
    public function getReadyScript(): string
78
    {
79
        return $this->xHelper->render('pnotify/ready.js.php', [
80
            'options' => $this->xHelper->getOptionScript('PNotify.prototype.options.', 'options.')
81
        ]);
82
    }
83
84
    /**
85
     * Print an alert message.
86
     *
87
     * @param string $sMessage The text of the message
88
     * @param string $sTitle The title of the message
89
     * @param string $sType The type of the message
90
     *
91
     * @return string
92
     */
93
    protected function alert(string $sMessage, string $sTitle, string $sType): string
94
    {
95
        if($this->returnCode())
96
        {
97
            return "jaxon.dialogs.pnotify.alert({text:" . $sMessage . ", type:'" . $sType . "', title:'" . $sTitle . "'})";
98
        }
99
        $aOptions = ['text' => $sMessage, 'title' => $sTitle, 'type' => $sType];
100
        // Show the alert
101
        $this->addCommand(['cmd' => 'pnotify.alert'], $aOptions);
102
        return '';
103
    }
104
105
    /**
106
     * @inheritDoc
107
     */
108
    public function success(string $sMessage, string $sTitle = ''): string
109
    {
110
        return $this->alert($sMessage, $sTitle, 'success');
111
    }
112
113
    /**
114
     * @inheritDoc
115
     */
116
    public function info(string $sMessage, string $sTitle = ''): string
117
    {
118
        return $this->alert($sMessage, $sTitle, 'info');
119
    }
120
121
    /**
122
     * @inheritDoc
123
     */
124
    public function warning(string $sMessage, string $sTitle = ''): string
125
    {
126
        return $this->alert($sMessage, $sTitle, 'notice');
127
    }
128
129
    /**
130
     * @inheritDoc
131
     */
132
    public function error(string $sMessage, string $sTitle = ''): string
133
    {
134
        return $this->alert($sMessage, $sTitle, 'error');
135
    }
136
137
    /**
138
     * @inheritDoc
139
     */
140
    public function confirm(string $sQuestion, string $sYesScript, string $sNoScript): string
141
    {
142
        $sTitle = $this->xHelper->getQuestionTitle();
143
        if(!$sNoScript)
144
        {
145
            return "jaxon.dialogs.pnotify.confirm(" . $sQuestion . ",'" . $sTitle . "',function(){" . $sYesScript . ";})";
146
        }
147
        else
148
        {
149
            return "jaxon.dialogs.pnotify.confirm(" . $sQuestion . ",'" . $sTitle . "',function(){" . $sYesScript . ";},function(){" . $sNoScript . ";})";
150
        }
151
    }
152
}
153