Completed
Push — develop ( fbdd82...317691 )
by Mike
09:29
created

FlySystemAssets   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 53
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 8 2
A has() 0 4 1
A includeTemplateAssets() 0 12 2
1
<?php
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2010-2016 Mike van Riel<[email protected]>
9
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 * @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor\Infrastructure\Renderer;
14
15
use League\Flysystem\Filesystem;
16
use League\Flysystem\MountManager;
17
use phpDocumentor\DomainModel\Path;
18
use phpDocumentor\DomainModel\Renderer\Asset;
19
use phpDocumentor\DomainModel\Renderer\AssetNotFoundException;
20
use phpDocumentor\DomainModel\Renderer\Assets;
21
use phpDocumentor\DomainModel\Renderer\Template;
22
23
final class FlySystemAssets implements Assets
24
{
25
    /** @var Filesystem|MountManager */
26
    private $filesystem;
27
28
    /**
29
     * @param Filesystem|MountManager $filesystem
30
     */
31
    public function __construct($filesystem)
32
    {
33
        $this->filesystem = $filesystem;
34
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39
    public function get(Path $location)
40
    {
41
        if (! $this->has($location)) {
42
            throw new AssetNotFoundException(sprintf('Asset at "%s" could not found', $location));
43
        }
44
45
        return new Asset($this->filesystem->get((string)$location));
46
    }
47
48
    /**
49
     * @inheritDoc
50
     */
51
    public function has(Path $location)
52
    {
53
        return $this->filesystem->has((string)$location);
54
    }
55
56
    /**
57
     * Returns a new instance of this collection with the assets for the given template included.
58
     *
59
     * @param Template $template
60
     *
61
     * @return Assets
62
     */
63
    public function includeTemplateAssets(Template $template)
64
    {
65
        $assets = clone $this;
66
        if ($assets->filesystem instanceof Filesystem) {
67
            $assets->filesystem = new MountManager([$assets->filesystem]);
68
        }
69
70
        // TODO: Add template location to the mount manager
71
        // $assets->filesystem->mountFilesystem('', $template->)
72
73
        return $assets;
74
    }
75
}
76