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

CarbonPresenter::fromCarbon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
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