StatusIndex::untracked()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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 StatusIndex
27
 *
28
 * @package GitElephant\Status
29
 */
30
class StatusIndex extends Status
31
{
32
    /**
33
     * @return Sequence<StatusFile>
0 ignored issues
show
Documentation introduced by
The doc-type Sequence<StatusFile> could not be parsed: Expected "|" or "end of type", but got "<" at position 8. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
34
     */
35 1
    public function untracked(): \PhpCollection\Sequence
36
    {
37 1
        return new Sequence();
38
    }
39
40
    /**
41
     * all files with modified status in the index
42
     *
43
     * @return Sequence<StatusFile>
0 ignored issues
show
Documentation introduced by
The doc-type Sequence<StatusFile> could not be parsed: Expected "|" or "end of type", but got "<" at position 8. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
44
     */
45 2
    public function all(): \PhpCollection\Sequence
46
    {
47 2
        return new Sequence(
48 2
            array_filter(
49 2
                $this->files,
50
                function (StatusFile $statusFile) {
51 2
                    return $statusFile->getIndexStatus() && '?' !== $statusFile->getIndexStatus();
52 2
                }
53
            )
54
        );
55
    }
56
57
    /**
58
     * filter files by index status
59
     *
60
     * @param string $type
61
     *
62
     * @return Sequence<StatusFile>
0 ignored issues
show
Documentation introduced by
The doc-type Sequence<StatusFile> could not be parsed: Expected "|" or "end of type", but got "<" at position 8. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
63
     */
64 3
    protected function filterByType(string $type): \PhpCollection\Sequence
65
    {
66 3
        if (!$this->files) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->files of type GitElephant\Status\StatusFile[] 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...
67 1
            return new Sequence();
68
        }
69
70 2
        return new Sequence(
71 2
            array_filter(
72 2
                $this->files,
73
                function (StatusFile $statusFile) use ($type) {
74 2
                    return $type === $statusFile->getIndexStatus();
75 2
                }
76
            )
77
        );
78
    }
79
}
80