deleteFolderContents()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 9
nc 4
nop 0
1
<?php
2
3
/**
4
 * This is an OrderStatusLog for the downloads
5
 * It shows the download links
6
 * To make it work, you will have to add files.
7
 *
8
 * When it is first written it creates a folder for the downloads
9
 * you can then add files using the AddFiles method.
10
 *
11
 *
12
 */
13
class ElectronicDelivery_OrderLog extends OrderStatusLog
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...
14
{
15
    /**
16
     * Use for debugging
17
     * uses debug::log
18
     * @boolean
19
     */
20
    private $debug = false;
21
22
    /**
23
     * Standard SS variable
24
     */
25
    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...
26
        "FolderName" => "Varchar(255)",
27
        "Completed" => "Boolean",
28
        "NumberOfHoursBeforeDownloadGetsDeleted" => "Float"
29
    );
30
31
    /**
32
     * Standard SS variable
33
     */
34
    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...
35
        "Files" => "File"
36
    );
37
38
    /**
39
     * Standard SS variable
40
     */
41
    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...
42
        "Created" => "Date",
43
        "Type" => "Type",
44
        "Title" => "Title",
45
        "FolderName" => "Folder"
46
    );
47
48
    /**
49
     * Standard SS variable
50
     */
51
    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...
52
        "InternalUseOnly" => false,
53
        "Completed" => false
54
    );
55
56
    /**
57
     * Set the default: the files are not ready yet!
58
     * Standard SS method
59
     */
60
    public function populateDefaults()
61
    {
62
        parent::populateDefaults();
63
        $this->Note =  "<p>"._t("OrderLog.NODOWNLOADSAREAVAILABLEYET", "No downloads are available yet.")."</p>";
0 ignored issues
show
Documentation introduced by
The property Note does not exist on object<ElectronicDelivery_OrderLog>. 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...
64
    }
65
66
    /**
67
     *
68
     * @return Boolean
69
     **/
70
    public function canDelete($member = null)
71
    {
72
        return true;
73
    }
74
75
    /**
76
     *
77
     * @return Boolean
78
     */
79
    public function canCreate($member = null)
80
    {
81
        return true;
82
    }
83
84
    /**
85
     *
86
     * @return Boolean
87
     **/
88
    public function canEdit($member = null)
89
    {
90
        return false;
91
    }
92
93
    /**
94
     * Standard SS var
95
     * @var Array
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
        'OrderID' => array(
99
            'field' => 'NumericField',
100
            'title' => 'Order Number'
101
        ),
102
        "Title" => "PartialMatchFilter",
103
        "Note" => "PartialMatchFilter",
104
        "FolderName" => "PartialMatchFilter"
105
    );
106
107
108
    /**
109
     * Standard SS var
110
     * @var String
111
     */
112
    private static $singular_name = "Electronic Delivery Details for one Order";
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...
113
    public function i18n_singular_name()
114
    {
115
        return _t("OrderStatusLog.ELECTRONICDELIVERYDETAIL", "Electronic Delivery Details for one Order");
116
    }
117
118
    /**
119
     * Standard SS var
120
     * @var String
121
     */
122
    private static $plural_name = "Electronic Deliveries Detail for many Orders";
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...
123
    public function i18n_plural_name()
124
    {
125
        return _t("OrderStatusLog.ELECTRONICDELIVERIESDETAILS", "Electronic Deliveries Detail for many Orders");
126
    }
127
128
    /**
129
     * Standard SS var
130
     * @var String
131
     */
132
    private static $default_sort = "\"Created\" 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...
133
134
135
    /**
136
    * Size of the folder name (recommended to be at least 5+)
137
    * @var Int
138
    */
139
    private static $random_folder_name_character_count = 12;
0 ignored issues
show
Unused Code introduced by
The property $random_folder_name_character_count 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...
140
141
    /**
142
     * if set to anything except an empty string,
143
     * an .htaccess file will be added to the download folder
144
     * with the content of the variable
145
     * content idea: Options -Indexes (stops directly from listing folders)
146
     * @var String
147
     */
148
    private static $htaccess_content = "";
0 ignored issues
show
Unused Code introduced by
The property $htaccess_content 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...
149
150
    /**
151
     * List of files to be ignored when searching for files in the folder
152
     * This may allow you to add "hidden" files or ignore other files.
153
     * Can be added as
154
     *     1 => mypng.png
155
     *     2 => mysecondImage.jpg
156
     *
157
     * @var Array
158
     */
159
    private static $files_to_be_excluded = array();
0 ignored issues
show
Unused Code introduced by
The property $files_to_be_excluded 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...
160
161
    /**
162
     * Permissions on download folders
163
     * if not set, it will use:
164
     * Config::inst()->get('Filesystem', 'folder_create_mask')
165
     * @var string
166
     */
167
    private static $permissions_on_folder = "";
0 ignored issues
show
Unused Code introduced by
The property $permissions_on_folder 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...
168
169
    /**
170
     * @var String $order_dir - the root folder for the place where the files for the order are saved.
171
     * if the variable is equal to downloads then the downloads URL is www.mysite.com/downloads/
172
     */
173
    private static $order_dir = '_downloads';
0 ignored issues
show
Unused Code introduced by
The property $order_dir 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...
174
175
    public function getCMSFields()
176
    {
177
        $fields = parent::getCMSFields();
178
        $fields->addFieldToTab("Root.Main", new LiteralField("FilesInFolder", _t("OrderStep.ACTUALFilesInFolder", "Actual files in folder: ").implode(", ", $this->getFilesInFolder())));
179
        return $fields;
180
    }
181
182
    /**
183
     * Adds the download files to the Log and makes them available for download.
184
     * @param ArrayList | Null $dosWithFiles - Data Object Set with files
185
     */
186
    public function AddFiles($listOfFiles)
187
    {
188
        //update log fields
189
        $this->Title = _t("OrderStatusLog.DOWNLOADFILES", "Download Files");
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<ElectronicDelivery_OrderLog>. 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...
190
        $this->Note = "<ul>";
0 ignored issues
show
Documentation introduced by
The property Note does not exist on object<ElectronicDelivery_OrderLog>. 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...
191
        if (!$this->OrderID) {
0 ignored issues
show
Documentation introduced by
The property OrderID does not exist on object<ElectronicDelivery_OrderLog>. 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...
192
            user_error("Tried to add files to an ElectronicDelivery_OrderStatus object without an OrderID");
193
        }
194
        if ($this->debug) {
195
            debug::log(print_r($listOfFiles, 1));
196
            debug::log("COUNT: ".$listOfFiles->count());
197
        }
198
        //are there any files?
199
        if ($listOfFiles && $listOfFiles->count()) {
200
            if ($this->debug) {
201
                debug::log("doing it");
202
            }
203
            //create folder
204
            $fullFolderPath = $this->getOrderDownloadFolder(true);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $fullFolderPath is correct as $this->getOrderDownloadFolder(true) (which targets ElectronicDelivery_Order...etOrderDownloadFolder()) seems to always return null.

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

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

}

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

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

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

Loading history...
205
            $folderOnlyPart = $this->getOrderDownloadFolder(false);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $folderOnlyPart is correct as $this->getOrderDownloadFolder(false) (which targets ElectronicDelivery_Order...etOrderDownloadFolder()) seems to always return null.

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

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

}

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

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

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

Loading history...
206
            $existingFiles = $this->Files();
0 ignored issues
show
Documentation Bug introduced by
The method Files does not exist on object<ElectronicDelivery_OrderLog>? 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...
207
            $alreadyCopiedFileNameArray = array();
208
209
            //loop through files
210
            foreach ($listOfFiles as $file) {
211
                if ($file->exists() && file_exists($file->getFullPath())) {
212
                    $existingFiles->add($file);
213
                    $copyFrom = $file->getFullPath();
214
                    $fileName = $file->Name;
215
                    $destinationFile = $fullFolderPath."/".$file->Name;
216
                    $destinationURL = Director::absoluteURL("/".$this->getBaseFolder(false)."/".$folderOnlyPart."/".$fileName);
217
                    if (!in_array($copyFrom, $alreadyCopiedFileNameArray)) {
218
                        $alreadyCopiedFileNameArray[] = $fileName;
219
                        if (copy($copyFrom, $destinationFile)) {
220
                            if ($this->debug) {
221
                                debug::log("\r\n COPYING $copyFrom to $destinationFile \r\n |||".serialize($file));
222
                            }
223
                            $this->Note .= '<li><a href="'.$destinationURL.'" target="_blank">'.$file->Title.'</a></li>';
0 ignored issues
show
Documentation introduced by
The property Note does not exist on object<ElectronicDelivery_OrderLog>. 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...
224
                        }
225
                    } else {
226
                        $this->Note .= "<li>"._t("OrderLog.NOTINCLUDEDIS", "no download available: ").$file->Title."</li>";
0 ignored issues
show
Documentation introduced by
The property Note does not exist on object<ElectronicDelivery_OrderLog>. 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...
227
                    }
228
                }
229
            }
230
        } else {
231
            $this->Completed = true;
0 ignored issues
show
Documentation introduced by
The property Completed does not exist on object<ElectronicDelivery_OrderLog>. 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...
232
            $this->Note .= "<li>"._t("OrderStatusLog.THEREARENODOWNLOADSWITHTHISORDER", "There are no downloads for this order.")."</li>";
0 ignored issues
show
Documentation introduced by
The property Note does not exist on object<ElectronicDelivery_OrderLog>. 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...
233
        }
234
        $this->Note .= "</ul>";
0 ignored issues
show
Documentation introduced by
The property Note does not exist on object<ElectronicDelivery_OrderLog>. 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...
235
        $this->write();
236
    }
237
238
239
    /**
240
     * checks if the download has expired (i.e. too much time has passed)
241
     * @return Boolean
242
     */
243
    public function IsExpired()
244
    {
245
        if ($this->Completed) {
0 ignored issues
show
Documentation introduced by
The property Completed does not exist on object<ElectronicDelivery_OrderLog>. 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...
246
            return true;
247
        }
248
        if (!$this->Created) {
249
            return false;
250
        }
251
        return (strtotime("Now") - strtotime($this->Created)) > (60 * 60 * $this->NumberOfHoursBeforeDownloadGetsDeleted);
0 ignored issues
show
Documentation introduced by
The property NumberOfHoursBeforeDownloadGetsDeleted does not exist on object<ElectronicDelivery_OrderLog>. 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...
252
    }
253
254
    /**
255
     * Standard SS method
256
     * Creates the folder and files.
257
     */
258
    public function onBeforeWrite()
259
    {
260
        parent::onBeforeWrite();
261
        if (!$this->IsExpired()) {
262
            $this->FolderName = $this->getOrderDownloadFolder(true);
0 ignored issues
show
Documentation introduced by
The property FolderName does not exist on object<ElectronicDelivery_OrderLog>. 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...
Bug introduced by
Are you sure the assignment to $this->FolderName is correct as $this->getOrderDownloadFolder(true) (which targets ElectronicDelivery_Order...etOrderDownloadFolder()) seems to always return null.

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

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

}

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

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

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

Loading history...
263
        }
264
    }
265
266
    /**
267
     * Standard SS method
268
     * If it has expired, then the folder is deleted...
269
     */
270
    public function onAfterWrite()
271
    {
272
        parent::onAfterWrite();
273
        $this->deleteFolderIfExpired();
274
    }
275
276
    /**
277
     * making sure we dont end up in an infinite loop
278
     * @var int
279
     */
280
    private $loopEscape = 0;
281
282
    public function deleteFolderIfExpired()
283
    {
284
        if ($this->FolderName) {
0 ignored issues
show
Documentation introduced by
The property FolderName does not exist on object<ElectronicDelivery_OrderLog>. 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...
285
            if ($this->Completed) {
0 ignored issues
show
Documentation introduced by
The property Completed does not exist on object<ElectronicDelivery_OrderLog>. 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...
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...
286
                //do nothing ...
287
            } else {
288
                if ($this->IsExpired() && $this->loopEscape > 0) {
289
                    $this->loopEscape++;
290
                    $this->Note = "<p>"._t("OrderStatusLog.DOWNLOADSHAVEEXPIRED", "Downloads have expired.")."</p>";
0 ignored issues
show
Documentation introduced by
The property Note does not exist on object<ElectronicDelivery_OrderLog>. 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...
291
                    $this->Completed = $this->deleteFolderContents();
0 ignored issues
show
Documentation introduced by
The property Completed does not exist on object<ElectronicDelivery_OrderLog>. 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...
292
                    $this->write();
293
                } elseif ($this->loopEscape == 10) {
294
                    user_error("Tried to deleted ".$this->FolderName." 10 times without success", E_USER_NOTICE);
0 ignored issues
show
Documentation introduced by
The property FolderName does not exist on object<ElectronicDelivery_OrderLog>. 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
                }
296
            }
297
        } 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...
298
        }
299
    }
300
301
    /**
302
     * Standard SS method
303
     * Deletes the files in the download folder,
304
     * and the actual download folder itself.
305
     */
306
    public function onBeforeDelete()
307
    {
308
        parent::onBeforeDelete();
309
        if ($this->FolderName && !$this->Completed) {
0 ignored issues
show
Documentation introduced by
The property FolderName does not exist on object<ElectronicDelivery_OrderLog>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property Completed does not exist on object<ElectronicDelivery_OrderLog>. 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...
310
            $this->deleteFolderContents();
311
        }
312
    }
313
314
    /**
315
     * returns the list of files that are in the current folder
316
     * @return Array
317
     */
318
    protected function getFilesInFolder()
319
    {
320
        if ($this->FolderName && file_exists($this->FolderName)) {
0 ignored issues
show
Documentation introduced by
The property FolderName does not exist on object<ElectronicDelivery_OrderLog>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
321
            return $this->getDirectoryContents($this->FolderName, $showFiles = 1, $showFolders = 0);
0 ignored issues
show
Documentation introduced by
The property FolderName does not exist on object<ElectronicDelivery_OrderLog>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
$showFiles = 1 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$showFolders = 0 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
322
        } else {
323
            return array(_t("OrderStatus.NOFOLDER", "No folder is associated with this download entry."));
324
        }
325
    }
326
327
    /**
328
     * creates a folder and returns the full folder path
329
     * if the folder is already created it still returns the folder path,
330
     * but it does not create the folder.
331
     *
332
     * @param Boolean $absolutePath
333
     *
334
     * @return NULL | String
335
     */
336
    protected function getOrderDownloadFolder($absolutePath = true)
337
    {
338
        //already exists - do nothing
339
        if ($this->FolderName) {
0 ignored issues
show
Documentation introduced by
The property FolderName does not exist on object<ElectronicDelivery_OrderLog>. 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...
340
            $fullFolderName = $this->FolderName;
0 ignored issues
show
Documentation introduced by
The property FolderName does not exist on object<ElectronicDelivery_OrderLog>. 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...
341
        } elseif ($baseFolder = $this->getBaseFolder(true)) {
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $baseFolder is correct as $this->getBaseFolder(true) (which targets ElectronicDelivery_OrderLog::getBaseFolder()) seems to always return null.

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

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

}

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

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

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

Loading history...
342
            //create folder....
343
            $randomFolderName = substr(md5(time()+rand(1, 999)), 0, $this->Config()->get("random_folder_name_character_count"))."_".$this->OrderID;
0 ignored issues
show
Documentation introduced by
The property OrderID does not exist on object<ElectronicDelivery_OrderLog>. 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
            $fullFolderName = $baseFolder."/".$randomFolderName;
345
            if (file_exists($fullFolderName)) {
346
                $allOk = true;
347
            } else {
348
                $allOk = mkdir($fullFolderName, $this->getFolderPermissions());
349
            }
350
            if (!file_exists($fullFolderName)) {
351
                user_error("Can not create folder: ".$fullFolderName);
352
                return;
353
            }
354
            if ($allOk) {
355
                $this->FolderName = $fullFolderName;
0 ignored issues
show
Documentation introduced by
The property FolderName does not exist on object<ElectronicDelivery_OrderLog>. 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...
356
            }
357
        }
358
        if ($absolutePath) {
359
            return $fullFolderName;
0 ignored issues
show
Bug introduced by
The variable $fullFolderName does not seem to be defined for all execution paths leading up to this point.

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
360
        } else {
361
            //TO DO: test
362
            return str_replace($this->getBaseFolder(true)."/", "", $fullFolderName);
363
        }
364
    }
365
366
    /**
367
     * returns the folder in which all the downloads are kept
368
     * (each order has an individual folder within this base folder)
369
     * returns location of base folder.
370
     *
371
     * @param Boolean $absolutePath - absolute folder path (set to false to get relative path)
372
     *
373
     * @return NULL | String
374
     */
375
    protected function getBaseFolder($absolutePath = true)
376
    {
377
        $baseFolderRelative = $this->Config()->get("order_dir");
378
        $baseFolderAbsolute = Director::baseFolder()."/".$baseFolderRelative;
379
        if (!file_exists($baseFolderAbsolute)) {
380
            mkdir($baseFolderAbsolute, $this->getFolderPermissions());
381
        }
382
        if (!file_exists($baseFolderAbsolute)) {
383
            user_error("Can not create folder: ".$baseFolderAbsolute);
384
            return;
385
        }
386
        $manifestExcludeFile = $baseFolderAbsolute."/"."_manifest_exclude";
387 View Code Duplication
        if (!file_exists($manifestExcludeFile)) {
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...
388
            $manifestExcludeFileHandle = fopen($manifestExcludeFile, 'w') or user_error("Can not create ".$manifestExcludeFile);
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
389
            fwrite($manifestExcludeFileHandle, "Please do not delete this file");
390
            fclose($manifestExcludeFileHandle);
391
        }
392
        if ($htAccessContent = $this->Config()->get("htaccess_content")) {
393
            $htAccessFile = $baseFolderAbsolute."/".".htaccess";
394 View Code Duplication
            if (!file_exists($htAccessFile)) {
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...
395
                $htAccessFileHandle = fopen($htaccessfile, 'w') or user_error("Can not create ".$htAccessFile);
0 ignored issues
show
Bug introduced by
The variable $htaccessfile does not exist. Did you mean $htAccessFile?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
396
                fwrite($htAccessFileHandle, $htAccessContent);
397
                fclose($htAccessFileHandle);
398
            }
399
        }
400
        if ($absolutePath) {
401
            return $baseFolderAbsolute;
402
        } else {
403
            return $baseFolderRelative;
404
        }
405
    }
406
407
    /**
408
     * returns the permissions for the folder to be created.
409
     * @return String
410
     */
411
    protected function getFolderPermissions()
412
    {
413
        return $this->Config()->get("permissions_on_folder") ? $this->Config()->get("permissions_on_folder") : Config::inst()->get('Filesystem', 'folder_create_mask');
414
    }
415
416
    /**
417
     * get folder contents
418
     *
419
     * @param String $fullPath (e.g. /var/www/mysite.co.nz/downloads)
420
     * @param Boolean $showFiles - list the files in the directory?
421
     * @param Boolean $showFolders - list the folders in the directory?
422
     *
423
     * @return array
424
     */
425
    protected function getDirectoryContents($fullPath, $showFiles = false, $showFolders = false)
426
    {
427
        $files = array();
428
        if (file_exists($fullPath)) {
429
            if ($directoryHandle = opendir($fullPath)) {
430
                while (($file = readdir($directoryHandle)) !== false) {
431
                    /* no links ! */
432
                    $fullFileName = $fullPath."/".$file;
433
                    if (substr($file, strlen($file) - 1) != ".") {
434
                        if ((!is_dir($fullFileName) && $showFiles) || ($showFolders && is_dir($fullFileName))) {
435
                            if (!in_array($file, $this->Config()->get("files_to_be_excluded"))) {
436
                                array_push($files, $fullFileName);
437
                            }
438
                        }
439
                    }
440
                }
441
                closedir($directoryHandle);
442
            }
443
        }
444
        return $files;
445
    }
446
447
    /**
448
     * remove all the folder contents and remove the folder itself
449
     * as well... Returns true on success.
450
     * Assumes that there are no folders in the folder...
451
     *
452
     * @return Boolean
453
     */
454
    protected function deleteFolderContents()
455
    {
456
        if ($this->FolderName) {
0 ignored issues
show
Documentation introduced by
The property FolderName does not exist on object<ElectronicDelivery_OrderLog>. 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...
457
            if (file_exists($this->FolderName)) {
0 ignored issues
show
Documentation introduced by
The property FolderName does not exist on object<ElectronicDelivery_OrderLog>. 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...
458
                $files = $this->getDirectoryContents($this->FolderName, $showFiles = 1, $showFolders = 0);
0 ignored issues
show
Documentation introduced by
The property FolderName does not exist on object<ElectronicDelivery_OrderLog>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
$showFiles = 1 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$showFolders = 0 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
459
                if ($files) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $files of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
460
                    foreach ($files as $file) {
461
                        unlink($file);
462
                    }
463
                }
464
                return rmdir($this->FolderName);
0 ignored issues
show
Documentation introduced by
The property FolderName does not exist on object<ElectronicDelivery_OrderLog>. 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...
465
            }
466
        }
467
        return true;
468
    }
469
}
470