ProductMediaDefinition   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A defineFields() 0 15 1
A getCollectionClass() 0 3 1
A getHydratorClass() 0 3 1
A getParentDefinitionClass() 0 3 1
A since() 0 3 1
A getEntityClass() 0 3 1
A getEntityName() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Content\Product\Aggregate\ProductMedia;
4
5
use Shopware\Core\Content\Media\MediaDefinition;
6
use Shopware\Core\Content\Product\ProductDefinition;
7
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
8
use Shopware\Core\Framework\DataAbstractionLayer\Field\CustomFields;
9
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
10
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ApiAware;
11
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
12
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required;
13
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ReverseInherited;
14
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\SetNullOnDelete;
15
use Shopware\Core\Framework\DataAbstractionLayer\Field\IdField;
16
use Shopware\Core\Framework\DataAbstractionLayer\Field\IntField;
17
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField;
18
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
19
use Shopware\Core\Framework\DataAbstractionLayer\Field\ReferenceVersionField;
20
use Shopware\Core\Framework\DataAbstractionLayer\Field\VersionField;
21
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
22
use Shopware\Core\Framework\Log\Package;
23
24
#[Package('inventory')]
25
class ProductMediaDefinition extends EntityDefinition
26
{
27
    final public const ENTITY_NAME = 'product_media';
28
29
    public function getEntityName(): string
30
    {
31
        return self::ENTITY_NAME;
32
    }
33
34
    public function getCollectionClass(): string
35
    {
36
        return ProductMediaCollection::class;
37
    }
38
39
    public function getEntityClass(): string
40
    {
41
        return ProductMediaEntity::class;
0 ignored issues
show
Bug introduced by
The type Shopware\Core\Content\Pr...edia\ProductMediaEntity 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...
42
    }
43
44
    public function since(): ?string
45
    {
46
        return '6.0.0.0';
47
    }
48
49
    public function getHydratorClass(): string
50
    {
51
        return ProductMediaHydrator::class;
52
    }
53
54
    protected function getParentDefinitionClass(): ?string
55
    {
56
        return ProductDefinition::class;
57
    }
58
59
    protected function defineFields(): FieldCollection
60
    {
61
        return new FieldCollection([
62
            (new IdField('id', 'id'))->addFlags(new ApiAware(), new PrimaryKey(), new Required()),
63
            (new VersionField())->addFlags(new ApiAware()),
64
65
            (new FkField('product_id', 'productId', ProductDefinition::class))->addFlags(new ApiAware(), new Required()),
66
            (new ReferenceVersionField(ProductDefinition::class))->addFlags(new ApiAware(), new Required()),
67
68
            (new FkField('media_id', 'mediaId', MediaDefinition::class))->addFlags(new ApiAware(), new Required()),
69
            (new IntField('position', 'position'))->addFlags(new ApiAware()),
70
            (new ManyToOneAssociationField('product', 'product_id', ProductDefinition::class, 'id', false))->addFlags(new ReverseInherited('media')),
71
            (new ManyToOneAssociationField('media', 'media_id', MediaDefinition::class, 'id', true))->addFlags(new ApiAware()),
72
            (new OneToManyAssociationField('coverProducts', ProductDefinition::class, 'product_media_id'))->addFlags(new SetNullOnDelete(false)),
73
            (new CustomFields())->addFlags(new ApiAware()),
74
        ]);
75
    }
76
}
77