Code Duplication    Length = 113-115 lines in 2 locations

src/Platfourm/Database/Helpers/CacheKeys.php 1 location

@@ 16-128 (lines=113) @@
13
/**
14
 * Class CacheKeys.
15
 */
16
class CacheKeys
17
{
18
    /**
19
     * @var string
20
     */
21
    protected static $storeFile = 'repository-cache-keys.json';
22
23
    /**
24
     * @var array
25
     */
26
    protected static $keys = null;
27
28
    /**
29
     * @param $group
30
     * @param $key
31
     *
32
     * @return void
33
     */
34
    public static function putKey($group, $key)
35
    {
36
        self::loadKeys();
37
38
        self::$keys[$group] = self::getKeys($group);
39
40
        if (!in_array($key, self::$keys[$group])) {
41
            self::$keys[$group][] = $key;
42
        }
43
44
        self::storeKeys();
45
    }
46
47
    /**
48
     * @param $group
49
     *
50
     * @return array|mixed
51
     */
52
    public static function getKeys($group)
53
    {
54
        self::loadKeys();
55
        self::$keys[$group] = isset(self::$keys[$group]) ? self::$keys[$group] : [];
56
57
        return self::$keys[$group];
58
    }
59
60
    /**
61
     * @return array|mixed
62
     */
63
    public static function loadKeys()
64
    {
65
        if (!is_null(self::$keys) && is_array(self::$keys)) {
66
            return self::$keys;
67
        }
68
69
        $file = self::getFileKeys();
70
71
        if (!file_exists($file)) {
72
            self::storeKeys();
73
        }
74
75
        $content    = file_get_contents($file);
76
        self::$keys = json_decode($content, true);
77
78
        return self::$keys;
79
    }
80
81
    /**
82
     * @return int
83
     */
84
    public static function storeKeys()
85
    {
86
        $file       = self::getFileKeys();
87
        self::$keys = is_null(self::$keys) ? [] : self::$keys;
88
        $content    = json_encode(self::$keys);
89
90
        return file_put_contents($file, $content);
91
    }
92
93
    /**
94
     * @return string
95
     */
96
    public static function getFileKeys()
97
    {
98
        $file = storage_path('framework/cache/' . self::$storeFile);
99
100
        return $file;
101
    }
102
103
    /**
104
     * @param $method
105
     * @param $parameters
106
     *
107
     * @return mixed
108
     */
109
    public static function __callStatic($method, $parameters)
110
    {
111
        $instance = new static();
112
113
        return call_user_func_array([$instance, $method], $parameters);
114
    }
115
116
    /**
117
     * @param $method
118
     * @param $parameters
119
     *
120
     * @return mixed
121
     */
122
    public function __call($method, $parameters)
123
    {
124
        $instance = new static();
125
126
        return call_user_func_array([$instance, $method], $parameters);
127
    }
128
}
129

src/Platfourm/Repository/Helpers/CacheKeys.php 1 location

@@ 16-130 (lines=115) @@
13
/**
14
 * Class CacheKeys.
15
 */
16
class CacheKeys
17
{
18
    /**
19
     * @var string
20
     */
21
    protected static $storeFile = 'repository-cache-keys.json';
22
23
    /**
24
     * @var array
25
     */
26
    protected static $keys = null;
27
28
    /**
29
     * @param $group
30
     * @param $key
31
     *
32
     * @return void
33
     */
34
    public static function putKey($group, $key)
35
    {
36
        self::loadKeys();
37
38
        self::$keys[$group] = self::getKeys($group);
39
40
        if (!in_array($key, self::$keys[$group])) {
41
            self::$keys[$group][] = $key;
42
        }
43
44
        self::storeKeys();
45
    }
46
47
    /**
48
     * @param $group
49
     *
50
     * @return array|mixed
51
     */
52
    public static function getKeys($group)
53
    {
54
        self::loadKeys();
55
        self::$keys[$group] = isset(self::$keys[$group]) ? self::$keys[$group] : [];
56
57
        return self::$keys[$group];
58
    }
59
60
    /**
61
     * @return array|mixed
62
     */
63
    public static function loadKeys()
64
    {
65
66
        if (!is_null(self::$keys) && is_array(self::$keys)) {
67
            return self::$keys;
68
        }
69
70
        $file = self::getFileKeys();
71
72
        if (!file_exists($file)) {
73
            self::storeKeys();
74
        }
75
76
        $content    = file_get_contents($file);
77
        self::$keys = json_decode($content, true);
78
79
        return self::$keys;
80
    }
81
82
    /**
83
     * @return int
84
     */
85
    public static function storeKeys()
86
    {
87
        $file       = self::getFileKeys();
88
        self::$keys = is_null(self::$keys) ? [] : self::$keys;
89
        $content    = json_encode(self::$keys);
90
91
        return file_put_contents($file, $content);
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public static function getFileKeys()
98
    {
99
        $file = storage_path('framework/cache/' . self::$storeFile);
100
101
        return $file;
102
    }
103
104
    /**
105
     * @param $method
106
     * @param $parameters
107
     *
108
     * @return mixed
109
     */
110
    public static function __callStatic($method, $parameters)
111
    {
112
        $instance = new static();
113
114
        return call_user_func_array([$instance, $method], $parameters);
115
    }
116
117
    /**
118
     * @param $method
119
     * @param $parameters
120
     *
121
     * @return mixed
122
     */
123
    public function __call($method, $parameters)
124
    {
125
        $instance = new static();
126
127
        return call_user_func_array([$instance, $method], $parameters);
128
    }
129
130
}
131