CandidateBuilder::build()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
ccs 7
cts 7
cp 1
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Tworzenieweb\SqlProvisioner\Model;
4
5
use Symfony\Component\Finder\SplFileInfo;
6
7
/**
8
 * @author Luke Adamczewski
9
 * @package Tworzenieweb\SqlProvisioner\Model
10
 */
11
class CandidateBuilder
12
{
13
    const DELIMITER_PATTERN = '/-{2}\s*\/{2}\s*@\s?UNDO/';
14
15
16
17
    /**
18
     * @param SplFileInfo $fileInfo
19
     * @return Candidate
20
     */
21 2
    public function build(SplFileInfo $fileInfo)
22
    {
23 2
        $content = $fileInfo->getContents();
24 2
        preg_match(self::DELIMITER_PATTERN, $content, $matches, PREG_OFFSET_CAPTURE);
25
26 2
        if (!empty($matches)) {
27 1
            $content = substr($content, 0, $matches[0][1] - 1);
28 1
        }
29
30 2
        return new Candidate($fileInfo->getFilename(), $content);
31
    }
32
}
33