Completed
Push — master ( 586888...6f962e )
by Paweł
16s
created

ThemeSettingsSchemaProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getSchema() 0 25 3
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