Passed
Push — master ( 4ab488...bcfbc7 )
by Bálint
03:58
created

NorthWindDataService   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 19
dl 0
loc 50
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 7 1
A getService() 0 17 6
1
<?php
2
3
use POData\Configuration\EntitySetRights;
4
require_once 'POData\IBaseService.php';
5
require_once 'POData\IRequestHandler.php';
6
require_once 'POData\DataService.php';
7
require_once 'POData\IServiceProvider.php';
8
use POData\Configuration\ProtocolVersion;
9
use POData\Configuration\ServiceConfiguration;
10
use POData\BaseService;
11
require_once 'NorthWindMetadata.php';
12
require_once 'NorthWindQueryProvider.php';
13
require_once 'NorthWindStreamProvider.php';
14
15
16
class NorthWindDataService extends BaseService
17
{
18
    private $_northWindMetadata = null;
19
    private $_northWindQueryProvider = null;
20
    
21
    /**
22
     * This method is called only once to initialize service-wide policies
23
     * 
24
     * @param ServiceConfiguration $config Data service configuration object
25
     * 
26
     * @return void
27
     */
28
    public function initialize(ServiceConfiguration $config)
29
    {
30
        $config->setEntitySetPageSize('*', 5);
31
        $config->setEntitySetAccessRule('*', EntitySetRights::ALL);
0 ignored issues
show
Bug introduced by
POData\Configuration\EntitySetRights::ALL of type integer is incompatible with the type POData\Configuration\EntitySetRights expected by parameter $rights of POData\Configuration\Ser...etEntitySetAccessRule(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
        $config->setEntitySetAccessRule('*', /** @scrutinizer ignore-type */ EntitySetRights::ALL);
Loading history...
32
        $config->setAcceptCountRequests(true);
33
        $config->setAcceptProjectionRequests(true);
34
        $config->setMaxDataServiceVersion(ProtocolVersion::V3());
35
    }
36
37
    /**
38
     * Get the service like IMetadataProvider, IDataServiceQueryProvider,
39
     * IStreamProvider
40
     * 
41
     * @param String $serviceType Type of service IMetadataProvider,
42
     *                            IDataServiceQueryProvider,
43
     *                            IQueryProvider,
44
     *                            IStreamProvider
45
     * 
46
     * @see library/POData.IServiceProvider::getService()
47
     * @return object
48
     */
49
    public function getService($serviceType)
50
    {
51
        if ($serviceType === 'IMetadataProvider') {
52
            if (is_null($this->_northWindMetadata)) {
53
                $this->_northWindMetadata = CreateNorthWindMetadata::create();
54
            }
55
            
56
            return $this->_northWindMetadata;
57
        } else if ($serviceType === 'IQueryProvider') {
58
            if (is_null($this->_northWindQueryProvider)) {
59
                $this->_northWindQueryProvider = new NorthWindQueryProvider();
60
            }
61
            return $this->_northWindQueryProvider;
62
        } else if ($serviceType === 'IStreamProvider') {
63
            return new NorthWindStreamProvider();
64
        }
65
        return null;
66
    }
67
}