CampaignMonitorCampaign::onAfterWrite()   C
last analyzed

Complexity

Conditions 8
Paths 12

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 6.6037
c 0
b 0
f 0
cc 8
eloc 15
nc 12
nop 0
1
<?php
2
3
/**
4
 *@author nicolaas [at] sunnysideup.co.nz
5
 *
6
 *
7
 **/
8
9
class CampaignMonitorCampaign 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
     *
14
     * @var array
15
     */
16
    private static $emogrifier_add_allowed_media_types = array(
0 ignored issues
show
Unused Code introduced by
The property $emogrifier_add_allowed_media_types 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...
17
        "screen"
18
    );
19
20
    /**
21
     *
22
     * @var array
23
     */
24
    private static $emogrifier_remove_allowed_media_types = array();
0 ignored issues
show
Unused Code introduced by
The property $emogrifier_remove_allowed_media_types 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...
25
26
    /**
27
     *
28
     * @var string
29
     */
30
    private static $default_template = "CampaignMonitorCampaign";
0 ignored issues
show
Unused Code introduced by
The property $default_template is not used and could be removed.

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

Loading history...
31
    
32
    private static $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...
33
        "HasBeenSent" => "Boolean",
34
        "MessageFromNewsletterServer" => "Text",
35
        "CreateAsTemplate" => "Boolean",
36
        "CreateFromWebsite" => "Boolean",
37
        "CreatedFromWebsite" => "Boolean",
38
        "TemplateID" => "Varchar(40)",
39
        "CampaignID" => "Varchar(40)",
40
        "Name" => "Varchar(100)",
41
        "Subject" => "Varchar(100)",
42
        "FromName" => "Varchar(100)",
43
        "FromEmail" => "Varchar(100)",
44
        "ReplyTo" => "Varchar(100)",
45
        "SentDate" => "SS_Datetime",
46
        "WebVersionURL" => "Varchar(255)",
47
        "WebVersionTextURL" => "Varchar(255)",
48
        "Hide" => "Boolean",
49
        "Content" => "HTMLText",
50
        "Hash" => "Varchar(32)"
51
    );
52
53
    private static $indexes = 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 $indexes is not used and could be removed.

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

Loading history...
54
        "TemplateID" => true,
55
        "CampaignID" => true,
56
        "Hide" => true,
57
        "Hash" => true
58
    );
59
60
    private static $field_labels = 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 $field_labels is not used and could be removed.

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

Loading history...
61
        "CreateFromWebsite" => "Create on newsletter server"
62
    );
63
64
    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...
65
        "CampaignMonitorCampaignStyle" => "CampaignMonitorCampaignStyle"
66
    );
67
68
    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...
69
        "Pages" => "CampaignMonitorSignupPage"
70
    );
71
72
    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...
73
        "Subject" => "PartialMatchFilter",
74
        "Content" => "PartialMatchFilter",
75
        "Hide" => "ExactMatch"
76
    );
77
78
    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...
79
        "Subject" => "Subject",
80
        "SentDate" => "Sent Date"
81
    );
82
83
    private static $singular_name = "Campaign";
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...
84
85
    private static $plural_name = "Campaigns";
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...
86
87
    private static $default_sort = "Hide ASC, SentDate DESC";
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...
88
89
    public function canDelete($member = null)
90
    {
91
        return $this->HasBeenSentCheck() ? false : parent::canDelete($member);
92
    }
93
94
    public function getCMSFields()
95
    {
96
        $fields = parent::getCMSFields();
97
        //readonly
98
        $fields->makeFieldReadonly("MessageFromNewsletterServer");
99
        $fields->makeFieldReadonly("CampaignID");
100
        $fields->makeFieldReadonly("TemplateID");
101
        $fields->makeFieldReadonly("WebVersionURL");
102
        $fields->makeFieldReadonly("WebVersionTextURL");
103
        $fields->makeFieldReadonly("SentDate");
104
        $fields->makeFieldReadonly("HasBeenSent");
105
        $fields->makeFieldReadonly("Hash");
106
        //removed
107
        $fields->removeFieldFromTab("Root.Main", "CreatedFromWebsite");
108
        $fields->removeFieldFromTab("Root.Main", "CreatedTemplateFromWebsite");
109
        $fields->removeFieldFromTab("Root.Main", "SecurityCode");
110
        //pages
111
        $pages = CampaignMonitorSignupPage::get()->map("ID", "Title")->toArray();
112
        $fields->removeFieldFromTab("Root.Main", "Pages");
113
        $fields->replaceField("CreateAsTemplate", new OptionsetField("CreateAsTemplate", "Type", array(0 => "Create as Campaign", 1 => "Create as Template")));
114
        if (count($pages)) {
115
            $fields->addFieldToTab("Root.Pages", new CheckboxSetField("Pages", "Shown on the following pages ...", $pages));
116
        }
117
        if ($this->ExistsOnCampaignMonitorCheck()) {
118
            $fields->removeFieldFromTab("Root.Main", "CreateAsTemplate");
119
            if (!$this->CreateAsTemplate) {
0 ignored issues
show
Documentation introduced by
The property CreateAsTemplate does not exist on object<CampaignMonitorCampaign>. 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...
120
                $fields->removeFieldFromTab("Root.Main", "CreateFromWebsite");
121
                if (!$this->HasBeenSentCheck()) {
122
                    $fields->addFieldToTab("Root.Main", new LiteralField("CreateFromWebsiteRemake", "<h2>To edit this newsletter, please first delete it from your newsletter server</h2>"), "CampaignID");
123
                }
124
            }
125
            $fields->removeFieldFromTab("Root.Main", "Hash");
126
            $fields->removeFieldFromTab("Root.Main", "CampaignMonitorCampaignStyleID");
127
128
            $fields->makeFieldReadonly("Name");
129
            $fields->makeFieldReadonly("Subject");
130
            $fields->makeFieldReadonly("FromName");
131
            $fields->makeFieldReadonly("FromEmail");
132
            $fields->makeFieldReadonly("ReplyTo");
133
            $fields->makeFieldReadonly("SentDate");
134
            $fields->makeFieldReadonly("WebVersionURL");
135
            $fields->makeFieldReadonly("WebVersionTextURL");
136
            $fields->makeFieldReadonly("Content");
137
        } else {
138
            $this->CampaignID = null;
0 ignored issues
show
Documentation introduced by
The property CampaignID does not exist on object<CampaignMonitorCampaign>. 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...
139
            $this->TemplateID = null;
0 ignored issues
show
Documentation introduced by
The property TemplateID does not exist on object<CampaignMonitorCampaign>. 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...
140
        }
141
        if ($this->HasBeenSentCheck()) {
142
            $fields->addFieldToTab("Root.Main", new LiteralField("Link", "<h2><a target=\"_blank\" href=\"".$this->Link()."\">Link</a></h2>"), "CampaignID");
143
        } else {
144
            $fields->removeFieldFromTab("Root.Main", "Hide");
145
            if ($this->exists()) {
146
                if ($this->ExistsOnCampaignMonitorCheck()) {
147
                    $fields->removeFieldFromTab("Root.Main", "CreateFromWebsite");
148
                } else {
149
                    $fields->addFieldToTab("Root.Main", new LiteralField("PreviewLink", "<h2><a target=\"_blank\" href=\"".$this->PreviewLink()."\">Preview Link</a></h2>"), "CampaignID");
150
                }
151
            } else {
152
                $fields->removeFieldFromTab("Root.Main", "CreateFromWebsite");
153
            }
154
        }
155
        return $fields;
156
    }
157
158
    /**
159
     * returns link to view campaign
160
     * @var return
161
     */
162 View Code Duplication
    public function Link($action = "")
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
163
    {
164
        if ($page = $this->Pages()->First()) {
0 ignored issues
show
Documentation Bug introduced by
The method Pages does not exist on object<CampaignMonitorCampaign>? 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...
165
            $link = $page->Link("viewcampaign".$action."/".$this->ID."/");
166
            return Director::absoluteURL($link);
167
        }
168
        return "#";
169
    }
170
171
    /**
172
     * returns link to view preview campaign
173
     * this link is used to create templates / campaigns on Campaign Monitor
174
     * @var return
175
     */
176 View Code Duplication
    public function PreviewLink($action = "")
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
177
    {
178
        if ($page = $this->Pages()->First()) {
0 ignored issues
show
Documentation Bug introduced by
The method Pages does not exist on object<CampaignMonitorCampaign>? 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...
179
            $link = $page->Link("previewcampaign".$action."/".$this->ID."/?hash=".$this->Hash);
0 ignored issues
show
Documentation introduced by
The property Hash does not exist on object<CampaignMonitorCampaign>. 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...
180
            return Director::absoluteURL($link);
181
        }
182
        return "";
183
    }
184
    
185
    /**
186
     * html for newsletter to be created
187
     * @var return
188
     */
189
    public function getNewsletterContent()
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...
190
    {
191
        $extension = $this->extend("updateNewsletterContent", $content);
192
        if (is_array($extension) && count($extension)) {
193
            return $extension[0];
194
        }
195
        $html = "";
196
        if (class_exists('\Pelago\Emogrifier')) {
197
            $allCSS = "";
198
            $cssFileLocations = $this->getCSSFileLocations();
199
            foreach ($cssFileLocations as $cssFileLocation) {
200
                $cssFileHandler = fopen($cssFileLocation, 'r');
201
                $allCSS .= fread($cssFileHandler, filesize($cssFileLocation));
202
                fclose($cssFileHandler);
203
            }
204
            $isThemeEnabled = Config::inst()->get('SSViewer', 'theme_enabled');
205
            if (!$isThemeEnabled) {
206
                Config::inst()->update('SSViewer', 'theme_enabled', true);
207
            }
208
            Requirements::clear();
209
            $templateName = $this->getRenderWithTemplate();
210
            $html = $this->renderWith($templateName);
211
            if (!$isThemeEnabled) {
212
                Config::inst()->update('SSViewer', 'theme_enabled', false);
213
            }
214
            $emogrifier = new \Pelago\Emogrifier($html, $allCSS);
215
            $addMediaTypes = $this->Config()->get("emogrifier_add_allowed_media_types");
216
            foreach ($addMediaTypes as $type) {
0 ignored issues
show
Unused Code introduced by
This foreach statement is empty and can be removed.

This check looks for foreach loops 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.

Consider removing the loop.

Loading history...
217
                //$emogrifier->addAllowedMediaType($type);
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
218
            }
219
            $removeMediaTypes = $this->Config()->get("emogrifier_remove_allowed_media_types");
220
            foreach ($removeMediaTypes as $type) {
221
                $emogrifier->removeAllowedMediaType($type);
222
            }
223
            $html = $emogrifier->emogrify();
224
        } else {
225
            user_error("Please include Emogrifier module");
226
        }
227
        return $html;
228
    }
229
230
    /**
231
     * provide template used for RenderWith
232
     * @return string
233
     */
234
    public function getRenderWithTemplate()
235
    {
236
        if ($style = $this->CampaignMonitorCampaignStyle()) {
0 ignored issues
show
Documentation Bug introduced by
The method CampaignMonitorCampaignStyle does not exist on object<CampaignMonitorCampaign>? 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...
237
            if ($style->exists() && $style->TemplateName) {
238
                return $style->TemplateName;
239
            }
240
        }
241
        return $this->Config()->get("default_template");
242
    }
243
244
    /**
245
     * @return array
246
     */
247
    protected function getCSSFileLocations()
248
    {
249
        if ($style = $this->CampaignMonitorCampaignStyle()) {
0 ignored issues
show
Documentation Bug introduced by
The method CampaignMonitorCampaignStyle does not exist on object<CampaignMonitorCampaign>? 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...
250
            return $style->getCSSFilesAsArray();
251
        }
252
        return array();
253
    }
254
255
    /**
256
     * @return array
257
     */
258
    public function getHTMLContent()
259
    {
260
        if ($style = $this->CampaignMonitorCampaignStyle()) {
0 ignored issues
show
Documentation Bug introduced by
The method CampaignMonitorCampaignStyle does not exist on object<CampaignMonitorCampaign>? 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...
261
            return $style->getHTMLContent($this);
262
        }
263
        return $this->renderWith("CampaignMonitorCampaign");
264
    }
265
266
    protected $countOfWrites = 0;
267
268
    public function onBeforeWrite()
269
    {
270
        parent::onBeforeWrite();
271
        if (!$this->Hash) {
0 ignored issues
show
Documentation introduced by
The property Hash does not exist on object<CampaignMonitorCampaign>. 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...
272
            $this->Hash = substr(hash("md5", uniqid()), 0, 7);
0 ignored issues
show
Documentation introduced by
The property Hash does not exist on object<CampaignMonitorCampaign>. 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...
273
        }
274
        if (!$this->ExistsOnCampaignMonitorCheck($forceRecheck = true)) {
275
            if ($this->CreateAsTemplate) {
0 ignored issues
show
Documentation introduced by
The property CreateAsTemplate does not exist on object<CampaignMonitorCampaign>. 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...
276
                $this->TemplateID = null;
0 ignored issues
show
Documentation introduced by
The property TemplateID does not exist on object<CampaignMonitorCampaign>. 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...
277
            } else {
278
                $this->CampaignID = null;
0 ignored issues
show
Documentation introduced by
The property CampaignID does not exist on object<CampaignMonitorCampaign>. 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...
279
            }
280
        }
281
    }
282
283
    public function onAfterWrite()
284
    {
285
        parent::onAfterWrite();
286
        if ($this->Pages()->count() == 0) {
0 ignored issues
show
Documentation Bug introduced by
The method Pages does not exist on object<CampaignMonitorCampaign>? 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...
287
            if ($page = CampaignMonitorSignupPage::get()->first()) {
288
                $this->Pages()->add($page);
0 ignored issues
show
Documentation Bug introduced by
The method Pages does not exist on object<CampaignMonitorCampaign>? 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...
289
            }
290
        }
291
        $this->countOfWrites++;
292
        if (!$this->ExistsOnCampaignMonitorCheck($forceRecheck = true) && $this->CreateFromWebsite && $this->countOfWrites < 3) {
0 ignored issues
show
Documentation introduced by
The property CreateFromWebsite does not exist on object<CampaignMonitorCampaign>. 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...
293
            $api = $this->getAPI();
294
            if ($this->CreateAsTemplate) {
0 ignored issues
show
Documentation introduced by
The property CreateAsTemplate does not exist on object<CampaignMonitorCampaign>. 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...
295
                if ($this->TemplateID) {
0 ignored issues
show
Documentation introduced by
The property TemplateID does not exist on object<CampaignMonitorCampaign>. 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...
296
                    $api->updateTemplate($this, $this->TemplateID);
0 ignored issues
show
Documentation introduced by
The property TemplateID does not exist on object<CampaignMonitorCampaign>. 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...
297
                } else {
298
                    $api->createTemplate($this);
299
                }
300
            } else {
301
                $api->createCampaign($this);
302
            }
303
        }
304
    }
305
306
    public function onBeforeDelete()
307
    {
308
        parent::onBeforeDelete();
309
        if ($this->HasBeenSentCheck()) {
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...
310
            //do nothing
311
        } else {
312
            if ($this->ExistsOnCampaignMonitorCheck($forceRecheck = true)) {
313
                $api = $this->getAPI();
314
                if ($this->CreateAsTemplate) {
0 ignored issues
show
Documentation introduced by
The property CreateAsTemplate does not exist on object<CampaignMonitorCampaign>. 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
                    $api->deleteTemplate($this->TemplateID);
0 ignored issues
show
Documentation introduced by
The property TemplateID does not exist on object<CampaignMonitorCampaign>. 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...
316
                } else {
317
                    $api->deleteCampaign($this->CampaignID);
0 ignored issues
show
Documentation introduced by
The property CampaignID does not exist on object<CampaignMonitorCampaign>. 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...
318
                }
319
            }
320
        }
321
    }
322
323
    private static $_api = null;
324
325
    /**
326
     *
327
     * @return CampaignMonitorAPIConnector
328
     */
329
    protected function getAPI()
330
    {
331
        if (!self::$_api) {
332
            self::$_api = CampaignMonitorAPIConnector::create();
333
            self::$_api->init();
334
        }
335
        return self::$_api;
336
    }
337
338
    private $_hasBeenSent = null;
339
340
    public function HasBeenSentCheck()
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...
341
    {
342
        //lazy check
343
        if ($this->HasBeenSent || $this->WebVersionURL) {
0 ignored issues
show
Bug introduced by
The property HasBeenSent does not seem to exist. Did you mean _hasBeenSent?

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...
Documentation introduced by
The property WebVersionURL does not exist on object<CampaignMonitorCampaign>. 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...
344
            return true;
345
        }
346
        //real check
347
        if ($this->_hasBeenSent === null) {
348
            if (!$this->CampaignID) {
0 ignored issues
show
Documentation introduced by
The property CampaignID does not exist on object<CampaignMonitorCampaign>. 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...
349
                $this->_hasBeenSent = false;
350
            } elseif (!$this->HasBeenSent) {
0 ignored issues
show
Bug introduced by
The property HasBeenSent does not seem to exist. Did you mean _hasBeenSent?

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
                $api = $this->getAPI();
0 ignored issues
show
Unused Code introduced by
$api 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...
352
                $result = $this->api->getCampaigns();
0 ignored issues
show
Documentation introduced by
The property api does not exist on object<CampaignMonitorCampaign>. 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...
353
                if (isset($result)) {
354
                    foreach ($result as $key => $campaign) {
355
                        if ($this->CampaignID == $campaign->CampaignID) {
0 ignored issues
show
Documentation introduced by
The property CampaignID does not exist on object<CampaignMonitorCampaign>. 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...
356
                            $this->HasBeenSent = true;
0 ignored issues
show
Bug introduced by
The property HasBeenSent does not seem to exist. Did you mean _hasBeenSent?

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...
357
                            $this->HasBeenSent->write();
0 ignored issues
show
Bug introduced by
The property HasBeenSent does not seem to exist. Did you mean _hasBeenSent?

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...
Bug introduced by
The method write cannot be called on $this->HasBeenSent (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
358
                            $this->_hasBeenSent = true;
359
                            break;
360
                        }
361
                    }
362
                }
363
            } else {
364
                $this->_hasBeenSent = $this->HasBeenSent;
0 ignored issues
show
Bug introduced by
The property HasBeenSent does not seem to exist. Did you mean _hasBeenSent?

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...
365
            }
366
        }
367
        return $this->_hasBeenSent;
368
    }
369
370
    private $_existsOnCampaignMonitorCheck = null;
371
372
    /**
373
     * checks if the template and/or the campaign exists
374
     * @return boolean
375
     */
376
    public function ExistsOnCampaignMonitorCheck($forceRecheck = false)
377
    {
378
        //lazy check
379
        if ($this->HasBeenSent) {
0 ignored issues
show
Bug introduced by
The property HasBeenSent does not seem to exist. Did you mean _hasBeenSent?

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...
380
            return true;
381
        }
382
        //real check
383
        if ($this->_existsOnCampaignMonitorCheck === null || $forceRecheck) {
384
            $this->_existsOnCampaignMonitorCheck = false;
385
            if ($this->CreateAsTemplate) {
0 ignored issues
show
Documentation introduced by
The property CreateAsTemplate does not exist on object<CampaignMonitorCampaign>. 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...
386
                $field = "TemplateID";
387
                $apiMethod1 = "getTemplates";
388
                $apiMethod2 = "";
389
            } else {
390
                $field = "CampaignID";
391
                $apiMethod1 = "getDrafts";
392
                $apiMethod2 = "getCampaigns";
393
            }
394
            if (!$this->$field) {
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...
395
                //do nothing
396
            } else {
397
                $api = $this->getAPI();
0 ignored issues
show
Unused Code introduced by
$api 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...
398
                //check drafts
399
                $result = $this->api->$apiMethod1();
0 ignored issues
show
Documentation introduced by
The property api does not exist on object<CampaignMonitorCampaign>. 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...
400
                if (isset($result)) {
401 View Code Duplication
                    foreach ($result as $key => $campaign) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
402
                        if ($this->$field == $campaign->$field) {
403
                            $this->_existsOnCampaignMonitorCheck = true;
404
                            break;
405
                        }
406
                    }
407
                } elseif ($apiMethod2) {
408
                    //check sent ones
409
                    $result = $this->api->$apiMethod2();
0 ignored issues
show
Documentation introduced by
The property api does not exist on object<CampaignMonitorCampaign>. 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...
410
                    if (isset($result)) {
411 View Code Duplication
                        foreach ($result as $key => $campaign) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
412
                            if ($this->$field == $campaign->$field) {
413
                                $this->_existsOnCampaignMonitorCheck = true;
414
                                break;
415
                            }
416
                        }
417
                    }
418
                }
419
            }
420
        }
421
        return $this->_existsOnCampaignMonitorCheck;
422
    }
423
}
424