VersionedFolderExtension   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B onBeforeDelete() 0 23 7
1
<?php
2
/**
3
 * @package silverstripe-versionedfiles
4
 */
5
class VersionedFolderExtension extends DataExtension
6
{
7
    public function onBeforeDelete()
8
    {
9
        // A workaround for that fact that Folder::onBeforeDelete() only removes
10
        // the folder if only a _resampled dir exists. If the folder is empty
11
        // and only has _resampled and _versions directories then delete it.
12
        if ($this->owner->Filename && is_dir($this->owner->getFullPath())) {
0 ignored issues
show
Bug introduced by
The property Filename does not seem to exist in SS_Object.

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...
13
            $items       = scandir($this->owner->getFullPath());
14
            $versionsDir = FileVersion::VERSION_FOLDER;
15
16
            // Remove . and .. items.
17
            array_shift($items);
18
            array_shift($items);
19
20
            $delete = (
21
                count($items) == 1 && $items[0] == $versionsDir
22
                || count($items) == 2 && $items == array('_resampled', $versionsDir)
23
            );
24
25
            if ($delete) {
26
                Filesystem::removeFolder($this->owner->getFullPath());
27
            }
28
        }
29
    }
30
}
31