Completed
Push — develop ( ab9f70...4afa03 )
by
unknown
02:16
created

StatusWorkingTree   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 42
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

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