Completed
Push — master ( 9b25f2...d42705 )
by Tomáš
09:42 queued 07:08
created

FileFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 24
ccs 0
cts 9
cp 0
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
    public function __construct(string $sourceDirectory)
23
    {
24
        $this->sourceDirectory = $sourceDirectory;
25
    }
26
27
    public function create(SplFileInfo $file) : File
28
    {
29
        $relativeSource = substr($file->getPathname(), strlen($this->sourceDirectory));
30
        $relativeSource = ltrim($relativeSource, DIRECTORY_SEPARATOR);
31
32
        if (Strings::endsWith($file->getPath(), '_posts')) {
33
            return new PostFile($file, $relativeSource);
34
        }
35
36
        return new File($file, $relativeSource);
37
    }
38
}
39