1 | <?php |
||||
2 | /** |
||||
3 | * @category Library |
||||
4 | * @license MIT http://opensource.org/licenses/MIT |
||||
5 | * @link https://github.com/emlynwest/changelog |
||||
6 | */ |
||||
7 | |||||
8 | namespace ChangeLog\IO; |
||||
9 | |||||
10 | use ChangeLog\AbstractIO; |
||||
11 | use InvalidArgumentException; |
||||
12 | use League\Flysystem\Filesystem; |
||||
13 | |||||
14 | /** |
||||
15 | * Allows change logs to be loaded via a Flysystem adaptor. |
||||
16 | * |
||||
17 | * Config can contain the keys 'file', 'filesystem' and 'line_separator'. 'file' and 'filesystem' are not optional. |
||||
18 | */ |
||||
19 | class Flysystem extends AbstractIO |
||||
20 | { |
||||
21 | |||||
22 | protected $configDefaults = [ |
||||
23 | 'line_separator' => "\n", |
||||
24 | ]; |
||||
25 | |||||
26 | /** |
||||
27 | * {@inheritdoc} |
||||
28 | * |
||||
29 | * @throws InvalidArgumentException |
||||
30 | */ |
||||
31 | 3 | public function getContent() |
|||
32 | { |
||||
33 | 3 | $file = $this->getFileLocation(); |
|||
34 | 2 | $filesystem = $this->getFilesystem(); |
|||
35 | |||||
36 | 1 | $content = $filesystem->read($file); |
|||
37 | |||||
38 | 1 | return explode( |
|||
39 | 1 | $this->getConfig('line_separator'), |
|||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
40 | 1 | $content |
|||
41 | 1 | ); |
|||
42 | } |
||||
43 | |||||
44 | /** |
||||
45 | * {@inheritdoc} |
||||
46 | */ |
||||
47 | 1 | public function setContent($content) |
|||
48 | { |
||||
49 | 1 | $file = $this->getFileLocation(); |
|||
50 | 1 | $filesystem = $this->getFilesystem(); |
|||
51 | |||||
52 | 1 | $filesystem->put($file, $content); |
|||
0 ignored issues
–
show
The method
put() does not exist on League\Flysystem\Filesystem .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||
53 | } |
||||
54 | |||||
55 | /** |
||||
56 | * Gets the file location from the config. |
||||
57 | * |
||||
58 | * @return string |
||||
59 | */ |
||||
60 | 4 | protected function getFileLocation() |
|||
61 | { |
||||
62 | 4 | $file = $this->getConfig('file'); |
|||
63 | |||||
64 | 4 | if ( ! $file) |
|||
65 | { |
||||
66 | 1 | throw new InvalidArgumentException('File not specified.'); |
|||
67 | } |
||||
68 | |||||
69 | 3 | return $file; |
|||
0 ignored issues
–
show
|
|||||
70 | } |
||||
71 | |||||
72 | /** |
||||
73 | * @return Filesystem |
||||
74 | */ |
||||
75 | 3 | protected function getFilesystem() |
|||
76 | { |
||||
77 | 3 | $adaptor = $this->getConfig('filesystem'); |
|||
78 | |||||
79 | 3 | if ( ! $adaptor) |
|||
80 | { |
||||
81 | 1 | throw new InvalidArgumentException('Filesystem object not specified.'); |
|||
82 | } |
||||
83 | |||||
84 | 2 | return $adaptor; |
|||
0 ignored issues
–
show
|
|||||
85 | } |
||||
86 | |||||
87 | } |
||||
88 |