Completed
Push — master ( 7746c2...0a0629 )
by Gareth
02:53
created

API::getPrimarySmptEmailAddress()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 3
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
3
namespace jamesiarmes\PEWS;
4
5
use jamesiarmes\PEWS\API\ExchangeWebServices;
6
use jamesiarmes\PEWS\API\Message\GetServerTimeZonesType;
7
use jamesiarmes\PEWS\API\Message\SyncFolderItemsResponseMessageType;
8
use jamesiarmes\PEWS\API\Type;
9
use jamesiarmes\PEWS\Calendar\CalendarAPI;
10
use jamesiarmes\PEWS\Mail\MailAPI;
11
12
/**
13
 * A base class for APIs
14
 *
15
 * Class BaseAPI
16
 * @package jamesiarmes\PEWS
17
 */
18
class API
19
{
20
    protected static $defaultClientOptions = array(
21
        'version' => ExchangeWebServices::VERSION_2010
22
    );
23 23
24
    public function __construct(ExchangeWebServices $client = null)
25 23
    {
26 10
        if ($client) {
27 10
            $this->setClient($client);
28 23
        }
29
    }
30
31
    /**
32
     * @return Type\EmailAddressType
33 15
     */
34
    public function getPrimarySmtpMailbox()
35 15
    {
36
        return $this->getClient()->getPrimarySmtpMailbox();
37
    }
38
39
    private $fieldUris = array();
40
41
    /**
42
     * Storing the API client
43
     * @var ExchangeWebServices
44
     */
45
    private $client;
46 4
47
    public function setupFieldUris()
48
    {
49 4
        //So, since we have to pass in URI's of everything we update, we need to fetch them
50 4
        $reflection = new \ReflectionClass('jamesiarmes\PEWS\API\Enumeration\UnindexedFieldURIType');
51 4
        $constants = $reflection->getConstants();
52
        $constantsFound = array();
53
54 4
        //Loop through all URI's to list them in an array
55 4
        foreach ($constants as $constant) {
56 4
            $exploded = explode(":", $constant);
57 4
            if (count($exploded) == 1) {
58 4
                $exploded = ['item', $exploded[0]];
59
            }
60 4
61 4
            $name = strtolower($exploded[1]);
62
            $category = strtolower($exploded[0]);
63 4
64 4
            if (!isset($constantsFound[$name])) {
65 4
                $constantsFound[$name] = array();
66 4
            }
67 4
            $constantsFound[$name][$category] = $constant;
68
        }
69 4
70 4
        $this->fieldUris = $constantsFound;
71
    }
72 4
73
    public function getFieldUriByName($fieldName, $preference = 'item')
74 4
    {
75 4
        $fieldName = strtolower($fieldName);
76
        $preference = strtolower($preference);
77 4
78 4
        if (empty($this->fieldUris)) {
79 4
            $this->setupFieldUris();
80
        }
81 4
82 1
        if (!isset($this->fieldUris[$fieldName])) {
83
            return false;
84
        }
85 4
86 1
        if (!isset($this->fieldUris[$fieldName][$preference])) {
87 1
            $preference = 'item';
88
        }
89 4
90
        if (!isset($this->fieldUris[$fieldName][$preference])) {
91
            throw new \Exception("Could not find uri $preference:$fieldName");
92
        }
93 4
94
        return $this->fieldUris[$fieldName][$preference];
95
    }
96
97
    /**
98
     * Get a calendar item
99
     *
100
     * @param string $name
101
     * @return CalendarAPI
102 6
     */
103
    public function getCalendar($name = null)
104 6
    {
105 6
        $calendar = new CalendarAPI();
106 6
        $calendar->setClient($this->getClient());
107
        $calendar->pickCalendar($name);
108 6
109
        return $calendar;
110
    }
111
112
    /**
113
     * @param string $folderName
114
     * @return MailAPI
115 8
     */
116
    public function getMailbox($folderName = null)
117 8
    {
118 6
        $mailApi = new MailAPI();
119 6
        $mailApi->setClient($this->getClient());
120
        $mailApi->pickMailFolder($folderName);
121 6
122
        return $mailApi;
123
    }
124
125
    /**
126
     * Set the API client
127
     *
128
     * @param ExchangeWebServices $client
129
     * @return $this
130 23
     */
131
    public function setClient($client)
132 23
    {
133 23
        $this->client = $client;
134
        return $this;
135
    }
136
137
    /**
138
     * Get the API client
139
     *
140
     * @return ExchangeWebServices
141 22
     */
142
    public function getClient()
143 22
    {
144
        return $this->client;
145
    }
146
147
    /**
148
     * Instantiate and set a client (ExchangeWebServices) based on the parameters given
149
     *
150
     * @deprecated Since 0.6.3
151
     * @param $server
152
     * @param $username
153
     * @param $password
154
     * @param array $options
155
     * @return $this
156
     */
157
    public function buildClient(
158
        $server,
159
        $username,
160
        $password,
161
        $options = [ ]
162
    ) {
163
        $this->setClient(ExchangeWebServices::fromUsernameAndPassword(
164
            $server,
165
            $username,
166
            $password,
167
            array_replace_recursive(self::$defaultClientOptions, $options)
168
        ));
169
    }
170 9
171
    public static function withUsernameAndPassword($server, $username, $password, $options = [ ])
172 9
    {
173 9
        return new static(ExchangeWebServices::fromUsernameAndPassword(
174 9
            $server,
175 9
            $username,
176 9
            $password,
177 9
            array_replace_recursive(self::$defaultClientOptions, $options)
178
        ));
179
    }
180 1
181
    public static function withCallbackToken($server, $token, $options = [ ])
182 1
    {
183 1
        return new static(ExchangeWebServices::fromCallbackToken(
184 1
            $server,
185 1
            $token,
186 1
            array_replace_recursive(self::$defaultClientOptions, $options)
187
        ));
188
    }
189
190
    public function getPrimarySmptEmailAddress()
191
    {
192
        if ($this->getPrimarySmtpMailbox() == null) {
193
            return null;
194
        }
195
196
        return $this->getPrimarySmtpMailbox()->getEmailAddress();
197
    }
198
199
    public function setPrimarySmtpEmailAddress($emailAddress)
200
    {
201
        $this->getClient()->setPrimarySmtpEmailAddress($emailAddress);
202
203
        return $this;
204
    }
205
206
    /**
207
     * Create items through the API client
208
     *
209
     * @param $items
210
     * @param array $options
211
     * @return API\CreateItemResponseType
212 9
     */
213 View Code Duplication
    public function createItems($items, $options = array())
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...
214 9
    {
215
        if (!is_array($items)) {
216
            $items = array($items);
217
        }
218
219
        $request = array(
220 9
            'Items' => $items
221
        );
222 9
223 9
        $request = array_replace_recursive($request, $options);
224
        $request = Type::buildFromArray($request);
225 9
226
        $response = $this->getClient()->CreateItem($request);
227 9
228
        return $response;
229
    }
230 2
231
    public function updateItems($items, $options = array())
232
    {
233 2
        $request = array(
234 2
            'ItemChanges' => $items,
235
            'MessageDisposition' => 'SaveOnly',
236 2
            'ConflictResolution' => 'AlwaysOverwrite'
237
        );
238 2
239
        $request = array_replace_recursive($request, $options);
240 2
241
        $request = Type::buildFromArray($request);
242 2
243
        return $this->getClient()->UpdateItem($request)->getItems();
0 ignored issues
show
Documentation Bug introduced by
The method getItems does not exist on object<jamesiarmes\PEWS\API\Type>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
244
    }
245 2
246
    protected function buildUpdateItemChanges($itemType, $uriType, $changes)
247 2
    {
248
        $setItemFields = array();
249
250 2
        //Add each property to a setItemField
251 2
        foreach ($changes as $key => $value) {
252
            $fullName = $this->getFieldUriByName($key, $uriType);
253 2
254 2
            $setItemFields[] = array(
255 2
                'FieldURI' => array('FieldURI' => $fullName),
256 2
                $itemType => array($key => $value)
257 2
            );
258
        }
259 2
260
        return $setItemFields;
261
    }
262
263
    public function createFolders($names, Type\FolderIdType $parentFolder, $options = array())
264
    {
265
        $request = array('Folders' => array('Folder' => array()));
266
        if (!empty($parentFolder)) {
267
            $request['ParentFolderId'] = array('FolderId' => $parentFolder->toArray());
268
        }
269
270
        if (!is_array($names)) {
271
            $names = array($names);
272
        }
273
274
        foreach ($names as $name) {
275
            $request['Folders']['Folder'][] = array(
276
                'DisplayName' => $name
277
            );
278
        }
279
280
        $request = array_merge_recursive($request, $options);
281
282
        $this->client->CreateFolder($request);
0 ignored issues
show
Documentation Bug introduced by
The method CreateFolder does not exist on object<jamesiarmes\PEWS\API\ExchangeWebServices>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
283
284
        return true;
285
    }
286
287 View Code Duplication
    public function deleteFolder(Type\FolderIdType $folderId, $options = array())
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...
288
    {
289
        $request = array(
290
            'DeleteType' => 'HardDelete',
291
            'FolderIds' => array(
292
                'FolderId' => $folderId->toArray()
293
            )
294
        );
295
296
        $request = array_merge_recursive($request, $options);
297
        return $this->client->DeleteFolder($request);
0 ignored issues
show
Documentation Bug introduced by
The method DeleteFolder does not exist on object<jamesiarmes\PEWS\API\ExchangeWebServices>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
298
    }
299
300 View Code Duplication
    public function moveItem(Type\ItemIdType $itemId, Type\FolderIdType $folderId, $options = array())
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...
301
    {
302
        $request = array(
303 9
            'ToFolderId' => array('FolderId' => $folderId->toArray()),
304
            'ItemIds' => array('ItemId' => $itemId->toArray())
305 9
        );
306 9
307 9
        $request = array_merge_recursive($request, $options);
308
309 9
        return $this->client->MoveItem($request);
0 ignored issues
show
Documentation Bug introduced by
The method MoveItem does not exist on object<jamesiarmes\PEWS\API\ExchangeWebServices>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
310 9
    }
311 9
312 8
    /**
313 8
     * @param $items Type\ItemIdType|Type\ItemIdType[]
314 9
     * @param array $options
315 9
     * @return bool
316 9
     */
317 9
    public function deleteItems($items, $options = array())
318 9
    {
319 9
        if (!is_array($items) || Type::arrayIsAssoc($items)) {
320
            $items = array($items);
321
        }
322 9
323
        $itemIds = array();
324 9
        foreach ($items as $item) {
325
            if ($item instanceof Type\ItemIdType) {
0 ignored issues
show
Bug introduced by
The class jamesiarmes\PEWS\API\Type\ItemIdType 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...
326 9
                $item = $item->toArray();
327 9
            }
328 9
            $item = (array) $item;
329
            $itemIds[] = array(
330
                'Id' => $item['Id'],
331 9
                'ChangeKey' => $item['ChangeKey']
332
            );
333
        }
334
335
        $request = array(
336
            'ItemIds' => array('ItemId' => $itemIds),
337
            'DeleteType' => 'MoveToDeletedItems'
338 15
        );
339
340
        $request = array_replace_recursive($request, $options);
341
        $request = Type::buildFromArray($request);
342 15
        $this->getClient()->DeleteItem($request);
343 15
344
        //If the delete fails, an Exception will be thrown in processResponse before it gets here
345 15
        return true;
346 15
    }
347
348 15
    /**
349 15
     * @param $identifier
350
     * @return Type\BaseFolderType
351
     */
352
    public function getFolder($identifier)
353
    {
354
        $request = array(
355
            'FolderShape' => array(
356
                'BaseShape' => array('_' => 'Default')
357
            ),
358 15
            'FolderIds' => $identifier
359
        );
360 15
        $request = Type::buildFromArray($request);
361
362 15
        $response = $this->getClient()->GetFolder($request);
363 15
        return $response;
364 15
    }
365 15
366
    /**
367
     * Get a folder by it's distinguishedId
368
     *
369
     * @param string $distinguishedId
370
     * @return Type\BaseFolderType
371
     */
372 4
    public function getFolderByDistinguishedId($distinguishedId)
373
    {
374 4
        return $this->getFolder(array(
375 4
            'DistinguishedFolderId' => array(
376 4
                'Id' => $distinguishedId,
377
                'Mailbox' => $this->getPrimarySmtpMailbox()
378
            )
379
        ));
380
    }
381
382
    /**
383
     * @param $folderId
384 14
     * @return Type\BaseFolderType
385
     */
386 14
    public function getFolderByFolderId($folderId)
387 14
    {
388 14
        return $this->getFolder(array(
389
            'FolderId' => array('Id'=>$folderId, 'Mailbox' => $this->getPrimarySmtpMailbox())
390
        ));
391 14
    }
392
393
    /**
394 14
     * @param string|Type\FolderIdType $parentFolderId
395
     * @param array $options
396 14
     * @return bool|Type\BaseFolderType
397 14
     */
398 14
    public function getChildrenFolders($parentFolderId = 'root', $options = array())
399
    {
400 14
        if (is_string($parentFolderId)) {
401
            $parentFolderId = $this->getFolderByDistinguishedId($parentFolderId)->getFolderId();
0 ignored issues
show
Documentation Bug introduced by
The method getFolderId does not exist on object<jamesiarmes\PEWS\API\Type>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
402 14
        }
403
404
        $request = array(
405 14
            'Traversal' => 'Shallow',
406
            'FolderShape' => array(
407
                'BaseShape' => 'AllProperties'
408
            ),
409
            'ParentFolderIds' => array(
410
                'FolderId' => $parentFolderId->toArray()
411
            )
412
        );
413
414
        $request = array_replace_recursive($request, $options);
415 14
416
        $request = Type::buildFromArray($request);
417 14
418
        /** @var \jamesiarmes\PEWS\API\Message\FindFolderResponseMessageType $folders */
419 14
        return $this->getClient()->FindFolder($request);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getClient()->FindFolder($request); (jamesiarmes\PEWS\API\Type) is incompatible with the return type documented by jamesiarmes\PEWS\API::getChildrenFolders of type boolean|jamesiarmes\PEWS\API\Type\BaseFolderType.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
420 14
        return $folders->getFolders();
0 ignored issues
show
Unused Code introduced by
return $folders->getFolders(); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
421 14
    }
422
423 6
    /**
424
     * @param $folderName
425
     * @param string|Type\FolderIdType $parentFolderId
426
     * @param array $options
427
     * @return bool|Type\BaseFolderType
428
     */
429
    public function getFolderByDisplayName($folderName, $parentFolderId = 'root', $options = array())
430
    {
431
        $folders = $this->getChildrenFolders($parentFolderId, $options);
432
433 1
        foreach ($folders as $folder) {
0 ignored issues
show
Bug introduced by
The expression $folders of type boolean|object<jamesiarm...PI\Type\BaseFolderType> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
434
            if ($folder->getDisplayName() == $folderName) {
435 1
                return $folder;
436
            }
437
        }
438
439
        return false;
440 1
    }
441 1
442 1
    /**
443
     * @param $itemId array|Type\ItemIdType
444 1
     * @param array $options
445
     * @return Type
446 1
     */
447
    public function getItem($itemId, $options = array())
448
    {
449
        if ($itemId instanceof Type\ItemIdType) {
0 ignored issues
show
Bug introduced by
The class jamesiarmes\PEWS\API\Type\ItemIdType 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...
450
            $itemId = $itemId->toArray();
451
        }
452
453
        $request = array(
454
            'ItemShape' => array('BaseShape' => 'AllProperties'),
455
            'ItemIds' => array('ItemId' => $itemId)
456
        );
457 2
458
        $request = array_replace_recursive($request, $options);
459
460 2
        return $this->getClient()->GetItem($request);
461 2
    }
462 2
463
    /**
464 2
     * Get a list of sync changes on a folder
465
     *
466 2
     * @param Type\FolderIdType $folderId
467
     * @param null $syncState
468
     * @param array $options
469
     * @return SyncFolderItemsResponseMessageType
470
     */
471 2
    public function listItemChanges($folderId, $syncState = null, $options = array())
472
    {
473 2
        $request = array(
474 2
            'ItemShape' => array('BaseShape' => 'IdOnly'),
475 2
            'SyncFolderId' => array('FolderId' => $folderId->toXmlObject()),
476
            'SyncScope' => 'NormalItems',
477
            'MaxChangesReturned' => '10'
478
        );
479
480
        if ($syncState != null) {
481
            $request['SyncState'] = $syncState;
482
            $request['ItemShape']['BaseShape'] = 'AllProperties';
483
        }
484
485
        $request = array_replace_recursive($request, $options);
486
487
        $request = Type::buildFromArray($request);
488
        $response = $this->getClient()->SyncFolderItems($request);
489
        return $response;
490
    }
491
492 View Code Duplication
    public function getServerTimezones($timezoneIDs = array(), $fullTimezoneData = false)
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...
493
    {
494
        $request = GetServerTimeZonesType::buildFromArray(array(
495
            'returnFullTimeZoneData' => $fullTimezoneData
496
        ));
497
498
        if (!empty($timezoneIDs)) {
499
            $request->setIds($timezoneIDs);
500
        }
501
502
        $timezones = $this->getClient()->GetServerTimeZones($request);
0 ignored issues
show
Documentation Bug introduced by
The method GetServerTimeZones does not exist on object<jamesiarmes\PEWS\API\ExchangeWebServices>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
503
        $timezones = $timezones->TimeZoneDefinition;
504
505
        if (!is_array($timezones)) {
506
            $timezones = array($timezones);
507
        }
508
509
        return $timezones;
510
    }
511
}
512