Completed
Push — develop ( 141adb...8f70d4 )
by Jaap
05:39
created

CollectFiles::__invoke()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 1
nop 1
dl 0
loc 29
ccs 0
cts 25
cp 0
crap 6
rs 9.456
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of phpDocumentor.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @author    Mike van Riel <[email protected]>
12
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
13
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
14
 * @link      http://phpdoc.org
15
 */
16
namespace phpDocumentor\Application\Stage\Parser;
17
18
use phpDocumentor\Parser\FileCollector;
19
use Psr\Log\LoggerInterface;
20
use Psr\Log\LogLevel;
21
22
final class CollectFiles
23
{
24
    /**
25
     * @var FileCollector
26
     */
27
    private $fileCollector;
28
    /**
29
     * @var LoggerInterface
30
     */
31
    private $logger;
32
33
    public function __construct(FileCollector $fileCollector, LoggerInterface $logger)
34
    {
35
        $this->fileCollector = $fileCollector;
36
        $this->logger = $logger;
37
    }
38
39
    public function __invoke(Payload $payload)
40
    {
41
        $this->log('Collecting files .. ');
42
        $apiConfig = $payload->getApiConfig();
43
44
        $ignorePaths = array_map(
45
            static function ($value) {
46
                if (substr((string) $value, -1) === '*') {
47
                    return substr($value, 0, -1);
48
                }
49
50
                return $value;
51
            },
52
            $apiConfig['ignore']['paths']
53
        );
54
55
        $files = $this->fileCollector->getFiles(
56
            $apiConfig['source']['dsn'],
57
            $apiConfig['source']['paths'],
58
            [
59
                'paths' => $ignorePaths,
60
                'hidden' => $apiConfig['ignore']['hidden'],
61
            ],
62
            $apiConfig['extensions']
63
        );
64
        $this->log('OK');
65
66
        return $payload->withFiles($files);
67
    }
68
69
    /**
70
     * Dispatches a logging request.
71
     *
72
     * @param string   $priority The logging priority as declared in the LogLevel PSR-3 class.
73
     * @param string[] $parameters
74
     */
75
    private function log(string $message, string $priority = LogLevel::INFO, array $parameters = []): void
76
    {
77
        $this->logger->log($priority, $message, $parameters);
78
    }
79
}
80