Completed
Push — master ( ed11ea...d84521 )
by Gareth
08:53
created

ContactsAPI::setFolderId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace jamesiarmes\PEWS\Contacts;
4
5
use jamesiarmes\PEWS\API;
6
use jamesiarmes\PEWS\API\Type;
7
8
class ContactsAPI extends API
9
{
10
    /**
11
     * @var Type\FolderIdType
12
     */
13
    protected $folderId;
14
15
    /**
16
     * @return Type\FolderIdType
17
     */
18
    public function getFolderId()
19
    {
20
        if (!$this->folderId) {
21
            $this->folderId = $this->getFolderByDistinguishedId('contacts')->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...
22
        }
23
24
        return $this->folderId;
25
    }
26
27
    /**
28
     * @param Type\FolderIdType $folderId
29
     */
30
    public function setFolderId($folderId)
31
    {
32
        $this->folderId = $folderId;
33
    }
34
35
    /**
36
     * @param Type\FolderIdType $folderId
37
     * @param array $options
38
     * @return Type
39
     */
40
    public function getContacts($folderId = null, $options = array())
41
    {
42
        if (!$folderId) {
43
            $folderId = $this->getFolderId();
44
        }
45
46
        $request = array(
47
            'Traversal' => 'Shallow',
48
            'ItemShape' => array(
49
                'BaseShape' => 'AllProperties'
50
            ),
51
            'ParentFolderIds' => array(
52
                'FolderId' => $folderId->toXmlObject()
53
            )
54
        );
55
56
        $request = array_replace_recursive($request, $options);
57
58
        $request = Type::buildFromArray($request);
59
        return $this->getClient()->FindItem($request);
60
    }
61
}
62