Passed
Push — master ( a52d27...2c727c )
by Thomas
32:49
created

FilePondFileExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 11
c 2
b 0
f 1
dl 0
loc 36
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onAfterUpload() 0 4 2
A getObjectFiles() 0 6 1
1
<?php
2
3
namespace LeKoala\FilePond;
4
5
use SilverStripe\Assets\File;
6
use SilverStripe\ORM\DataObject;
7
use SilverStripe\ORM\DataExtension;
8
use SilverStripe\AssetAdmin\Controller\AssetAdmin;
0 ignored issues
show
Bug introduced by
The type SilverStripe\AssetAdmin\Controller\AssetAdmin was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class FilePondFileExtension extends DataExtension
11
{
12
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
13
        // This helps tracking state of files uploaded through ajax uploaders
14
        "IsTemporary" => "Boolean",
15
    ];
16
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
17
        // Record is already used by versioned extensions
18
        // ChangeSetItem already uses Object convention so we use the same
19
        "Object" => DataObject::class,
20
    ];
21
22
    /**
23
     * Get a list of files for the given DataObject
24
     *
25
     * This is just a convenience method, not a public api
26
     *
27
     * @param DataObject $record
28
     * @return DataList|File[]
29
     */
30
    public static function getObjectFiles(DataObject $record)
31
    {
32
        return File::get()->filter([
0 ignored issues
show
Bug Best Practice introduced by
The expression return SilverStripe\Asse...clude('IsTemporary', 1) returns the type SilverStripe\ORM\DataList which is incompatible with the documented return type SilverStripe\Assets\File...Koala\FilePond\DataList.
Loading history...
33
            'ObjectID' => $record->ID,
34
            'ObjectClass' => get_class($record),
35
        ])->exclude('IsTemporary', 1);
36
    }
37
38
    /**
39
     * Called by Upload::loadIntoFile
40
     * @return void
41
     */
42
    public function onAfterUpload()
43
    {
44
        if (File::config()->enable_auto_thumbnail) {
45
            AssetAdmin::create()->generateThumbnails($this->owner);
46
        }
47
    }
48
}
49