Completed
Push — master ( 1fb75b...494ce5 )
by Jakob
04:50
created

Result::jsonLDSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php declare(strict_types=1);
2
3
namespace JSKOS;
4
5
/**
6
 * Result set in response to query a JSKOS Service.
7
 */
8
class Result extends Set
9
{
10
    protected $totalCount=0;
11
12
    /**
13
     * Ignores the argument to ensure that a Result is always closed.
14
     */
15
    public function setClosed(bool $closed = true)
16
    {
17
        $this->closed = true;
18
    }
19
20
    /**
21
     * Get the total number of members including other pages.
22
     */
23
    public function getTotalCount(): int
24
    {
25
        return $this->totalCount;
26
    }
27
28
    /**
29
     * Append a Resource and possibly increase totalCount.
30
     */
31
    public function append($resource)
32
    {
33
        parent::append($resource);
34
        $this->totalCount = max($this->totalCount, count($this));
35
    }
36
37
    /**
38
     * Serialize with type and context fields for each member.
39
     */
40
    public function jsonLDSerialize(string $context = self::DEFAULT_CONTEXT, bool $types = true)
41
    {
42
        return array_map(function($m) use ($context, $types) {
43
            return $m->jsonLDSerialize($context, $types); 
44
        }, $this->members);
45
    }
46
}
47