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

DoclerLabs / api-client-generator / 7259428899

19 Dec 2023 08:47AM UTC coverage: 89.733% (-0.3%) from 90.043%
7259428899

push

github

web-flow
Merge pull request #102 from DoclerLabs/generator-php-8

generator php 8

355 of 381 new or added lines in 40 files covered. (93.18%)

6 existing lines in 4 files now uncovered.

2657 of 2961 relevant lines covered (89.73%)

3.35 hits per line

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

86.11
/src/Input/Factory/ResponseFactory.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace DoclerLabs\ApiClientGenerator\Input\Factory;
6

7
use cebe\openapi\spec\Reference;
8
use DoclerLabs\ApiClientGenerator\Entity\Response;
9
use DoclerLabs\ApiClientGenerator\Input\InvalidSpecificationException;
10
use DoclerLabs\ApiClientGenerator\Naming\SchemaNaming;
11
use Icecave\Parity\Parity;
12

13
class ResponseFactory
14
{
15
    public function __construct(private FieldFactory $fieldMapper)
16
    {
17
    }
2✔
18

19
    public function createSuccessfulResponses(string $operationName, array $openApiResponses): array
20
    {
21
        $responses = [];
2✔
22

23
        $body = null;
2✔
24
        foreach ($openApiResponses as $code => $response) {
2✔
25
            if ($response instanceof Reference) {
2✔
26
                $response = $response->resolve();
1✔
27
            }
28

29
            if ($code === 204) {
2✔
30
                $responses[] = new Response(204, null);
×
31

UNCOV
32
                continue;
×
33
            }
34

35
            if (200 <= $code && $code < 300) {
2✔
36
                if (empty($response->content) || current($response->content) === false) {
2✔
37
                    $responses[] = new Response((int)$code, null);
×
38

UNCOV
39
                    continue;
×
40
                }
41

42
                $contentTypes = [];
2✔
43
                $schema       = null;
2✔
44
                foreach ($response->content as $contentType => $content) {
2✔
45
                    if ($schema !== null && !Parity::isEqualTo($content->schema, $schema)) {
2✔
46
                        throw new InvalidSpecificationException('Multiple schemas per response is not currently supported.');
×
47
                    }
48
                    $schema         = $content->schema;
2✔
49
                    $contentTypes[] = $contentType;
2✔
50
                }
51

52
                $schemaName = SchemaNaming::getClassName($schema, ucfirst($operationName) . 'ResponseBody');
2✔
53

54
                $body = $this->fieldMapper->create(
2✔
55
                    $operationName,
56
                    lcfirst($schemaName),
2✔
57
                    $schema,
58
                    true,
2✔
59
                    $schemaName
60
                );
61

62
                $responses[] = new Response((int)$code, $body, $contentTypes);
2✔
63
            }
64
        }
65

66
        if (empty($responses)) {
2✔
67
            $warningMessage = sprintf(
1✔
68
                'Successful response is not found for %s operation, 200 response assumed.',
1✔
69
                $operationName
70
            );
71
            trigger_error($warningMessage, E_USER_WARNING);
1✔
72

73
            $responses[] = new Response(200, null);
1✔
74
        }
75

76
        return $responses;
2✔
77
    }
78

79
    public function createPossibleErrors(array $openApiResponses): array
80
    {
81
        $responses = [];
2✔
82
        foreach ($openApiResponses as $code => $response) {
2✔
83
            if ($code > 399) {
2✔
84
                $responses[] = new Response((int)$code, null);
1✔
85
            }
86
        }
87

88
        return $responses;
2✔
89
    }
90
}
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

© 2025 Coveralls, Inc