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

DateIntervalFilter::apply()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
rs 9.4285
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