Passed
Pull Request — master (#68)
by Aleksei
02:18
created

FromFileSchemaProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 12
c 1
b 0
f 0
dl 0
loc 30
ccs 0
cts 13
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withConfig() 0 6 1
A __construct() 0 3 1
A clear() 0 3 1
A read() 0 7 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Cycle\Schema\Provider;
6
7
use Yiisoft\Aliases\Aliases;
8
use Yiisoft\Yii\Cycle\Schema\SchemaProviderInterface;
9
10
/**
11
 * Be careful, using this class may be insecure.
12
 *
13
 * @deprecated use {@see FromFilesSchemaProvider} instead
14
 */
15
final class FromFileSchemaProvider implements SchemaProviderInterface
16
{
17
    private string $file = '';
18
    private Aliases $aliases;
19
20
    public function __construct(Aliases $aliases)
21
    {
22
        $this->aliases = $aliases;
23
    }
24
25
    public function withConfig(array $config): self
26
    {
27
        $new = clone $this;
28
        // required option
29
        $new->file = $this->aliases->get($config['file']);
30
        return $new;
31
    }
32
33
    public function read(?SchemaProviderInterface $nextProvider = null): ?array
34
    {
35
        if (!is_file($this->file)) {
36
            return null;
37
        }
38
        $schema = include $this->file;
39
        return $schema !== null || $nextProvider === null ? $schema : $nextProvider->read();
40
    }
41
42
    public function clear(): bool
43
    {
44
        return false;
45
    }
46
}
47