Issues (3541)

samples/inbox/FindItems.php (12 issues)

Labels
Severity
1
<?php
2
/**
3
 * Composer autoload
4
 */
5
require_once __DIR__ . '/../../vendor/autoload.php';
6
7
/**
8
 * Used classes
9
 */
10
use WsdlToPhp\PackageBase\AbstractSoapClientBase;
11
use Ews\EnumType\EwsExchangeVersionType;
0 ignored issues
show
The type Ews\EnumType\EwsExchangeVersionType 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...
12
use Ews\EwsClassMap;
0 ignored issues
show
This use statement conflicts with another class in this namespace, EwsClassMap. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
The type Ews\EwsClassMap 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...
13
use Ews\StructType\EwsFindItemType;
0 ignored issues
show
The type Ews\StructType\EwsFindItemType 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...
14
use Ews\StructType\EwsItemResponseShapeType;
0 ignored issues
show
The type Ews\StructType\EwsItemResponseShapeType 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...
15
use Ews\EnumType\EwsDefaultShapeNamesType;
0 ignored issues
show
The type Ews\EnumType\EwsDefaultShapeNamesType 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 Ews\StructType\EwsNonEmptyArrayOfBaseFolderIdsType;
0 ignored issues
show
The type Ews\StructType\EwsNonEmptyArrayOfBaseFolderIdsType 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...
17
use Ews\EnumType\EwsDistinguishedFolderIdNameType;
0 ignored issues
show
The type Ews\EnumType\EwsDistinguishedFolderIdNameType 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...
18
use Ews\EnumType\EwsItemQueryTraversalType;
0 ignored issues
show
The type Ews\EnumType\EwsItemQueryTraversalType 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...
19
use Ews\StructType\EwsDistinguishedFolderIdType;
0 ignored issues
show
The type Ews\StructType\EwsDistinguishedFolderIdType 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...
20
use Ews\StructType\EwsRequestServerVersion;
0 ignored issues
show
The type Ews\StructType\EwsRequestServerVersion 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...
21
22
/**
23
 * Your Office 365 login
24
 */
25
define('EWS_WS_LOGIN', '***************************');
26
/**
27
 * Your Office 365 passowrd
28
 */
29
define('EWS_WS_PASSWORD', '************');
30
31
/**
32
 * Minimal options in order to instanciate the ServiceType named Get
33
 */
34
$options = array(
35
    AbstractSoapClientBase::WSDL_URL => __DIR__ . '/../../wsdl/services.updated.wsdl',
36
    AbstractSoapClientBase::WSDL_CLASSMAP => EwsClassMap::get(),
37
    AbstractSoapClientBase::WSDL_LOGIN => EWS_WS_LOGIN,
38
    AbstractSoapClientBase::WSDL_PASSWORD => EWS_WS_PASSWORD,
39
);
40
41
/**
42
 * Instanciation of the ServiceType get that gather all the operations beginnig with "get".
43
 */
44
$find = new \Ews\ServiceType\EwsFind($options);
0 ignored issues
show
The type Ews\ServiceType\EwsFind 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...
45
$find->setLocation('https://pod51036.outlook.com/ews/Exchange.asmx');
46
/**
47
 * Configure the SoapHeader, each header's method begins with "setSoapHeader".
48
 */
49
$find->setSoapHeaderRequestServerVersion(new EwsRequestServerVersion(EwsExchangeVersionType::VALUE_EXCHANGE_2013_SP_1));
50
/**
51
 * Send the request
52
 */
53
$itemType = new EwsFindItemType();
54
$itemShape = new EwsItemResponseShapeType(EwsDefaultShapeNamesType::VALUE_ALL_PROPERTIES);
55
$itemType
56
    ->setItemShape($itemShape)
57
    ->setParentFolderIds(new EwsNonEmptyArrayOfBaseFolderIdsType(null, new EwsDistinguishedFolderIdType(EwsDistinguishedFolderIdNameType::VALUE_INBOX)))
58
    ->setTraversal(EwsItemQueryTraversalType::VALUE_SHALLOW);
59
$result = $find->FindItem($itemType);
60
61
/**
62
 * Debug informations provided by the utility methods
63
 */
64
if (false) {
65
    echo 'XML Request: ' . $find->getLastRequest() . "\r\n";
66
    echo 'Headers Request: ' . $find->getLastRequestHeaders() . "\r\n";
67
    echo 'XML Response: ' . $find->getLastResponse() . "\r\n";
68
    echo 'Headers Response: ' . $find->getLastResponseHeaders() . "\r\n";
69
}
70
71
if ($result !== false) {
72
    /**
73
     * Display the Inbox items if there is at least one:
74
     *
75
     * Message from "{name} <{email}>" with subject "{subject}" sent at "2017-02-03T20:51:20Z"
76
     * Message from "{name} <{email}>" with subject "{subject}" sent at "2017-02-02T17:48:25Z"
77
     * ... etc
78
     */
79
    foreach($result->getResponseMessages()->getFindItemResponseMessage() as $message) {
80
        $messages = $message->getRootFolder()->getItems()->getMessage();
81
        if (is_array($messages)) {
82
            foreach($messages as $item) {
83
                echo PHP_EOL . sprintf('Message from "%s <%s>" with subject "%s" sent at "%s"',
84
                    $item->getFrom()->getMailbox()->getName(),
85
                    $item->getFrom()->getMailbox()->getEmailAddress(),
86
                    $item->getSubject(),
87
                    $item->getDateTimeSent());
88
            }
89
        } else {
90
            echo PHP_EOL . 'No message found';
91
        }
92
        echo  PHP_EOL;
93
    }
94
} else {
95
    /**
96
     * In this case, we get the \SoapFault object
97
     */
98
    print_r($find->getLastErrorForMethod('\Ews\ServiceType\EwsFind::FindItem'));
99
}