| Conditions | 19 |
| Paths | 9216 |
| Total Lines | 71 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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' ]; |
||
|
|
|||
| 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( |
||
| 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); |
||
| 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 | } |