Completed
Push — master ( 59c799...149ad0 )
by Will
02:15
created

ElementContact::ObfuscatedEmail()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * @package elemental
5
 */
6
class ElementContact extends BaseElement
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
9
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
10
        'ContactName' => 'Varchar(255)',
11
        'Phone' => 'Varchar(100)',
12
        'Mobile' => 'Varchar(100)',
13
        'Fax' => 'Varchar(100)',
14
        'Email' => 'Varchar(255)',
15
        'Website' => 'Varchar(255)',
16
    );
17
18
    private static $extensions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $extensions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
        'Addressable',
20
        'Geocodable'
21
    );
22
23
    /**
24
     * @var string
25
     */
26
    private static $title = "Contact Element";
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $title is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
27
28
    /**
29
     * @return FieldList
30
     */
31
    public function getCMSFields()
32
    {
33
        $this->beforeUpdateCMSFields(function ($fields) {
34
            $fields->addFieldsToTab('Root.Main', array(
35
                Textfield::create('ContactName', 'Name'),
36
                TextField::create('Phone', 'Phone'),
37
                TextField::create('Mobile', 'Mobile'),
38
                TextField::create('Fax', 'Fax'),
39
                EmailField::create('Email', 'Email'),
40
                $website = TextField::create('Website', 'Website')
41
            ));
42
43
            $website->setRightTitle('e.g '.Director::absoluteBaseURL());
44
        });
45
46
        return parent::getCMSFields();
47
    }
48
49
    /**
50
     * Return the obfuscated email.
51
     *
52
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
53
     */
54
    public function ObfuscatedEmail()
55
    {
56
        return ($this->Email) ? Email::obfuscate($this->Email, 'hex') : null;
0 ignored issues
show
Documentation introduced by
The property Email does not exist on object<ElementContact>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
57
    }
58
}
59