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

stripe / stripe-php / 6471862601

10 Oct 2023 04:02PM UTC coverage: 69.665% (-0.5%) from 70.141%
6471862601

push

github

web-flow
Merge pull request #1570 from localheinz/feature/coveralls

Enhancement: Use `coverallsapp/github-action` to report code coverage

2393 of 3435 relevant lines covered (69.67%)

3.5 hits per line

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

66.67
/lib/Util/CaseInsensitiveArray.php
1
<?php
2

3
namespace Stripe\Util;
4

5
/**
6
 * CaseInsensitiveArray is an array-like class that ignores case for keys.
7
 *
8
 * It is used to store HTTP headers. Per RFC 2616, section 4.2:
9
 * Each header field consists of a name followed by a colon (":") and the field value. Field names
10
 * are case-insensitive.
11
 *
12
 * In the context of stripe-php, this is useful because the API will return headers with different
13
 * case depending on whether HTTP/2 is used or not (with HTTP/2, headers are always in lowercase).
14
 */
15
class CaseInsensitiveArray implements \ArrayAccess, \Countable, \IteratorAggregate
16
{
17
    private $container = [];
18

19
    public function __construct($initial_array = [])
3✔
20
    {
21
        $this->container = \array_change_key_case($initial_array, \CASE_LOWER);
3✔
22
    }
23

24
    /**
25
     * @return int
26
     */
27
    #[\ReturnTypeWillChange]
1✔
28
    public function count()
29
    {
30
        return \count($this->container);
1✔
31
    }
32

33
    /**
34
     * @return \ArrayIterator
35
     */
36
    #[\ReturnTypeWillChange]
1✔
37
    public function getIterator()
38
    {
39
        return new \ArrayIterator($this->container);
1✔
40
    }
41

42
    /**
43
     * @return void
44
     */
45
    #[\ReturnTypeWillChange]
1✔
46
    public function offsetSet($offset, $value)
47
    {
48
        $offset = self::maybeLowercase($offset);
1✔
49
        if (null === $offset) {
1✔
50
            $this->container[] = $value;
×
51
        } else {
52
            $this->container[$offset] = $value;
1✔
53
        }
54
    }
55

56
    /**
57
     * @return bool
58
     */
59
    #[\ReturnTypeWillChange]
×
60
    public function offsetExists($offset)
61
    {
62
        $offset = self::maybeLowercase($offset);
×
63

64
        return isset($this->container[$offset]);
×
65
    }
66

67
    /**
68
     * @return void
69
     */
70
    #[\ReturnTypeWillChange]
×
71
    public function offsetUnset($offset)
72
    {
73
        $offset = self::maybeLowercase($offset);
×
74
        unset($this->container[$offset]);
×
75
    }
76

77
    /**
78
     * @return mixed
79
     */
80
    #[\ReturnTypeWillChange]
1✔
81
    public function offsetGet($offset)
82
    {
83
        $offset = self::maybeLowercase($offset);
1✔
84

85
        return isset($this->container[$offset]) ? $this->container[$offset] : null;
1✔
86
    }
87

88
    private static function maybeLowercase($v)
1✔
89
    {
90
        if (\is_string($v)) {
1✔
91
            return \strtolower($v);
1✔
92
        }
93

94
        return $v;
×
95
    }
96
}
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