Issues (3627)

Segment/Decorator/CustomMappedDecorator.php (1 issue)

1
<?php
2
3
/*
4
 * @copyright   2018 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\LeadBundle\Segment\Decorator;
13
14
use Mautic\LeadBundle\Segment\ContactSegmentFilterCrate;
15
use Mautic\LeadBundle\Segment\ContactSegmentFilterOperator;
16
use Mautic\LeadBundle\Services\ContactSegmentFilterDictionary;
17
18
/**
19
 * Class CustomMappedDecorator.
20
 */
21
class CustomMappedDecorator extends BaseDecorator
22
{
23
    /**
24
     * @var ContactSegmentFilterDictionary
25
     */
26
    protected $dictionary;
27
28
    /**
29
     * CustomMappedDecorator constructor.
30
     */
31
    public function __construct(
32
        ContactSegmentFilterOperator $contactSegmentFilterOperator,
33
        ContactSegmentFilterDictionary $contactSegmentFilterDictionary
34
    ) {
35
        parent::__construct($contactSegmentFilterOperator);
36
        $this->dictionary = $contactSegmentFilterDictionary;
37
    }
38
39
    /**
40
     * @return string|null
41
     */
42
    public function getField(ContactSegmentFilterCrate $contactSegmentFilterCrate)
43
    {
44
        $originalField = $contactSegmentFilterCrate->getField();
45
46
        if (empty($this->dictionary[$originalField]['field'])) {
47
            return parent::getField($contactSegmentFilterCrate);
48
        }
49
50
        return $this->dictionary[$originalField]['field'];
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getTable(ContactSegmentFilterCrate $contactSegmentFilterCrate)
57
    {
58
        $originalField = $contactSegmentFilterCrate->getField();
59
60
        if (empty($this->dictionary[$originalField]['foreign_table'])) {
61
            return parent::getTable($contactSegmentFilterCrate);
62
        }
63
64
        return MAUTIC_TABLE_PREFIX.$this->dictionary[$originalField]['foreign_table'];
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    public function getQueryType(ContactSegmentFilterCrate $contactSegmentFilterCrate)
71
    {
72
        $originalField = $contactSegmentFilterCrate->getField();
73
74
        if (!isset($this->dictionary[$originalField]['type'])) {
75
            return parent::getQueryType($contactSegmentFilterCrate);
76
        }
77
78
        return $this->dictionary[$originalField]['type'];
79
    }
80
81
    /**
82
     * @return string|bool if no func needed
83
     */
84
    public function getAggregateFunc(ContactSegmentFilterCrate $contactSegmentFilterCrate)
85
    {
86
        $originalField = $contactSegmentFilterCrate->getField();
87
88
        return isset($this->dictionary[$originalField]['func']) ?
89
            $this->dictionary[$originalField]['func'] : false;
90
    }
91
92
    /**
93
     * @return \Mautic\LeadBundle\Segment\Query\Expression\CompositeExpression|string|null
94
     */
95
    public function getWhere(ContactSegmentFilterCrate $contactSegmentFilterCrate)
96
    {
97
        $originalField = $contactSegmentFilterCrate->getField();
98
99
        if (!isset($this->dictionary[$originalField]['where'])) {
100
            return parent::getWhere($contactSegmentFilterCrate);
0 ignored issues
show
Are you sure the usage of parent::getWhere($contactSegmentFilterCrate) targeting Mautic\LeadBundle\Segmen...seDecorator::getWhere() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
101
        }
102
103
        return $this->dictionary[$originalField]['where'];
104
    }
105
}
106