TermsAndConditionsField::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
/**
3
 * TermsAndConditionsField
4
 *
5
 * @author Bram de Leeuw
6
 */
7
8
namespace Broarm\EventTickets;
9
10
use CheckboxField;
11
use SiteConfig;
12
13
class TermsAndConditionsField extends CheckboxField
14
{
15
    protected $fieldHolderTemplate = 'TermsAndConditionsField_holder';
16
17
    /**
18
     * @var \Page
19
     */
20
    protected $termsPage;
21
22
    public function __construct($name)
23
    {
24
        if (($this->termsPage = SiteConfig::current_site_config()->TermsPage()) && $this->termsPage->exists()) {
25
            parent::__construct($name, _t(
26
                'TermsAndConditionsField.TERMS_CONDITIONS',
27
                "I agree to the terms and conditions stated on the <a href='{link}' target='new' title='Read the shop terms and conditions for this site'>{title}</a> page",
28
                null,
29
                array('link' => $this->termsPage->Link(), 'title' => $this->termsPage->Title)
0 ignored issues
show
Documentation introduced by
array('link' => $this->t...this->termsPage->Title) is of type array<string,?,{"link":"?","title":"?"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
30
            ), $value = null);
31
        }
32
    }
33
34
    public function getCustomValidationMessage()
35
    {
36
        return _t('TermsAndConditionsField.AGREE_TO_TERMS', 'You must agree to the terms and conditions');
37
    }
38
39
    /**
40
     * If a therms page is set render the checkbox
41
     *
42
     * @param array $properties
43
     *
44
     * @return null|string
45
     */
46
    public function FieldHolder($properties = array()) {
47
        if ($this->termsPage->exists()) {
48
            return parent::FieldHolder($properties);
49
        } else {
50
            return null;
51
        }
52
    }
53
}