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

IsDateRule   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 14
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createDate() 0 8 2
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