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

stripe / stripe-php / 11129599820

01 Oct 2024 04:33PM UTC coverage: 62.613% (-1.3%) from 63.944%
11129599820

push

github

web-flow
Support for APIs in the new API version 2024-09-30.acacia (#1756)

175 of 409 new or added lines in 26 files covered. (42.79%)

3 existing lines in 3 files now uncovered.

3547 of 5665 relevant lines covered (62.61%)

2.46 hits per line

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

0.0
/lib/V2/Collection.php
1
<?php
2

3
namespace Stripe\V2;
4

5
/**
6
 * Class V2 Collection.
7
 *
8
 * @template TStripeObject of \Stripe\StripeObject
9
 * @template-implements \IteratorAggregate<TStripeObject>
10
 *
11
 * @property null|string $next_page_url
12
 * @property null|string $previous_page_url
13
 * @property TStripeObject[] $data
14
 */
15
class Collection extends \Stripe\StripeObject implements \Countable, \IteratorAggregate
16
{
17
    const OBJECT_NAME = 'list';
18

19
    use \Stripe\ApiOperations\Request;
20

21
    /**
22
     * @return string the base URL for the given class
23
     */
NEW
24
    public static function baseUrl()
×
25
    {
NEW
26
        return \Stripe\Stripe::$apiBase;
×
27
    }
28

29
    /**
30
     * @return mixed
31
     */
NEW
32
    #[\ReturnTypeWillChange]
×
33
    public function offsetGet($k)
34
    {
NEW
35
        if (\is_string($k)) {
×
NEW
36
            return parent::offsetGet($k);
×
37
        }
NEW
38
        $msg = "You tried to access the {$k} index, but V2Collection " .
×
NEW
39
            'types only support string keys. (HINT: List calls ' .
×
NEW
40
            'return an object with a `data` (which is the data ' .
×
NEW
41
            "array). You likely want to call ->data[{$k}])";
×
42

NEW
43
        throw new \Stripe\Exception\InvalidArgumentException($msg);
×
44
    }
45

46
    /**
47
     * @return int the number of objects in the current page
48
     */
NEW
49
    #[\ReturnTypeWillChange]
×
50
    public function count()
51
    {
NEW
52
        return \count($this->data);
×
53
    }
54

55
    /**
56
     * @return \ArrayIterator an iterator that can be used to iterate
57
     *    across objects in the current page
58
     */
NEW
59
    #[\ReturnTypeWillChange]
×
60
    public function getIterator()
61
    {
NEW
62
        return new \ArrayIterator($this->data);
×
63
    }
64

65
    /**
66
     * @return \ArrayIterator an iterator that can be used to iterate
67
     *    backwards across objects in the current page
68
     */
NEW
69
    public function getReverseIterator()
×
70
    {
NEW
71
        return new \ArrayIterator(\array_reverse($this->data));
×
72
    }
73

74
    /**
75
     * @throws \Stripe\Exception\ApiErrorException
76
     *
77
     * @return \Generator|TStripeObject[] A generator that can be used to
78
     *    iterate across all objects across all pages. As page boundaries are
79
     *    encountered, the next page will be fetched automatically for
80
     *    continued iteration.
81
     */
NEW
82
    public function autoPagingIterator()
×
83
    {
NEW
84
        $page = $this->data;
×
NEW
85
        $next_page_url = $this->next_page_url;
×
86

NEW
87
        while (true) {
×
NEW
88
            foreach ($page as $item) {
×
NEW
89
                yield $item;
×
90
            }
NEW
91
            if (null === $next_page_url) {
×
NEW
92
                break;
×
93
            }
94

NEW
95
            list($response, $opts) = $this->_request(
×
NEW
96
                'get',
×
NEW
97
                $next_page_url,
×
NEW
98
                null,
×
NEW
99
                null,
×
NEW
100
                [],
×
NEW
101
                'v2'
×
NEW
102
            );
×
NEW
103
            $obj = \Stripe\Util\Util::convertToStripeObject($response, $opts, 'v2');
×
104
            /** @phpstan-ignore-next-line */
NEW
105
            $page = $obj->data;
×
106
            /** @phpstan-ignore-next-line */
NEW
107
            $next_page_url = $obj->next_page_url;
×
108
        }
109
    }
110
}
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