Passed
Push — master ( f0273f...a7db3c )
by Afshin
02:04
created

SessionHandler   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 31
Duplicated Lines 35.48 %

Importance

Changes 0
Metric Value
dl 11
loc 31
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 10 3
A set() 0 2 1
A getRecursiveSessionKey() 10 10 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: afshin
5
 * Date: 12/8/17
6
 * Time: 1:04 AM
7
 */
8
9
namespace Core\Handlers\Session;
10
11
12
use Core\Interfaces\_Session;
13
14
class SessionHandler implements _Session
15
{
16
    public function get($key = null)
17
    {
18
        if(!isset($_SESSION)) return [];
19
20
        if(!$key){
21
            return $_SESSION;
22
        }else{
23
            $keys = explode('.',$key);
24
            $sessionVal = $this->getRecursiveSessionKey($_SESSION,$keys);
25
            return $sessionVal;
26
        }
27
    }
28
29 View Code Duplication
    public function getRecursiveSessionKey($data , $keyArr){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
        $arrayFound  = isset($data[$keyArr[0]]) ? $data[$keyArr[0]] : '';
31
        if($arrayFound){
32
            unset($keyArr[0]);
33
            $keyArr = array_values($keyArr);
34
            if(isset($keyArr[0])){
35
                return $this->getRecursiveSessionKey($arrayFound,$keyArr);
36
            }
37
        }
38
        return $arrayFound ;
39
    }
40
41
42
43
    public function set($key,$val)
0 ignored issues
show
Unused Code introduced by
The parameter $key 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

43
    public function set(/** @scrutinizer ignore-unused */ $key,$val)

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...
Unused Code introduced by
The parameter $val 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

43
    public function set($key,/** @scrutinizer ignore-unused */ $val)

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...
44
    {
45
//        $keys = explode('.',$key);
46
//        foreach ($keys as $key) {
47
//            if (!array_key_exists($key, $_SESSION)) {
48
//                $reference[$key] = [];
49
//            }
50
//            $reference[$key] = 1;
51
//        }
52
////        $reference = $val;
53
//
54
//
55
//
56
//        dd($reference);
57
//        $_SESSION = $val;
58
    }
59
}