Completed
Push — 1.x ( 0fa590...3b8a3a )
by Théo
01:13
created

DateIntervalFilter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 10 2
1
<?php
2
3
namespace DeepCopy\TypeFilter\Date;
4
5
use DateInterval;
6
use DeepCopy\TypeFilter\TypeFilter;
7
8
/**
9
 * @final
10
 *
11
 * @deprecated Will be removed in 2.0. This filter will no longer be necessary in PHP 7.1+.
12
 */
13
class DateIntervalFilter implements TypeFilter
14
{
15
16
    /**
17
     * {@inheritdoc}
18
     *
19
     * @param DateInterval $element
20
     *
21
     * @see http://news.php.net/php.bugs/205076
22
     */
23
    public function apply($element)
24
    {
25
        $copy = new DateInterval('P0D');
26
27
        foreach ($element as $propertyName => $propertyValue) {
0 ignored issues
show
Bug introduced by Théo FIDRY
The expression $element of type object<DateInterval> is not traversable.
Loading history...
28
            $copy->{$propertyName} = $propertyValue;
29
        }
30
31
        return $copy;
32
    }
33
}
34