ProductQuestion::getFieldForProductName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Define the Product Questions ...
5
 *
6
 * @package ecommerce
7
 * @subpackage ProductQuestion
8
 */
9
class ProductQuestion 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...
10
{
11
12
    /**
13
     * Standard SS variable.
14
     */
15
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $db is not used and could be removed.

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

Loading history...
16
        'InternalCode' => 'Varchar(30)',
17
        'Question' => 'Varchar(255)',
18
        'AnswerRequired' => 'Boolean',
19
        'Label' => 'Varchar(100)',
20
        'DefaultAnswer' => 'Varchar(150)',
21
        'DefaultFormField' => 'Varchar(255)',
22
        'Options' => 'Text',
23
        "HasImages" => "Boolean",
24
        "ApplyToAllProducts" => "Boolean"
25
    );
26
27
    /**
28
     * Standard SS variable.
29
     */
30
    private static $casting = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $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...
31
        'Title' => 'Varchar',
32
        'FullName' => 'Varchar'
33
    );
34
35
    /**
36
     * Standard SS variable.
37
     * Links questions to products
38
     */
39
    private static $many_many = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $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...
40
        'Products' => 'Product'
41
    );
42
43
    /**
44
     * Standard SS variable.
45
     * Links to folder for images
46
     */
47
    private static $has_one = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $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...
48
        'Folder' => 'Folder'
49
    );
50
51
    /**
52
     * Standard SS variable.
53
     * Links questions to products
54
     */
55
    private static $summary_fields = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $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...
56
        'InternalCode' => 'InternalCode',
57
        'Question' => 'Question'
58
    );
59
60
    /**
61
     * Standard SS variable.
62
     * Links questions to products
63
     */
64
    private static $searchable_fields = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $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...
65
        'InternalCode' => 'PartialMatch',
66
        'Question' => 'Varchar(255)',
67
        'Label' => 'PartialMatch',
68
        'DefaultAnswer' => 'PartialMatch',
69
        'DefaultFormField' => 'PartialMatch',
70
        'Options' => 'PartialMatch',
71
        "HasImages" => true
72
    );
73
74
    /**
75
     * Standard SS variable.
76
     */
77
    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...
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...
78
        'Question' =>  'ASC',
79
        'ID' => 'ASC'
80
    ];
81
82
    /**
83
     * Standard SS variable.
84
     */
85
    private static $defaults = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $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...
86
        "DefaultFormField" => "TextField",
87
        "DefaultAnswer" => "tba"
88
    );
89
90
    /**
91
     * form fields used without a list
92
     * @var array
93
     */
94
    private static $available_form_fields_free = array(
0 ignored issues
show
Unused Code introduced by
The property $available_form_fields_free 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
        "TextField" => "Text Field",
96
        "TextareaField" => "Text Field with several lines",
97
        "DateField" => "Date Field",
98
        "EmailField" => "Email Field"
99
    );
100
101
    /**
102
     * form fields used with a list
103
     * @var array
104
     */
105
    private static $available_form_fields_list = array(
0 ignored issues
show
Unused Code introduced by
The property $available_form_fields_list 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...
106
        "DropdownField" => "Dropdown Field",
107
        "OptionSetField" => "Option list Field"
108
    );
109
110
    /**
111
     * Maximum number of products on the site before the CheckboxSetField is
112
     * replaced with a GridField.
113
     * This field is used for selecting the products the question applies to.
114
     *
115
     * @var Int
116
     */
117
    private static $max_products_for_checkbox_set_field = 300;
0 ignored issues
show
Unused Code introduced by
The property $max_products_for_checkbox_set_field 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...
118
119
    /**
120
     * Standard SS variable.
121
     */
122
    private static $singular_name = "Product Question";
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $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...
123
    public function i18n_singular_name()
124
    {
125
        return _t("ProductQuestion.PRODUCT_QUESTION", "Product Question");
126
    }
127
128
    /**
129
     * Standard SS variable.
130
     */
131
    private static $plural_name = "Product Questions";
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $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...
132
    public function i18n_plural_name()
133
    {
134
        return _t("ProductQuestion.PRODUCT_QUESTIONS", "Product Questions");
135
    }
136
    public static function get_plural_name()
0 ignored issues
show
Documentation introduced by
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...
137
    {
138
        $obj = Singleton("ProductQuestion");
139
        return $obj->i18n_plural_name();
140
    }
141
142
    /**
143
     * turns an option into potential file names
144
     * e.g. red
145
     * returns
146
     * red.jpg, red.png, red.gif
147
     * @param String $option
148
     * @return Array
149
     */
150
    public static function create_file_array_from_option($option)
151
    {
152
        $option = str_replace(' ', "-", trim($option));
153
        $option = preg_replace("/[^a-z0-9_-]+/i", "", $option);
154
        $imageOptions = array(
155
            $option.".png",
156
            $option.".PNG",
157
            $option.".gif",
158
            $option.".GIF" ,
159
            $option.".jpg",
160
            $option.".JPG",
161
            $option.".jpeg",
162
            $option.".JPEG"
163
        );
164
        return $imageOptions;
165
    }
166
167
    /**
168
     * Standard SS method
169
     * @return FieldSet
170
     */
171
    public function getCMSFields()
172
    {
173
        $fields = parent::getCMSFields();
174
        $fields->addFieldToTab("Root.Images", new CheckboxField("HasImages", _t("ProductQuestion.HAS_IMAGES", "This question makes use of images")));
175
        $fields->addFieldToTab("Root.Products", new CheckboxField("ApplyToAllProducts", _t("ProductQuestion.APPLY_TO_ALL_PRODUCTS", "Apply to all products ...")));
176
        if (!$this->HasImages) {
0 ignored issues
show
Documentation introduced by
The property HasImages does not exist on object<ProductQuestion>. 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...
177
            $fields->addFieldToTab(
178
                "Root.DefaultFormField",
179
                new OptionSetField(
180
                    "DefaultFormField",
181
                    _t("ProductQuestion.DEFAULTFORMFIELD", "Field type to use"),
182
                    $this->Options ? $this->Config()->get("available_form_fields_list") : $this->Config()->get("available_form_fields_free")
0 ignored issues
show
Bug introduced by
The property Options does not seem to exist. Did you mean create_table_options?

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...
183
                )
184
            );
185
        } else {
186
            $fields->removeFieldFromTab("Root.Main", "DefaultFormField");
187
        }
188
        $productFieldTitle = _t("ProductQuestion.PRODUCTS", "Products showing this question");
189
        if ($this->ApplyToAllProducts) {
0 ignored issues
show
Documentation introduced by
The property ApplyToAllProducts does not exist on object<ProductQuestion>. 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...
190
            $productField = new HiddenField("Products");
191
        } elseif (Product::get()->count() < $this->Config()->get("max_products_for_checkbox_set_field")) {
192
            $productField = new CheckboxSetField("Products", $productFieldTitle, Product::get()->map("ID", "FullName")->toArray());
193
        } else {
194
            $productField = new GridField(
195
                'Products',
196
                _t("ProductQuestion.PRODUCTS", "Products showing this question"),
197
                $this->Products(),
0 ignored issues
show
Documentation Bug introduced by
The method Products does not exist on object<ProductQuestion>? 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...
198
                GridFieldEditOriginalPageConfigWithDelete::create()
199
            );
200
        }
201
        $fields->addFieldToTab("Root.Products", $productField);
202
        if (!$this->ApplyToAllProducts) {
0 ignored issues
show
Documentation introduced by
The property ApplyToAllProducts does not exist on object<ProductQuestion>. 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...
203 View Code Duplication
            foreach ($this->Products() as $product) {
0 ignored issues
show
Documentation Bug introduced by
The method Products does not exist on object<ProductQuestion>? 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...
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...
204
                $fields->addFieldToTab(
205
                    "Root.Products",
206
                    new LiteralField(
207
                        "Product".$product->ID,
208
                        "<h5><a href=\"".$product->CMSEditLink()."\">"._t("ProductQuestion.BACK_TO", "Edit ")." ".$product->Title."</a></h5>"
209
                    )
210
                );
211
            }
212
        }
213
        if ($this->HasImages) {
0 ignored issues
show
Documentation introduced by
The property HasImages does not exist on object<ProductQuestion>. 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...
214
            $folders = Folder::get();
215
            if ($folders->count()) {
216
                $folderMap = $folders->map("ID", "Title")->toArray();
0 ignored issues
show
Unused Code introduced by
$folderMap 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...
217
                $folders = null;
0 ignored issues
show
Unused Code introduced by
$folders 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...
218
                $fields->removeFieldFromTab("Root.Main", "Folder");
219
                $fields->addFieldToTab(
220
                    "Root.Images",
221
                    $treeDropdownField = new TreeDropdownField("FolderID", _t("ProductQuestion.FOLDER", "Folder"), "Folder")
222
                );
223
                $treeDropdownFieldRightTitle = _t(
224
                    "ProductQuestion.FOLDER_ID",
225
                    "Select the folder in which the images live.
226
                    <br />
227
                    <strong>
228
                        The images need to have the exact same file name as the options listed.
229
                        For example, if one of your options is 'red' then there should be a file in your folder called 'red.png' or 'red.jpg' or 'red.gif',
230
                        the following filenames would not work: 'Red.png', 'red1.jpg', 'RED.gif', etc...
231
                    </strong>"
232
                );
233
                $folder = Folder::get()->byID($this->FolderID);
0 ignored issues
show
Documentation introduced by
The property FolderID does not exist on object<ProductQuestion>. 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...
234
                if ($folder) {
235
                    $treeDropdownFieldRightTitle .= "
236
                        <br /><a href=\"admin/assets/show/".$folder->ID."/\">"._t("ProductQuestion.OPEN", "Open")." ".$folder->Title."</a>
237
                        <br /><a href=\"admin/assets/add/?ID".$folder->ID."/\">"._t("ProductQuestion.ADD_IMAGES_TO", "Add images to")." ".$folder->Title."</a>";
238
                }
239
                $treeDropdownField->setRightTitle($treeDropdownFieldRightTitle);
240
            }
241
            if ($this->FolderID) {
0 ignored issues
show
Documentation introduced by
The property FolderID does not exist on object<ProductQuestion>. 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...
242
                $imagesInFolder = Image::get()->filter(array("ParentID" => $this->FolderID));
0 ignored issues
show
Documentation introduced by
The property FolderID does not exist on object<ProductQuestion>. 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...
243
                if ($imagesInFolder->count()) {
244
                    $imagesInFolderArray = $imagesInFolder->map("ID", "Name")->toArray();
245
                    $options = explode(",", $this->Options);
0 ignored issues
show
Bug introduced by
The property Options does not seem to exist. Did you mean create_table_options?

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...
Unused Code introduced by
$options 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...
246
                    $imagesInFolderField = new ReadonlyField("ImagesInFolder", _t("ProductQuestion.NO_IMAGES", "Images in folder"), implode("<br />", $imagesInFolderArray));
247
                    $imagesInFolderField->dontEscape = true;
248
                    $fields->addFieldToTab("Root.Images", $imagesInFolderField);
249
                    //matches
250
                    if ($this->exists()) {
251
                        $matchesInFolderArray = array();
252
                        $nonMatchesInFolderArray = array();
253
                        $options = explode(",", $this->Options);
0 ignored issues
show
Bug introduced by
The property Options does not seem to exist. Did you mean create_table_options?

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...
254
                        if (count($options)) {
255
                            foreach ($options as $option) {
256
                                $fileNameArray = self::create_file_array_from_option($option);
257
                                foreach ($fileNameArray as $fileName) {
258
                                    if (in_array($fileName, $imagesInFolderArray)) {
259
                                        $matchesInFolderArray[$option] = "<strong>".$option."</strong>: ".$fileName;
260
                                    }
261
                                }
262
                                if (!isset($matchesInFolderArray[$option])) {
263
                                    $nonMatchesInFolderArray[$option] = "<strong>".$option." - add one these files: </strong>".implode(",", $fileNameArray);
264
                                }
265
                            }
266
                        }
267
                        $matchesInFolderField = new ReadonlyField("MatchesInFolder", _t("ProductQuestion.MATCHES_IN_FOLDER", "Matches in folder"), implode("<br />", $matchesInFolderArray));
268
                        $matchesInFolderField->dontEscape = true;
269
                        $fields->addFieldToTab("Root.Images", $matchesInFolderField);
270
                        $nonMatchesInFolderField = new ReadonlyField("NonMatchesInFolder", _t("ProductQuestion.NON_MATCHES_IN_FOLDER", "NON Matches in folder"), implode("<br />", $nonMatchesInFolderArray));
271
                        $nonMatchesInFolderField->dontEscape = true;
272
                        $fields->addFieldToTab("Root.Images", $nonMatchesInFolderField);
273
                    }
274
                } else {
275
                    $imagesInFolderField = new ReadonlyField("ImagesInFolder", "Images in folder", _t("ProductQuestion.NO_IMAGES", "There are no images in this folder"));
276
                    $fields->addFieldToTab("Root.Main", $imagesInFolderField);
277
                }
278
            }
279
        } else {
280
            $fields->removeByName("Folder");
281
        }
282
        if ($this->Products()->count()) {
0 ignored issues
show
Documentation Bug introduced by
The method Products does not exist on object<ProductQuestion>? 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...
283
            $randomProduct = $this->Products()->First();
0 ignored issues
show
Documentation Bug introduced by
The method Products does not exist on object<ProductQuestion>? 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...
284
            $fields->addFieldToTab("Root.Example", $this->getFieldForProduct($randomProduct));
285
        }
286
        $folderExplanation = _t(
287
            "ProductQuestion.FOLDER_EXPLANATION",
288
            "Tick the box to link each option to an image (e.g. useful if you have colour swatches).
289
                Once ticked and the question is saved you will be able to select a folder from where to select the images."
290
        );
291
        $field = $fields->dataFieldByName("HasImages");
292
        if ($field) {
293
            $field->setDescription($folderExplanation);
294
        }
295
296
        $this->extend('updateCMSFields', $fields);
297
298
        //custom field labels
299
        $internalCodeField = $fields->dataFieldByName("InternalCode");
300
        $internalCodeField->setRightTitle(_t("ProductQuestion.INTERNALCODE", "Code used to identify question (not shown to customers)"));
301
        $questionField = $fields->dataFieldByName("Question");
302
        $questionField->setRightTitle(_t("ProductQuestion.QUESTION", "Question (e.g. what configuration do you prefer?)"));
303
        $labelField = $fields->dataFieldByName("Label");
304
        $labelField->setRightTitle(_t("ProductQuestion.LABEL", "Label (e.g. Your selected configuration)"));
305
        $defaultAnswerField = $fields->dataFieldByName("DefaultAnswer");
306
        $defaultAnswerField->setRightTitle(_t("ProductQuestion.DEFAULT_ANSWER", "Default Answer if no Answer has been provided.  Can be blank or, for example, tba."));
307
        $optionsField = $fields->dataFieldByName("Options");
308
        $optionsField->setRightTitle(_t("ProductQuestion.OPTIONS", "Predefined Options (leave blank for any option).  These must be comma separated (e.g. red, blue, yellow, orange)"));
309
        return $fields;
310
    }
311
312
313
314
    /**
315
     * casted variable
316
     * @return String
317
     */
318
    public function FullName()
319
    {
320
        return $this->getFullName();
321
    }
322
    public function getFullName()
323
    {
324
        return $this->Question." (".$this->InternalCode.")";
0 ignored issues
show
Documentation introduced by
The property Question does not exist on object<ProductQuestion>. 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 InternalCode does not exist on object<ProductQuestion>. 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...
325
    }
326
327
    /**
328
     * casted variable
329
     * @return String
330
     */
331
    public function Title()
332
    {
333
        return $this->getTitle();
334
    }
335
    public function getTitle()
336
    {
337
        return $this->Question." (".$this->InternalCode.")";
0 ignored issues
show
Documentation introduced by
The property Question does not exist on object<ProductQuestion>. 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 InternalCode does not exist on object<ProductQuestion>. 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...
338
    }
339
340
    /**
341
     *
342
     * @return FormField
343
     */
344
    public function getFieldForProduct($product, $value = null)
345
    {
346
        //switch from variation to product ...
347
        if ($product instanceof ProductVariation) {
0 ignored issues
show
Bug introduced by
The class ProductVariation 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...
348
            $product = $product->getParent();
349
        }
350
        if ($this->Options) {
0 ignored issues
show
Bug introduced by
The property Options does not seem to exist. Did you mean create_table_options?

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...
351
            //if HasImages?
352
            $finalOptions = array();
353
            $optionArray = explode(",", $this->Options);
0 ignored issues
show
Bug introduced by
The property Options does not seem to exist. Did you mean create_table_options?

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...
354
            foreach ($optionArray as $option) {
355
                $option = trim($option);
356
                $finalOptions[Convert::raw2htmlatt($option)] = $option;
357
            }
358
            if ($this->HasImages) {
0 ignored issues
show
Documentation introduced by
The property HasImages does not exist on object<ProductQuestion>. 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...
359
                return new ProductQuestionImageSelectorField($this->getFieldForProductName($product), $this->Question, $finalOptions, $value, $this->FolderID);
0 ignored issues
show
Documentation introduced by
The property Question does not exist on object<ProductQuestion>. 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 FolderID does not exist on object<ProductQuestion>. 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...
360
            } else {
361
                $formFieldClass = $this->DefaultFormField;
0 ignored issues
show
Documentation introduced by
The property DefaultFormField does not exist on object<ProductQuestion>. 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...
362
                if (!$formFieldClass) {
363
                    $formFieldClass = "DropdownField";
364
                }
365
                $finalOptions = array("" => _t("ProductQuestion.PLEASE_SELECT", " -- please select --")) + $finalOptions;
366
                return $formFieldClass::create($this->getFieldForProductName($product), $this->Question, $finalOptions, $value);
0 ignored issues
show
Documentation introduced by
The property Question does not exist on object<ProductQuestion>. 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...
367
            }
368
        } else {
369
            $formFieldClass = $this->DefaultFormField;
0 ignored issues
show
Documentation introduced by
The property DefaultFormField does not exist on object<ProductQuestion>. 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...
370
            if (!$formFieldClass) {
371
                $formFieldClassd = "TextField";
0 ignored issues
show
Unused Code introduced by
$formFieldClassd 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...
372
            }
373
            return $formFieldClass::create($this->getFieldForProductName($product), $this->Question, $value);
0 ignored issues
show
Documentation introduced by
The property Question does not exist on object<ProductQuestion>. 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...
374
        }
375
    }
376
377
    public function getFieldForProductName(Product $product)
0 ignored issues
show
Unused Code introduced by
The parameter $product is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
378
    {
379
        return "ProductQuestions[".$this->ID."]";
380
    }
381
382
    /**
383
     *
384
     * making sure all the data is clean
385
     */
386
    public function onBeforeWrite()
387
    {
388
        parent::onBeforeWrite();
389
        if (!$this->InternalCode) {
0 ignored issues
show
Documentation introduced by
The property InternalCode does not exist on object<ProductQuestion>. 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...
390
            $this->InternalCode = $this->Label;
0 ignored issues
show
Documentation introduced by
The property InternalCode does not exist on object<ProductQuestion>. 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...
Documentation introduced by
The property Label does not exist on object<ProductQuestion>. 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...
391
        }
392
        if (!$this->HasImages) {
0 ignored issues
show
Documentation introduced by
The property HasImages does not exist on object<ProductQuestion>. 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...
393
            $this->FolderID = 0;
0 ignored issues
show
Documentation introduced by
The property FolderID does not exist on object<ProductQuestion>. 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...
394
        }
395
        if ($this->Options) {
0 ignored issues
show
Bug introduced by
The property Options does not seem to exist. Did you mean create_table_options?

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...
396
            $optionsForFields = $this->Config()->get("available_form_fields_list");
397
            if (!isset($optionsForFields[$this->DefaultFormField])) {
0 ignored issues
show
Documentation introduced by
The property DefaultFormField does not exist on object<ProductQuestion>. 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...
398
                //get the first one if none is set.
399
                $this->DefaultFormField = key($optionsForFields);
0 ignored issues
show
Documentation introduced by
The property DefaultFormField does not exist on object<ProductQuestion>. 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...
400
            }
401
        } else {
402
            $optionsForFields = $this->Config()->get("available_form_fields_free");
403
            if (!isset($optionsForFields[$this->DefaultFormField])) {
0 ignored issues
show
Documentation introduced by
The property DefaultFormField does not exist on object<ProductQuestion>. 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...
404
                //get the first one if none is set.
405
                $this->DefaultFormField = key($optionsForFields);
0 ignored issues
show
Documentation introduced by
The property DefaultFormField does not exist on object<ProductQuestion>. 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...
406
            }
407
        }
408
    }
409
410
    public function onAfterWrite()
411
    {
412
        parent::onAfterWrite();
413
        if ($this->ApplyToAllProducts) {
0 ignored issues
show
Documentation introduced by
The property ApplyToAllProducts does not exist on object<ProductQuestion>. 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...
414
            $this->Products()->removeAll();
0 ignored issues
show
Documentation Bug introduced by
The method Products does not exist on object<ProductQuestion>? 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...
415
        }
416
    }
417
418
    /**
419
     * link to edit the record
420
     * @param String | Null $action - e.g. edit
421
     * @return String
422
     */
423
    public function CMSEditLink($action = null)
424
    {
425
        return Controller::join_links(
426
            Director::baseURL(),
427
            "/admin/product-config/".$this->ClassName."/EditForm/field/".$this->ClassName."/item/".$this->ID."/edit",
428
            $action
429
        );
430
    }
431
}
432