CacheConfig::setLoggerPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 3
b 0
f 0
nc 1
nop 1
dl 0
loc 14
rs 9.9666
1
<?php
2
3
namespace Silviooosilva\CacheerPhp\Helpers;
4
5
use Silviooosilva\CacheerPhp\Cacheer;
6
use Silviooosilva\CacheerPhp\CacheStore\ArrayCacheStore;
7
use Silviooosilva\CacheerPhp\CacheStore\DatabaseCacheStore;
8
use Silviooosilva\CacheerPhp\CacheStore\FileCacheStore;
9
use Silviooosilva\CacheerPhp\CacheStore\RedisCacheStore;
10
use Silviooosilva\CacheerPhp\Core\Connect;
11
use Silviooosilva\CacheerPhp\Utils\CacheDriver;
12
13
/**
14
 * Class CacheConfig
15
 * @author Sílvio Silva <https://github.com/silviooosilva>
16
 * @package Silviooosilva\CacheerPhp
17
 */
18
class CacheConfig
19
{
20
21
    /**
22
     * @var Cacheer
23
     */
24
    protected $cacheer;
25
26
    public function __construct(Cacheer $cacheer)
27
    {
28
        $this->cacheer = $cacheer;
29
        $this->setTimeZone(date_default_timezone_get());
30
    }
31
32
    /**
33
     * @param string $timezone
34
     * @return $this
35
     */
36
    public function setTimeZone($timezone)
37
    {
38
        /**
39
         * Certifique-se de que o timezone fornecido é válido * 
40
         * https://www.php.net/manual/en/timezones.php 
41
         * */
42
43
        if (in_array($timezone, timezone_identifiers_list())) {
0 ignored issues
show
Bug introduced by
Are you sure the usage of timezone_identifiers_list() is correct as it 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...
Bug introduced by
timezone_identifiers_list() of type void is incompatible with the type array expected by parameter $haystack of in_array(). ( Ignorable by Annotation )

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

43
        if (in_array($timezone, /** @scrutinizer ignore-type */ timezone_identifiers_list())) {
Loading history...
44
            date_default_timezone_set($timezone);
45
        }
46
        return $this;
47
    }
48
49
    /**
50
     * @return CacheDriver
51
     */
52
    public function setDriver()
53
    {
54
        return new CacheDriver($this->cacheer);
55
    }
56
57
    /**
58
     * @param string $path
59
     * @return mixed
60
     */
61
    public function setLoggerPath(string $path)
62
    {
63
        
64
        $cacheDriver = $this->setDriver();
65
        $cacheDriver->logPath = $path;
66
67
        $cacheDriverInstance = $this->cacheer->cacheStore;
68
69
        return match (get_class($cacheDriverInstance)) {
70
            FileCacheStore::class => $cacheDriver->useFileDriver(),
71
            RedisCacheStore::class => $cacheDriver->useRedisDriver(),
72
            ArrayCacheStore::class => $cacheDriver->useArrayDriver(),
73
            DatabaseCacheStore::class => $cacheDriver->useDatabaseDriver(),
74
            default => $cacheDriver->useDatabaseDriver(),
75
        };
76
    }
77
78
    /**
79
     * @param string $driver
80
     * @return void
81
     */
82
    public function setDatabaseConnection(string $driver)
83
    {
84
        Connect::setConnection($driver);
85
    }
86
}
87