ComponentTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 16
ccs 4
cts 5
cp 0.8
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromContainer() 0 8 3
1
<?php
2
/**
3
 * Copyright 2017 NanoSector
4
 *
5
 * You should have received a copy of the MIT license with the project.
6
 * See the LICENSE file for more information.
7
 */
8
9
namespace Yoshi2889\Container;
10
11
use Psr\Container\ContainerInterface;
12
13
trait ComponentTrait
14
{
15
	/**
16
	 * @param ContainerInterface $container
17
	 *
18
	 * @return static
19
	 * @throws NotFoundException
20
	 */
21 4
	public static function fromContainer(ContainerInterface $container)
22
	{
23 4
		$obj = $container->get(__CLASS__);
24
25 2
		if ($obj && $obj instanceof static)
26 2
			return $obj;
27
28
		throw new NotFoundException();
29
	}
30
}