NowArgumentResolver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 20
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doResolve() 0 8 2
A __construct() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Diezz\YamlToObjectMapper\Resolver;
4
5
use DateTime;
6
7
/**
8
 * Returns current timestamp in given format;
9
 * If format isn't provided by default `Y-m-d H:i:s` would be used.
10
 *
11
 * Example of usage:
12
 * $now::Y-m-d H:i:s
13
 */
14
class NowArgumentResolver extends CustomArgumentResolver
15
{
16
    private ?ScalarArgumentResolver $format;
17
18
    /**
19
     * @param ScalarArgumentResolver|null $format
20
     */
21 1
    public function __construct(?ScalarArgumentResolver $format)
22
    {
23 1
        $this->format = $format;
24 1
    }
25
26 1
    protected function doResolve($context = null): mixed
27
    {
28 1
        $now = new DateTime();
29 1
        if ($this->format !== null) {
30 1
            return $now->format($this->format->resolve($context));
31
        }
32
33
        return $now;
34
    }
35
}
36