FileFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
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
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