RuntimeStorage::save()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (c) Ne-Lexa
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 *
11
 * @see https://github.com/Ne-Lexa/guzzle-doh-middleware
12
 */
13
14
namespace Nelexa\Doh\Storage;
15
16
class RuntimeStorage implements StorageInterface
17
{
18
    /** @var array<string, \Nelexa\Doh\Storage\DnsRecord> */
19
    private $cache = [];
20
21 11
    public function get(string $domainName): ?DnsRecord
22
    {
23 11
        $dnsRecord = $this->cache[$domainName] ?? null;
24
25 11
        if ($dnsRecord !== null && $dnsRecord->getExpiredAt() < new \DateTimeImmutable()) {
26
            unset($this->cache[$domainName]);
27
            $dnsRecord = null;
28
        }
29
30 11
        return $dnsRecord;
31
    }
32
33 11
    public function save(string $domainName, DnsRecord $dnsRecord): void
34
    {
35 11
        $this->cache[$domainName] = $dnsRecord;
36
    }
37
}
38