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

ContactsAPI::updateContactItem()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 10

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 20
loc 20
ccs 11
cts 11
cp 1
rs 9.4285
cc 2
eloc 10
nc 2
nop 2
crap 2
1
<?php
2
3
namespace garethp\ews;
4
5
use garethp\ews\API\Type;
6
7
class ContactsAPI extends API
8
{
9
    /**
10
     * @var Type\FolderIdType
11
     */
12
    protected $folderId;
13
14
    /**
15
     * @return Type\FolderIdType
16
     */
17 5
    public function getFolderId()
18
    {
19 5
        if (!$this->folderId) {
20 5
            $this->folderId = $this->getFolderByDistinguishedId('contacts')->getFolderId();
0 ignored issues
show
Documentation Bug introduced by
The method getFolderId does not exist on object<garethp\ews\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...
21 5
        }
22
23 5
        return $this->folderId;
24
    }
25
26
    /**
27
     * @param Type\FolderIdType $folderId
28
     */
29 5
    public function setFolderId($folderId)
30
    {
31 5
        $this->folderId = $folderId;
32 5
    }
33
34
    /**
35
     * @param Type\FolderIdType $folderId
36
     * @param array $options
37
     * @return Type\ContactItemType[]
38
     */
39 2
    public function getContacts($folderId = null, $options = array())
40
    {
41 2
        if (!$folderId) {
42 2
            $folderId = $this->getFolderId();
43 2
        }
44
45
        $request = array(
46 2
            'Traversal' => 'Shallow',
47
            'ItemShape' => array(
48
                'BaseShape' => 'AllProperties'
49 2
            ),
50
            'ParentFolderIds' => array(
51 2
                'FolderId' => $folderId->toXmlObject()
52 2
            )
53 2
        );
54
55 2
        $request = array_replace_recursive($request, $options);
56
57 2
        $request = Type::buildFromArray($request);
58
59 2
        return $this->getClient()->FindItem($request);
60
    }
61
62
    /**
63
     * @param Type\ItemIdType $itemId
64
     * @return Type\ContactItemType
65
     */
66 3
    public function getContact($itemId)
67
    {
68 3
        return $this->getItem($itemId);
69
    }
70
71
    /**
72
     * @param $contacts
73
     * @param array $options
74
     * @return Type\ItemIdType[]
75
     */
76 5 View Code Duplication
    public function createContacts($contacts, $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...
77
    {
78 5
        $request = array('Contact' => $contacts);
79
80
        $defaultOptions = array(
81 5
            'MessageDisposition' => 'SaveOnly',
82 5
            'SavedItemFolderId' => array('FolderId' => $this->getFolderId()->toArray())
83 5
        );
84 5
        $options = array_replace_recursive($defaultOptions, $options);
85
86 5
        $result = $this->createItems($request, $options);
87
88 5
        if (!is_array($result)) {
89 4
            $result = array($result);
90 4
        }
91
92 5
        return $result;
93
    }
94
95 4 View Code Duplication
    public function updateContactItem(Type\ItemIdType $itemId, $changes)
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...
96
    {
97
        //Create the request
98
        $request = array(
99
            'ItemChange' => array(
100 2
                'ItemId' => $itemId->toArray(),
101 2
                'Updates' => $this->buildUpdateItemChanges('Contact', 'contacts', $changes)
102 4
            )
103 2
        );
104
105 2
        $options = array();
106
107 2
        $items = $this->updateItems($request, $options);
108
109 2
        if (!is_array($items)) {
110 2
            $items = array($items);
111 2
        }
112
113 2
        return $items;
114
    }
115
}
116