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

eliashaeussler / composer-package-template / 12861990819

20 Jan 2025 01:05AM UTC coverage: 99.502%. Remained the same
12861990819

push

github

web-flow
[TASK] Update all dependencies

400 of 402 relevant lines covered (99.5%)

3.5 hits per line

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

100.0
/src/Resource/TokenStorage.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer package "eliashaeussler/composer-package-template".
7
 *
8
 * Copyright (C) 2023-2025 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\ComposerPackageTemplate\Resource;
25

26
use EliasHaeussler\ComposerPackageTemplate\Enums;
27

28
use function getenv;
29
use function strtoupper;
30

31
/**
32
 * TokenStorage.
33
 *
34
 * @author Elias Häußler <elias@haeussler.dev>
35
 * @license GPL-3.0-or-later
36
 */
37
final class TokenStorage
38
{
39
    /**
40
     * @var array<non-empty-string, non-empty-string>
41
     */
42
    private static array $storage = [];
43

44
    /**
45
     * @return non-empty-string|null
46
     */
47
    public function get(Enums\TokenIdentifier $identifier): ?string
5✔
48
    {
49
        if ($this->has($identifier)) {
5✔
50
            return self::$storage[$identifier->value];
2✔
51
        }
52

53
        $envVariable = strtoupper($identifier->value.'_token');
4✔
54
        $token = getenv($envVariable);
4✔
55

56
        if (false !== $token && '' !== $token) {
4✔
57
            $this->set($identifier, $token);
1✔
58

59
            return self::$storage[$identifier->value];
1✔
60
        }
61

62
        return null;
3✔
63
    }
64

65
    public function has(Enums\TokenIdentifier $identifier): bool
6✔
66
    {
67
        return isset(self::$storage[$identifier->value]);
6✔
68
    }
69

70
    /**
71
     * @param non-empty-string $token
72
     */
73
    public function set(Enums\TokenIdentifier $identifier, string $token): void
4✔
74
    {
75
        self::$storage[$identifier->value] = $token;
4✔
76
    }
77
}
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