Passed
Push — master ( 6eb156...b34d93 )
by Thierry
04:25
created

DialogFacade::setMessageLibrary()   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 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * DialogFacade.php - Shows alert and confirm dialogs
5
 *
6
 * @author Thierry Feuzeu <[email protected]>
7
 * @copyright 2019 Thierry Feuzeu <[email protected]>
8
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
9
 * @link https://github.com/jaxon-php/jaxon-core
10
 */
0 ignored issues
show
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
11
12
namespace Jaxon\Ui\Dialogs;
13
14
use Jaxon\Di\Container;
15
use Jaxon\Response\Response;
16
17
class DialogFacade
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class DialogFacade
Loading history...
18
{
19
    /**
20
     * @var Container
21
     */
22
    private $di;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
23
24
    /**
25
     * The QuestionInterface class name (javascript confirm function)
26
     *
27
     * @var string
28
     */
29
    private $sQuestionLibrary = '';
30
31
    /**
32
     * The MessageInterface class name (javascript alert function)
33
     *
34
     * @var string
35
     */
36
    private $sMessageLibrary = '';
37
38
    /**
39
     * The ModalInterface class name
40
     *
41
     * @var string
42
     */
43
    private $sModalLibrary = '';
44
45
    /**
46
     * Default javascript alert libray
47
     *
48
     * @var AlertLibrary
49
     */
50
    private $xAlertLibrary;
51
52
    /**
53
     * The constructor
54
     *
55
     * @param Container $di
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
56
     */
57
    public function __construct(Container $di)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
58
    {
59
        $this->di = $di;
60
        // Javascript confirm function
61
        $this->xAlertLibrary = new AlertLibrary();
62
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
63
64
    /**
65
     * Set the QuestionInterface class name
66
     *
67
     * @param string $sQuestionLibrary    The QuestionInterface class name
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
68
     *
69
     * @return void
70
     */
71
    public function setQuestionLibrary(string $sQuestionLibrary)
72
    {
73
        $this->sQuestionLibrary = $sQuestionLibrary;
74
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
75
76
    /**
77
     * Get the QuestionInterface instance (javascript question function)
78
     *
79
     * @param string $sQuestionLibrary
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
80
     *
81
     * @return QuestionInterface
82
     */
83
    public function getQuestionLibrary(string $sQuestionLibrary = '')
84
    {
85
        if($sQuestionLibrary === '')
86
        {
87
            $sQuestionLibrary = $this->sQuestionLibrary;
88
        }
89
        return ($sQuestionLibrary) ? $this->di->g($sQuestionLibrary) : $this->xAlertLibrary;
90
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
91
92
    /**
93
     * Set MessageInterface class name
94
     *
95
     * @param string $sMessageLibrary    The MessageInterface class name
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
96
     *
97
     * @return void
98
     */
99
    public function setMessageLibrary(string $sMessageLibrary)
100
    {
101
        $this->sMessageLibrary = $sMessageLibrary;
102
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
103
104
    /**
105
     * Get the MessageInterface instance (javascript alert function)
106
     *
107
     * @param bool $bReturn Whether to return the code
0 ignored issues
show
Coding Style introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 9 spaces after parameter name; 1 found
Loading history...
108
     * @param Response|null $xResponse
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
109
     * @param string $sMessageLibrary
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
110
     *
111
     * @return MessageInterface
112
     */
113
    public function getMessageLibrary(bool $bReturn, ?Response $xResponse = null, string $sMessageLibrary = ''): MessageInterface
114
    {
115
        if($sMessageLibrary === '')
116
        {
117
            $sMessageLibrary = $this->sMessageLibrary;
118
        }
119
        $xLibrary = ($sMessageLibrary) ? $this->di->g($sMessageLibrary) : $this->xAlertLibrary;
120
        $xLibrary->setReturn($bReturn);
121
        if($xResponse !== null)
122
        {
123
            $xLibrary->setResponse($xResponse);
124
        }
125
        return $xLibrary;
126
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
127
128
    /**
129
     * Set the ModalInterface class name
130
     *
131
     * @param string $sModalLibrary    The ModalInterface class name
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
132
     *
133
     * @return void
134
     */
135
    public function setModalLibrary(string $sModalLibrary)
136
    {
137
        $this->sModalLibrary = $sModalLibrary;
138
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
139
140
    /**
141
     * Get the ModalInterface instance (javascript question function)
142
     *
143
     * @param Response|null $xResponse
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
144
     * @param string $sModalLibrary
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
145
     *
146
     * @return ModalInterface
147
     */
148
    public function getModalLibrary(?Response $xResponse = null, string $sModalLibrary = ''): ?ModalInterface
149
    {
150
        if($sModalLibrary === '')
151
        {
152
            $sModalLibrary = $this->sModalLibrary;
153
        }
154
        $xLibrary = ($sModalLibrary) ? $this->di->g($sModalLibrary) : null;
155
        if($xResponse !== null)
156
        {
157
            $xLibrary->setResponse($xResponse);
0 ignored issues
show
Bug introduced by
The method setResponse() does not exist on null. ( Ignorable by Annotation )

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

157
            $xLibrary->/** @scrutinizer ignore-call */ 
158
                       setResponse($xResponse);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
158
        }
159
        return $xLibrary;
160
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
161
}
162