HasFormatTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 7
c 0
b 0
f 0
dl 0
loc 34
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A withFormat() 0 3 1
A withDefaultFormat() 0 5 1
A getFormat() 0 3 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
}