Completed
Push — master ( ea5582...dd6b15 )
by Cedric
06:36
created

ContentService::all()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 3
eloc 12
nc 4
nop 2
1
<?php
2
/*
3
 * This file is part of the Adlogix package.
4
 *
5
 * (c) Allan Segebarth <[email protected]>
6
 * (c) Jean-Jacques Courtens <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Adlogix\ConfluenceClient\Service;
13
14
use Adlogix\ConfluenceClient\Entity\Collection\ContentCollection;
15
use Adlogix\ConfluenceClient\Entity\Content;
16
17
/**
18
 * Class PageService
19
 * @package Adlogix\ConfluenceClient\Service
20
 * @author  Cedric Michaux <[email protected]>
21
 */
22
class ContentService extends AbstractApiService
23
{
24
25
    /**
26
     * @param string $spaceKey
27
     * @param array  $options
28
     *
29
     * @return ContentCollection|null
30
     */
31
    public function all($spaceKey = "", array $options = [])
32
    {
33
34
        if (!empty($spaceKey)) {
35
            $options = $this->mergeQueryOptions($options, [
36
                "query" => [
37
                    "spaceKey" => $spaceKey
38
                ]
39
            ]);
40
        }
41
42
        $all = $this->get('content', $options);
43
        $contentCollection = $this->deserialize(
44
            $all,
45
            ContentCollection::class
46
        );
47
48
        if(!$contentCollection instanceof ContentCollection){
49
            return null;
50
        }
51
52
        return $contentCollection;
53
54
    }
55
56
57
    /**
58
     * @param $id
59
     *
60
     * @return mixed
61
     */
62
    public function findById($id)
63
    {
64
        $content = $this->get('content/' . $id);
65
        $content = $this->deserialize(
66
            $content,
67
            Content::class
68
        );
69
70
        if(!$content instanceof Content){
71
            return null;
72
        }
73
74
        return $content;
75
    }
76
77
}
78