Completed
Push — master ( 649e1f...bdce94 )
by Gareth
04:10
created

MiddlewareFactory::getSoapCall()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php
2
3
namespace garethp\ews\API\ExchangeWebServices;
4
5
use garethp\ews\API\MiddlewareRequest;
6
use garethp\ews\API\MiddlewareResponse;
7
use garethp\ews\API\Type;
8
use garethp\ews\API\ExchangeWebServices;
9
use garethp\ews\API\Type\FindFolderParentType;
10
use garethp\ews\API\Type\FindItemParentType;
11
12
class MiddlewareFactory
13
{
14 28
    public function getSoapCall()
15
    {
16
        return function (MiddlewareRequest $request) {
17 28
            $client = $this->getClient();
0 ignored issues
show
Bug introduced by
The method getClient() does not seem to exist on object<garethp\ews\API\E...ices\MiddlewareFactory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
18 28
            $response = $client->__call($request->getName(), $request->getArguments());
19 28
            $response = MiddlewareResponse::newResponse($response);
20
21 28
            return $response;
22 1
        };
23
    }
24
25 28
    public function getTypeToXMLObject()
26
    {
27
        return function (MiddlewareRequest $request, callable $next) {
28 28
            if ($request->getRequest() instanceof Type) {
29 28
                $request->setRequest($request->getRequest()->toXmlObject());
30 28
            }
31
32 28
            return $next($request);
33 1
        };
34
    }
35
36 28
    public function getStripSyncScopeForExchange2007()
37
    {
38
        return function (MiddlewareRequest $request, callable $next) {
39 28
            $options = $request->getOptions();
40 28
            $version2007SP1 = ($options['version'] == ExchangeWebServices::VERSION_2007
41 28
                || $options['version'] == ExchangeWebServices::VERSION_2007_SP1);
42
43 28
            $requestObj = $request->getName();
44
45 28
            if ($request->getName() == "SyncFolderItems" && $version2007SP1 && isset($requestObj->SyncScope)) {
46
                unset($requestObj->SyncScope);
47
                $request->setRequest($requestObj);
48
            }
49
50 28
            return $next($request);
51 1
        };
52
    }
53
54 28
    public function getProcessResponse()
55
    {
56
        return function (MiddlewareRequest $request, callable $next) {
57 28
            $response = $next($request);
58
59 28
            $response->setResponse($this->processResponse($response->getResponse()));
0 ignored issues
show
Bug introduced by
The method processResponse() does not exist on garethp\ews\API\Exchange...vices\MiddlewareFactory. Did you maybe mean getProcessResponse()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
60
61 28
            return $response;
62 1
        };
63
    }
64
65
    public function getAddLastRequestToPagedResults()
66
    {
67 28
        return function (MiddlewareRequest $request, callable $next) {
68 28
            $response = $next($request);
69
70 28
            $responseObject = $response->getResponse();
71
            if (($responseObject instanceof FindItemParentType
0 ignored issues
show
Bug introduced by
The class garethp\ews\API\Type\FindItemParentType does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
72 28
                    || $responseObject instanceof FindFolderParentType)
0 ignored issues
show
Bug introduced by
The class garethp\ews\API\Type\FindFolderParentType does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
73 28
                && !$responseObject->isIncludesLastItemInRange()) {
74 1
                $responseObject->setLastRequest($request->getRequest());
75 1
                $response->setResponse($responseObject);
76 1
            }
77
78 28
            return $response;
79 1
        };
80
    }
81
}