Completed
Pull Request — master (#5)
by Brent
13:30
created

IsDateRule::createDate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Spatie\ValidationRules;
4
5
use Carbon\Carbon;
6
use InvalidArgumentException;
7
use Spatie\ValidationRules\Exceptions\InvalidDate;
8
9
trait IsDateRule
10
{
11
    /** @var string */
12
    protected $format;
13
14
    protected function createDate(string $value): Carbon
15
    {
16
        try {
17
            return Carbon::createFromFormat($this->format, $value);
18
        } catch (InvalidArgumentException $exception) {
19
            throw InvalidDate::withFormat($this->format, $value);
20
        }
21
    }
22
}
23