GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Config::__construct()   F
last analyzed

Complexity

Conditions 19
Paths 9216

Size

Total Lines 71
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 19
eloc 40
nc 9216
nop 1
dl 0
loc 71
rs 0.3499
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Session\DataStructures;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Kernel\DataStructures;
19
20
/**
21
 * Class Config
22
 *
23
 * @package O2System\Session\Metadata
24
 */
25
class Config extends DataStructures\Config
26
{
27
    /**
28
     * Config::__construct
29
     *
30
     * @param array $config
31
     */
32
    public function __construct(array $config)
33
    {
34
        // Define Session Name
35
        $config[ 'name' ] = isset($config[ 'name' ]) ? $config[ 'name' ] : 'o2session';
36
37
        // Define Session Match IP
38
        $config[ 'match' ][ 'ip' ] = isset($config[ 'match' ][ 'ip' ]) ? $config[ 'match' ][ 'ip' ] : false;
39
40
        // Re-Define Session Name base on Match IP
41
        $config[ 'name' ] = $config[ 'name' ] . ':' . ($config[ 'match' ][ 'ip' ] ? $_SERVER[ 'REMOTE_ADDR' ] . ':' : '');
42
        $config[ 'name' ] = rtrim($config[ 'name' ], ':');
43
44
        if (isset($config[ 'handler' ])) {
45
            $config[ 'handler' ] = $config[ 'handler' ] === 'files' ? 'file' : $config[ 'handler' ];
46
            // $config[ 'handler' ] = $config[ 'handler' ] === 'memcache' ? 'memcached' : $config[ 'handler' ];
47
        }
48
49
        if ($config[ 'handler' ] === 'file') {
50
            if (isset($config[ 'filePath' ])) {
51
                $config[ 'filePath' ] = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $config[ 'filePath' ]);
52
53
                if ( ! is_dir($config[ 'filePath' ])) {
54
                    if (defined('PATH_CACHE')) {
55
                        $config[ 'filePath' ] = PATH_CACHE . $config[ 'filePath' ];
0 ignored issues
show
Bug introduced by
The constant O2System\Session\DataStructures\PATH_CACHE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
56
                    } else {
57
                        $config[ 'filePath' ] = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $config[ 'filePath' ];
58
                    }
59
                }
60
            } elseif (defined('PATH_CACHE')) {
61
                $config[ 'filePath' ] = PATH_CACHE . 'sessions';
62
            } else {
63
                $this->path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . implode(
0 ignored issues
show
Bug Best Practice introduced by
The property path does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
64
                        DIRECTORY_SEPARATOR,
65
                        ['o2system', 'cache', 'sessions']
66
                    );
67
            }
68
69
            $config[ 'filePath' ] = rtrim($config[ 'filePath' ], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
70
71
            if ( ! is_writable($config[ 'filePath' ])) {
72
                if ( ! file_exists($config[ 'filePath' ])) {
73
                    @mkdir($config[ 'filePath' ], 0777, true);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for mkdir(). 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

73
                    /** @scrutinizer ignore-unhandled */ @mkdir($config[ 'filePath' ], 0777, true);

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...
74
                }
75
            }
76
        }
77
78
        if (empty($config[ 'cookie' ]) AND php_sapi_name() !== 'cli') {
79
            $config[ 'cookie' ] = [
80
                'name'     => 'o2session',
81
                'lifetime' => 7200,
82
                'domain'   => isset($_SERVER[ 'HTTP_HOST' ]) ? $_SERVER[ 'HTTP_HOST' ] : $_SERVER[ 'SERVER_NAME' ],
83
                'path'     => '/',
84
                'secure'   => false,
85
                'httpOnly' => false,
86
            ];
87
        }
88
89
        if ( ! isset($config[ 'regenerate' ])) {
90
            $config[ 'regenerate' ][ 'destroy' ] = false;
91
            $config[ 'regenerate' ][ 'lifetime' ] = 600;
92
        }
93
94
        if ( ! isset($config[ 'lifetime' ])) {
95
            $config[ 'lifetime' ] = $config[ 'cookie' ][ 'lifetime' ];
96
        }
97
98
        if ( ! isset($config[ 'path' ])) {
99
            $config[ 'path' ] = '/';
100
        }
101
102
        parent::__construct($config, Config::CAMELCASE_OFFSET);
103
    }
104
}