• 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

76.67
/src/Client.php
1
<?php
2

3
namespace Jira\Client;
4

5
use Closure;
6
use Jira\Client\Http\Contracts\Transporter as TransporterContract;
7
use Jira\Client\Http\Deserializer;
8
use Jira\Client\Http\Dto;
9
use Jira\Client\Http\Exceptions\StrayRequestException;
10
use Jira\Client\Http\PendingOperation;
11
use Jira\Client\Http\PolymorphicDto;
12
use Jira\Client\Http\Processor;
13
use Jira\Client\Http\Request;
14
use Jira\Client\Http\Response;
15
use Jira\Client\Http\TransporterFactory;
16

17
class Client
18
{
19
    use PerformsOperations;
20

21
    public readonly Configuration $configuration;
22
    public readonly TransporterContract $transporter;
23
    public readonly Processor $processor;
24

25
    /** @var list<Closure(Request):?Response> */
26
    protected array $stubCallbacks = [];
27

28
    public function __construct(
512✔
29
        Configuration $configuration,
30
        ?TransporterContract $transporter = null,
31
        ?Processor $processor = null
32
    ) {
33
        $this->configuration = $configuration;
512✔
34
        $this->transporter = $transporter ?: TransporterFactory::make();
512✔
35
        $this->processor = $processor ?: new Processor(new Deserializer());
512✔
36
    }
37

38
    /**
39
     * @phpstan-template TDto of Dto
40
     * 
41
     * @param 'get'|'post'|'put'|'patch'|'delete' $method
42
     * @param array{0:class-string<TDto>}|class-string<TDto>|true $schema
43
     * @param Dto|array<string,mixed> $body
44
     * @param array<string,mixed> $header
45
     * @param array<string,mixed> $query
46
     * @param array<string,int|string|null> $path
47
     *
48
     * @return (
49
     *     $schema is array ? (TDto is PolymorphicDto ? list<Dto> : list<TDto>) : (
50
     *     $schema is string ? (TDto is PolymorphicDto ? Dto : TDto) : (
51
     *     true
52
     * )))
53
     */
54
    public function call(
512✔
55
        string $uri,
56
        string $method,
57
        int $success,
58
        array|string|true $schema,
59
        Dto|array $body = [],
60
        array $header = [],
61
        array $query = [],
62
        array $path = [],
63
    ): array|Dto|true {
64
        $operation = new PendingOperation(
512✔
65
            uri: $uri,
512✔
66
            method: $method,
512✔
67
            body: $body,
512✔
68
            header: $header,
512✔
69
            query: $query,
512✔
70
            path: $path,
512✔
71
        );
512✔
72

73
        $request = $this->transporter->newRequest($operation, $this->configuration);
512✔
74

75
        $response = $this->handleStubCallbacks($request)
512✔
NEW
76
            ?: $this->transporter->newResponse($request, $this->configuration);
×
77

78
        return $this->processor->process($operation, $response, $success, $schema);
512✔
79
    }
80

81
    /** @param Closure(Request):?Response $callback */
82
    public function fake(Closure $callback): static
512✔
83
    {
84
        $this->stubCallbacks[] = $callback;
512✔
85

86
        return $this;
512✔
87
    }
88

89
    protected function handleStubCallbacks(Request $request): ?Response
512✔
90
    {
91
        foreach ($this->stubCallbacks as $callback) {
512✔
92
            if (! is_null($response = $callback($request))) {
512✔
93
                return $response;
512✔
94
            }
95
        }
96

NEW
97
        if (! empty($this->stubCallbacks)) {
×
NEW
98
            throw new StrayRequestException(sprintf(
×
NEW
99
                'Attempted request to [%s] without a matching fake.',
×
NEW
100
                $request->uri,
×
NEW
101
            ));
×
102
        }
103

NEW
104
        return null;
×
105
    }
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc