Completed
Push — develop ( ceb446...cffdc8 )
by Carlo
03:56
created

ApiUser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 12 1
A _buildApiRoleFixture() 0 9 1
1
<?php
2
3
namespace Magefix\Fixture\Builder;
4
5
use FixturesLocator;
6
use Mage;
7
use Magefix\Fixture\Builder\Helper\ApiUser as ApiUserHelper;
8
9
/**
10
 * Class ApiUser
11
 * @package Magefix\Fixture\Builder
12
 *
13
 * @author  Carlo Tasca <[email protected]>
14
 */
15
class ApiUser extends AbstractBuilder
16
{
17
    /**
18
     *
19
     * Concrete classes to provide implementation for build method
20
     *
21
     * @return mixed
22
     */
23
    public function build()
24
    {
25
        $this->iterateFixture();
26
27
        $this->_throwUndefinedAttributesException(isset($this->_data['fixture']['api_role']['model']),
28
            'Api Role model has not been defined. Check fixture yml.');
29
        $roleId = $this->_buildApiRoleFixture();
30
31
        $fixtureId = ApiUserHelper::create($this->_getMageModel(), $roleId, $this->_data['fixture']['attributes']);
32
33
        return $fixtureId;
34
    }
35
36
    /**
37
     * @return mixed
38
     */
39
    protected function _buildApiRoleFixture()
40
    {
41
        $roleBuilderData = [];
42
        $roleModel = Mage::getModel($this->_data['fixture']['api_role']['model']);
43
        $roleBuilderData['fixture'] = $this->_data['fixture']['api_role'];
44
        $role = new ApiRole($roleBuilderData, $roleModel, $this->_getHook());
45
        $roleId = $role->buildAndRegister();
46
        return $roleId;
47
    }
48
}