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

DoclerLabs / api-client-generator / 9254068657

27 May 2024 11:30AM UTC coverage: 86.981% (-1.4%) from 88.428%
9254068657

push

github

web-flow
Merge pull request #112 from DoclerLabs/php81

php 8.1 features

106 of 172 new or added lines in 20 files covered. (61.63%)

4 existing lines in 2 files now uncovered.

2913 of 3349 relevant lines covered (86.98%)

4.92 hits per line

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

31.71
/src/Generator/Security/BasicAuthenticationSecurityStrategy.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace DoclerLabs\ApiClientGenerator\Generator\Security;
6

7
use DoclerLabs\ApiClientGenerator\Entity\ImportCollection;
8
use DoclerLabs\ApiClientGenerator\Entity\Operation;
9
use DoclerLabs\ApiClientGenerator\Input\Specification;
10
use DoclerLabs\ApiClientGenerator\Naming\CopiedNamespace;
11
use DoclerLabs\ApiClientGenerator\Output\Copy\Request\AuthenticationCredentials;
12
use PhpParser\Node\Expr;
13

14
class BasicAuthenticationSecurityStrategy extends HttpBasedSecurityStrategyAbstract
15
{
16
    public const SCHEME = 'basic';
17

18
    private const PROPERTY_CREDENTIALS = 'credentials';
19

20
    public function getImports(string $baseNamespace): ImportCollection
21
    {
22
        return parent::getImports($baseNamespace)
1✔
23
            ->add(CopiedNamespace::getImport($baseNamespace, AuthenticationCredentials::class));
1✔
24
    }
25

26
    public function getProperties(Operation $operation, Specification $specification): array
27
    {
28
        if ($this->phpVersion->isConstructorPropertyPromotionSupported()) {
1✔
29
            return [];
×
30
        }
31

32
        $statements = [];
1✔
33

34
        if ($this->isAuthenticationAvailable($operation, $specification)) {
1✔
35
            $statements[] = $this->builder->localProperty(
×
36
                self::PROPERTY_CREDENTIALS,
×
37
                'AuthenticationCredentials',
×
NEW
38
                'AuthenticationCredentials',
×
NEW
39
                readonly: true
×
40
            );
41
        }
42

43
        return $statements;
1✔
44
    }
45

46
    public function getConstructorParams(Operation $operation, Specification $specification): array
47
    {
48
        $params = [];
1✔
49

50
        if ($this->isAuthenticationAvailable($operation, $specification)) {
1✔
51
            $params[] = $this->builder
×
52
                ->param(self::PROPERTY_CREDENTIALS)
×
53
                ->setType('AuthenticationCredentials');
×
54
        }
55

56
        return $params;
1✔
57
    }
58

59
    public function getConstructorParamInits(Operation $operation, Specification $specification): array
60
    {
61
        if ($this->phpVersion->isConstructorPropertyPromotionSupported()) {
1✔
62
            return [];
×
63
        }
64

65
        $paramInits = [];
1✔
66

67
        if ($this->isAuthenticationAvailable($operation, $specification)) {
1✔
68
            $paramInits[] = $this->builder->assign(
×
69
                $this->builder->localPropertyFetch(self::PROPERTY_CREDENTIALS),
×
70
                $this->builder->var(self::PROPERTY_CREDENTIALS)
×
71
            );
72
        }
73

74
        return $paramInits;
1✔
75
    }
76

77
    protected function getScheme(): string
78
    {
79
        return self::SCHEME;
×
80
    }
81

82
    protected function getAuthorizationHeader(): Expr
83
    {
84
        return $this->builder->funcCall(
×
85
            'sprintf',
×
86
            [
87
                'Basic %s',
×
88
                $this->builder->funcCall(
×
89
                    'base64_encode',
×
90
                    [
91
                        $this->builder->funcCall(
×
92
                            'sprintf',
×
93
                            [
94
                                '%s:%s',
×
95
                                $this->builder->methodCall(
×
96
                                    $this->builder->localPropertyFetch(self::PROPERTY_CREDENTIALS),
×
97
                                    'getUsername'
×
98
                                ),
99
                                $this->builder->methodCall(
×
100
                                    $this->builder->localPropertyFetch(self::PROPERTY_CREDENTIALS),
×
101
                                    'getPassword'
×
102
                                ),
103
                            ]
104
                        ),
105
                    ]
106
                ),
107
            ]
108
        );
109
    }
110
}
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