WordPressDataService::getService()   D
last analyzed

Complexity

Conditions 10
Paths 18

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 4.8196
c 0
b 0
f 0
cc 10
eloc 17
nc 18
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 21 and the first side effect is on line 4.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
use POData\OperationContext\ServiceHost;
12
use POData\Common\ODataException;
13
use POData\Common\ODataConstants;
14
use POData\Common\Messages;
15
use POData\UriProcessor\UriProcessor;
16
require_once 'WordPressMetadata.php';
17
require_once 'WordPressQueryProvider.php';
18
require_once 'WordPressDSExpressionProvider.php';
19
20
21
class WordPressDataService extends BaseService
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: getMetadataProvider, getQueryProvider, getStreamProviderX
Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
22
{
23
    private $_wordPressMetadata = null;
24
    private $_wordPressQueryProvider = null;
25
    private $_wordPressExpressionProvider = null;
26
    
27
    /**
28
     * This method is called only once to initialize service-wide policies
29
     * 
30
     * @param ServiceConfiguration $config Data service configuration object
31
     * 
32
     * @return void
33
     */
34 View Code Duplication
    public function initialize(ServiceConfiguration $config)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36
        $config->setEntitySetPageSize('*', 5);
37
        $config->setEntitySetAccessRule('*', EntitySetRights::ALL);
38
        $config->setAcceptCountRequests(true);
39
        $config->setAcceptProjectionRequests(true);
40
        $config->setMaxDataServiceVersion(ProtocolVersion::V3());
41
    }
42
43
    /**
44
     * Get the service like IMetadataProvider, IDataServiceQueryProvider,
45
     * IStreamProvider
46
     * 
47
     * @param String $serviceType Type of service IMetadataProvider,
48
     *                            IDataServiceQueryProvider,
49
     *                            IStreamProvider
50
     * 
51
     * @see library/POData.IServiceProvider::getService()
52
     * @return object
53
     */
54
    public function getService($serviceType)
55
    {
56
      if(($serviceType === 'IMetadataProvider') ||
57
        ($serviceType === 'IQueryProvider') ||
58
        ($serviceType === 'IStreamProvider')) {
59
        if (is_null($this->_wordPressExpressionProvider)) {
60
        $this->_wordPressExpressionProvider = new WordPressDSExpressionProvider();    			
61
        }    	
62
      }
63
        if ($serviceType === 'IMetadataProvider') {
64
            if (is_null($this->_wordPressMetadata)) {
65
                $this->_wordPressMetadata = CreateWordPressMetadata::create();
66
                // $this->_wordPressMetadata->mappedDetails = CreateWordPressMetadata::mappingInitialize();
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
67
            }
68
            return $this->_wordPressMetadata;
69
        } else if ($serviceType === 'IQueryProvider') {
70
            if (is_null($this->_wordPressQueryProvider)) {
71
                $this->_wordPressQueryProvider = new WordPressQueryProvider();
72
            }
73
            return $this->_wordPressQueryProvider;
74
        } else if ($serviceType === 'IStreamProvider') {
75
            return new WordPressStreamProvider();
76
        }
77
        return null;
78
    }
79
}
80