Completed
Push — develop ( 61d4f1...4b8b90 )
by
unknown
9s
created

StatusWorkingTree::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1.0046

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1.0046
1
<?php
2
/**
3
 * GitElephant - An abstraction layer for git written in PHP
4
 * Copyright (C) 2013  Matteo Giachino
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see [http://www.gnu.org/licenses/].
18
 */
19
20
namespace GitElephant\Status;
21
22
use \PhpCollection\Sequence;
23
24
/**
25
 * Class StatusWorkingTree
26
 *
27
 * @package GitElephant\Status
28
 */
29
class StatusWorkingTree extends Status
30
{
31
    /**
32
     * all files with modified status in the working tree
33
     *
34
     * @return Sequence
35
     */
36 1
    public function all()
37
    {
38 1
        return new Sequence(
39 1
            array_filter(
40 1
                $this->files,
41
                function (StatusFile $statusFile) {
42
                    return $statusFile->getWorkingTreeStatus();
43 1
                }
44
            )
45
        );
46
    }
47
48
    /**
49
     * filter files by working tree status
50
     *
51
     * @param string $type
52
     *
53
     * @return Sequence
54
     */
55 1
    protected function filterByType(string $type)
56
    {
57 1
        if (!$this->files) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->files of type array 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...
58
            return new Sequence();
59
        }
60
61 1
        return new Sequence(
62 1
            array_filter(
63 1
                $this->files,
64
                function (StatusFile $statusFile) use ($type) {
65 1
                    return $type === $statusFile->getWorkingTreeStatus();
66 1
                }
67
            )
68
        );
69
    }
70
}
71