Field   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 2
dl 0
loc 48
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getName() 0 4 1
A create() 0 14 1
1
<?php
2
3
/**
4
 * @package Faker
5
 * @author Iurii Makukh <[email protected]>
6
 * @copyright Copyright (c) 2017, Iurii Makukh <[email protected]>
7
 * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License 3.0
8
 */
9
10
namespace gplcart\modules\faker\models\generators;
11
12
use gplcart\core\models\Field as FieldModel;
13
use gplcart\modules\faker\models\Generator as FakerModuleGenerator;
14
15
/**
16
 * Manages basic behaviors and data related to fields
17
 */
18
class Field extends FakerModuleGenerator
19
{
20
21
    /**
22
     * Field model class instance
23
     * @var \gplcart\core\models\Field $field
24
     */
25
    protected $field;
26
27
    /**
28
     * @param FieldModel $field
29
     */
30
    public function __construct(FieldModel $field)
31
    {
32
        parent::__construct();
33
34
        $this->field = $field;
35
    }
36
37
    /**
38
     * Returns the generator name
39
     * @return string
40
     */
41
    public function getName()
42
    {
43
        return $this->translation->text('Field');
44
    }
45
46
    /**
47
     * Generate a single field
48
     * @return bool
49
     */
50
    public function create()
51
    {
52
        $types = $this->field->getTypes();
53
        $widgets = $this->field->getWidgetTypes();
54
55
        $field = array(
56
            'type' => array_rand($types),
57
            'widget' => array_rand($widgets),
58
            'title' => $this->faker->text(50),
59
            'weight' => $this->faker->numberBetween(0, 20)
60
        );
61
62
        return (bool) $this->field->add($field);
63
    }
64
65
}
66