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

FileFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\PHP7_Sculpin\Renderable\File;
11
12
use Nette\Utils\Strings;
13
use SplFileInfo;
14
15
final class FileFactory
16
{
17
    /**
18
     * @var string
19
     */
20
    private $sourceDirectory;
21
22 7
    public function __construct(string $sourceDirectory)
23
    {
24 7
        $this->sourceDirectory = $sourceDirectory;
25 7
    }
26
27
    /**
28
     * @return File|PostFile
29
     */
30 7
    public function create(SplFileInfo $file) : File
31
    {
32 7
        $relativeSource = substr($file->getPathname(), strlen($this->sourceDirectory));
33 7
        $relativeSource = ltrim($relativeSource, DIRECTORY_SEPARATOR);
34
35 7
        if (Strings::endsWith($file->getPath(), '_posts')) {
36 2
            return new PostFile($file, $relativeSource);
37
        }
38
39 5
        return new File($file, $relativeSource);
40
    }
41
}
42