Passed
Push — develop ( 2749c8...d768fa )
by Dylan
02:40
created

AutomatedLink::constructDOMDocument()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.2
c 0
b 0
f 0
cc 4
eloc 13
nc 3
nop 1
1
<?php
2
/**
3
 * Plugin: SEOToolbox
4
 * Author: Dylan Grech
5
 * Copyright: 2016
6
 *
7
 * Automated Link is a dataobject that contains all the data
8
 * about a link that should be created automatically to a page
9
 *
10
 * @method SiteTree|null Page()
11
 */
12
class AutomatedLink extends DataObject implements PermissionProvider {
1 ignored issue
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...
13
14
    private static $db = array(
2 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...
15
        'Phrase'     	  => 'VARCHAR(255)',
16
        'TitleTag'   	  => 'VARCHAR(255)',
17
        'AnchorTag' 	  => 'VARCHAR(255)',
18
        'NewWindow'  	  => 'Boolean',
19
        'NoFollow'   	  => 'Boolean',
20
        'SelfLinking'     => 'Boolean',
21
        'CaseSensitive'   => 'Boolean',
22
        'MaxLinksPerPage' => 'INT',
23
        'Priority'		  => 'Int'
24
    );
25
26
    private static $defaults = array(
2 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 $defaults 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
        'MaxLinksPerPage' => 10
28
    );
29
30
    private static $default_sort = 'Priority';
2 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 $default_sort 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...
31
32
    private static $has_one = array(
2 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 $has_one 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...
33
        'Page' => 'SiteTree'
34
    );
35
36
    private static $summary_fields    = array( 'Phrase', 'PointsTo' );
2 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 $summary_fields 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...
37
    private static $searchable_fields = array( 'Phrase' );
2 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 $searchable_fields 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...
38
    private static $singular_name	  = 'Automated Link';
2 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 $singular_name 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...
39
    private static $plural_name	      = 'Automated Links';
2 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 $plural_name 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...
40
    private static $parsableFields    = array();
41
42
    /**
43
     * Get the url of the page linked to this object
44
     *
45
     * @return string
46
     */
47
    public function PointsTo(){
48
        return $this->Page()->Link();
49
    }
50
51
    /**
52
     * Return the phrase set for this object
53
     *
54
     * @return string
55
     */
56
    public function Title(){
57
        return $this->Phrase;
0 ignored issues
show
Documentation introduced by
The property Phrase does not exist on object<AutomatedLink>. 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...
58
    }
59
60
    /**
61
     * Return the rendered version of this object
62
     *
63
     * @return String
64
     */
65
    public function forTemplate(){
66
        return $this->getHTML();
67
    }
68
69
    function canView( $member = false ){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
70
        return Permission::check('AUTOMATEDLINK_VIEW');
71
    }
72
73
    function canEdit( $member = false ){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
74
        return Permission::check('AUTOMATEDLINK_EDIT');
75
    }
76
77
    function canDelete( $member = false ){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
78
        return Permission::check('AUTOMATEDLINK_DELETE');
79
    }
80
81
    function canCreate( $member = false ){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
82
        return Permission::check('AUTOMATEDLINK_CREATE');
83
    }
84
85
    function providePermissions() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
86
       return array(
87
         'AUTOMATEDLINK_VIEW'   => 'View Automated Links',
88
         'AUTOMATEDLINK_EDIT'   => 'Edit Automated Links',
89
         'AUTOMATEDLINK_DELETE' => 'Delete Automated Links',
90
         'AUTOMATEDLINK_CREATE' => 'Create Automated Links',
91
       );
92
     }
93
94
	public function requireDefaultRecords(){
95
		parent::requireDefaultRecords();
96
97
		// Update all links to redirector pages during dev/build
98
		foreach( self::get() as $link ) {
99
		    $link->CheckAndUpdateDestination( true );
100
		}
101
	}
102
103
	/**
104
	 * Returns the HTML Representation of this object
105
	 *
106
     * @param  String $originalPhrase
107
	 * @return String
108
	 */
109
	public function getHTML($originalPhrase = NULL) {
110
		$link     = ($this->PageID) ? $this->Page()->Link() : '#';
0 ignored issues
show
Documentation introduced by
The property PageID does not exist on object<AutomatedLink>. 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...
111
		$title    = ($this->TitleTag) ? "title='{$this->TitleTag}'" : '';
0 ignored issues
show
Documentation introduced by
The property TitleTag does not exist on object<AutomatedLink>. 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...
112
		$nofollow = ($this->NoFollow) ? 'rel="nofollow"' : '';
0 ignored issues
show
Documentation introduced by
The property NoFollow does not exist on object<AutomatedLink>. 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...
113
		$newtab   = ($this->NewWindow) ? 'target="_blank"' : '';
0 ignored issues
show
Documentation introduced by
The property NewWindow does not exist on object<AutomatedLink>. 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...
114
        $anchor = ($originalPhrase) ? $originalPhrase : $this->Phrase;
0 ignored issues
show
Documentation introduced by
The property Phrase does not exist on object<AutomatedLink>. 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...
115
		$link     = ($this->AnchorTag) ? rtrim($link, '#').'#'.$this->AnchorTag : $link;
0 ignored issues
show
Documentation introduced by
The property AnchorTag does not exist on object<AutomatedLink>. 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...
116
		return "<a href=\"$link\" $title $nofollow $newtab data-id=\"{$this->ID}\">{$anchor}</a>";
117
	}
118
119
	public function getCMSFields() {
120
		$fields = FieldList::create(TabSet::create('Root'));
121
122
		$fields->addFieldsToTab('Root.LinkSettings', array(
123
			TextField::create('Phrase', 'Phrase to search for', $this->Phrase, 255),
0 ignored issues
show
Documentation introduced by
The property Phrase does not exist on object<AutomatedLink>. 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...
124
			TextField::create('TitleTag', 'Title Tag', $this->TitleTag, 255),
0 ignored issues
show
Documentation introduced by
The property TitleTag does not exist on object<AutomatedLink>. 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...
125
			TextField::create('AnchorTag', 'Anchor Tag(#)', $this->AnchorTag, 255),
0 ignored issues
show
Documentation introduced by
The property AnchorTag does not exist on object<AutomatedLink>. 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...
126
			FieldGroup::create(
127
				CheckboxField::create('NoFollow'),
128
				CheckboxField::create('NewWindow'),
129
				CheckboxField::create('SelfLinking', 'Allow page to link to itself'),
130
				CheckboxField::create('CaseSensitive', 'Match the case of the phrase')
131
			),
132
			NumericField::create('MaxLinksPerPage', 'Maximum amount of this link to be created on a single page( 0 = unlimited )'),
133
			TreeDropdownField::create('PageID', 'Page to link to', 'SiteTree')
134
		));
135
136
		$settings = GlobalAutoLinkSettings::get_current();
137
		if ($settings) {
138
			$fields->addFieldsToTab('Root.Global', array(
139
				NumericField::create(
140
					'Global_MaxLinksPerPage',
141
					'Maximum amount of links a single page can have ( 0 = unlimited )',
142
					$settings->MaxLinksPerPage
143
				),
144
				TextField::create(
145
					'Global_ExcludeTags',
146
					'Do not include links into these HTML Tags ( comma seperated )',
147
					$settings->ExcludeTags
148
				),
149
				TextField::create(
150
				    'Global_AddTo',
151
				    'Page types where links should be created in ( leave blank for all page types )',
152
				    $settings->AddTo ),
153
				TextField::create(
154
					'Global_IncludeIn',
155
					'Include Links into these fields ( comma seperated & field must support html injection )',
156
					$settings->IncludeIn
157
				)
158
			));
159
		}
160
161
		return $fields;
162
	}
163
164
    public function getCMSValidator() {
165
        return new RequiredFields(array('Phrase', 'PageID'));
166
    }
167
168
	/**
169
	 * Save the Global Settings into the
170
	 * Global Auto Link Settings Object
171
	 *
172
	 * @return void
173
	 */
174
	public function onBeforeWrite() {
175
		parent::onBeforeWrite();
176
177
		$settings = GlobalAutoLinkSettings::get_current();
178
		if ($settings) {
179
180
			foreach ($this->getChangedFields() as $field => $value) {
181
				if (strpos($field, 'Global_') === 0 && isset($value['after'])) {
182
					$field = str_replace('Global_', '', $field);
183
					$settings->$field = $value['after'];
184
				}
185
			}
186
187
			$settings->write();
188
		}
189
190
		$this->CheckAndUpdateDestination();
191
	}
192
193
	/**
194
	 * Checks if the destination is a redirector page if so
195
	 * it updates it to the destination of the redirector page
196
	 *
197
	 * @Boolean $write - Write the changes if any
198
	 * @return void
199
	 */
200
	public function CheckAndUpdateDestination( $write = false ){
201
		$this->extend('beforeCheckAndUpdateDestination', $write);
202
203
		if( $this->PageID && $this->Page() &&
0 ignored issues
show
Documentation introduced by
The property PageID does not exist on object<AutomatedLink>. 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...
204
			$this->Page()->ClassName == 'RedirectorPage' &&
205
			$this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal' )
206
		{
207
			$this->PageID = $this->Page()->LinkToID;
0 ignored issues
show
Documentation introduced by
The property PageID does not exist on object<AutomatedLink>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
208
			if( $write ) {
209
			    $this->write();
210
			}
211
		}
212
	}
213
214
    /**
215
     * Checks if the field is parable
216
     *
217
     * @param SiteTree $page
218
     * @param String   $field
219
     * @return Boolean
220
     */
221
    public static function isFieldParsable(SiteTree $page, $field) {
222
        if (!isset(self::$parsableFields[$page->ID]) || !isset(self::$parsableFields[$page->ID][$field])) {
223
            $fields = array();
224
225 View Code Duplication
            foreach (ClassInfo::ancestry($page->ClassName, true) as $class)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
226
                $fields = array_merge($fields, (array) DataObject::database_fields($class));
227
228
            self::$parsableFields[$page->ID][$field] =
229
                (Boolean) array_key_exists($field, $fields) && strtolower($fields[$field]) === 'htmltext' && $page->$field;
230
        }
231
232
        return self::$parsableFields[$page->ID][$field];
233
    }
234
235
    /**
236
     * Checks if this link can be added to the provided
237
     * page and field
238
     *
239
     * @param ContentController $controller
240
     * @return Boolean
241
     */
242
    public function canBeAdded( ContentController $controller ){
243
        return ( $this->SelfLinking || $controller->ID != $this->PageID );
0 ignored issues
show
Documentation introduced by
The property SelfLinking does not exist on object<AutomatedLink>. 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...
Documentation introduced by
The property PageID does not exist on object<AutomatedLink>. 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...
244
    }
245
246
    /**
247
     * Turn the string passed into a DOMDocument object
248
     *
249
     * @param string $html
250
     * @return DOMDocument
251
     */
252
    public static function constructDOMDocument($html){
253
        if( class_exists( 'HTML5_Parser' ) ){
254
            $html5 = HTML5_Parser::parse( $html );
255
            if($html5 instanceof DOMNodeList){
256
                $dom = new DOMDocument();
257
                while($html5->length > 0) {
258
                    $dom->appendChild($html5->item(0));
259
                }
260
            }else{
261
                $dom = $html5;
262
            }
263
        } else{
264
            $dom = new DOMDocument();
265
            $dom->loadHTML( $html );
266
        }
267
268
        return $dom;
269
    }
270
}
271