Passed
Push — master ( e6bc2a...a7212f )
by Kirill
04:45
created

TypeLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 53
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A filterExtension() 0 4 1
A withExtension() 0 6 1
A withoutExtension() 0 12 1
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\TypeLoader;
11
12
/**
13
 * Class TypeLoader
14
 */
15
abstract class TypeLoader implements TypeLoaderInterface
16
{
17
    /**
18
     * @var string[]
19
     */
20
    private const DEFAULT_SCHEMA_EXTENSIONS = [
21
        'graphqls',
22
        'graphql',
23
        'gql',
24
    ];
25
26
    /**
27
     * @var array|string[]
28
     */
29
    protected $fileExtensions = self::DEFAULT_SCHEMA_EXTENSIONS;
30
31
    /**
32
     * @param string $extension
33
     * @return string
34
     */
35
    private function filterExtension(string $extension): string
36
    {
37
        return \ltrim(\trim($extension), '.');
38
    }
39
40
    /**
41
     * @param string $extension
42
     * @return TypeLoader|$this
43
     */
44
    public function withExtension(string $extension): self
45
    {
46
        $this->fileExtensions[] = $this->filterExtension($extension);
47
48
        return $this;
49
    }
50
51
    /**
52
     * @param string $extension
53
     * @return TypeLoader|$this
54
     */
55
    public function withoutExtension(string $extension): self
56
    {
57
        $extension = $this->filterExtension($extension);
58
59
        $filter = function (string $haystack) use ($extension): bool {
60
            return $haystack !== $extension;
61
        };
62
63
        $this->fileExtensions = \array_filter($this->fileExtensions, $filter);
64
65
        return $this;
66
    }
67
}
68