Issues (136)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

code/model/PageRow.php (80 issues)

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
5
class PageRow extends DataObject
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...
6
{
7
8
    /**
9
     *
10
     * @var string
11
     */
12
    private static $bg_image_prefix = '';
0 ignored issues
show
The property $bg_image_prefix 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...
13
14
15
    /**
16
     *
17
     * @var string
18
     */
19
    private static $bg_image_postfix = '';
0 ignored issues
show
The property $bg_image_postfix 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...
20
21
    /**
22
     *
23
     * @var array
24
     */
25
    private static $background_image_options = [];
0 ignored issues
show
The property $background_image_options 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...
26
27
    /**
28
     *
29
     * @var array
30
     */
31
    private static $background_style_options = [];
0 ignored issues
show
The property $background_style_options 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...
32
33
    /**
34
     *
35
     * @var int
36
     */
37
    private static $max_number_of_pages_for_tree_selector = 500;
0 ignored issues
show
The property $max_number_of_pages_for_tree_selector 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
39
    #######################
40
    ### Names Section
41
    #######################
42
43
    private static $singular_name = 'Content Block';
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...
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...
44
45
    public function i18n_singular_name()
46
    {
47
        return _t('PageRows.SINGULAR_NAME', 'Content Block');
48
    }
49
50
    private static $plural_name = 'PageRows';
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...
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...
51
52
    public function i18n_plural_name()
53
    {
54
        return _t('PageRows.PLURAL_NAME', 'Content Blocks');
55
    }
56
57
58
    #######################
59
    ### Model Section
60
    #######################
61
62
    private static $db = [
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...
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...
63
        'ReadyForPublication' => 'Boolean',
64
        'Code' => 'Varchar(7)',
65
        'Title' => 'Varchar(255)',
66
        'BackgroundImage' => 'Varchar(255)',
67
        'BackgroundStyle' => 'Varchar(100)'
68
    ];
69
70
    private static $belongs_many_many = [
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...
The property $belongs_many_many 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...
71
        'Pages' => 'Page'
72
    ];
73
74
75
    #######################
76
    ### Further DB Field Details
77
    #######################
78
79
    private static $indexes = [
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...
The property $indexes 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...
80
        'Created' => true,
81
        'Code' => true,
82
        'ReadyForPublication' => true
83
    ];
84
85
    private static $default_sort = [
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...
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...
86
        'ReadyForPublication' => 'DESC',
87
        'Created' => 'DESC'
88
    ];
89
90
    private static $required_fields = [
0 ignored issues
show
The property $required_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...
91
        'Title'
92
    ];
93
94
    private static $searchable_fields = [
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...
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...
95
        'ClassName' => 'ExactMatchFilter',
96
        'ReadyForPublication' => 'ExactMatchFilter',
97
        'Code' => 'PartialMatchFilter',
98
        'Title' => 'PartialMatchFilter'
99
    ];
100
101
    public function scaffoldSearchFields($_params = null) {
102
        $list = ClassInfo::subclassesFor('PageRow');
103
        $newList = [];
104
        foreach($list as $key => $entry) {
0 ignored issues
show
The expression $list of type null|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
105
            $newList[$entry] = Injector::inst()->get($entry)->i18n_singular_name();
106
        }
107
        $fields = parent::scaffoldSearchFields($_params);
108
        $fields->replaceField(
109
            'ClassName',
110
            DropdownField::create(
111
                'ClassName',
112
                'Type',
113
                ['' => '--- ANY ---'] + $newList
114
            )
115
        );
116
        return $fields;
117
    }
118
119
    #######################
120
    ### Field Names and Presentation Section
121
    #######################
122
123
    private static $summary_fields = [
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...
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...
124
        'CodeNice' => 'Code',
125
        'Type' => 'Type',
126
        'TitleStrong' => 'Title',
127
        'UsedOn' => 'Used On',
128
        'ReadyForPublicationStrong' => 'Published'
129
    ];
130
131
    private static $field_labels = [
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...
The property $field_labels 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...
132
        'ReadyForPublication' => 'Ready'
133
    ];
134
135
    private static $field_labels_right = [
0 ignored issues
show
The property $field_labels_right 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...
136
        'Code' => 'This is auto-generated (unique) code to keep track of content blocks',
137
        'ReadyForPublication' => 'Is this Content Block ready for publication?'
138
    ];
139
140
141
    #######################
142
    ### Casting Section
143
    #######################
144
145
    private static $casting = [
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...
The property $casting 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...
146
        'CodeNice' => 'HTMLText',
147
        'Type' => 'Varchar',
148
        'UsedOn' => 'Varchar',
149
        'ChildPageRowHTML' => 'HTMLText',
150
        'TitleStrong' => 'HTMLText',
151
        'ReadyForPublicationStrong' => 'HTMLText'
152
    ];
153
154
155
    public function getType()
156
    {
157
        return $this->singular_name();
158
    }
159
160
    public function getCodeNice()
161
    {
162
        $v = '<span style="font-family: monospace;">'.substr($this->Code, 0, 3).'-'.substr($this->Code, -4).'</span>';
0 ignored issues
show
The property Code does not exist on object<PageRow>. 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...
163
164
        return DBField::create_field('HTMLText', $v);
165
    }
166
167
    public function getUsedOn()
168
    {
169
        $v = [];
170
        $pages = $this->Pages();
0 ignored issues
show
Documentation Bug introduced by
The method Pages does not exist on object<PageRow>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
171
        foreach($pages as $page) {
172
            $v[] = $page->MenuTitle;
173
        }
174
175
        return DBField::create_field('Varchar', implode(', ', $v));
176
    }
177
178
    public function getTitleStrong()
179
    {
180
        $v = '<strong style="color: blue">'.$this->Title.'</strong>';
0 ignored issues
show
The property Title does not exist on object<PageRow>. 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...
181
182
        return DBField::create_field('HTMLText', $v);
183
    }
184
185
    public function getReadyForPublicationStrong()
186
    {
187
        if($this->ReadyForPublication) {
0 ignored issues
show
The property ReadyForPublication does not exist on object<PageRow>. 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...
188
            $v = '<span style="color: green">Published</span>';
189
        } else {
190
            $v = '<span style="color: red">NOT published</span>';
191
        }
192
193
        return DBField::create_field('HTMLText', $v);
194
    }
195
196
197
198
    #######################
199
    ### can Section
200
    #######################
201
202
    /**
203
     * only children can be created
204
     */
205
206
207
    public function canDelete($member = null)
208
    {
209
        return $this->Pages()->count() ? false : true;
0 ignored issues
show
Documentation Bug introduced by
The method Pages does not exist on object<PageRow>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
210
    }
211
212
213
214
    #######################
215
    ### write Section
216
    #######################
217
218
    public function requireDefaultRecords()
219
    {
220
        parent::requireDefaultRecords();
221
222
        //make template
223
        $theme = SSViewer::current_theme();
0 ignored issues
show
Deprecated Code introduced by
The method SSViewer::current_theme() has been deprecated with message: 4.0 Use the "SSViewer.theme" config setting instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
224
        if($theme) {
225
            if ($this->ClassName !== 'PageRow') {
226
                $folder = Director::baseFolder().
227
                '/themes/'.
228
                $theme.'_mysite/templates/Includes/page-row/types/';
229
                if(! file_exists($folder)) {
230
                    DB::alteration_message('✓ Creating '.$folder, 'created');
231
                    mkdir($folder, 0755, true);
232
                }
233
                if(file_exists($folder)){
234
                    $fileName =
235
                        $folder . $this->templateForHTMLOutput($this->ClassName).'.ss';
236 View Code Duplication
                    if (! file_exists($fileName)) {
0 ignored issues
show
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...
237
                        DB::alteration_message('✓ Creating ...' . $fileName, 'created');
238
                        file_put_contents(
239
                            $fileName,
240
        '<% include PageRowHeader %>
241
242
        <% include PageRowFooter %>'
243
                        );
244
                    } else {
245
                        DB::alteration_message('✓ Checked ...' . $fileName);
246
                    }
247
                }
248
            }
249
250
            //scss files ...
251
            $folder =
252
                Director::baseFolder().'/themes/'.
253
                $theme.'_mysite/src/sass/page-rows/';
254
            $fileName = $folder . $this->ClassName.'.scss';
255
            if(! file_exists($folder)) {
256
                mkdir($folder, 0755, true);
257
            }
258 View Code Duplication
            if (! file_exists($fileName)) {
0 ignored issues
show
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...
259
                DB::alteration_message('✓ Creating ...' . $fileName, 'created');
260
                file_put_contents(
261
                    $fileName,
262
    '.'.strtolower($this->ClassName).'.row {
263
264
    }'
265
                );
266
            } else {
267
                DB::alteration_message('✓ Checked ...' . $fileName);
268
            }
269
        }
270
    }
271
272
273
    public function validate()
274
    {
275
        $result = parent::validate();
276
        if ($this->ReadyForPublication) {
0 ignored issues
show
The property ReadyForPublication does not exist on object<PageRow>. 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...
277
            $fieldLabels = $this->FieldLabels();
278
            $indexes = $this->Config()->get('indexes');
279
            foreach ($this->Config()->get('required_fields') as $field) {
280
                $value = $this->$field;
281
                if (! $value) {
282
                    $fieldWithoutID = $field;
283
                    if (substr($fieldWithoutID, -2) === 'ID') {
284
                        $fieldWithoutID = substr($fieldWithoutID, 0, -2);
285
                    }
286
                    $myName = isset($fieldLabels[$fieldWithoutID]) ? $fieldLabels[$fieldWithoutID] : $fieldWithoutID;
287
                    $result->error(
288
                        _t(
289
                            'PageRows.'.$field.'_REQUIRED',
290
                            $myName.' is required'
291
                        ),
292
                        'REQUIRED_PageRows_'.$field
293
                    );
294
                }
295
                if (isset($indexes[$field]) && isset($indexes[$field]['type']) && $indexes[$field]['type'] === 'unique') {
296
                    $id = (empty($this->ID) ? 0 : $this->ID);
297
                    $count = PageRows::get()
298
                        ->filter(array($field => $value))
299
                        ->exclude(array('ID' => $id))
300
                        ->count();
301
                    if ($count > 0) {
302
                        $myName = $fieldLabels['$field'];
303
                        $result->error(
304
                            _t(
305
                                'PageRows.'.$field.'_UNIQUE',
306
                                $myName.' needs to be unique'
307
                            ),
308
                            'UNIQUE_PageRows_'.$field
309
                        );
310
                    }
311
                }
312
            }
313
        }
314
        return $result;
315
    }
316
317
    public function onBeforeWrite()
318
    {
319
        parent::onBeforeWrite();
320
        if (!$this->Code) {
0 ignored issues
show
The property Code does not exist on object<PageRow>. 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...
321
            $this->Code = hash('md5', rand());
0 ignored issues
show
The property Code does not exist on object<PageRow>. 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...
322
        }
323
        //...
324
    }
325
326
    public function onAfterWrite()
327
    {
328
        parent::onAfterWrite();
329
        if (!$this->Code) {
0 ignored issues
show
The property Code does not exist on object<PageRow>. 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...
330
            $this->Code = hash('md5', rand());
0 ignored issues
show
The property Code does not exist on object<PageRow>. 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...
331
        }
332
        if(class_exists('DynamicCache')) {
333
            DynamicCache::inst()->clear();
334
        }
335
    }
336
337
338
    #######################
339
    ### Import / Export Section
340
    #######################
341
342
343
    #######################
344
    ### CMS Edit Section
345
    #######################
346
347
348
    protected $runCMSFieldFixups = true;
349
350
    public function getCMSFields()
351
    {
352
        $fields = parent::getCMSFields();
353
        $fields->removeByName('BackgroundImage');
354
        $fields->removeByName('BackgroundStyle');
355
        $fields->removeByName('Pages');
356
        if ($this->exists() && $this->Code) {
0 ignored issues
show
The property Code does not exist on object<PageRow>. 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...
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
357
            //too late now!
358
        } else {
359
            $list = ClassInfo::subclassesFor('PageRow');
360
            $arrayOfTypes = [];
361
            foreach ($list as $className) {
0 ignored issues
show
The expression $list of type null|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
362
                if ($className === 'PageRow') {
363
                    continue;
364
                }
365
                $arrayOfTypes[$className] = Injector::inst()->get($className)->singular_name();
366
            }
367
            $fields->addFieldToTab(
368
                'Root.Main',
369
                DropdownField::create(
370
                    'ClassName',
371
                    'Type',
372
                    $arrayOfTypes
373
                ),
374
                'Title'
375
            );
376
        }
377
        $fieldLabels = $this->FieldLabels();
0 ignored issues
show
$fieldLabels is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
378
        $fields->insertAfter(
379
            'ReadyForPublication',
380
            ReadonlyField::create(
381
                'ClassNameNice',
382
                'Type',
383
                $this->singular_name()
384
            )
385
        );
386
        $fields->replaceField(
387
            'Code',
388
            ReadonlyField::create(
389
                'Code',
390
                'Code'
391
            )
392
        );
393
394
395
396
        $fieldGroups = $this->myCMSFieldGroups();
397
        foreach ($fieldGroups as $tabTitle => $fieldGroup) {
398
            if(is_array($fieldGroup) && count($fieldGroup)) {
399
                foreach ($fieldGroup as $fieldNameOrFormField) {
400
                    if($fieldNameOrFormField instanceof FormField) {
401
                        $fields->addFieldToTab(
402
                            'Root.'.$tabTitle,
403
                            $fieldNameOrFormField
404
                        );
405
                    } else {
406
                        $fieldObject = $fields->dataFieldByName($fieldNameOrFormField);
407
                        if ($fieldObject) {
408
                            $fields->addFieldToTab(
409
                                'Root.'.$tabTitle,
410
                                $fieldObject
411
                            );
412
                        }
413
                    }
414
                }
415
            }
416
        }
417
418
        //...
419
420
421
422
        if ($this->exists()) {
423
            $fields->addFieldsToTab(
424
                'Root.Preview',
425
                [
426
                    LiteralField::create(
427
                        'PreviewClassName',
428
                        '<h2><a href="'.$this->MyPreviewLink(strtolower($this->ClassName)).'">View All '.$this->singular_name().' Page Blocks</a></h2>'
429
                    ),
430
                    LiteralField::create(
431
                        'PreviewIframe',
432
                        '<iframe src="'.$this->MyPreviewLink($this->ID).'" style="width: calc(100% - 2px); height: 600px; border: 1px solid #000;"></iframe>'
433
                    ),
434
                    LiteralField::create(
435
                        'PreviewAll',
436
                        '<h2><a href="'.$this->MyPreviewLink('all').'">View All Page Blocks</a></h2>'
437
                    ),
438
                    LiteralField::create(
439
                        'PreviewOneOfEach',
440
                        '<h2><a href="'.$this->MyPreviewLink('oneofeach').'">View One Of Each Page Block Type</a></h2>'
441
                    )
442
                ]
443
            );
444
            if(Page::get()->count() > $this->Config()->get('max_number_of_pages_for_tree_selector')) {
445
                $fields->addFieldToTab(
446
                    'Root.Pages',
447
                    GridField::create(
448
                        'Pages',
449
                        'Shown On ...',
450
                        $this->Pages(),
0 ignored issues
show
Documentation Bug introduced by
The method Pages does not exist on object<PageRow>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
451
                        GridFieldConfig_RecordViewer::create()
452
                    )
453
                );
454
            } else {
455
                $fields->addFieldToTab(
456
                    'Root.Pages',
457
                    TreeMultiselectField::create(
458
                        'Pages',
459
                        'Shown On ...',
460
                        'SiteTree'
461
                        )
462
                    );
463
            }
464
465
466
            $usedInArray = [];
467
            $pageClasses = ClassInfo::subclassesFor('SiteTree');
468
            foreach ($pageClasses as $pageClass) {
0 ignored issues
show
The expression $pageClasses of type null|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
469
                $pageClassObject = Injector::inst()->get($pageClass);
470
                if ($pageClassObject instanceof Page) {
0 ignored issues
show
The class Page does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
471
                    $classesUsed = $pageClassObject->DefaultPageRows();
472
                    foreach ($classesUsed as $individualItems) {
473
                        if (
474
                            (
475
                                is_array($individualItems) &&
476
                                (
477
                                    $individualItems['Parent'] === $this->ClassName ||
478
                                    $individualItems['Child']=== $this->ClassName
479
                                )
480
                            )
481
                            ||
482
                            (is_string($individualItems) && $individualItems=== $this->ClassName)
483
                        ) {
484
                            $usedInArray[$pageClassObject->ClassName] = $pageClassObject->singular_name();
485
                        }
486
                    }
487
                }
488
            }
489
            if (count($usedInArray)) {
490
                $fields->addFieldToTab(
491
                    'Root.Pages',
492
                    LiteralField::create(
493
                        'UsedInInfo',
494
                        '<h2>'.$this->plural_name().' ('.$this->ClassName.') are used in the following pages ...</h2><p>
495
                        - '.implode('<br />- ', $usedInArray).'
496
                        </p>'
497
                    )
498
                );
499
            }
500
        }
501
502
        if ($this->runCMSFieldFixups) {
503
            $this->decorateCMSFields($fields);
0 ignored issues
show
Documentation Bug introduced by
The method decorateCMSFields does not exist on object<PageRow>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
504
        }
505
506
        return $fields;
507
    }
508
509
    protected function myCMSFieldGroups()
510
    {
511
        return [
512
            'Image' => $this->getImageCMSFields(),
513
            'Layout' => $this->getLayoutCMSFields(),
514
            'Background' => $this->getBackgroundFields(),
515
            'Publish' => $this->getPublishCMSFields()
516
        ];
517
    }
518
519
    #############################################
520
    ### TEMPLATE STUFF
521
    #############################################
522
523
524
    public function HTMLClassNamesAsString()
525
    {
526
        $str = $this->makeIntoHTMLClasses($this->baseClassesForHTMLAsArray());
527
        $str .= ' '.$this->makeIntoHTMLClasses($this->AdditionalHTMLClassNamesAsArray());
528
529
        return $str;
530
    }
531
532
    public function ChildInheritedClassNamesAsString()
533
    {
534
        return "";
535
    }
536
537
    protected function baseClassesForHTMLAsArray()
538
    {
539
        /**
540
         * we avoid the use of Advertisement as this will be blocked by adblockers ...
541
         */
542
        $array = [
543
            ($this->HasChildPageRowHTML() ? 'has-child-row' : 'no-child-row'),
544
            $this->ClassName
545
        ];
546
        foreach($this->hasOne() as $method => $item) {
0 ignored issues
show
The expression $this->hasOne() of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
547
            $field = $method.'ID';
548
            if($this->$field) {
549
                $array [] = 'has-'.strtolower($method);
550
            }
551
        }
552
        return $array;
553
    }
554
555
    protected function makeIntoHTMLClasses($array)
556
    {
557
        $str = implode(' ', $array);
558
        $str = str_replace('  ', ' ', $str);
559
        $str = str_replace('  ', ' ', $str);
560
        $str = strtolower($str);
561
562
        return $str;
563
    }
564
565
    public function UserCanEditMe()
566
    {
567
        return $this->canEdit();
568
    }
569
570
571
    private static $_current_owner_page_object_overridden = null;
572
573
    public static function set_current_page_object($page)
574
    {
575
        self::$_current_owner_page_object_overridden = $page;
576
    }
577
578
579
    public function CurrentOwnerPageObject()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
580
    {
581
        if (self::$_current_owner_page_object_overridden) {
582
            return self::$_current_owner_page_object_overridden;
583
        }
584
        $controller = $this->CurrentOwnerController();
0 ignored issues
show
Are you sure the assignment to $controller is correct as $this->CurrentOwnerController() (which targets PageRow::CurrentOwnerController()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

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

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

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

Loading history...
585
        if ($controller) {
586
            return $controller->data();
587
        }
588
    }
589
590
    public function CurrentOwnerController()
591
    {
592
        $controller = Controller::curr();
593
        if ($controller instanceof Page_Controller) {
0 ignored issues
show
The class Page_Controller does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
594
            return $controller;
595
        }
596
    }
597
598
    public function AdditionalHTMLClassNamesAsArray()
599
    {
600
        return [];
601
    }
602
603
    public function HTMLOutputAlwaysOutput($includeJS = true)
604
    {
605
        return $this->HTMLOutput($includeJS, true);
606
    }
607
608
609
    public function HTMLOutput($includeJS = true, $alwaysShow = false)
610
    {
611
        if ($this->ReadyForPublication || $alwaysShow) {
0 ignored issues
show
The property ReadyForPublication does not exist on object<PageRow>. 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...
612
            $scripts = $this->customScripts();
613
            if ($includeJS) {
614
                foreach ($scripts as $key => $script) {
615
                    Requirements::customScript(
616
                        $script,
617
                        $key
618
                    );
619
                }
620
            }
621
622
            return $this->renderWith($this->templateForHTMLOutput());
623
        }
624
    }
625
626
    /**
627
     * custom scripts required to run this show
628
     * @return array
629
     */
630
    protected function customScripts()
631
    {
632
        return [];
633
    }
634
635
    protected function templateForHTMLOutput($className = null)
636
    {
637
        if (! $className) {
638
            $className = $this->ClassName;
639
        }
640
        return 'PageRow-'.$className;
641
    }
642
643 View Code Duplication
    public function MyPreviewLink($id = 0)
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
This method seems to be duplicated in 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...
644
    {
645
        if (! $id) {
646
            $id = $this->ID;
647
        }
648
        $controller = Injector::inst()->get('PreviewPageRow');
649
650
        return $controller->Link('preview/'.$id);
651
    }
652
653 View Code Duplication
    public function MyPublicViewLink()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
This method seems to be duplicated in 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...
654
    {
655
        if (! $id) {
0 ignored issues
show
The variable $id seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
656
            $id = $this->ID;
657
        }
658
        $controller = Injector::inst()->get('PreviewPageRow');
659
        return $controller->Link('preview/'.$id);
0 ignored issues
show
The variable $id does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
660
    }
661
662
663
    public function MoreDetailsRowChildLinkingID()
664
    {
665
        return 'PageRow-'.$this->ID;
666
    }
667
668
669
670
    public function UserCanEditBlock($member = null)
671
    {
672
        return $this->canEdit($member);
673
    }
674
675
    public function ContextRelevantCMSEditLink()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
676
    {
677
        $ownerPage = $this->CurrentOwnerPageObject();
678
        if ($ownerPage && $ownerPage instanceof SiteTree) {
679
            return '/admin/pages/edit/EditForm/'.$ownerPage->ID.'/field/PageRows/item/'.$this->ID.'/edit/';
680
        } else {
681
            return $this->CMSEditLink();
0 ignored issues
show
The method CMSEditLink() does not exist on PageRow. Did you maybe mean ContextRelevantCMSEditLink()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
682
        }
683
    }
684
685
686
    public function ChildClassMethodName()
687
    {
688
        return '';
689
    }
690
691
    private $_childPageRowHTML = null;
692
693
    /**
694
     * @alias for HasChildPageRowHTML
695
     * @return bool
696
     */
697
    public function HasChild()
698
    {
699
        return $this->CalculatedHasMoreDetailsRow();
700
    }
701
702
    public function AsChildOpenByDefault()
703
    {
704
        return false;
705
    }
706
707
708
    public function MoreDetailsRowParentLinkingID()
709
    {
710
        if($this->CalculatedHasMoreDetailsRow()) {
711
            return 'PageRow'.$this->MoreDetailsRowID;
0 ignored issues
show
The property MoreDetailsRowID does not exist on object<PageRow>. 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...
712
        }
713
714
        return null;
715
    }
716
717
718
    public function CalculatedHasMoreDetailsRow()
719
    {
720
        if(!empty($this->HasMoreDetailsSection)) {
0 ignored issues
show
The property HasMoreDetailsSection does not exist on object<PageRow>. 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...
721
            if(!empty($this->MoreDetailsRowID)) {
0 ignored issues
show
The property MoreDetailsRowID does not exist on object<PageRow>. 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...
722
                if($object = $this->MoreDetailsRow()){
0 ignored issues
show
The method MoreDetailsRow() does not exist on PageRow. Did you maybe mean MoreDetailsRowChildLinkingID()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
723
                    if($object->exists() && $object->ReadyForPublication) {
724
                        return true;
725
                    }
726
                }
727
            }
728
        }
729
730
        return false;
731
    }
732
733
    /**
734
     *
735
     * @return bool
736
     */
737
    public function HasChildPageRowHTML()
738
    {
739
        return $this->CalculatedHasMoreDetailsRow();
740
    }
741
742
    /**
743
     * @return null / string
744
     */
745
    public function ChildPageRowHTML()
746
    {
747
        return $this->getChildPageRowHTML();
748
    }
749
750
    /**
751
     * @return null / string
752
     */
753
    public function getChildPageRowHTML()
754
    {
755
        if ($this->_childPageRowHTML === null) {
756
            $this->_childPageRowHTML = false;
757
            $method = $this->ChildClassMethodName();
758
            if ($method) {
759
                $object = $this->$method();
760
                if ($object && $object->exists()) {
761
                    $this->_childPageRowHTML = $object->HTMLOutput();
762
                }
763
            }
764
        }
765
        return $this->_childPageRowHTML;
766
    }
767
768
    ###############################
769
    # COPIED AND PATCHED FROM:
770
    # https://github.com/jonom/silverstripe-version-history/blob/master/code/VersionHistoryExtension.php
771
    ###############################
772
773
    protected function getImageCMSFields()
774
    {
775
        return [];
776
    }
777
778
    protected function getLayoutCMSFields()
779
    {
780
        return [];
781
    }
782
783
    protected function getBackgroundFields()
784
    {
785
        $a = [];
786
        if($this->IsPageRowWithBackgroundStyle()) {
787
            $a[] = DropdownField::create(
788
                'BackgroundStyle',
789
                'Background Style',
790
                $this->BackgroundStyleOptionsWithBasics()
791
            );
792
        }
793
        if($this->IsPageRowWithBackgroundImage()) {
794
            $a[] = DropdownField::create(
795
                'BackgroundImage',
796
                'Background Image',
797
                $this->BackgroundImageOptionsWithBasics()
798
            );
799
        }
800
        return $a;
801
    }
802
803
804
    protected function getPublishCMSFields()
805
    {
806
        return [
807
            'ReadyForPublication',
808
            'Code'
809
        ];
810
    }
811
812
    private $_bgImage = null;
813
814
    protected $_theSameBackgroundImageForAllOfThisTypeToDo = true;
815
816
    public function IsPageRowWithBackgroundImage()
817
    {
818
        $prefix = $this->Config()->get('bg_image_prefix');
819
        $postfix = $this->Config()->get('bg_image_postfix');
820
        if($prefix || $postfix) {
821
            $options = $this->BackgroundImageOptions();
822
            if(count($options)) {
823
                return true;
824
            }
825
        }
826
    }
827
828
    public function HasBackgroundImage()
829
    {
830
        return $this->BackgroundImage ? true : false;
0 ignored issues
show
The property BackgroundImage does not seem to exist. Did you mean _theSameBackgroundImageForAllOfThisTypeToDo?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
831
    }
832
833
    public function CalculatedBackgroundImage()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
834
    {
835
        if($this->_bgImage === null) {
836
            $this->_bgImage = false;
837
            if($this->BackgroundImage) {
0 ignored issues
show
The property BackgroundImage does not seem to exist. Did you mean _theSameBackgroundImageForAllOfThisTypeToDo?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
838
                $prefix = $this->Config()->get('bg_image_prefix');
839
                $postfix = $this->Config()->get('bg_image_postfix');
840
                if($this->BackgroundImage == 'random') {
0 ignored issues
show
The property BackgroundImage does not seem to exist. Did you mean _theSameBackgroundImageForAllOfThisTypeToDo?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
841
                    $a = $this->BackgroundImageOptions();
842
                    if(count($a)) {
843
                        $this->_bgImage = $prefix.$a[array_rand($a)].$postfix;
844
                    }
845
                } else {
846
                    $this->_bgImage = $prefix.$this->BackgroundImage.$postfix;
0 ignored issues
show
The property BackgroundImage does not seem to exist. Did you mean _theSameBackgroundImageForAllOfThisTypeToDo?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
847
                }
848
                if($this->HasSameBackgroundImageForAllOfThisType() && $this->_theSameBackgroundImageForAllOfThisTypeToDo) {
849
                    $this->_theSameBackgroundImageForAllOfThisTypeToDo = false;
850
                    Requirements::customCSS('
851
                        section.row.'.strtolower($this->ClassName).' {
852
                            background-image: url('.$this->_bgImage.');
853
                        }
854
                    ');
855
                }
856
            }
857
        }
858
        return $this->_bgImage;
859
    }
860
861
    protected function HasSameBackgroundImageForAllOfThisType()
862
    {
863
        return false;
864
    }
865
866
    protected function BackgroundImageOptions()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
867
    {
868
        return $this->Config()->get('background_image_options');
869
    }
870
871 View Code Duplication
    protected function BackgroundImageOptionsWithBasics()
0 ignored issues
show
This method seems to be duplicated in 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...
872
    {
873
        $a = ['' => '--- no background image selected ---']
874
            + $this->BackgroundImageOptions();
875
        if(count($a) > 2) {
876
            $a['random'] = 'Random Background Image';
877
        }
878
        return $a;
879
    }
880
881
882
    protected $_bgStyle = null;
883
884
    public function IsPageRowWithBackgroundStyle()
885
    {
886
        $options = $this->BackgroundStyleOptions();
887
        if(count($options)) {
888
            return true;
889
        }
890
    }
891
892
    public function CalculatedBackgroundStyle()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
893
    {
894
        if($this->_bgStyle === null) {
895
            $this->_bgStyle = false;
896
            if($this->BackgroundStyle) {
0 ignored issues
show
The property BackgroundStyle does not exist on object<PageRow>. 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...
897
                if($this->BackgroundStyle == 'random') {
0 ignored issues
show
The property BackgroundStyle does not exist on object<PageRow>. 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...
898
                    $a = $this->BackgroundStyleOptions();
899
                    if(count($a)) {
900
                        $this->_bgStyle = $a[array_rand($a)];
901
                    }
902
                } else {
903
                    $this->_bgStyle = $this->BackgroundStyle;
0 ignored issues
show
The property BackgroundStyle does not exist on object<PageRow>. 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...
904
                }
905
            }
906
        }
907
        return $this->_bgStyle;
908
    }
909
910
911 View Code Duplication
    protected function BackgroundStyleOptionsWithBasics()
0 ignored issues
show
This method seems to be duplicated in 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...
912
    {
913
        $a = ['' => '--- default style ---']
914
            + $this->BackgroundstyleOptions();
915
        if(count($a) > 2) {
916
            $a['random'] = 'Random Background Style';
917
        }
918
        return $a;
919
    }
920
921
922
    protected function BackgroundStyleOptions()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
923
    {
924
        return $this->Config()->get('background_style_options');
925
    }
926
}
927