Passed
Pull Request — master (#190)
by Arman
02:47
created

App::getAdapter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.9.5
13
 */
14
15
namespace Quantum\App;
16
17
use Quantum\App\Exceptions\AppException;
18
use Quantum\App\Contracts\AppInterface;
19
use Quantum\Exceptions\BaseException;
20
21
/**
22
 * Class App
23
 * @package Quantum\App
24
 */
25
class App
26
{
27
28
    /**
29
     * Web app adapter
30
     */
31
    const WEB = 'web';
32
33
    /**
34
     * Console app adapter
35
     */
36
    const CONSOLE = 'console';
37
38
    /**
39
     * @var string
40
     */
41
    private static $baseDir;
42
43
    /**
44
     * @var AppInterface
45
     */
46
    private $adapter;
47
48
    /**
49
     * @param AppInterface $adapter
50
     */
51
    public function __construct(AppInterface $adapter)
52
    {
53
        $this->adapter = $adapter;
54
    }
55
56
    /**
57
     * @param string $baseDir
58
     */
59
    public static function setBaseDir(string $baseDir)
60
    {
61
        self::$baseDir = $baseDir;
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    public static function getBaseDir(): string
68
    {
69
        return self::$baseDir;
70
    }
71
72
    /**
73
     * @return AppInterface
74
     */
75
    public function getAdapter(): AppInterface
76
    {
77
        return $this->adapter;
78
    }
79
80
    /**
81
     * @param string $method
82
     * @param array|null $arguments
83
     * @return mixed
84
     * @throws BaseException
85
     */
86
    public function __call(string $method, ?array $arguments)
87
    {
88
        if (!method_exists($this->adapter, $method)) {
89
            throw AppException::methodNotSupported($method, get_class($this->adapter));
90
        }
91
92
        return $this->adapter->$method(...$arguments);
93
    }
94
}