Caller   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 87
rs 10
wmc 8
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getFromEntityName() 0 9 2
A parser() 0 11 2
A repository() 0 11 2
A getClass() 0 4 1
1
<?php namespace Algorit\Synchronizer\Request;
2
3
use Illuminate\Container\Container;
4
use Illuminate\Filesystem\Filesystem;
5
use Algorit\Synchronizer\Request\Contracts\ParserInterface;
6
use Algorit\Synchronizer\Request\Exceptions\ParserException;
7
use Algorit\Synchronizer\Request\Contracts\RepositoryInterface;
8
use Algorit\Synchronizer\Request\Exceptions\RepositoryException;
9
10
class Caller {
11
12
	/**
13
	 * The container instance
14
	 *
15
	 * @var \Algorit\Synchronizer\Container
16
	 */
17
	protected $container;
18
19
	/**
20
	 * Create a new instance.
21
	 *
22
	 * @param  \Algorit\Synchronizer\Container   $container
23
	 * @return
24
	 */
25
	public function __construct(Container $container)
26
	{
27
		// $this->files = $files;
28
		$this->container = $container;
0 ignored issues
show
Documentation Bug introduced by
It seems like $container of type object<Illuminate\Container\Container> is incompatible with the declared type object<Algorit\Synchronizer\Container> of property $container.

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...
29
	}
30
31
	/**
32
	 * Get the base name given an entity plural name.
33
	 *
34
	 * @param  string  $name
35
	 * @return string
36
	 */
37
	public function getFromEntityName($name)
38
	{
39
		if( ! is_string($name))
40
		{
41
			throw new Exception('Wrong name format');
42
		}
43
44
		return ucfirst(strtolower(str_singular($name)));
45
	}
46
47
	/**
48
	 * Call a parser instance and set the aliases.
49
	 *
50
	 * @param  string $name
51
	 * @param  array  $alias
52
	 * @return \Algorit\Synchronizer\Request\Contracts\ParserInterface
53
	 */
54
	public function parser($name, Array $alias)
55
	{
56
		$parser = $this->container->make($this->getClass('Parsers', $name));
57
58
		if( ! $parser instanceof ParserInterface)
59
		{
60
			throw new ParserException('Parser must implement \Algorit\Synchronizer\Request\Contracts\ParserInterface');
61
		}
62
		
63
		return $parser->setAliases($alias);
64
	}
65
66
	/**
67
	 * Call a repository instance.
68
	 *
69
	 * @param  string $name
70
	 * @return \Algorit\Synchronizer\Request\Contracts\RepositoryInterface
71
	 */
72
	public function repository($name)
73
	{
74
		$repository = $this->container->make($this->getClass('Repositories', $name));
75
76
		if( ! $repository instanceof RepositoryInterface)
77
		{
78
			throw new RepositoryException('Repository must implement \Algorit\Synchronizer\Request\Contracts\RepositoryInterface');
79
		}
80
81
		return $repository;
82
	}
83
84
	/**
85
	* Get the class name
86
	*
87
	* @param  string  $type
88
	* @param  string  $name
89
	* @return string
90
	*/
91
	public function getClass($type, $name)
92
	{
93
		return $this->container->namespace . '\\' . $type . '\\' . $this->getFromEntityName($name);
94
	}
95
96
}
97