Shorturl   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getDriverInstance() 0 6 2
A onDriver() 0 5 1
A setDriverInstance() 0 3 1
A __call() 0 3 1
A getDriver() 0 3 2
1
<?php
2
	
3
	namespace Ako\Shorturl;
4
	
5
	use Ako\Shorturl\Drivers\BaseDriver;
6
7
	class Shorturl
8
	{
9
		protected $factory;
10
		protected $driver;
11
		private $driver_instance;
12
13
		public function __construct (DriverFactory $factory)
14
		{
15
			$this->factory = $factory;
16
		}
17
		
18
		/**
19
		 * @param string $driver
20
		 *
21
		 * @return Shorturl
22
		 */
23
		public function onDriver (string $driver)
24
		{
25
			$this->driver = $driver;
26
			$this->setDriverInstance();
27
			return $this;
28
		}
29
30
		/**
31
		 * @return void
32
		 */
33
		private function setDriverInstance ()
34
		{
35
			$this->driver_instance = $this->factory->make($this->getDriver());
36
		}
37
		
38
		/**
39
		 *
40
		 * Get name of current driver in use
41
		 *
42
		 * @return string
43
		 */
44
		public function getDriver (): string
45
		{
46
			return $this->driver ?: config("shorturl.drivers.default");
47
		}
48
		
49
		public function __call ($method, $args)
50
		{
51
			return call_user_func_array(array ($this->getDriverInstance(), $method), $args);
52
		}
53
		
54
		private function getDriverInstance ()
55
		{
56
			if (!$this->driver_instance)
57
				$this->setDriverInstance();
58
			
59
			return $this->driver_instance;
60
		}
61
	}