Failed Conditions
Pull Request — develop (#6)
by Carlo
03:05
created

ApiUser::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4286
cc 1
eloc 10
nc 1
nop 0
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
        $roleModel = Mage::getModel($this->_data['fixture']['api_role']['model']);
30
        $roleBuilderData['fixture'] = $this->_data['fixture']['api_role'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$roleBuilderData was never initialized. Although not strictly required by PHP, it is generally a good practice to add $roleBuilderData = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
31
        $role =  new ApiRole($roleBuilderData, $roleModel, $this->_getHook());
32
        $roleId = $role->build();
33
34
        $fixtureId = ApiUserHelper::create($this->_getMageModel(), $roleId, $this->_data['fixture']['attributes']);
35
36
        return $fixtureId;
37
    }
38
}