Completed
Push — master ( 3b5f38...c5ceed )
by Tomáš
04:59
created

SourceFilesProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 60
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getFiles() 0 11 2
A wrapFilesToValueObjects() 0 8 2
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\File;
9
10
use SplFileInfo;
11
use Symplify\PHP7_CodeSniffer\Configuration\Configuration;
12
use Symplify\PHP7_CodeSniffer\Finder\SourceFinder;
13
use Symplify\PHP7_CodeSniffer\Ruleset;
14
15
final class SourceFilesProvider
16
{
17
    /**
18
     * @var File[]
19
     */
20
    private $files;
21
22
    /**
23
     * @var SourceFinder
24
     */
25
    private $sourceFinder;
26
27
    /**
28
     * @var FileFactory
29
     */
30
    private $fileFactory;
31
32
    /**
33
     * @var Configuration
34
     */
35
    private $configuration;
36
37
    public function __construct(
38
        SourceFinder $sourceFinder,
39
        FileFactory $fileFactory,
40
        Configuration $configuration
41
    ) {
42
        $this->sourceFinder = $sourceFinder;
43
        $this->fileFactory = $fileFactory;
44
        $this->configuration = $configuration;
45
    }
46
47
    /**
48
     * @return File[]
49
     */
50
    public function getFiles() : array
51
    {
52
        if ($this->files) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->files of type Symplify\PHP7_CodeSniffer\File\File[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
53
            return $this->files;
54
        }
55
56
        $files = $this->sourceFinder->find($this->configuration->getSource());
57
        $this->files = $this->wrapFilesToValueObjects($files);
58
59
        return $this->files;
60
    }
61
62
    /**
63
     * @param SplFileInfo[] $files
64
     * @return File[]
65
     */
66
    private function wrapFilesToValueObjects(array $files) : array
67
    {
68
        foreach ($files as $name => $fileInfo) {
69
            $files[$name] = $this->fileFactory->create($name);
70
        }
71
72
        return $files;
73
    }
74
}
75