Completed
Push — master ( 2bf901...7d3f30 )
by Christopher
24s queued 15s
created

SimpleDataService::initializeDefaultConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace POData;
6
7
use POData\Common\ODataException;
8
use POData\Configuration\EntitySetRights;
9
use POData\Configuration\IServiceConfiguration;
10
use POData\ObjectModel\IObjectSerialiser;
11
use POData\OperationContext\ServiceHost;
12
use POData\Providers\Metadata\IMetadataProvider;
13
use POData\Providers\Metadata\SimpleMetadataProvider;
14
use POData\Providers\Query\IQueryProvider;
15
use POData\Providers\Query\SimpleQueryProvider;
0 ignored issues
show
Bug introduced by
The type POData\Providers\Query\SimpleQueryProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use POData\Providers\Stream\IStreamProvider2;
17
use POData\Providers\Stream\SimpleStreamProvider;
18
19
/**
20
 * DataService that implements IServiceProvider.
21
 **/
22
class SimpleDataService extends BaseService implements IService
23
{
24
    /**
25
     * @var IMetadataProvider
26
     */
27
    protected $metaProvider;
28
    /**
29
     * @var IQueryProvider
30
     */
31
    protected $queryProvider;
32
33
    /**
34
     * @var IStreamProvider2;
35
     */
36
    protected $streamProvider;
37
38
    /**
39
     * SimpleDataService constructor.
40
     * @param $db
41
     * @param  SimpleMetadataProvider     $metaProvider
42
     * @param  ServiceHost                $host
43
     * @param  IObjectSerialiser|null     $serialiser
44
     * @param  IStreamProvider2|null      $streamProvider
45
     * @param  IServiceConfiguration|null $config
46
     * @throws ODataException
47
     */
48
    public function __construct(
49
        $db,
50
        SimpleMetadataProvider $metaProvider,
51
        ServiceHost $host,
52
        IObjectSerialiser $serialiser = null,
53
        IStreamProvider2 $streamProvider = null,
54
        IServiceConfiguration $config = null
55
    ) {
56
        $this->metaProvider = $metaProvider;
57
        if ($db instanceof IQueryProvider) {
58
            $this->queryProvider = $db;
59
        } elseif (!empty($db->queryProviderClassName)) {
60
            $queryProviderClassName = $db->queryProviderClassName;
61
            $this->queryProvider    = new $queryProviderClassName($db);
62
        } else {
63
            throw new ODataException('Invalid query provider supplied', 500);
64
        }
65
        $this->setStreamProvider($streamProvider);
66
67
        $this->setHost($host);
68
        parent::__construct($serialiser, $metaProvider, $config);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     * @throws Common\InvalidOperationException
74
     */
75
    public function initializeDefaultConfig(IServiceConfiguration $config)
76
    {
77
        $config->setEntitySetPageSize('*', 400);
78
        $config->setEntitySetAccessRule('*', EntitySetRights::ALL());
79
        $config->setAcceptCountRequests(true);
80
        $config->setAcceptProjectionRequests(true);
81
        return $config;
82
    }
83
84
    public function initialize(IServiceConfiguration $config)
85
    {
86
    }
87
88
    /**
89
     * @return IQueryProvider
90
     */
91
    public function getQueryProvider(): ?IQueryProvider
92
    {
93
        return $this->queryProvider;
94
    }
95
96
    /**
97
     * @return IMetadataProvider
98
     */
99
    public function getMetadataProvider()
100
    {
101
        return $this->metaProvider;
102
    }
103
104
    /**
105
     * @param  IStreamProvider2|null $streamProvider
106
     * @return void
107
     */
108
    public function setStreamProvider(IStreamProvider2 $streamProvider = null)
109
    {
110
        $this->streamProvider = (null == $streamProvider) ? new SimpleStreamProvider() : $streamProvider;
111
    }
112
    /**
113
     * @return IStreamProvider2
114
     */
115
    public function getStreamProviderX()
116
    {
117
        return $this->streamProvider;
118
    }
119
120
    /**
121
     * This method is called only once to initialize service-wide policies.
122
     *
123
     * @param IServiceConfiguration $config data service configuration
124
     */
125
    public function initializeService(IServiceConfiguration $config)
126
    {
127
        $config->setEntitySetAccessRule('*', EntitySetRights::ALL());
128
    }
129
}
130