Passed
Push — master ( a403c4...843515 )
by Diego
07:39 queued 01:51
created

AffiliateFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 27
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A generateTokenValue() 0 3 1
A createNew() 0 3 1
A createForCustomer() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Odiseo\SyliusReferralsPlugin\Factory;
6
7
use Odiseo\SyliusReferralsPlugin\Entity\AffiliateInterface;
8
use Sylius\Component\Core\Model\CustomerInterface;
9
use Sylius\Component\Resource\Factory\FactoryInterface;
10
11
final class AffiliateFactory implements AffiliateFactoryInterface
12
{
13
    private FactoryInterface $decoratedFactory;
14
15
    public function __construct(FactoryInterface $decoratedFactory)
16
    {
17
        $this->decoratedFactory = $decoratedFactory;
18
    }
19
20
    public function createNew(): object
21
    {
22
        return $this->decoratedFactory->createNew();
23
    }
24
25
    public function createForCustomer(CustomerInterface $customer): AffiliateInterface
26
    {
27
        /** @var AffiliateInterface $affiliate */
28
        $affiliate = $this->decoratedFactory->createNew();
29
        $affiliate->setCustomer($customer);
30
        $affiliate->setTokenValue($this->generateTokenValue());
31
32
        return $affiliate;
33
    }
34
35
    private function generateTokenValue(): string
36
    {
37
        return uniqid('ap_', true);
38
    }
39
}
40