Shorturl::getDriver()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
	}