Completed
Push — master ( 2af2d7...ce9658 )
by Kirill
02:09
created

CarbonPresenter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 35
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromDateTime() 0 4 1
A fromString() 0 4 1
A fromCarbon() 0 5 1
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\CarbonExtension;
11
12
use Carbon\Carbon;
13
14
/**
15
 * Class CarbonPresenter
16
 */
17
final class CarbonPresenter
18
{
19
    /**
20
     * @param \DateTimeInterface $dateTime
21
     * @return array
22
     * @throws \InvalidArgumentException
23
     * @throws \Symfony\Component\Translation\Exception\InvalidArgumentException
24
     */
25
    public function fromDateTime(\DateTimeInterface $dateTime): iterable
26
    {
27
        yield from $this->fromCarbon(Carbon::instance($dateTime));
28
    }
29
30
    /**
31
     * @param string $dateTimeString
32
     * @return iterable
33
     * @throws \InvalidArgumentException
34
     * @throws \Symfony\Component\Translation\Exception\InvalidArgumentException
35
     */
36
    public function fromString(string $dateTimeString): iterable
37
    {
38
        yield from $this->fromCarbon(Carbon::parse($dateTimeString));
39
    }
40
41
    /**
42
     * @param Carbon $carbon
43
     * @return iterable
44
     * @throws \Symfony\Component\Translation\Exception\InvalidArgumentException
45
     */
46
    public function fromCarbon(Carbon $carbon): iterable
47
    {
48
        yield 'date' => $carbon->toRfc3339String();
49
        yield 'diff' => $carbon->diffForHumans();
50
    }
51
}
52