Completed
Pull Request — master (#5)
by Brent
13:35 queued 12:15
created

IsDateRule   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 14
ccs 4
cts 4
cp 1
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 60
    protected function createDate(string $value): Carbon
15
    {
16
        try {
17 60
            return Carbon::createFromFormat($this->format, $value);
18 6
        } catch (InvalidArgumentException $exception) {
19 6
            throw InvalidDate::withFormat($this->format, $value);
20
        }
21
    }
22
}
23