Completed
Push — master ( d42705...573ee7 )
by Tomáš
05:03 queued 02:39
created

PathAnalyzer::startsWithDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of Symplify
5
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
6
 */
7
8
namespace Symplify\PHP7_Sculpin\Utils;
9
10
use DateTime;
11
use DateTimeInterface;
12
use SplFileInfo;
13
14
final class PathAnalyzer
15
{
16 2
    public static function startsWithDate(SplFileInfo $file) : bool
17
    {
18 2
        return (bool) preg_match('/(\d{4})[\/\-]*(\d{2})[\/\-]*(\d{2})[\/\-]*(\d+|)/', $file->getFilename(), $matches);
19
    }
20
21 1
    public static function detectDate(SplFileInfo $file) : DateTimeInterface
22
    {
23 1
        preg_match('/(\d{4})[\/\-]*(\d{2})[\/\-]*(\d{2})[\/\-]*(\d+|)/', $file->getFilename(), $matches);
24 1
        list($dummy, $year, $month, $day) = $matches;
0 ignored issues
show
Unused Code introduced by
The assignment to $dummy is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
25
26 1
        return new DateTime(implode('-', [$year, $month, $day]));
27
    }
28
29 1
    public static function detectFilenameWithoutDate(SplFileInfo $file) : string
30
    {
31 1
        preg_match('/(\d{4})[\/\-]*(\d{2})[\/\-]*(\d{2})[\/\-]*(.+?)(\.[^\.]+|\.[^\.]+\.[^\.]+)$/', $file->getFilename(), $matches);
32
33 1
        return $matches[4];
34
    }
35
}
36