Configurable   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 5
c 2
b 0
f 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A config() 0 3 1
A setConfigRepository() 0 5 1
1
<?php
2
3
namespace FigTree\Config\Concerns;
4
5
use FigTree\Config\Contracts\{
6
	ConfigRepositoryInterface,
7
	ConfigInterface,
8
	ConfigurableInterface,
9
};
10
11
trait Configurable
12
{
13
	/**
14
	 * ConfigRepository instance.
15
	 *
16
	 * @var \FigTree\Config\Contracts\ConfigRepositoryInterface
17
	 */
18
	protected ConfigRepositoryInterface $configRepo;
19
20
	/**
21
	 * Set the Config instance.
22
	 *
23
	 * @param \FigTree\Config\Contracts\ConfigRepositoryInterface $configRepo
24
	 *
25
	 * @return $this
26
	 */
27
	public function setConfigRepository(ConfigRepositoryInterface $configRepo)
28
	{
29
		$this->configRepo = $configRepo;
30
31
		return $this;
32
	}
33
34
	/**
35
	 * Shorthand to either get the associated Config instance or the given
36
	 * top-level key from the Config file.
37
	 *
38
	 * @param string $fileName
39
	 *
40
	 * @return \FigTree\Config\Contracts\ConfigInterface|null
41
	 */
42
	protected function config(string $fileName): ?ConfigInterface
43
	{
44
		return $this->configRepo->get($fileName);
45
	}
46
}
47