dimtrovich /
php-db-dumper
| 1 | <?php |
||||
| 2 | |||||
| 3 | /** |
||||
| 4 | * This file is part of dimtrovich/db-dumper". |
||||
| 5 | * |
||||
| 6 | * (c) 2024 Dimitri Sitchet Tomkeu <[email protected]> |
||||
| 7 | * |
||||
| 8 | * For the full copyright and license information, please view |
||||
| 9 | * the LICENSE file that was distributed with this source code. |
||||
| 10 | */ |
||||
| 11 | |||||
| 12 | namespace Dimtrovich\DbDumper\Compressor; |
||||
| 13 | |||||
| 14 | use Dimtrovich\DbDumper\Exceptions\Exception; |
||||
| 15 | |||||
| 16 | class NoneCompressor extends Factory |
||||
| 17 | { |
||||
| 18 | /** |
||||
| 19 | * @var false|resource |
||||
| 20 | */ |
||||
| 21 | private $handler; |
||||
| 22 | |||||
| 23 | /** |
||||
| 24 | * {@inheritDoc} |
||||
| 25 | */ |
||||
| 26 | public function open(string $filename, string $mode = 'wb'): bool |
||||
| 27 | { |
||||
| 28 | 4 | $this->handler = fopen($filename, $mode); |
|||
| 29 | if (false === $this->handler) { |
||||
| 30 | 4 | throw Exception::fileNotWritable($filename); |
|||
| 31 | } |
||||
| 32 | |||||
| 33 | 4 | return true; |
|||
| 34 | } |
||||
| 35 | |||||
| 36 | /** |
||||
| 37 | * {@inheritDoc} |
||||
| 38 | */ |
||||
| 39 | public function write(string $data): int |
||||
| 40 | { |
||||
| 41 | 2 | $bytesWritten = fwrite($this->handler, $data); |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 42 | |||||
| 43 | if (false === $bytesWritten) { |
||||
| 44 | 2 | throw Exception::failledToWrite(); |
|||
| 45 | } |
||||
| 46 | |||||
| 47 | 2 | return $bytesWritten; |
|||
| 48 | } |
||||
| 49 | |||||
| 50 | /** |
||||
| 51 | * {@inheritDoc} |
||||
| 52 | */ |
||||
| 53 | public function read(): string |
||||
| 54 | { |
||||
| 55 | 2 | $content = ''; |
|||
| 56 | |||||
| 57 | while (! feof($this->handler)) { |
||||
|
0 ignored issues
–
show
It seems like
$this->handler can also be of type boolean; however, parameter $stream of feof() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 58 | // Read buffer-size bytes |
||||
| 59 | 2 | $content .= fread($this->handler, 4096); // read 4kb at a time |
|||
|
0 ignored issues
–
show
It seems like
$this->handler can also be of type boolean; however, parameter $stream of fread() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 60 | } |
||||
| 61 | |||||
| 62 | 2 | return $content; |
|||
| 63 | } |
||||
| 64 | |||||
| 65 | /** |
||||
| 66 | * {@inheritDoc} |
||||
| 67 | */ |
||||
| 68 | public function close(): bool |
||||
| 69 | { |
||||
| 70 | 4 | return fclose($this->handler); |
|||
|
0 ignored issues
–
show
It seems like
$this->handler can also be of type boolean; however, parameter $stream of fclose() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 71 | } |
||||
| 72 | } |
||||
| 73 |