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

FileExtensionFilter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A accept() 0 9 2
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