• 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

45.83
/src/Generator/Security/BearerAuthenticationSecurityStrategy.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace DoclerLabs\ApiClientGenerator\Generator\Security;
6

7
use DoclerLabs\ApiClientGenerator\Entity\Operation;
8
use DoclerLabs\ApiClientGenerator\Input\Specification;
9
use PhpParser\Node\Expr;
10

11
class BearerAuthenticationSecurityStrategy extends HttpBasedSecurityStrategyAbstract
12
{
13
    private const PROPERTY_NAME = 'bearerToken';
14

15
    private const SCHEME = 'bearer';
16

17
    public function getProperties(Operation $operation, Specification $specification): array
18
    {
19
        if ($this->phpVersion->isConstructorPropertyPromotionSupported()) {
1✔
20
            return [];
×
21
        }
22

23
        $statements = [];
1✔
24

25
        if ($this->isAuthenticationAvailable($operation, $specification)) {
1✔
NEW
26
            $statements[] = $this->builder->localProperty(self::PROPERTY_NAME, 'string', 'string', readonly: true);
×
27
        }
28

29
        return $statements;
1✔
30
    }
31

32
    public function getConstructorParams(Operation $operation, Specification $specification): array
33
    {
34
        $params = [];
1✔
35

36
        if ($this->isAuthenticationAvailable($operation, $specification)) {
1✔
37
            $params[] = $this->builder
×
38
                ->param(self::PROPERTY_NAME)
×
39
                ->setType('string');
×
40
        }
41

42
        return $params;
1✔
43
    }
44

45
    public function getConstructorParamInits(Operation $operation, Specification $specification): array
46
    {
47
        if ($this->phpVersion->isConstructorPropertyPromotionSupported()) {
1✔
48
            return [];
×
49
        }
50

51
        $paramInits = [];
1✔
52

53
        if ($this->isAuthenticationAvailable($operation, $specification)) {
1✔
54
            $paramInits[] = $this->builder->assign(
×
55
                $this->builder->localPropertyFetch(self::PROPERTY_NAME),
×
56
                $this->builder->var(self::PROPERTY_NAME)
×
57
            );
58
        }
59

60
        return $paramInits;
1✔
61
    }
62

63
    protected function getScheme(): string
64
    {
65
        return self::SCHEME;
×
66
    }
67

68
    protected function getAuthorizationHeader(): Expr
69
    {
70
        return $this->builder->funcCall(
×
71
            'sprintf',
×
72
            ['Bearer %s', $this->builder->localPropertyFetch(self::PROPERTY_NAME)]
×
73
        );
74
    }
75
}
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