ClassLoaderDecorator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 44
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A decorate() 0 18 3
A isDefaultStandard() 0 7 1
A detectStandardNamespaceFromStandardName() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of Symplify
5
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
6
 */
7
8
namespace Symplify\PHP7_CodeSniffer\Composer;
9
10
use Composer\Autoload\ClassLoader;
11
use Symplify\PHP7_CodeSniffer\Standard\Finder\StandardFinder;
12
13
final class ClassLoaderDecorator
14
{
15
    /**
16
     * @var StandardFinder
17
     */
18
    private $standardFinder;
19
20 1
    public function __construct(StandardFinder $standardFinder)
21
    {
22 1
        $this->standardFinder = $standardFinder;
23 1
    }
24
25 1
    public function decorate(ClassLoader $classLoader)
26
    {
27 1
        $standards = $this->standardFinder->getStandards();
28
29 1
        foreach ($standards as $stadardName => $standardRuleset) {
30 1
            if ($this->isDefaultStandard($stadardName)) {
31 1
                continue;
32
            }
33
34 1
            $standardNamespace = $this->detectStandardNamespaceFromStandardName($stadardName);
35 1
            $standardDir = dirname($standardRuleset);
36
37 1
            $classLoader->addPsr4(
38 1
                $standardNamespace . '\\',
39 1
                $standardDir . DIRECTORY_SEPARATOR . $standardNamespace
40
            );
41
        }
42 1
    }
43
44 1
    private function isDefaultStandard(string $stadardName) : bool
45
    {
46 1
        return in_array(
47
            $stadardName,
48 1
            ['PSR1', 'MySource', 'PSR2', 'Zend', 'PEAR', 'Squiz', 'Generic']
49
        );
50
    }
51
52 1
    private function detectStandardNamespaceFromStandardName(string $standardName) : string
53
    {
54 1
        return str_replace(' ', '', $standardName);
55
    }
56
}
57