ergebnis / php-cs-fixer-config-template
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * Copyright (c) 2019-2021 Andreas Möller
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE.md file that was distributed with this source code.
10
 *
11
 * @see https://github.com/ergebnis/php-cs-fixer-config-template
12
 */
13

14
namespace Ergebnis\PhpCsFixer\Config;
15

16
use PhpCsFixer\Config;
17

18
final class Factory
19
{
20
    /**
21
     * Creates a configuration based on a rule set.
22
     *
23
     * @param array<string, array|bool> $overrideRules
24
     *
25
     * @throws \RuntimeException
26
     */
27 1
    public static function fromRuleSet(RuleSet $ruleSet, array $overrideRules = []): Config
28
    {
29 1
        if (\PHP_VERSION_ID < $ruleSet->targetPhpVersion()) {
30 1
            throw new \RuntimeException(\sprintf(
31
                'Current PHP version "%s" is less than targeted PHP version "%s".',
32
                \PHP_VERSION_ID,
33 1
                $ruleSet->targetPhpVersion()
34
            ));
35
        }
36

37 1
        $config = new Config($ruleSet->name());
38

39 1
        $config->setRiskyAllowed(true);
40 1
        $config->setRules(\array_merge(
41 1
            $ruleSet->rules(),
42 1
            $overrideRules
43
        ));
44

45 1
        return $config;
46
    }
47
}

Read our documentation on viewing source code .

Loading