GenericCollection   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isEmpty() 0 3 1
A getFieldValues() 0 7 2
1
<?php
2
/**
3
 *
4
 * This file is part of the Aura project for PHP.
5
 *
6
 * @package Aura.Marshal
7
 *
8
 * @license https://opensource.org/licenses/mit-license.php MIT
9
 *
10
 */
11
namespace Aura\Marshal\Collection;
12
13
use Aura\Marshal\Data;
14
use Aura\Marshal\ToArrayInterface;
15
use Aura\Marshal\ToArrayTrait;
16
17
/**
18
 *
19
 * Represents a generic collection of entities.
20
 *
21
 * @package Aura.Marshal
22
 *
23
 */
24
class GenericCollection extends Data implements ToArrayInterface
25
{
26
    use ToArrayTrait;
27
28
    /**
29
     *
30
     * Returns an array of all values for a single field in the collection.
31
     *
32
     * @param string $field The field name to retrieve values for.
33
     *
34
     * @return array<int|string, mixed>
35
     *
36
     */
37
    public function getFieldValues($field)
38
    {
39
        $values = [];
40
        foreach ($this->data as $offset => $entity) {
41
            $values[$offset] = $entity->$field;
42
        }
43
        return $values;
44
    }
45
46
    /**
47
     *
48
     * Is the collection empty?
49
     *
50
     * @return bool
51
     *
52
     */
53
    public function isEmpty()
54
    {
55
        return empty($this->data);
56
    }
57
}
58