CacheTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setCache() 0 5 1
A getCache() 0 4 1
A getHashForMethodCall() 0 11 1
1
<?php declare(strict_types=1);
2
/**
3
 * Anime List Client
4
 *
5
 * An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
6
 *
7
 * PHP version 7
8
 *
9
 * @package     AnimeListClient
10
 * @author      Timothy J. Warren <[email protected]>
11
 * @copyright   2015 - 2017  Timothy J. Warren
12
 * @license     http://www.opensource.org/licenses/mit-license.html  MIT License
13
 * @version     4.0
14
 * @link        https://github.com/timw4mail/HummingBirdAnimeClient
15
 */
16
17
namespace Aviat\AnimeClient\API;
18
19
use Aviat\Banker\Pool;
20
use Aviat\Ion\Di\ContainerAware;
21
22
/**
23
 * Helper methods for dealing with the Cache
24
 */
25
trait CacheTrait {
26
	
27
	/**
28
	 * @var Aviat\Banker\Pool
29
	 */
30
	protected $cache;
31
	
32
	/**
33
	 * Inject the cache object
34
	 *
35
	 * @param Pool $cache
36
	 * @return $this
37
	 */
38
	public function setCache(Pool $cache): self
39
	{
40
		$this->cache = $cache;
0 ignored issues
show
Documentation Bug introduced by
It seems like $cache of type object<Aviat\Banker\Pool> is incompatible with the declared type object<Aviat\AnimeClient\API\Aviat\Banker\Pool> of property $cache.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41
		return $this;
42
	}
43
	
44
	/**
45
	 * Get the cache object if it exists
46
	 *
47
	 * @return Pool
48
	 */
49
	public function getCache()
50
	{
51
		return $this->cache;
52
	}
53
	
54
	/**
55
	 * Generate a hash as a cache key from the current method call
56
	 *
57
	 * @param object $object
58
	 * @param string $method
59
	 * @param array  $args
60
	 * @return string
61
	 */
62
	public function getHashForMethodCall($object, string $method, array $args = []): string
63
	{
64
		$classname = get_class($object);
65
		$keyObj = [
66
			'class' => $classname,
67
			'method' => $method,
68
			'args' => $args,
69
		];
70
		$hash = sha1(json_encode($keyObj));
71
		return $hash;
72
	}
73
}