Passed
Push — assets ( 786873...de28b7 )
by Arnaud
08:23 queued 05:44
created

Asset::getHtml()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 0
dl 0
loc 13
rs 9.9666
c 0
b 0
f 0
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
    protected $fileLoaded = false;
20
21
    /**
22
     * Loads a file.
23
     *
24
     * @param string $path
25
     *
26
     * @return self
27
     */
28
    public function getFile(string $path): self
29
    {
30
        $filePath = Util::joinFile($this->config->getStaticPath(), $path);
31
32
        if (!Util::getFS()->exists($filePath)) {
33
            throw new Exception(sprintf('Asset file "%s" doesn\'t exist.', $path));
34
        }
35
        $this->fileLoaded = true;
36
37
        $fileInfo = new \SplFileInfo($filePath);
38
39
        $this->asset['path'] = $path;
40
        $this->asset['ext'] = $fileInfo->getExtension();
41
42
        return $this;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function __toString(): string
49
    {
50
        return $this->asset['path'];
51
    }
52
53
    public function getHtml(): string
54
    {
55
        if (!$this->fileLoaded) {
56
            throw new Exception(\sprintf('%s() error: you must load a file first.', __FUNCTION__));
57
        }
58
59
        switch ($this->asset['ext']) {
60
            case 'css':
61
                return \sprintf('<link rel="stylesheet" href="%s">', $this->asset['path']);
62
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
63
            default:
64
                return 'POUET';
65
                break;
66
        }
67
    }
68
}
69