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 StatusIndex |
26
|
|
|
* |
27
|
|
|
* @package GitElephant\Status |
28
|
|
|
*/ |
29
|
|
|
class StatusIndex extends Status |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @return Sequence |
33
|
|
|
*/ |
34
|
1 |
|
public function untracked() |
35
|
|
|
{ |
36
|
1 |
|
return new Sequence(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* all files with modified status in the index |
41
|
|
|
* |
42
|
|
|
* @return Sequence |
43
|
|
|
*/ |
44
|
2 |
|
public function all() |
45
|
|
|
{ |
46
|
|
|
return new Sequence(array_filter($this->files, function (StatusFile $statusFile) { |
47
|
2 |
|
return $statusFile->getIndexStatus() && '?' !== $statusFile->getIndexStatus(); |
48
|
2 |
|
})); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* filter files by index status |
53
|
|
|
* |
54
|
|
|
* @param string $type |
55
|
|
|
* |
56
|
|
|
* @return Sequence |
57
|
|
|
*/ |
58
|
1 |
|
protected function filterByType($type) |
59
|
|
|
{ |
60
|
1 |
|
if (!$this->files) { |
|
|
|
|
61
|
|
|
return new Sequence(); |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
return new Sequence(array_filter($this->files, function (StatusFile $statusFile) use ($type) { |
65
|
1 |
|
return $type === $statusFile->getIndexStatus(); |
66
|
1 |
|
})); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
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.