Passed
Push — master ( 28a3ce...b9357e )
by Siad
05:23
created

LastModifiedAlgorithm::isValid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19
20
class LastModifiedAlgorithm implements Algorithm
21
{
22
    /**
23
     * This algorithm doesn't need any configuration.
24
     * Therefore it's always valid.
25
     * @return bool always true
26
     */
27 1
    public function isValid(): bool
28
    {
29 1
        return true;
30
    }
31
32
    /**
33
     * Computes a 'timestamp' for a file based on the lastModified time.
34
     * @param file  The file for which the value should be computed
35
     * @return string|null the timestamp or <i>null</i> if the timestamp couldn't be computed
36
     */
37 1
    public function getValue(PhingFile $file): ?string
38
    {
39 1
        $lastModified = $file->lastModified();
40 1
        if ($lastModified === 0) {
41
            return null;
42
        }
43
44 1
        return (string) $lastModified;
45
    }
46
47
    /**
48
     * @return string some information about this algorithm.
49
     */
50 1
    public function __toString(): string
51
    {
52 1
        return sprintf('<%s>', __CLASS__);
53
    }
54
}
55