PrimaryFileSystemWrapper::getSize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * This file is part of the IrishDan\ResponsiveImageBundle package.
4
 *
5
 * (c) Daniel Byrne <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE file that was distributed with this source
8
 * code.
9
 */
10
11
namespace IrishDan\ResponsiveImageBundle\FileSystem;
12
13
use IrishDan\ResponsiveImageBundle\Event\FileSystemEvent;
14
use IrishDan\ResponsiveImageBundle\Event\FileSystemEvents;
15
use League\Flysystem\FilesystemInterface;
16
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
17
18
/**
19
 * Class PrimaryFileSystemWrapper
20
 *
21
 * This is a wrapper around a flysystem filesystem.
22
 * It includes some helper methods for easy access to flysystem.
23
 * If event dispatcher is injected it will fire events whenerever the filesystem is set is gotten.
24
 * This is to allow for swapping of filesystem.
25
 *
26
 * @package IrishDan\ResponsiveImageBundle\FileSystem
27
 */
28
class PrimaryFileSystemWrapper
29
{
30
    /**
31
     * @var FilesystemInterface
32
     */
33
    private $fileSystem;
34
    /**
35
     * @var EventDispatcherInterface
36
     */
37
    private $eventDispatcher;
38
39
    /**
40
     * PrimaryFileSystemWrapper constructor.
41
     *
42
     * @param EventDispatcherInterface|null $eventDispatcher
43
     * @param FilesystemInterface|null      $fileSystem
44
     */
45
    public function __construct(EventDispatcherInterface $eventDispatcher = null, FilesystemInterface $fileSystem = null)
46
    {
47
        $this->eventDispatcher = $eventDispatcher;
48
        $this->fileSystem      = $fileSystem;
49
    }
50
51
    /**
52
     * @return FilesystemInterface|null
53
     */
54 View Code Duplication
    public function getFileSystem()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        if (!empty($this->eventDispatcher)) {
57
            $fileSystemEvent = new FileSystemEvent($this);
58
            $this->eventDispatcher->dispatch(FileSystemEvents::FILE_SYSTEM_FACTORY_GET, $fileSystemEvent);
59
        }
60
61
        return $this->fileSystem;
62
    }
63
64
    public function getAdapter()
65
    {
66
        if (!empty($this->fileSystem)) {
67
            return $this->fileSystem->getAdapter();
68
        }
69
70
        return null;
71
    }
72
73
    /**
74
     * @param FilesystemInterface $fileSystem
75
     */
76 View Code Duplication
    public function setFileSystem(FilesystemInterface $fileSystem)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
    {
78
        if (!empty($this->eventDispatcher)) {
79
            $fileSystemEvent = new FileSystemEvent($this);
80
            $this->eventDispatcher->dispatch(FileSystemEvents::FILE_SYSTEM_FACTORY_SET, $fileSystemEvent);
81
        }
82
        $this->fileSystem = $fileSystem;
83
    }
84
85
    /**
86
     * @param $path
87
     * @param $contents
88
     */
89
    public function write($path, $contents)
90
    {
91
        $this->fileSystem->write($path, $contents);
92
    }
93
94
    /**
95
     * @param $path
96
     * @param $contents
97
     */
98
    public function update($path, $contents)
99
    {
100
        $this->fileSystem->update($path, $contents);
101
    }
102
103
    /**
104
     * @param $path
105
     * @param $contents
106
     */
107
    public function put($path, $contents)
108
    {
109
        $this->fileSystem->put($path, $contents);
110
    }
111
112
    /**
113
     * @param $path
114
     *
115
     * @return false|string
116
     */
117
    public function read($path)
118
    {
119
        return $this->fileSystem->read($path);
120
    }
121
122
    /**
123
     * @param $path
124
     *
125
     * @return bool
126
     */
127
    public function has($path)
128
    {
129
        return $this->fileSystem->has($path);
130
    }
131
132
    /**
133
     * @param $path
134
     */
135
    public function delete($path)
136
    {
137
        $this->fileSystem->delete($path);
138
    }
139
140
    /**
141
     * @param $path
142
     *
143
     * @return false|string
144
     */
145
    public function readAndDelete($path)
146
    {
147
        return $this->fileSystem->readAndDelete($path);
148
    }
149
150
    /**
151
     * @param $currentPath
152
     * @param $newPath
153
     */
154
    public function rename($currentPath, $newPath)
155
    {
156
        $this->fileSystem->rename($currentPath, $newPath);
157
    }
158
159
    /**
160
     * @param $currentPath
161
     * @param $duplicatePath
162
     */
163
    public function copy($currentPath, $duplicatePath)
164
    {
165
        $this->fileSystem->copy($currentPath, $duplicatePath);
166
    }
167
168
    /**
169
     * @param $path
170
     *
171
     * @return false|string
172
     */
173
    public function getMimetype($path)
174
    {
175
        return $this->fileSystem->getMimetype($path);
176
    }
177
178
    /**
179
     * @param $path
180
     *
181
     * @return false|string
182
     */
183
    public function getTimeStamp($path)
184
    {
185
        return $this->fileSystem->getTimestamp($path);
186
    }
187
188
    /**
189
     * @param $path
190
     *
191
     * @return false|int
192
     */
193
    public function getSize($path)
194
    {
195
        return $this->fileSystem->getSize($path);
196
    }
197
198
    /**
199
     * @param $path
200
     */
201
    public function createDir($path)
202
    {
203
        $this->fileSystem->createDir($path);
204
    }
205
206
    /**
207
     * @param $path
208
     */
209
    public function deleteDir($path)
210
    {
211
        $this->fileSystem->deleteDir($path);
212
    }
213
}