Passed
Pull Request — master (#24)
by
unknown
02:15
created

SchemaFromFileFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 9
ccs 0
cts 9
cp 0
crap 6
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Yiisoft\Yii\Cycle\Factory;
4
5
use Cycle\ORM\Schema;
6
use Psr\Container\ContainerInterface;
7
use Yiisoft\Aliases\Aliases;
8
9
final class SchemaFromFileFactory
10
{
11
    private string $file;
12
13
    public function __construct(string $file) {
14
        $this->file = $file;
15
    }
16
17
    public function __invoke(ContainerInterface $container)
18
    {
19
        $aliases = $container->get(Aliases::class);
20
        $file = $aliases->get($this->file);
21
        if (!is_file($file)) {
22
            throw new \Exception('Schema file not found');
23
        }
24
        $schemaArray = include $file;
25
        return new Schema($schemaArray);
26
    }
27
}
28