FileResource::getBody()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the puli/repository package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Puli\Repository\Resource;
13
14
use Puli\Repository\Api\Resource\BodyResource;
15
use Puli\Repository\Api\ResourceNotFoundException;
16
use Puli\Repository\Resource\Collection\ArrayResourceCollection;
17
use Webmozart\Assert\Assert;
18
19
/**
20
 * Represents a file on the file system.
21
 *
22
 * @since  1.0
23
 *
24
 * @author Bernhard Schussek <[email protected]>
25
 */
26
class FileResource extends AbstractFilesystemResource implements BodyResource
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31 397
    public function __construct($filesystemPath, $path = null)
32
    {
33 397
        Assert::file($filesystemPath);
34
35 395
        parent::__construct($filesystemPath, $path);
36 395
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 56
    public function getBody()
42
    {
43 56
        return file_get_contents($this->getFilesystemPath());
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 3
    public function getChild($relPath)
50
    {
51 3
        throw ResourceNotFoundException::forPath($this->getPath().'/'.$relPath);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 3
    public function hasChild($relPath)
58
    {
59 3
        return false;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 27
    public function hasChildren()
66
    {
67 27
        return false;
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73 107
    public function listChildren()
74
    {
75 107
        return new ArrayResourceCollection();
76
    }
77
}
78