GenericHelper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 31
ccs 6
cts 8
cp 0.75
rs 10
c 2
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A emptyStringAsNull() 0 3 2
A convertToDateTime() 0 6 2
A convertToBoolean() 0 3 1
1
<?php
2
3
namespace Mpyw\OpenGraph;
4
5
use DateTimeImmutable;
6
use DateTimeInterface;
7
use Throwable;
8
9
/**
10
 * Trait GenericHelper
11
 */
12
trait GenericHelper
13
{
14
    /**
15
     * @param  string                 $value
16
     * @return null|DateTimeInterface
17
     */
18 1
    protected function convertToDateTime(string $value): ?DateTimeInterface
19
    {
20
        try {
21 1
            return new DateTimeImmutable($value);
22
        } catch (Throwable $e) {
23
            return null;
24
        }
25
    }
26
27
    /**
28
     * @param  string $value
29
     * @return bool
30
     */
31 1
    protected function convertToBoolean(string $value): bool
32
    {
33 1
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
34
    }
35
36
    /**
37
     * @param  null|string $string
38
     * @return null|string
39
     */
40 17
    protected function emptyStringAsNull(?string $string): ?string
41
    {
42 17
        return (string)$string !== '' ? (string)$string : null;
43
    }
44
}
45