FlyCache   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 38
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A instance() 0 19 3
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL, Commercial license.
5
 *
6
 * @package maslosoft/addendum
7
 * @licence AGPL, Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]> (Meta container, further improvements, bugfixes)
9
 * @copyright Copyright (c) Maslosoft (Meta container, further improvements, bugfixes)
10
 * @copyright Copyright (c) Jan Suchal (Original version, builder, parser)
11
 * @link https://maslosoft.com/addendum/ - maslosoft addendum
12
 * @link https://code.google.com/p/addendum/ - original addendum project
13
 */
14
15
namespace Maslosoft\Addendum\Cache;
16
17
use Maslosoft\Addendum\Addendum;
18
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
19
use Maslosoft\Addendum\Options\MetaOptions;
20
21
/**
22
 * Flyweight accessor for meta cache
23
 *
24
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
25
 */
26
class FlyCache
27
{
28
29
	/**
30
	 * Instances of meta cache
31
	 * @var ClassCache[]
32
	 */
33
	private static $_instances = [];
34
35
	/**
36
	 * Get flyweight instance of meta cache.
37
	 * This is based on meta class and addendum instance id.
38
	 * @param string $metaClass
39
	 * @param string|object|AnnotatedInterface $component
40
	 * @param MetaOptions $options
41
	 * @return ClassCache
42
	 */
43 37
	public static function instance($metaClass = null, $component = null, MetaOptions $options = null)
44
	{
45 37
		if (empty($options))
46
		{
47 33
			$instanceId = Addendum::DefaultInstanceId;
48
		}
49
		else
50
		{
51 4
			$instanceId = $options->instanceId;
52
		}
53 37
		$key = sprintf('%s@%s', $metaClass, $instanceId);
54
55 37
		if (empty(self::$_instances[$key]))
56
		{
57 1
			self::$_instances[$key] = new ClassCache($metaClass, $component, $options);
0 ignored issues
show
Bug introduced by
It seems like $component defined by parameter $component on line 43 can also be of type null; however, Maslosoft\Addendum\Cache\ClassCache::__construct() does only seem to accept object|string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
58
		}
59 37
		self::$_instances[$key]->setOptions($options);
60 37
		return self::$_instances[$key];
61
	}
62
63
}
64