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

tylernathanreed / jira-client-php / 14503644156

16 Apr 2025 10:16PM UTC coverage: 81.656% (-0.4%) from 82.08%
14503644156

push

github

tylernathanreed
- Dropped guzzle as a requirement

53 of 99 new or added lines in 8 files covered. (53.54%)

5738 of 7027 relevant lines covered (81.66%)

10.35 hits per line

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

91.43
/src/Http/Transporter.php
1
<?php
2

3
namespace Jira\Client\Http;
4

5
use InvalidArgumentException;
6
use Jira\Client\Configuration;
7
use Jira\Client\Http\Contracts\Transporter as TransporterContract;
8

9
/**
10
 * @phpstan-type THeaders array{
11
 *    Accept:string,
12
 *    Authorization?:string,
13
 *    'User-Agent'?:string,
14
 * }
15
 */
16
abstract class Transporter implements TransporterContract
17
{
18
    public function newRequest(PendingOperation $operation, Configuration $config): Request
512✔
19
    {
20
        return new Request(
512✔
21
            method: $operation->method,
512✔
22
            uri: $this->getUri($operation, $config),
512✔
23
            headers: $this->getHeaders($operation, $config),
512✔
24
            body: $this->getBody($operation, $config),
512✔
25
        );
512✔
26
    }
27

28
    protected function getUri(PendingOperation $operation, Configuration $config): string
512✔
29
    {
30
        $host = trim($config->host, '/');
512✔
31
        $path = ltrim($operation->getExpandedUri(), '/');
512✔
32

33
        $query = ! empty($operation->query)
512✔
34
            ? http_build_query($operation->query, '', '&', PHP_QUERY_RFC3986)
207✔
35
            : null;
305✔
36

37
        return ! is_null($query)
512✔
38
            ? "{$host}/{$path}?{$query}"
207✔
39
            : "{$host}/{$path}";
512✔
40
    }
41

42
    /** @return THeaders */
43
    protected function getHeaders(PendingOperation $operation, Configuration $config): array
512✔
44
    {
45
        $headers = [
512✔
46
            'Accept' => 'application/json',
512✔
47
            'Host' => $config->host,
512✔
48
        ];
512✔
49

50
        if (! empty($config->accessToken)) {
512✔
NEW
51
            $headers['Authorization'] = trim('Bearer ' . $config->accessToken);
×
52
        } elseif (! empty($config->username) && ! empty($config->password)) {
512✔
53
            $headers['Authorization'] = 'Basic ' . base64_encode("{$config->username}:{$config->password}");
512✔
54
        }
55

56
        if (! empty($config->userAgent)) {
512✔
NEW
57
            $headers['User-Agent'] = trim($config->userAgent);
×
58
        }
59

60
        return $headers;
512✔
61
    }
62

63
    protected function getBody(PendingOperation $operation, Configuration $config): ?string
512✔
64
    {
65
        if (empty($operation->body)) {
512✔
66
            return null;
336✔
67
        }
68

69
        $json = json_encode($operation->body);
176✔
70

71
        if (json_last_error() !== JSON_ERROR_NONE) {
176✔
NEW
72
            throw new InvalidArgumentException('Unable to encode json: ' . json_last_error_msg());
×
73
        }
74

75
        assert(is_string($json));
76

77
        return $json;
176✔
78
    }
79
}
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