Passed
Push — master ( 03f7d7...c4abfd )
by Christian
11:46 queued 12s
created

PromotionPersonaCustomerDefinition   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntityName() 0 3 1
A since() 0 3 1
A defineFields() 0 8 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Promotion\Aggregate\PromotionPersonaCustomer;
4
5
use Shopware\Core\Checkout\Customer\CustomerDefinition;
6
use Shopware\Core\Checkout\Promotion\PromotionDefinition;
7
use Shopware\Core\Framework\Api\Context\SalesChannelApiSource;
8
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
9
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
10
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ReadProtected;
11
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required;
12
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField;
13
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
14
use Shopware\Core\Framework\DataAbstractionLayer\MappingEntityDefinition;
15
16
class PromotionPersonaCustomerDefinition extends MappingEntityDefinition
17
{
18
    public const ENTITY_NAME = 'promotion_persona_customer';
19
20
    /**
21
     * This class is used as m:n relation between promotions and customers.
22
     * It gives the option to assign what customers may use this
23
     * promotion based on a whitelist algorithm.
24
     */
25
    public function getEntityName(): string
26
    {
27
        return self::ENTITY_NAME;
28
    }
29
30
    public function since(): ?string
31
    {
32
        return '6.0.0.0';
33
    }
34
35
    protected function defineFields(): FieldCollection
36
    {
37
        return new FieldCollection([
38
            (new FkField('promotion_id', 'promotionId', PromotionDefinition::class))->addFlags(new PrimaryKey(), new Required()),
39
            (new FkField('customer_id', 'customerId', CustomerDefinition::class))->addFlags(new PrimaryKey(), new Required()),
40
            new ManyToOneAssociationField('promotion', 'promotion_id', PromotionDefinition::class, 'id'),
41
            (new ManyToOneAssociationField('customer', 'customer_id', CustomerDefinition::class, 'id'))
42
                ->addFlags(new ReadProtected(SalesChannelApiSource::class)),
43
        ]);
44
    }
45
}
46