Passed
Pull Request — master (#9)
by Jason
01:48
created

MemberFactory   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
eloc 28
c 1
b 0
f 0
dl 0
loc 91
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 3
A setMember() 0 33 6
A getMember() 0 7 2
A getTransaction() 0 3 1
A setTransaction() 0 5 1
1
<?php
2
3
namespace Dynamic\Foxy\SingleSignOn\Factory;
4
5
use Dynamic\Foxy\Orders\Factory\FoxyFactory;
0 ignored issues
show
Bug introduced by
The type Dynamic\Foxy\Orders\Factory\FoxyFactory 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 Dynamic\Foxy\Parser\Foxy\Transaction;
0 ignored issues
show
Bug introduced by
The type Dynamic\Foxy\Parser\Foxy\Transaction 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 SilverStripe\Core\Config\Configurable;
8
use SilverStripe\Core\Extensible;
9
use SilverStripe\Core\Injector\Injectable;
10
use SilverStripe\Security\Member;
11
use SilverStripe\Security\Security;
12
use SilverStripe\View\ArrayData;
13
14
class MemberFactory
15
{
16
    use Configurable;
17
    use Extensible;
18
    use Injectable;
19
20
    /**
21
     * @var Transaction
22
     */
23
    private $transaction;
24
25
    /**
26
     * @var
27
     */
28
    private $member;
29
30
    /**
31
     * OrderDetailFactory constructor.
32
     * @param Transaction|null $transaction
33
     */
34
    public function __construct(Transaction $transaction = null)
35
    {
36
        if ($transaction instanceof Transaction && $transaction !== null) {
37
            $this->setTransaction($transaction);
38
        }
39
    }
40
41
    /**
42
     * @param Transaction $transaction
43
     * @return $this
44
     */
45
    public function setTransaction(Transaction $transaction)
46
    {
47
        $this->transaction = $transaction;
48
49
        return $this;
50
    }
51
52
    /**
53
     * @return Transaction
54
     */
55
    protected function getTransaction()
56
    {
57
        return $this->transaction;
58
    }
59
60
    /**
61
     * @return Member
62
     */
63
    public function getMember()
64
    {
65
        if (!$this->member instanceof Member) {
66
            $this->setMember();
67
        }
68
69
        return $this->member;
70
    }
71
72
    protected function setMember()
73
    {
74
        /** @var ArrayData $transaction */
75
        $transaction = $this->getTransaction()->getParsedTransactionData()->getField('transaction');
76
77
        // if not a guest transaction in Foxy
78
        if ($transaction->getField('customer_email')
79
            && $transaction->getField('is_anonymous') == 0) {
80
81
            /** @var $encryption - disable password encryption to prevent double encryption */
82
            $encryption = Config::inst()->get(Security::class, 'password_encryption_algorithm');
0 ignored issues
show
Bug introduced by
The type Dynamic\Foxy\SingleSignOn\Factory\Config 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...
83
            Config::modify()->set(Security::class, 'password_encryption_algorithm', 'none');
84
85
            if (!$customer = Member::get()->filter('Email', $transaction->getField('customer_email'))->first()) {
86
                $customer = Member::create();
87
            }
88
89
            foreach ($this->config()->get('member_mapping') as $foxy => $ssFoxy) {
90
                if ($transaction->hasField($foxy)) {
91
                    $order->{$ssFoxy} = $transaction->getField($foxy);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $order seems to be never defined.
Loading history...
92
                }
93
            }
94
95
            /** manuall set encryption type to sha1 */
96
            $customer->PasswordEncryption = 'sha1';
97
98
            /** flag to prevent push to Foxy on write */
99
            $customer->FromDataFeed = true;
100
101
            $customer->write();
102
103
            /** re-enable password encryption */
104
            Config::modify()->set(Security::class, 'password_encryption_algorithm', $encryption);
105
        }
106
    }
107
}
108