Passed
Push — 3.0 ( 5e1ed3...5a5495 )
by Rubén
04:22
created

StatelessContext::setConfigTime()   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
 * sysPass
4
 *
5
 * @author    nuxsmin
6
 * @link      https://syspass.org
7
 * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
8
 *
9
 * This file is part of sysPass.
10
 *
11
 * sysPass is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation, either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * sysPass is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 *  along with sysPass.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace SP\Core\Context;
26
27
use SP\DataModel\ProfileData;
28
use SP\Services\User\UserLoginResponse;
29
30
/**
31
 * Class ApiContext
32
 *
33
 * @package SP\Core\Context
34
 */
35
final class StatelessContext extends ContextBase
36
{
37
    /**
38
     * Establecer una variable de sesión
39
     *
40
     * @param string $key   El nombre de la variable
41
     * @param mixed  $value El valor de la variable
42
     *
43
     * @return mixed
44
     */
45
    protected function setContextKey(string $key, $value)
46
    {
47
        try {
48
            parent::setContextKey($key, $value);
49
50
            return $value;
51
        } catch (ContextException $e) {
52
            processException($e);
53
        }
54
55
        return null;
56
    }
57
58
    /**
59
     * Establece los datos del usuario en la sesión.
60
     *
61
     * @param UserLoginResponse $userLoginResponse
62
     */
63
    public function setUserData(UserLoginResponse $userLoginResponse = null)
64
    {
65
        $this->setContextKey('userData', $userLoginResponse);
66
    }
67
68
    /**
69
     * Obtiene el objeto de perfil de usuario de la sesión.
70
     *
71
     * @return ProfileData
72
     */
73
    public function getUserProfile()
74
    {
75
        return $this->getContextKey('userProfile');
76
    }
77
78
    /**
79
     * Devolver una variable de sesión
80
     *
81
     * @param string $key
82
     * @param mixed  $default
83
     *
84
     * @return mixed
85
     */
86
    protected function getContextKey(string $key, $default = null)
87
    {
88
        try {
89
            return parent::getContextKey($key, $default);
90
        } catch (ContextException $e) {
91
            processException($e);
92
        }
93
94
        return $default;
95
    }
96
97
    /**
98
     * Establece el objeto de perfil de usuario en la sesión.
99
     *
100
     * @param ProfileData $ProfileData
101
     */
102
    public function setUserProfile(ProfileData $ProfileData)
103
    {
104
        $this->setContextKey('userProfile', $ProfileData);
105
    }
106
107
    /**
108
     * Returns if user is logged in
109
     *
110
     * @return bool
111
     */
112
    public function isLoggedIn()
113
    {
114
        return !empty($this->getUserData()->getLogin());
115
    }
116
117
    /**
118
     * Devuelve los datos del usuario en la sesión.
119
     *
120
     * @return UserLoginResponse
121
     */
122
    public function getUserData()
123
    {
124
        return $this->getContextKey('userData', new UserLoginResponse());
125
    }
126
127
    /**
128
     * @return mixed
129
     */
130
    public function getSecurityKey()
131
    {
132
        return $this->getContextKey('sk');
133
    }
134
135
    /**
136
     * @param string $salt
137
     *
138
     * @return string
139
     */
140
    public function generateSecurityKey(string $salt)
141
    {
142
        return $this->setSecurityKey(sha1(time() . $salt));
143
    }
144
145
    /**
146
     * @param $sk
147
     *
148
     * @return mixed
149
     */
150
    public function setSecurityKey($sk)
151
    {
152
        return $this->setContextKey('sk', $sk);
153
    }
154
155
    /**
156
     * Establecer el lenguaje de la sesión
157
     *
158
     * @param $locale
159
     */
160
    public function setLocale($locale)
161
    {
162
        $this->setContextKey('locale', $locale);
163
    }
164
165
    /**
166
     * Devuelve el lenguaje de la sesión
167
     *
168
     * @return string
169
     */
170
    public function getLocale()
171
    {
172
        return $this->getContextKey('locale');
173
    }
174
175
    /**
176
     * Devuelve el estado de la aplicación
177
     *
178
     * @return bool
179
     */
180
    public function getAppStatus()
181
    {
182
        return $this->getContextKey('status');
183
    }
184
185
    /**
186
     * Establecer el estado de la aplicación
187
     *
188
     * @param string $status
189
     */
190
    public function setAppStatus($status)
191
    {
192
        $this->setContextKey('status', $status);
193
    }
194
195
    /**
196
     * Reset del estado de la aplicación
197
     *
198
     * @return bool
199
     */
200
    public function resetAppStatus()
201
    {
202
        return $this->setContextKey('status', null);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->setContextKey('status', null) targeting SP\Core\Context\StatelessContext::setContextKey() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
203
    }
204
205
    /**
206
     * @return void
207
     * @throws ContextException
208
     */
209
    public function initialize()
210
    {
211
        $this->setContext(new ContextCollection());
212
    }
213
214
    /**
215
     * Establecer la hora de carga de la configuración
216
     *
217
     * @param int $time
218
     */
219
    public function setConfigTime($time)
220
    {
221
        $this->setContextKey('configTime', (int)$time);
222
    }
223
224
    /**
225
     * Devolver la hora de carga de la configuración
226
     *
227
     * @return int
228
     */
229
    public function getConfigTime()
230
    {
231
        return $this->getContextKey('configTime');
232
    }
233
234
    /**
235
     * @return null
236
     */
237
    public function getAccountsCache()
238
    {
239
        return null;
240
    }
241
242
    /**
243
     * Sets a temporary master password
244
     *
245
     * @param string $password
246
     *
247
     * @throws ContextException
248
     */
249
    public function setTemporaryMasterPass(string $password)
250
    {
251
        $this->setTrasientKey('_tempmasterpass', $password);
252
    }
253
254
    /**
255
     * @param string $pluginName
256
     * @param string $key
257
     * @param mixed  $value
258
     *
259
     * @return mixed
260
     */
261
    public function setPluginKey(string $pluginName, string $key, $value)
262
    {
263
        $ctxKey = $this->getContextKey('plugins');
264
265
        $ctxKey[$pluginName][$key] = $value;
266
267
        return $value;
268
    }
269
270
    /**
271
     * @param string $pluginName
272
     * @param string $key
273
     *
274
     * @return mixed
275
     */
276
    public function getPluginKey(string $pluginName, string $key)
277
    {
278
        $ctxKey = $this->getContextKey('plugins');
279
280
        if (isset($ctxKey[$pluginName][$key])) {
281
            return $ctxKey[$pluginName][$key];
282
        }
283
284
        return null;
285
    }
286
}