Session::Destroy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * KNUT7 K7F (https://marciozebedeu.com/)
4
 * KNUT7 K7F (tm) : Rapid Development Framework (https://marciozebedeu.com/)
5
 *
6
 * Licensed under The MIT License
7
 * For full copyright and license information, please see the LICENSE.txt
8
 * Redistributions of files must retain the above copyright notice.
9
 *
10
 * @link      https://github.com/knut7/framework/ for the canonical source repository
11
 * @copyright (c) 2015.  KNUT7  Software Technologies AO Inc. (https://marciozebedeu.com/)
12
 * @license   https://marciozebedeu.com/license/new-bsd New BSD License
13
 * @author    Marcio Zebedeu - [email protected]
14
 * @version   1.0.2
15
 */
16
17
namespace Ballybran\Helpers\Security;
18
19
use Ballybran\Helpers\Hook;
0 ignored issues
show
Bug introduced by
The type Ballybran\Helpers\Hook 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...
20
use http\Url;
21
22
/**
23
 * Class Session
24
 * @package Ballybran\Helpers\Security
25
 */
26
class Session
27
{
28
29
30
    /**
31
     * @var string
32
     */
33
34
35
    /**
36
     *  init Sessin our Session Start
37
     * É usado para ativar o incio de sassão do usuário.
38
     */
39
    public static function init()
40
    {
41
        if (headers_sent()) {
42
            return;
43
        }
44
45
        $id = session_id();
46
        if (empty( $id )) {
47
            @session_start(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for session_start(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

47
            /** @scrutinizer ignore-unhandled */ @session_start(

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
48
                [
49
                    'cookie_lifetime' => 86400 ,
50
//            'read_and_close'  => true,
51
                ]
52
            );
53
        }
54
    }
55
56
    /**
57
     * @param $key
58
     * @param $value
59
     * @return mixed
60
     */
61
    public static function set($key, $value)
62
    {
63
        return $_SESSION[$key] = $value;
64
    }
65
66
    /**
67
     * @param $key
68
     * @return mixed
69
     */
70
    public static function get($key)
71
    {
72
        if(isset($_SESSION[$key])) {
73
            return $_SESSION[$key];
74
        }
75
    }
76
77
    /**
78
     * funtion usado para destruir a sessao
79
     *  exxemplo de uso:: public function DestruirSessao(){ Session::Destroy() }
80
     */
81
    public static function Destroy()
82
    {
83
        @session_destroy();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for session_destroy(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

83
        /** @scrutinizer ignore-unhandled */ @session_destroy();

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
84
85
    }
86
87
    /**
88
     * @param $key
89
     */
90
    public static function unsetValue($key)
91
    {
92
        if (isset($_SESSION[$key])) {
93
            unset($_SESSION[$key]);
94
        }
95
    }
96
97
    /**
98
     *  Usa-se como condicao. Se o usuario existe ou se for maior que zero ( > 0 )
99
     * entao, isso significa que o usuario existe
100
     * mais se for menor q zero ( < 0 ) sigifica que o usuario nao existe.
101
     * exemplo de uso: Session::exist(){
102
     *  .. .. .. .. your code .. .. .. .
103
     * }
104
     * @return bool
105
     */
106
    public static function exist()
107
    {
108
        if (sizeof($_SESSION) > 0) {
109
            session_regenerate_id();
110
            return true;
111
        } else {
112
            return false;
113
        }
114
    }
115
116
117
}
118