• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

podio-community / podio-php / 5155402462

pending completion
5155402462

push

github

daniel-sc
feat: isolated client class to allow for parallel usage + extension + mocking

BREAKING CHANGE: replace static Podio with instantiable PodioClient

648 of 648 new or added lines in 66 files covered. (100.0%)

917 of 2107 relevant lines covered (43.52%)

24.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.62
/models/PodioFieldCollection.php
1
<?php
2

3
/**
4
 * A collection for managing a list of PodioAppFields or PodioItemFields.
5
 * Don't instantiate this class manually. Use PodioAppFieldCollection or
6
 * PodioItemFieldCollection.
7
 */
8
class PodioFieldCollection extends PodioCollection
9
{
10
    private $__belongs_to;
11
    /**
12
     * @var PodioClient
13
     */
14
    private $podio_client;
15

16
    /**
17
     * Constructor. Pass in an array of fields.
18
     */
19
    public function __construct(PodioClient $podio_client, $fields)
20
    {
21
        parent::__construct($podio_client, $fields);
72✔
22
        $this->podio_client = $podio_client;
69✔
23
    }
24

25
    /**
26
     * Array access. Set fiels using external id or offset.
27
     */
28
    public function offsetSet($offset, $field)
29
    {
30

31
    // Allow you to set external id in the array offset.
32
        // E.g. $collection['external_id'] = $field;
33
        if (is_string($offset)) {
72✔
34
            $field->external_id = $offset;
×
35
            $offset = null;
×
36
        }
37

38
        if (!$field->id && !$field->external_id) {
72✔
39
            throw new PodioDataIntegrityError('Field must have id or external_id set.');
6✔
40
        }
41

42
        // Remove any existing field with this id
43
        $this->remove($field->id ? $field->id : $field->external_id);
69✔
44

45
        // Add to internal storage
46
        parent::offsetSet($offset, $field);
69✔
47
    }
48

49
    /**
50
     * Array access. Check for existence using external_id or offset.
51
     */
52
    public function offsetExists($offset)
53
    {
54
        if (is_string($offset)) {
3✔
55
            return $this->get($offset) ? true : false;
3✔
56
        }
57
        return parent::offsetExists($offset);
×
58
    }
59

60
    /**
61
     * Array access. Unset field using external)id or offset.
62
     */
63
    public function offsetUnset($offset)
64
    {
65
        if (is_string($offset)) {
3✔
66
            $this->remove($offset);
3✔
67
        } else {
68
            parent::offsetUnset($offset);
×
69
        }
70
    }
71

72
    /**
73
     * Array access. Get field using external_id or offset.
74
     */
75
    public function offsetGet($offset)
76
    {
77
        if (is_string($offset)) {
15✔
78
            return $this->get($offset);
3✔
79
        }
80
        return parent::offsetGet($offset);
12✔
81
    }
82

83
    /**
84
     * Returns all external_ids in use on this item
85
     */
86
    public function external_ids()
87
    {
88
        return array_map(function ($field) {
6✔
89
            return $field->external_id;
3✔
90
        }, $this->_get_items());
6✔
91
    }
92

93
    /**
94
     * Returns all readonly fields
95
     */
96
    public function readonly_fields(): PodioFieldCollection
97
    {
98
        $fields = new PodioFieldCollection($this->podio_client, array());
6✔
99
        foreach ($this->_get_items() as $field) {
6✔
100
            if ($field->type === 'calculation') {
6✔
101
                $fields[] = $field;
3✔
102
            }
103
        }
104
        return $fields;
6✔
105
    }
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc