Completed
Push — master ( 586888...6f962e )
by Kamil
14s
created

ThemeSettingsSchemaProvider::getSchema()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 3
eloc 15
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\ThemeBundle\Settings;
13
14
use Sylius\Bundle\SettingsBundle\Schema\SchemaInterface;
15
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
16
17
/**
18
 * @author Kamil Kokot <[email protected]>
19
 */
20
final class ThemeSettingsSchemaProvider implements ThemeSettingsSchemaProviderInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function getSchema(ThemeInterface $theme)
26
    {
27
        $schemaPath = sprintf('%s/Settings.php', $theme->getPath());
28
29
        if (!file_exists($schemaPath)) {
30
            throw new \InvalidArgumentException(sprintf(
31
                'Could not find settings schema of theme "%s" (%s) in file "%s"',
32
                $theme->getTitle(),
33
                $theme->getName(),
34
                $schemaPath
35
            ));
36
        }
37
38
        $schema = require $schemaPath;
39
40
        if (!$schema instanceof SchemaInterface) {
41
            throw new \InvalidArgumentException(sprintf(
42
                'File "%s" must return an instance of "%s"',
43
                $schemaPath,
44
                SchemaInterface::class
45
            ));
46
        }
47
48
        return $schema;
49
    }
50
}
51