GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

PHPRangeFile   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 59
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromFileInfo() 0 16 2
A fromRangeAndTotal() 0 8 1
A generateFilePath() 0 10 1
1
<?php
2
3
namespace UCD\Infrastructure\Repository\CharacterRepository\FileRepository\RangeFile;
4
5
use UCD\Exception\InvalidArgumentException;
6
use UCD\Infrastructure\Repository\CharacterRepository\FileRepository\File\PHPFile;
7
use UCD\Infrastructure\Repository\CharacterRepository\FileRepository\Range;
8
use UCD\Infrastructure\Repository\CharacterRepository\FileRepository\RangeFile;
9
10
class PHPRangeFile extends RangeFile
11
{
12
    const FILE_NAME_REGEX  = '/^(?P<start>\d+)-(?P<end>\d+)!(?P<total>\d+)\.php\.gz$/';
13
    const FILE_PATH_FORMAT = '%s/%08d-%08d!%04d.php.gz';
14
15
    /**
16
     * @param \SplFileInfo $fileInfo
17
     * @return PHPRangeFile
18
     * @throws InvalidArgumentException
19
     */
20
    public static function fromFileInfo(\SplFileInfo $fileInfo)
21
    {
22
        if (preg_match(self::FILE_NAME_REGEX, $fileInfo->getBasename(), $matches) !== 1) {
23
            throw new InvalidArgumentException();
24
        }
25
26
        $range = new Range(
27
            (int)$matches['start'],
28
            (int)$matches['end']
29
        );
30
31
        $file = new PHPFile($fileInfo);
32
        $total = (int)$matches['total'];
33
34
        return new self($file, $range, $total);
35
    }
36
37
    /**
38
     * @param \SplFileInfo $basePath
39
     * @param Range $range
40
     * @param int $total
41
     * @return PHPRangeFile
42
     */
43
    public static function fromRangeAndTotal(\SplFileInfo $basePath, Range $range, $total)
44
    {
45
        $filePath = self::generateFilePath($basePath, $range, $total);
46
        $fileInfo = new \SplFileInfo($filePath);
47
        $file = new PHPFile($fileInfo);
48
49
        return new self($file, $range, $total);
50
    }
51
52
    /**
53
     * @param \SplFileInfo $basePath
54
     * @param Range $range
55
     * @param int $total
56
     * @return string
57
     */
58
    private static function generateFilePath(\SplFileInfo $basePath, Range $range, $total)
59
    {
60
        return sprintf(
61
            self::FILE_PATH_FORMAT,
62
            $basePath->getPathname(),
63
            $range->getStart(),
64
            $range->getEnd() - 1,
65
            $total
66
        );
67
    }
68
}