Passed
Push — assets ( 3e13ea...57a633 )
by Arnaud
13:03 queued 10:25
created

Asset::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * This file is part of the Cecil/Cecil package.
4
 *
5
 * Copyright (c) Arnaud Ligny <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Cecil\Assets;
12
13
use Cecil\Exception\Exception;
14
use Cecil\Util;
15
16
class Asset extends AbstractAsset
17
{
18
    protected $asset = [];
19
20
    /**
21
     * Loads a file.
22
     *
23
     * @param string $path
24
     *
25
     * @return self
26
     */
27
    public function load(string $path): self
28
    {
29
        $filePath = Util::joinFile($this->config->getStaticPath(), $path);
30
31
        if (!Util::getFS()->exists($filePath)) {
32
            throw new Exception(sprintf('Asset file "%s" doesn\'t exist.', $path));
33
        }
34
35
        $fileInfo = new \SplFileInfo($filePath);
36
37
        $this->asset['path'] = $path;
38
        $this->asset['ext'] = $fileInfo->getExtension();
39
40
        return $this;
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function __toString(): string
47
    {
48
        return $this->asset['path'];
49
50
        //return \sprintf('<link rel="stylesheet" href="%s">', $this->asset['path']);
51
    }
52
}
53