Completed
Push — symfony-console ( 6e7652...a3a24c )
by Arnaud
01:56
created

FileExtensionFilter::accept()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/*
3
 * This file is part of the Cecil/Cecil package.
4
 *
5
 * Copyright (c) Arnaud Ligny <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Cecil\Command\ShowContent;
12
13
use RecursiveFilterIterator;
14
15
/**
16
 * Filter files by extension type.
17
 *
18
 * Class FileExtensionFilter
19
 */
20
class FileExtensionFilter extends RecursiveFilterIterator
21
{
22
    /**
23
     * @var array
24
     */
25
    protected $allowedExt = ['md', 'markdown'];
26
27
    public function __construct($iter, $ext = '')
28
    {
29
        parent::__construct($iter);
30
        if (!empty($ext)) {
31
            if (!is_array($ext)) {
32
                $ext = [$ext];
33
            }
34
            $this->allowedExt = $ext;
35
        }
36
    }
37
38
    /**
39
     * @return bool
40
     */
41
    public function accept(): bool
42
    {
43
        $file = $this->current();
44
        if ($file->isFile()) {
45
            return in_array($file->getExtension(), $this->allowedExt);
46
        }
47
48
        return true;
49
    }
50
}
51