Completed
Push — master ( a7ec5f...7812c9 )
by Jan-Petter
02:03
created

CacheDelay::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
namespace vipnytt\RobotsTxtParser\Directives;
3
4
/**
5
 * Class CacheDelay
6
 *
7
 * @package vipnytt\RobotsTxtParser\Directives
8
 */
9 View Code Duplication
class CacheDelay implements DirectiveInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    /**
12
     * Directive
13
     */
14
    const DIRECTIVE = 'Cache-delay';
15
16
    protected $array = [];
17
    protected $parent;
18
19
20
    public function __construct($array, $parent = null)
21
    {
22
        $this->array = $array;
0 ignored issues
show
Documentation Bug introduced by
It seems like $array of type string is incompatible with the declared type array of property $array.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
23
    }
24
25
    /**
26
     * Add
27
     *
28
     * @param string $line
29
     * @return bool
30
     */
31
    public function add($line)
32
    {
33
        if (empty(($float = floatval($this->array)))) {
34
            return false;
35
        }
36
        $this->array = [$float];
37
        return true;
38
    }
39
40
    public function export()
41
    {
42
        return empty($this->array) ? [] : [self::DIRECTIVE => $this->array];
43
    }
44
}
45