Completed
Push — master ( f9a203...1ba3b5 )
by MoshiMoshi
04:04
created

FileResource::hasAlias()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 2
eloc 2
nc 2
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the ConfigCacheBundle package.
5
 *
6
 * Copyright (c) 2015 Yahoo Japan Corporation
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 YahooJapan\ConfigCacheBundle\ConfigCache\Resource;
13
14
use Symfony\Component\Config\Definition\ConfigurationInterface;
15
use Symfony\Component\Config\Resource\FileResource as BaseFileResource;
16
17
/**
18
 * FileResource represents a resource stored on the filesystem.
19
 *
20
 * The resource can be a file or a directory.
21
 */
22
class FileResource extends BaseFileResource implements ResourceInterface
23
{
24
    protected $resource;
25
    protected $configuration;
26
    protected $alias;
27
28
    /**
29
     * Constructor.
30
     *
31
     * @param string                 $resource
32
     * @param ConfigurationInterface $configuration
33
     * @param string                 $alias
34
     */
35 34
    public function __construct($resource, ConfigurationInterface $configuration = null, $alias = null)
36
    {
37 34
        $this->resource      = $resource;
38 34
        $this->configuration = $configuration;
39 34
        $this->alias         = $alias;
40 34
    }
41
42
    /**
43
     * Creates a FileResource.
44
     *
45
     * @param string                 $resource
46
     * @param ConfigurationInterface $configuration
47
     * @param string                 $alias
48
     *
49
     * @return FileResource
50
     */
51 1
    public static function create($resource, ConfigurationInterface $configuration = null, $alias = null)
52
    {
53 1
        return new static($resource, $configuration, $alias);
54
    }
55
56
    /**
57
     * Gets configuration.
58
     *
59
     * @return ConfigurationInterface
60
     */
61 30
    public function getConfiguration()
62
    {
63 30
        return $this->configuration;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->configuration; of type null|Symfony\Component\C...\ConfigurationInterface adds the type Symfony\Component\Config...\ConfigurationInterface to the return on line 63 which is incompatible with the return type declared by the interface YahooJapan\ConfigCacheBu...rface::getConfiguration of type YahooJapan\ConfigCacheBu...\ConfigurationInterface.
Loading history...
64
    }
65
66
    /**
67
     * Sets configuration.
68
     *
69
     * @param ConfigurationInterface $configuration
70
     *
71
     * @return FileResource
72
     */
73 1
    public function setConfiguration(ConfigurationInterface $configuration)
74
    {
75 1
        $this->configuration = $configuration;
76
77 1
        return $this;
78
    }
79
80
    /**
81
     * Returns the resource tied to this Resource.
82
     *
83
     * @return mixed The resource
84
     */
85 34
    public function getResource()
86
    {
87 34
        return $this->resource;
88
    }
89
90
    /**
91
     * Sets the resource.
92
     *
93
     * @param string $resource
94
     *
95
     * @return FileResource
96
     */
97 1
    public function setResource($resource)
98
    {
99 1
        $this->resource = $resource;
100
101 1
        return $this;
102
    }
103
104
    /**
105
     * Gets an alias (as ConfigCache service name suffix).
106
     *
107
     * @return string
108
     */
109 7
    public function getAlias()
110
    {
111 7
        return $this->alias;
112
    }
113
114
    /**
115
     * Sets an alias (as ConfigCache service name suffix).
116
     *
117
     * @param string $alias
118
     *
119
     * @return FileResource
120
     *
121
     * @throws \InvalidArgumentException
122
     */
123 6
    public function setAlias($alias)
124
    {
125 6
        if (!is_string($alias)) {
126 2
            throw new \InvalidArgumentException("Alias[{$alias}] must be string.");
127
        }
128 4
        $this->alias = $alias;
129
130 4
        return $this;
131
    }
132
133
    /**
134
     * Whether FileResource has an alias or not.
135
     *
136
     * @return bool
137
     */
138 19
    public function hasAlias()
139
    {
140 19
        return !is_null($this->alias) && $this->alias !== '';
141
    }
142
143
    /**
144
     * {@inheritdoc}
145
     */
146 12
    public function exists()
147
    {
148 12
        return file_exists($this->resource);
149
    }
150
}
151