Completed
Push — master ( cc21e8...5c80a5 )
by Simonas
65:42
created

Filter/ViewData/RangeAwareViewData.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\FilterManagerBundle\Filter\ViewData;
13
14
use ONGR\FilterManagerBundle\Filter\ViewData;
15
16
/**
17
 * This class holds extra data for range and date_range filters.
18
 */
19
class RangeAwareViewData extends ViewData
20
{
21
    /**
22
     * @var float|\DateTime
23
     */
24
    private $minBounds;
25
26
    /**
27
     * @var float|\DateTime
28
     */
29
    private $maxBounds;
30
31
    /**
32
     * @return float|\DateTime
33
     */
34
    public function getMaxBounds()
35
    {
36
        return $this->maxBounds;
37
    }
38
39
    /**
40
     * @param float|\DateTime $maxBounds
41
     */
42
    public function setMaxBounds($maxBounds)
43
    {
44
        $this->maxBounds = $maxBounds;
45
    }
46
47
    /**
48
     * @return float|\DateTime
49
     */
50
    public function getMinBounds()
51
    {
52
        return $this->minBounds;
53
    }
54
55
    /**
56
     * @param float|\DateTime $minBounds
57
     */
58
    public function setMinBounds($minBounds)
59
    {
60
        $this->minBounds = $minBounds;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function getSerializableData()
67
    {
68
        $data = parent::getSerializableData();
69
70
        // TODO: handle \DateTime serialization
71
        $data['min_bound'] = $this->minBounds;
72
        $data['max_bound'] = $this->maxBounds;
73
74
        return $data;
0 ignored issues
show
The expression return $data; seems to be an array, but some of its elements' types (double|DateTime) are incompatible with the return type of the parent method ONGR\FilterManagerBundle...ta::getSerializableData of type array<string,string|array>.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
75
    }
76
}
77