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

FileFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 27
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 11 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