Factory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 3
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
abstract class Factory
17
{
18
    /**
19
     * Init instance of compressor
20
     *
21
     * @internal
22
     */
23
    public static function create(string $compressor): self
24
    {
25
        $class = __NAMESPACE__ . '\\' . ucfirst(strtolower($compressor)) . 'Compressor';
26
27
        if (! class_exists($class) || $class === self::class) {
28
            throw Exception::invalidCompressor($compressor);
29
        }
30
31
        return new $class();
32
    }
33
34
    /**
35
     * Open compression buffer
36
     */
37
    abstract public function open(string $filename, string $mode = 'wb'): bool;
38
39
    /**
40
     * Write data on compression buffer
41
     */
42
    abstract public function write(string $data): int;
43
44
    /**
45
     * Read data on compression buffer
46
     */
47
    abstract public function read(): string;
48
49
    /**
50
     * Close compression buffer
51
     */
52
    abstract public function close(): bool;
53
}
54