HasFormatTrait::withFormat()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nip\Controllers\Response\ResponsePayload\Traits;
6
7
/**
8
 * Trait HasFormatTrait
9
 * @package Nip\Controllers\Response\ResponsePayload
10
 */
11
trait HasFormatTrait
12
{
13
14
    /**
15
     * @var string
16
     */
17
    protected $defaultFormat = null;
18
19
    /**
20
     * @var string
21
     */
22
    protected $format = null;
23
24
    public function withDefaultFormat(string $format): self
25
    {
26
        $this->defaultFormat = $format;
27
28
        return $this;
29
    }
30
31
    /**
32
     * @param string|null $format
33
     */
34
    public function withFormat(?string $format): void
35
    {
36
        $this->format = $format;
37
    }
38
39
    /**
40
     * @return ?string
41
     */
42
    public function getFormat(): ?string
43
    {
44
        return $this->format ?? $this->defaultFormat;
45
    }
46
}