• 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

68.97
/lib/Service/AbstractService.php
1
<?php
2

3
namespace Stripe\Service;
4

5
/**
6
 * Abstract base class for all services.
7
 */
8
abstract class AbstractService
9
{
10
    /**
11
     * @var \Stripe\StripeClientInterface
12
     */
13
    protected $client;
14

15
    /**
16
     * @var \Stripe\StripeStreamingClientInterface
17
     */
18
    protected $streamingClient;
19

20
    /**
21
     * Initializes a new instance of the {@link AbstractService} class.
22
     *
23
     * @param \Stripe\StripeClientInterface $client
24
     */
25
    public function __construct($client)
5✔
26
    {
27
        $this->client = $client;
5✔
28
        $this->streamingClient = $client;
5✔
29
    }
30

31
    /**
32
     * Gets the client used by this service to send requests.
33
     *
34
     * @return \Stripe\StripeClientInterface
35
     */
36
    public function getClient()
1✔
37
    {
38
        return $this->client;
1✔
39
    }
40

41
    /**
42
     * Gets the client used by this service to send requests.
43
     *
44
     * @return \Stripe\StripeStreamingClientInterface
45
     */
46
    public function getStreamingClient()
×
47
    {
48
        return $this->streamingClient;
×
49
    }
50

51
    /**
52
     * Translate null values to empty strings. For service methods,
53
     * we interpret null as a request to unset the field, which
54
     * corresponds to sending an empty string for the field to the
55
     * API.
56
     *
57
     * @param null|array $params
58
     */
59
    private static function formatParams($params)
2✔
60
    {
61
        if (null === $params) {
2✔
62
            return null;
×
63
        }
64
        \array_walk_recursive($params, function (&$value, $key) {
2✔
65
            if (null === $value) {
2✔
66
                $value = '';
2✔
67
            }
68
        });
2✔
69

70
        return $params;
2✔
71
    }
72

73
    protected function request($method, $path, $params, $opts)
1✔
74
    {
75
        return $this->getClient()->request($method, $path, self::formatParams($params), $opts);
1✔
76
    }
77

78
    protected function requestStream($method, $path, $readBodyChunkCallable, $params, $opts)
×
79
    {
80
        // TODO (MAJOR): Add this method to StripeClientInterface
81
        // @phpstan-ignore-next-line
82
        return $this->getStreamingClient()->requestStream($method, $path, $readBodyChunkCallable, self::formatParams($params), $opts);
×
83
    }
84

85
    protected function requestCollection($method, $path, $params, $opts)
×
86
    {
87
        // TODO (MAJOR): Add this method to StripeClientInterface
88
        // @phpstan-ignore-next-line
89
        return $this->getClient()->requestCollection($method, $path, self::formatParams($params), $opts);
×
90
    }
91

92
    protected function requestSearchResult($method, $path, $params, $opts)
×
93
    {
94
        // TODO (MAJOR): Add this method to StripeClientInterface
95
        // @phpstan-ignore-next-line
96
        return $this->getClient()->requestSearchResult($method, $path, self::formatParams($params), $opts);
×
97
    }
98

99
    protected function buildPath($basePath, ...$ids)
4✔
100
    {
101
        foreach ($ids as $id) {
4✔
102
            if (null === $id || '' === \trim($id)) {
4✔
103
                $msg = 'The resource ID cannot be null or whitespace.';
3✔
104

105
                throw new \Stripe\Exception\InvalidArgumentException($msg);
3✔
106
            }
107
        }
108

109
        return \sprintf($basePath, ...\array_map('\urlencode', $ids));
1✔
110
    }
111
}
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