Passed
Pull Request — master (#182)
by Alex
05:31
created

LaravelBaseQuery::getAuth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: alex
5
 * Date: 29/09/19
6
 * Time: 4:55 PM
7
 */
8
9
namespace AlgoWeb\PODataLaravel\Query;
10
11
use AlgoWeb\PODataLaravel\Auth\NullAuthProvider;
12
use AlgoWeb\PODataLaravel\Controllers\MetadataControllerContainer;
13
use AlgoWeb\PODataLaravel\Interfaces\AuthInterface;
14
use AlgoWeb\PODataLaravel\Providers\MetadataProvider;
15
use Illuminate\Support\Facades\App;
16
use POData\Common\InvalidOperationException;
17
18
abstract class LaravelBaseQuery
19
{
20
    /** @var AuthInterface */
21
    protected $auth;
22
    /** @var MetadataProvider */
23
    protected $metadataProvider;
24
    /** @var MetadataControllerContainer */
25
    protected $controllerContainer;
26
27
    public function __construct(AuthInterface $auth = null)
28
    {
29
        $this->auth = isset($auth) ? $auth : new NullAuthProvider();
30
        $this->metadataProvider = new MetadataProvider(App::make('app'));
31
        $this->controllerContainer = App::make('metadataControllers');
32
    }
33
34
    /**
35
     * Dig out local copy of POData-Laravel metadata provider.
36
     *
37
     * @return MetadataProvider
38
     */
39
    public function getMetadataProvider()
40
    {
41
        return $this->metadataProvider;
42
    }
43
44
    /**
45
     * Dig out local copy of controller metadata mapping.
46
     *
47
     * @return MetadataControllerContainer
48
     * @throws InvalidOperationException
49
     */
50
    public function getControllerContainer()
51
    {
52
        if (null === $this->controllerContainer) {
53
            throw new InvalidOperationException('Controller container must not be null');
54
        }
55
        return $this->controllerContainer;
56
    }
57
58
    protected function getAuth()
59
    {
60
        return $this->auth;
61
    }
62
}
63