• 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

34.15
/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 SecurityStrategyAbstract
15
{
16
    public const SCHEME = 'basic';
17

18
    private const PROPERTY_CREDENTIALS = 'credentials';
19

20
    private const TYPE = 'http';
21

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

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

34
        $statements = [];
1✔
35

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

44
        return $statements;
1✔
45
    }
46

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

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

57
        return $params;
1✔
58
    }
59

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

66
        $paramInits = [];
1✔
67

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

75
        return $paramInits;
1✔
76
    }
77

78
    protected function getScheme(): string
79
    {
80
        return self::SCHEME;
1✔
81
    }
82

83
    protected function getType(): string
84
    {
85
        return self::TYPE;
×
86
    }
87

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