Completed
Push — master ( a8e426...cdcd92 )
by Simonas
62:46
created

Filter/Widget/Range/DateRange.php (1 issue)

Labels
Severity

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\Widget\Range;
13
14
use ONGR\ElasticsearchBundle\Result\DocumentIterator;
15
use ONGR\FilterManagerBundle\Filter\ViewData;
16
use ONGR\FilterManagerBundle\Filter\ViewData\RangeAwareViewData;
17
18
/**
19
 * Date range filter, selects documents from lower date to upper date.
20
 */
21
class DateRange extends Range
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function getViewData(DocumentIterator $result, ViewData $data)
27
    {
28
        $name = $data->getState()->getName();
29
30
        if (!$agg = $result->getAggregation($name)) {
31
            $agg = $result->getAggregation($name . '-filter')->getAggregation($name);
0 ignored issues
show
The method getAggregation cannot be called on $result->getAggregation($name . '-filter') (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
32
        }
33
        /** @var $data RangeAwareViewData */
34
        $data->setMinBounds(
35
            new \DateTime('@' . (int) ($agg['min'] / 1000))
36
        );
37
38
        $data->setMaxBounds(
39
            new \DateTime('@' . (int) ($agg['max'] / 1000))
40
        );
41
42
        return $data;
43
    }
44
}
45