ProductImages::updateCMSFields()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 12
c 1
b 0
f 1
nc 3
nop 1
dl 0
loc 17
rs 9.8666
1
<?php
2
3
namespace AntonyThorpe\SilverShopProductImages;
4
5
use SilverStripe\Core\Extension;
0 ignored issues
show
Bug introduced by
The type SilverStripe\Core\Extension 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...
6
use SilverStripe\ORM\ManyManyList;
0 ignored issues
show
Bug introduced by
The type SilverStripe\ORM\ManyManyList 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...
7
use SilverShop\Page\Product;
0 ignored issues
show
Bug introduced by
The type SilverShop\Page\Product 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...
8
use SilverStripe\Forms\FieldList;
0 ignored issues
show
Bug introduced by
The type SilverStripe\Forms\FieldList 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
use SilverStripe\Assets\Image;
0 ignored issues
show
Bug introduced by
The type SilverStripe\Assets\Image 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
use SilverStripe\Forms\LiteralField;
0 ignored issues
show
Bug introduced by
The type SilverStripe\Forms\LiteralField 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...
11
use SilverStripe\ORM\ArrayList;
0 ignored issues
show
Bug introduced by
The type SilverStripe\ORM\ArrayList 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...
12
use SilverStripe\ORM\DataList;
0 ignored issues
show
Bug introduced by
The type SilverStripe\ORM\DataList 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...
13
use Bummzack\SortableFile\Forms\SortableUploadField;
0 ignored issues
show
Bug introduced by
The type Bummzack\SortableFile\Forms\SortableUploadField 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...
14
15
/**
16
 * Extends SilverShop\Page\Product
17
 * @method ManyManyList<Image> AdditionalImages()
18
 * @extends Extension<(Product & static)>
19
 */
20
class ProductImages extends Extension
21
{
22
    /**
23
     * @config
24
     */
25
    private static array $many_many = [
0 ignored issues
show
introduced by
The private property $many_many is not used, and could be removed.
Loading history...
26
        'AdditionalImages' => Image::class,
27
    ];
28
29
    /**
30
     * @config
31
     */
32
    private static array $many_many_extraFields = [
0 ignored issues
show
introduced by
The private property $many_many_extraFields is not used, and could be removed.
Loading history...
33
        'AdditionalImages' => ['SortOrder' => 'Int'],
34
    ];
35
36
    public function updateCMSFields(FieldList $fieldList): void
37
    {
38
        $newfields = [
39
            SortableUploadField::create(
40
                'AdditionalImages',
41
                _t(self::class . '.AdditionalImages', 'Additional Images')
0 ignored issues
show
Bug introduced by
The function _t was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

41
                /** @scrutinizer ignore-call */ 
42
                _t(self::class . '.AdditionalImages', 'Additional Images')
Loading history...
42
            ),
43
            LiteralField::create(
44
                'additionalimagesinstructions',
45
                '<p>' . _t(self::class . '.Instructions', 'You can change the order of the Additional Images by clicking and dragging on the image thumbnail.') . '</p>'
46
            )
47
        ];
48
        if ($fieldList->hasTabset()) {
49
            $fieldList->addFieldsToTab('Root.Images', $newfields);
50
        } else {
51
            foreach ($newfields as $newfield) {
52
                $fieldList->push($newfield);
53
            }
54
        }
55
    }
56
57
    /**
58
     * Combines the main image and the secondary images
59
     */
60
    public function getAllImages(): ArrayList
61
    {
62
        $arrayList = ArrayList::create(
63
            $this->getOwner()->AdditionalImages()->sort('SortOrder')->toArray()
64
        );
65
        $main = $this->getOwner()->Image();
66
        if ($main->exists()) {
67
                $arrayList->unshift($main);
68
        }
69
70
        return $arrayList;
71
    }
72
73
    /**
74
     * Sorted images
75
     */
76
    public function getSortedAdditionalImages(): DataList
77
    {
78
        return $this->getOwner()->AdditionalImages()->sort('SortOrder');
79
    }
80
}
81