Passed
Push — master ( ff9826...71490e )
by Christian
10:39 queued 10s
created

TaxDefinition::getDefaults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
crap 2
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\System\Tax;
4
5
use Shopware\Core\Checkout\Shipping\ShippingMethodDefinition;
6
use Shopware\Core\Content\Product\ProductDefinition;
7
use Shopware\Core\Framework\Api\Context\SalesChannelApiSource;
8
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
9
use Shopware\Core\Framework\DataAbstractionLayer\Field\CustomFields;
10
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
11
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ReadProtected;
12
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required;
13
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\RestrictDelete;
14
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ReverseInherited;
15
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\SearchRanking;
16
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Since;
17
use Shopware\Core\Framework\DataAbstractionLayer\Field\FloatField;
18
use Shopware\Core\Framework\DataAbstractionLayer\Field\IdField;
19
use Shopware\Core\Framework\DataAbstractionLayer\Field\IntField;
20
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
21
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField;
22
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
23
use Shopware\Core\System\Tax\Aggregate\TaxRule\TaxRuleDefinition;
24 286
25
class TaxDefinition extends EntityDefinition
26 286
{
27
    public const ENTITY_NAME = 'tax';
28
29 247
    public function getEntityName(): string
30
    {
31 247
        return self::ENTITY_NAME;
32
    }
33
34 233
    public function getCollectionClass(): string
35
    {
36 233
        return TaxCollection::class;
37
    }
38
39 1
    public function getEntityClass(): string
40
    {
41 1
        return TaxEntity::class;
42 1
    }
43 1
44 1
    public function since(): ?string
45 1
    {
46 1
        return '6.0.0.0';
47 1
    }
48 1
49
    public function getDefaults(): array
50
    {
51
        return [
52
            'position' => 0,
53
        ];
54
    }
55
56
    protected function defineFields(): FieldCollection
57
    {
58
        return new FieldCollection([
59
            (new IdField('id', 'id'))->addFlags(new PrimaryKey(), new Required()),
60
            (new FloatField('tax_rate', 'taxRate'))->addFlags(new Required(), new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)),
61
            (new StringField('name', 'name'))->addFlags(new Required(), new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)),
62
            (new IntField('position', 'position'))->addFlags(new Required(), new Since('6.4.0.0')),
63
            new CustomFields(),
64
            (new OneToManyAssociationField('products', ProductDefinition::class, 'tax_id', 'id'))->addFlags(new RestrictDelete(), new ReverseInherited('tax')),
65
            (new OneToManyAssociationField('rules', TaxRuleDefinition::class, 'tax_id', 'id'))->addFlags(new RestrictDelete(), new ReadProtected(SalesChannelApiSource::class)),
66
            (new OneToManyAssociationField('shippingMethods', ShippingMethodDefinition::class, 'tax_id', 'id'))->addFlags(new RestrictDelete()),
67
        ]);
68
    }
69
}
70