FileFactory::create()   A
last analyzed

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
use Symplify\PHP7_Sculpin\Configuration\Configuration;
15
16
final class FileFactory
17
{
18
    /**
19
     * @var Configuration
20
     */
21
    private $configuration;
22
23 18
    public function __construct(Configuration $configuration)
24
    {
25 18
        $this->configuration = $configuration;
26 18
    }
27
28
    /**
29
     * @return File|PostFile
30
     */
31 15
    public function create(SplFileInfo $file) : AbstractFile
32
    {
33 15
        $relativeSource = substr($file->getPathname(), strlen($this->configuration->getSourceDirectory()));
34 15
        $relativeSource = ltrim($relativeSource, DIRECTORY_SEPARATOR);
35
36 15
        if (Strings::endsWith($file->getPath(), '_posts')) {
37 5
            return new PostFile($file, $relativeSource);
38
        }
39
40 11
        return new File($file, $relativeSource);
41
    }
42
}
43