FilePondFileExtension::getObjectFiles()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
namespace LeKoala\FilePond;
4
5
use SilverStripe\Assets\File;
6
use SilverStripe\ORM\DataList;
7
use SilverStripe\ORM\DataObject;
8
use SilverStripe\ORM\DataExtension;
9
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...
10
11
/**
12
 * @property File $owner
13
 */
14
class FilePondFileExtension extends DataExtension
0 ignored issues
show
Deprecated Code introduced by
The class SilverStripe\ORM\DataExtension has been deprecated: 5.3.0 Subclass SilverStripe\Core\Extension\Extension instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

14
class FilePondFileExtension extends /** @scrutinizer ignore-deprecated */ DataExtension
Loading history...
15
{
16
    /**
17
     * @var array<string,string>
18
     */
19
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
20
        // This helps tracking state of files uploaded through ajax uploaders
21
        "IsTemporary" => "Boolean",
22
    ];
23
    /**
24
     * @var array<string,string>
25
     */
26
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
27
        // Record is already used by versioned extensions
28
        // ChangeSetItem already uses Object convention so we use the same
29
        "Object" => DataObject::class,
30
    ];
31
32
    /**
33
     * Get a list of files uploaded the given DataObject
34
     * It doesn't mean that the files are currently or still associated!!
35
     *
36
     * @param DataObject $record
37
     * @return DataList|File[]
38
     */
39
    public static function getObjectFiles(DataObject $record)
40
    {
41
        return File::get()->filter([
42
            'ObjectID' => $record->ID,
43
            'ObjectClass' => get_class($record),
44
        ])->exclude('IsTemporary', 1);
45
    }
46
47
    /**
48
     * Called by Upload::loadIntoFile
49
     * @return void
50
     */
51
    public function onAfterUpload()
52
    {
53
        if (FilePondField::config()->enable_auto_thumbnails) {
54
            $thumbs = AssetAdmin::create()->generateThumbnails($this->owner);
0 ignored issues
show
Unused Code introduced by
The assignment to $thumbs is dead and can be removed.
Loading history...
55
        }
56
    }
57
}
58