Completed
Push — master ( 0db19d...6cf857 )
by Nicolaas
01:16
created

Advertisement::getFullTitle()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
c 0
b 0
f 0
rs 8.8571
cc 5
eloc 9
nc 4
nop 0
1
<?php
2
3
/* *
4
 *@author nicolaas[at] sunnysideup.co.nz
5
 *
6
 **/
7
8
class Advertisement 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...
9
{
10
    /**
11
     *
12
     * @var int
13
     */
14
    private static $thumbnail_size = 140;
0 ignored issues
show
Unused Code introduced by
The property $thumbnail_size is not used and could be removed.

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

Loading history...
15
16
    /**
17
     *
18
     * @var int
19
     */
20
    private static $width = 0;
0 ignored issues
show
Unused Code introduced by
The property $width 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...
21
22
    /**
23
     *
24
     * @var int
25
     */
26
    private static $height = 0;
0 ignored issues
show
Unused Code introduced by
The property $height is not used and could be removed.

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

Loading history...
27
28
    /**
29
     *
30
     * @var bool
31
     */
32
    private static $show_title = false;
0 ignored issues
show
Unused Code introduced by
The property $show_title is not used and could be removed.

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

Loading history...
33
34
    /**
35
     *
36
     * @var bool
37
     */
38
    private static $show_description = false;
0 ignored issues
show
Unused Code introduced by
The property $show_description is not used and could be removed.

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

Loading history...
39
40
    /**
41
     * must be a string as booleans dont work well on configs
42
     * @varchar yes / no
43
     */
44
    private static $resize_images = "yes";
0 ignored issues
show
Unused Code introduced by
The property $resize_images 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...
45
46
    /**
47
     *
48
     * @return string
49
     */
50
    public static function recommended_image_size_statement()
51
    {
52
        $array = array();
53
        if (Config::inst()->get("Advertisement", "width")) {
54
            $array[] = "width = ".Config::inst()->get("Advertisement", "width")."px";
55
        }
56
        if (Config::inst()->get("Advertisement", "height")) {
57
            $array[] = "height = ".Config::inst()->get("Advertisement", "height")."px";
58
        }
59
        $count = count($array);
60
        if ($count == 0) {
61
            return _t("Advertisement.NO_RECOMMENDED_SIZE_HAS_BEEN_SET", "No recommeded image size has been set.");
62
        } else {
63
            return _t("Advertisement.RECOMMENDED_SIZE", "Recommended Size").": ".implode(" "._t("Advertisement.AND", "and")." ", $array).".";
64
        }
65
    }
66
67
68
    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...
69
        "Title" => "Varchar(255)",
70
        "ExternalLink" => "Varchar(150)",
71
        "Description" => "Text",
72
        "Sort" => "Int"
73
    );
74
75
    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...
76
        "AdvertisementImage" => "Image",
77
        "LinkedPage" => "SiteTree",
78
        "AdditionalImage" => "Image"
79
    );
80
81
    private static $belongs_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 $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...
82
        "Parents" => "SiteTree",
83
    );
84
85
    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...
86
        "FullTitle" => "HTMLText",
87
        "Link" => "Varchar",
88
        "GroupID" => "Int"
89
    );
90
91
    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...
92
        "Sort" => 1000
93
    );
94
95
    private static $default_sort = "\"Sort\" ASC, \"Title\" ASC";
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...
96
97
    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...
98
        "Title" => "PartialMatchFilter"
99
    );
100
101
    private static $singular_name = "Advertisement";
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...
102
103
    private static $plural_name = "Advertisements";
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...
104
105
    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...
106
        "FullTitle" => "Image",
107
        "Link" => "Link"
108
    );
109
110
111
    /**
112
     * @alias getLink
113
     * @return string
114
     */
115
    public function Link()
116
    {
117
        return $this->getLink();
118
    }
119
120
121
    /**
122
     *
123
     * @return string
124
     */
125
    public function getLink()
126
    {
127
        $link = '';
128
        if ($this->ExternalLink) {
0 ignored issues
show
Documentation introduced by
The property ExternalLink does not exist on object<Advertisement>. 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...
129
            $link = $this->ExternalLink;
0 ignored issues
show
Documentation introduced by
The property ExternalLink does not exist on object<Advertisement>. 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...
130
        } elseif ($this->LinkedPageID) {
0 ignored issues
show
Documentation introduced by
The property LinkedPageID does not exist on object<Advertisement>. 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...
131
            if ($this->LinkedPage()) {
0 ignored issues
show
Documentation Bug introduced by
The method LinkedPage does not exist on object<Advertisement>? 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...
132
                $link = $this->LinkedPage()->Link();
0 ignored issues
show
Documentation Bug introduced by
The method LinkedPage does not exist on object<Advertisement>? 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...
133
            }
134
        }
135
        return $link;
136
    }
137
138
139
    /**
140
     *
141
     * @return HTMLText
142
     */
143
    public function getFullTitle()
144
    {
145
        $s = $this->Title;
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<Advertisement>. 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...
146
        if ($this->AdvertisementImageID) {
0 ignored issues
show
Documentation introduced by
The property AdvertisementImageID does not exist on object<Advertisement>. 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...
147
            $image = $this->AdvertisementImage();
0 ignored issues
show
Bug introduced by
The method AdvertisementImage() does not exist on Advertisement. Did you maybe mean ResizedAdvertisementImage()?

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...
148
            if ($image && $image->exists()) {
149
                $thumb = $image->setSize(Config::inst()->get("Advertisement", "thumbnail_size"), Config::inst()->get("Advertisement", "thumbnail_size"));
150
                if ($thumb) {
151
                    $s = " <img src=\"".$thumb->Link()."\" title=\"".$thumb->Link()."\"/ style=\"vertical-align: top; display: block; float: left; padding-right: 10px; \"><div style=\"width: 100%;\">".$s."</div><div style=\"clear: left;\"></div>";
152
                }
153
            }
154
        }
155
        return DBField::create_field("HTMLText", $s);
156
    }
157
158
    /**
159
     *
160
     * @return HTMLText
161
     */
162
    public function FullTitle()
163
    {
164
        return $this->getFullTitle();
165
    }
166
167
    /**
168
     *
169
     * @return int | null
170
     */
171
    public function getGroupID()
172
    {
173
        if ($this->AdvertisementImageID) {
0 ignored issues
show
Documentation introduced by
The property AdvertisementImageID does not exist on object<Advertisement>. 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...
174
            $image = Image::get()->byID($this->AdvertisementImageID);
0 ignored issues
show
Documentation introduced by
The property AdvertisementImageID does not exist on object<Advertisement>. 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...
175
            if ($image) {
176
                return $image->ParentID;
177
            }
178
        }
179
    }
180
181
    /**
182
     *
183
     * @return int | null
184
     */
185
    public function GroupID()
186
    {
187
        return $this->getGroupID();
188
    }
189
190
    public function getCMSFields()
191
    {
192
        $fields = parent::getCMSFields();
193
        $fields->removeFieldFromTab("Root", "Sort");
194
        $fields->removeFieldFromTab("Root.Main", "AdvertisementImage");
195
        $fields->removeFieldFromTab("Root.Main", "AdvertisementImageID");
196
        $fields->removeFieldFromTab("Root.Main", "LinkedPageID");
197
        $fields->removeFieldFromTab("Root.Main", "ExternalLink");
198
        $fields->removeFieldFromTab("Root.Parents", "Parents");
199
        $fields->removeFieldFromTab("Root", "Parents");
200
201
        if(! $this->ShowTitle()) {
202
            $fields->removeFieldFromTab("Root", "Title");
203
        }
204
205
        if(! $this->ShowDescription()) {
206
            $fields->removeFieldFromTab("Root", "Description");
207
        }
208
209
        $fields->addFieldToTab("Root.Main", ReadonlyField::create("Link", 'Calculated Link'));
210
        $fields->addFieldToTab("Root.Main", $mainImageField = new UploadField($name = "AdvertisementImage", $title = $this->i18n_singular_name()));
211
        $mainImageField->setRightTitle(self::recommended_image_size_statement());
212
        $fields->addFieldToTab(
213
            "Root.Main",
214
            $additionalImageField = UploadField::create(
215
                $name = "AdditionalImage",
216
                $title = $this->i18n_singular_name()." "._t("Advertisement.ADDITIONAL_IMAGE", "additional image")
217
            )
218
        );
219
        $additionalImageField->setRightTitle(self::recommended_image_size_statement());
220
        if ($this->ID) {
221
            $treeField = TreeMultiselectField::create(
222
                "Parents",
223
                _t("Advertisement.GETCMSFIELDSPARENTID", "only show on ... (leave blank to show on all "
224
                    .$this->i18n_singular_name()
225
                    ." pages)"),
226
                "SiteTree"
227
            );
228
            /*$callback = $this->callbackFilterFunctionForMultiSelect();
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
229
            if($callback) {
230
                $treeField->setFilterFunction ($callback);
231
            }*/
232
            $fields->addFieldToTab("Root.ShownOn", $treeField);
233
        }
234
        $fields->addFieldToTab(
235
            "Root.OptionalLink",
236
            $externalLinkField = new TextField($name = "ExternalLink", $title = _t("Advertisement.GETCMSFIELDSEXTERNALLINK", "link to external site"))
237
        );
238
        $externalLinkField->setRightTitle(_t("Advertisement.GETCMSFIELDSEXTERNALLINK_EXPLANATION", "(e.g. http://www.wikipedia.org) - this will override an internal link"));
239
        $fields->addFieldToTab("Root.OptionalLink", TreeDropdownField::create($name = "LinkedPageID", $title = _t("Advertisement.GETCMSFIELDSEXTERNALLINKID", "link to a page on this website"), $sourceObject = "SiteTree"));
240
        if (class_exists("DataObjectSorterController")) {
0 ignored issues
show
Unused Code introduced by
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...
241
            //sorted on parent page...
242
        } else {
243
            $fields->addFieldToTab(
244
                "Root.Position",
245
                $sortField = NumericField::create(
246
                    "Sort",
247
                    _t("Advertisement.SORT", "Sort index number")
248
                )
249
            );
250
            $sortField->setRightTitle(_t("Advertisement.SORT_EXPLANATION", "the lower the number, the earlier it shows"));
251
        }
252
        $fields->removeFieldFromTab("Root.Main", "AlternativeSortNumber");
253
254
        return $fields;
255
    }
256
257
    public function onBeforeWrite()
258
    {
259
        parent::onBeforeWrite();
260
        if (! $this->Sort) {
0 ignored issues
show
Documentation introduced by
The property Sort does not exist on object<Advertisement>. 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...
261
            $defaults = $this->Config()->get("defaults");
262
            $this->Sort = isset($defaults["Sort"]) ? $defaults["Sort"] : 0;
0 ignored issues
show
Documentation introduced by
The property Sort does not exist on object<Advertisement>. 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...
263
        }
264
    }
265
266
267
    public function requireDefaultRecords()
268
    {
269
        parent::requireDefaultRecords();
270
        DB::query("UPDATE \"Advertisement\" SET \"Title\" = \"ID\" WHERE \"Title\" = '' OR \"Title\" IS NULL;");
271
    }
272
273
274
    /**
275
     *
276
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be string|false?

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

Loading history...
277
     */
278
    protected function callbackFilterFunctionForMultiSelect()
279
    {
280
        $inc = Config::inst()->get("AdvertisementDecorator", "page_classes_with_advertisements");
281
        $exc = Config::inst()->get("AdvertisementDecorator", "page_classes_without_advertisements");
282
        if (is_array($inc) && count($inc)) {
283
            $string = 'return in_array($obj->class, array(\''.implode("','", $inc).'\'));';
284
        } elseif (is_array($exc) && count($exc)) {
285
            $string = 'return !in_array($obj->class, array(\''.implode("','", $exc).'\'));';
286
        }
287
        if (isset($string)) {
288
            return create_function('$obj', $string);
0 ignored issues
show
Security Best Practice introduced by
The use of create_function is highly discouraged, better use a closure.

create_function can pose a great security vulnerability as it is similar to eval, and could be used for arbitrary code execution. We highly recommend to use a closure instead.

// Instead of
$function = create_function('$a, $b', 'return $a + $b');

// Better use
$function = function($a, $b) { return $a + $b; }
Loading history...
289
        } else {
290
            return false;
291
        }
292
    }
293
294
    public function Image()
295
    {
296
        //will be depreciated in the future.
297
        return $this->ResizedAdvertisementImage();
298
    }
299
300
    /**
301
     *
302
     * @return Image | null
303
     */
304
    public function ResizedAdvertisementImage()
305
    {
306
        $resizedImage = null;
307
        $imageID = intval($this->AdvertisementImageID+ 0);
0 ignored issues
show
Documentation introduced by
The property AdvertisementImageID does not exist on object<Advertisement>. 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...
308
        if ($imageID) {
309
            if ($this->Config()->get("resize_images") == 'yes') {
310
                $imageObject = Image::get()->byID($imageID);
311
                $resizedImage = $imageObject;
312
                if ($imageObject) {
313
                    if ($imageObject->ID) {
314
                        $imageObject->Title = Convert::raw2att($this->Title);
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<Advertisement>. 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...
315
                        $w = Config::inst()->get("Advertisement", "width");
316
                        $h = Config::inst()->get("Advertisement", "height");
317
                        if ($h && $w) {
318
                            $resizedImage = $imageObject->SetSize($w, $h);
319
                        } elseif ($h) {
320
                            $resizedImage = $imageObject->SetHeight($h);
321
                        } elseif ($w) {
322
                            $resizedImage = $imageObject->SetWidth($w);
323
                        } else {
324
                            $resizedImage = $imageObject;
325
                        }
326
                    } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches 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 else branches can be removed.

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

could be turned into

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

This is much more concise to read.

Loading history...
327
                        //debug::show("no image");
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
328
                    }
329
                } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches 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 else branches can be removed.

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

could be turned into

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

This is much more concise to read.

Loading history...
330
                    //debug::show("could not find image");
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
331
                }
332
            } else {
333
                return $this->AdvertisementImage();
0 ignored issues
show
Bug introduced by
The method AdvertisementImage() does not exist on Advertisement. Did you maybe mean ResizedAdvertisementImage()?

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...
334
            }
335
        } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches 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 else branches can be removed.

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

could be turned into

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

This is much more concise to read.

Loading history...
336
            //debug::show("no imageID ($imageID) ");
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
337
        }
338
339
        return $resizedImage;
340
    }
341
342
    public function ThinyThumb()
343
    {
344
        return "This function has not been implemented";
345
    }
346
347
    /**
348
     *
349
     * @return bool
350
     */
351
    public function ShowTitle()
352
    {
353
        return $this->Config()->get('show_title');
354
    }
355
356
    /**
357
     *
358
     * @return bool
359
     */
360
    public function ShowDescription()
361
    {
362
        return $this->Config()->get('show_description');
363
    }
364
365
}
366