getTemporaryDocumentFilename()   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 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Nekhay <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Nekhay
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sunrise\Http\Router\OpenApi;
15
16
use Sunrise\Coder\MediaTypeInterface;
17
use Sunrise\Hydrator\TypeConverter\TimestampTypeConverter;
18
19
use function sys_get_temp_dir;
20
21
use const DIRECTORY_SEPARATOR;
22
23
/**
24
 * @since 3.0.0
25
 */
26
final class OpenApiConfiguration
27
{
28
    public const VERSION = '3.1.1';
29
    public const JSON_SCHEMA_DIALECT = 'https://json-schema.org/draft/2020-12/schema';
30
31
    public const DEFAULT_TIMESTAMP_FORMAT = TimestampTypeConverter::DEFAULT_FORMAT;
32
    public const DEFAULT_RESPONSE_DESCRIPTION = 'The operation was successful.';
33
34 5
    public function __construct(
35
        /** @var array<array-key, mixed> */
36
        public readonly array $initialDocument,
37
        /** @var array<array-key, mixed> */
38
        public readonly array $initialOperation,
39
        public readonly MediaTypeInterface $documentMediaType,
40
        /** @var array<array-key, mixed> */
41
        public readonly array $documentEncodingContext = [],
42
        public readonly ?string $documentFilename = null,
43
        public readonly string $defaultTimestampFormat = self::DEFAULT_TIMESTAMP_FORMAT,
44
        public readonly string $defaultResponseDescription = self::DEFAULT_RESPONSE_DESCRIPTION,
45
    ) {
46 5
    }
47
48 5
    public function getDocumentFilename(): string
49
    {
50 5
        return $this->documentFilename ?? $this->getTemporaryDocumentFilename();
51
    }
52
53 2
    public function getTemporaryDocumentFilename(): string
54
    {
55 2
        return sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'openapi';
56
    }
57
}
58