Code Duplication    Length = 56-72 lines in 2 locations

src/Cache/FlySystemStorage.php 1 location

@@ 12-83 (lines=72) @@
9
 * @author Vytautas Stankus <[email protected]>
10
 * @license MIT
11
 */
12
class FlySystemStorage implements StorageInterface
13
{
14
    /**
15
     * @var Filesystem
16
     */
17
    private $filesystem;
18
19
    /**
20
     * @param Filesystem $filesystem
21
     */
22
    public function __construct(Filesystem $filesystem)
23
    {
24
        $this->filesystem = $filesystem;
25
    }
26
27
    /**
28
     * Returns the value for a key.
29
     *
30
     * @param string $key A unique key
31
     *
32
     * @return string|false The file contents or false on failure.
33
     */
34
    public function get($key)
35
    {
36
        try {
37
            return $this->filesystem->read($key);
38
        } catch (FileNotFoundException $exception) {
39
            return false;
40
        }
41
    }
42
43
    /**
44
     * Checks if the cache has a value for a key.
45
     *
46
     * @param string $key A unique key
47
     *
48
     * @return Boolean Whether the cache has a value for this key
49
     */
50
    public function has($key)
51
    {
52
        return $this->filesystem->has($key);
53
    }
54
55
    /**
56
     * Sets a value in the cache.
57
     *
58
     * @param string $key      A unique key
59
     * @param string $contents The value to cache
60
     *
61
     * @return bool True on success, false on failure.
62
     */
63
    public function set($key, $contents)
64
    {
65
        $this->filesystem->put($key, $contents);
66
    }
67
68
    /**
69
     * Removes a value from the cache.
70
     *
71
     * @param string $key A unique key
72
     *
73
     * @return bool True on success, false on failure.
74
     */
75
    public function remove($key)
76
    {
77
        try {
78
            return $this->filesystem->delete($key);
79
        } catch (FileNotFoundException $exception) {
80
            return false;
81
        }
82
    }
83
}
84

src/Filesystem/Adapter/FlySystemAdapter.php 1 location

@@ 13-68 (lines=56) @@
10
 * @author Vytautas Stankus <[email protected]>
11
 * @license MIT
12
 */
13
class FlySystemAdapter implements FilesystemAdapterInterface
14
{
15
    /**
16
     * @var FilesystemInterface
17
     */
18
    private $filesystem;
19
20
    /**
21
     * @param FilesystemInterface $filesystem
22
     */
23
    public function __construct(FilesystemInterface $filesystem)
24
    {
25
        $this->filesystem = $filesystem;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function read($path)
32
    {
33
        try {
34
            return $this->filesystem->read($path);
35
        } catch (FileNotFoundException $exception) {
36
            return false;
37
        }
38
    }
39
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function has($path)
45
    {
46
        return $this->filesystem->has($path);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function put($path, $contents)
53
    {
54
        return $this->filesystem->put($path, $contents);
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function delete($path)
61
    {
62
        try {
63
            return $this->filesystem->delete($path);
64
        } catch (FileNotFoundException $exception) {
65
            return false;
66
        }
67
    }
68
}
69