Passed
Push — 0.8.x ( e71777...998c14 )
by Alexander
21:02 queued 18:05
created

FilesystemAdapter::write()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 2
rs 10
1
<?php
2
3
/**
4
 * Lenevor Framework
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file license.md.
10
 * It is also available through the world-wide-web at this URL:
11
 * https://lenevor.com/license
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to [email protected] so we can send you a copy immediately.
15
 *
16
 * @package     Lenevor
17
 * @subpackage  Base
18
 * @link        https://lenevor.com
19
 * @copyright   Copyright (c) 2019 - 2023 Alexander Campo <[email protected]>
20
 * @license     https://opensource.org/licenses/BSD-3-Clause New BSD license or see https://lenevor.com/license or see /license.md
21
 */
22
23
 namespace Syscodes\Components\Filesystem;
24
25
use Syscodes\Components\Contracts\Filesystem\Filesystem;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Syscodes\Components\Filesystem\Filesystem. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
26
27
/**
28
 * Allows manipulate the file system depending on the file adapter type.
29
 */
30
class FilesystemAdapter implements Filesystem
31
{
32
    /**
33
     * Get the config to file system.
34
     * 
35
     * @var array $config
36
     */
37
    protected $config = [];
38
39
    /**
40
     * Get the driver of file system.
41
     * 
42
     * @var string $driver
43
     */
44
    protected $driver;
45
46
    /**
47
     * Constructor. Create a new FilesystemAdapter instance.
48
     * 
49
     * @param  object  $driver
50
     * @param  array  $config
51
     * 
52
     * @return void
53
     */
54
    public function __construct(object $driver, array $config = [])
55
    {
56
        $this->driver = $driver;
0 ignored issues
show
Documentation Bug introduced by
It seems like $driver of type object is incompatible with the declared type string of property $driver.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
57
        $this->config = $config;
58
    }
59
60
    /**
61
	 * Append given data string to this file.
62
	 *
63
	 * @param  string  $path
64
	 * @param  string  $data
65
	 *
66
	 * @return bool
67
	 */
68
	public function append($path, $data)
69
    {
70
        
71
    }
72
73
    /**
74
	 * Copy a file to a new location.
75
	 *
76
	 * @param  string  $path
77
	 * @param  string  $target
78
	 * 
79
	 * @return bool
80
	 */
81
	public function copy($path, $target): bool
82
    {
83
84
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
85
86
    /**
87
	 * Get the contents of a file.
88
	 *
89
	 * @param  string  $path
90
	 * @param  bool  $lock  
91
	 * @param  bool  $force  
92
	 *
93
	 * @return string
94
	 *
95
	 * @throws FileNotFoundException
96
	 */
97
	public function get($path, $lock = false, $force = false): string
98
    {
99
100
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
101
102
    /**
103
	 * Get contents of a file with shared access.
104
	 *
105
	 * @param  string  $path
106
	 * @param  bool  $force  
107
	 *
108
	 * @return string
109
	 */
110
	public function read($path, $force = false): string
111
    {
112
113
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
114
115
    /**
116
	 * Creates the file.
117
	 * 
118
	 * @param  string  $path
119
	 * 
120
	 * @return bool
121
	 */
122
	public function create($path): bool
123
    {
124
125
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
126
127
    /**
128
	 * Determine if a file exists.
129
	 *
130
	 * @param  string  $path
131
	 *
132
	 * @return bool
133
	 */
134
	public function exists($path): bool
135
    {
136
137
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
138
139
    /**
140
	 * Retrieve the file size.
141
	 *
142
	 * Implementations SHOULD return the value stored in the "size" key of
143
	 * the file in the $_FILES array if available, as PHP calculates this
144
	 * based on the actual size transmitted.
145
	 *
146
	 * @param  string  $path
147
	 * @param  string  $unit
148
	 * 
149
	 * @return int|null  The file size in bytes or null if unknown
150
	 */
151
	public function size($path, $unit = 'b'): int|null
152
    {
153
154
    }
155
156
    /**
157
	 * Get all of the directories within a given directory.
158
	 * 
159
	 * @param  string  $directory
160
	 * 
161
	 * @return array
162
	 */
163
	public function directories($directory): array
164
    {
165
166
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
167
168
    /**
169
	 * Delete the file at a given path.
170
	 * 
171
	 * @param  string  $paths
172
	 * 
173
	 * @return bool
174
	 */
175
	public function delete($paths): bool
176
    {
177
178
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
179
180
    /**
181
	 * Create a directory.
182
	 *
183
	 * @param  string  $path
184
	 * @param  int  $mode
185
	 * @param  bool  $recursive
186
	 * @param  bool  $force
187
	 *
188
	 * @return bool
189
	 * 
190
	 * @throws FileException
191
	 */
192
	public function makeDirectory($path, $mode = 0755, $recursive = false, $force = false): bool
193
    {
194
195
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
196
197
    /**
198
	 * Recursively delete a directory and optionally you can keep 
199
	 * the directory if you wish.
200
	 * 
201
	 * @param  string  $directory
202
	 * @param  bool  $keep
203
	 * 
204
	 * @return bool
205
	 */
206
	public function deleteDirectory($directory, $keep = false): bool
207
    {
208
209
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
210
211
    /**
212
	 * Move a file to a new location.
213
	 *
214
	 * @param  string  $path
215
	 * @param  string  $target
216
	 *
217
	 * @return bool
218
	 */
219
	public function move($path, $target): bool
220
    {
221
222
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
223
224
    /**
225
	 * Prepend to a file.
226
	 * 
227
	 * @param  string  $path
228
	 * @param  string  $data
229
	 * 
230
	 * @return int
231
	 */
232
	public function prepend($path, $data): int
233
    {
234
235
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return integer. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
236
237
    /**
238
	 * Write the content of a file.
239
	 *
240
	 * @param  string  $path
241
	 * @param  string  $contents
242
	 * @param  bool  $lock  
243
	 *
244
	 * @return int|bool
245
	 */
246
	public function put($path, $contents, $lock = false): int|bool
247
    {
248
249
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean|integer. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
250
251
    /**
252
	 * Write given data to this file.
253
	 *
254
	 * @param  string  $path
255
	 * @param  string  $data  Data to write to this File
256
	 * @param  bool  $force  The file to open
257
	 *
258
	 * @return bool
259
	 */
260
	public function write($path, $data, $force = false): bool
261
    {
262
263
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
264
}