Storage::saveToCache()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Alex19pov31\LinkedData;
4
5
class Storage implements StorgeInterface
6
{
7
    /**
8
     * Список репозиториев
9
     *
10
     * @var array|null
11
     */
12
    private static $data;
13
14
    /**
15
     * Возвращает репозиторий по названию
16
     *
17
     * @param string $name
18
     * @return RepositoryInterface|null
19
     */
20
    public static function getRepository(string $name)
21
    {
22
        if (!isset(static::$data[$name])) {
0 ignored issues
show
Bug introduced by
Since $data is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $data to at least protected.
Loading history...
23
            return static::$data[$name] = new BaseRepository($name);
24
        }
25
26
        return static::$data[$name];
27
    }
28
29
    /**
30
     * Сохранить данные репозиториев в кеш
31
     *
32
     * @param integer $minutes
33
     * @return void
34
     */
35
    public static function saveToCache(int $minutes)
36
    {
37
        if (is_null(static::$data)) {
0 ignored issues
show
Bug introduced by
Since $data is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $data to at least protected.
Loading history...
38
            return;
39
        }
40
41
        foreach (static::$data as $repository) {
42
            $repository->updateCache($minutes);
43
        }
44
    }
45
}
46