DependencyGuard   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 19
c 1
b 0
f 1
dl 0
loc 58
ccs 16
cts 16
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A determineViolations() 0 11 1
A __construct() 0 12 1
1
<?php
2
/**
3
 * Copyright MediaCT. All rights reserved.
4
 * https://www.mediact.nl
5
 */
6
7
namespace Mediact\DependencyGuard;
8
9
use Composer\Composer;
10
use Mediact\DependencyGuard\Iterator\FileIteratorFactoryInterface;
11
use Mediact\DependencyGuard\Php\Filter\SymbolFilterFactoryInterface;
12
use Mediact\DependencyGuard\Php\SymbolExtractorInterface;
13
use Mediact\DependencyGuard\Violation\Filter\ViolationFilterFactoryInterface;
14
use Mediact\DependencyGuard\Violation\Finder\ViolationFinderInterface;
15
use Mediact\DependencyGuard\Violation\ViolationIterator;
16
use Mediact\DependencyGuard\Violation\ViolationIteratorInterface;
17
18
class DependencyGuard implements DependencyGuardInterface
19
{
20
    /** @var FileIteratorFactoryInterface */
21
    private $sourceFileFactory;
22
23
    /** @var SymbolExtractorInterface */
24
    private $extractor;
25
26
    /** @var SymbolFilterFactoryInterface */
27
    private $symbolFilterFactory;
28
29
    /** @var ViolationFinderInterface */
30
    private $finder;
31
32
    /** @var ViolationFilterFactoryInterface */
33
    private $violationFilterFactory;
34
35
    /**
36
     * Constructor.
37
     *
38
     * @param FileIteratorFactoryInterface    $sourceFileFactory
39
     * @param SymbolExtractorInterface        $extractor
40
     * @param SymbolFilterFactoryInterface    $symbolFilterFactory
41
     * @param ViolationFinderInterface        $finder
42
     * @param ViolationFilterFactoryInterface $resultFilterFactory
43
     */
44 1
    public function __construct(
45
        FileIteratorFactoryInterface $sourceFileFactory,
46
        SymbolExtractorInterface $extractor,
47
        SymbolFilterFactoryInterface $symbolFilterFactory,
48
        ViolationFinderInterface $finder,
49
        ViolationFilterFactoryInterface $resultFilterFactory
50
    ) {
51 1
        $this->sourceFileFactory      = $sourceFileFactory;
52 1
        $this->extractor              = $extractor;
53 1
        $this->symbolFilterFactory    = $symbolFilterFactory;
54 1
        $this->finder                 = $finder;
55 1
        $this->violationFilterFactory = $resultFilterFactory;
56 1
    }
57
58
    /**
59
     * Determine dependency violations for the given Composer instance.
60
     *
61
     * @param Composer $composer
62
     *
63
     * @return ViolationIteratorInterface
64
     */
65 1
    public function determineViolations(Composer $composer): ViolationIteratorInterface
66
    {
67 1
        $files        = $this->sourceFileFactory->create($composer);
68 1
        $symbolFilter = $this->symbolFilterFactory->create($composer);
69 1
        $symbols      = $this->extractor->extract($files, $symbolFilter);
70 1
        $violations   = $this->finder->find($composer, $symbols);
71
72 1
        return new ViolationIterator(
73 1
            ...array_filter(
74 1
                iterator_to_array($violations),
75 1
                $this->violationFilterFactory->create($composer)
76
            )
77
        );
78
    }
79
}
80