Completed
Push — master ( 0c873a...10905b )
by Anılcan
04:51
created

Former   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 65
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B make() 0 24 4
A makeFromRequest() 0 4 1
1
<?php
2
3
namespace AnilcanCakir\Former;
4
5
use AnilcanCakir\Former\Contracts\Former as Contract;
6
use AnilcanCakir\Former\Contracts\FormerHelper as HelperContract;
7
use Illuminate\Database\Eloquent\Model;
8
9
/**
10
 * Class FormFactory
11
 * @package AnilcanCakir\Former
12
 */
13
class Former implements Contract
14
{
15
    /**
16
     * The FormerHelper instance.
17
     *
18
     * @var HelperContract
19
     */
20
    private $helper;
21
22
    /**
23
     * FormFactory constructor.
24
     *
25
     * @param HelperContract $helper
26
     */
27
    public function __construct(HelperContract $helper)
28
    {
29
        $this->helper = $helper;
30
    }
31
32
    /**
33
     * Make a form instance by using the rules.
34
     *
35
     * @param array $formRules
36
     * @param Model|null $model
37
     * @param null $theme
38
     * @return Form
39
     */
40
    public function make(array $formRules, Model $model = null, $theme = null)
41
    {
42
        $form = new Form(
43
            $model, $this->helper
44
        );
45
46
        if ($theme) {
47
            $form->setTheme($theme);
48
        }
49
50
        foreach ($formRules as $name => $rules) {
51
            if (is_string($rules)) {
52
                $rules = explode('|', $rules);
53
            }
54
55
            $form->addField(
56
                $this->helper->getFieldClassFromRules($rules),
57
                $name,
58
                $rules
59
            );
60
        }
61
62
        return $form;
63
    }
64
65
    /**
66
     * Make a form instance by using the form request.
67
     *
68
     * @param $formRequest
69
     * @param Model $model
70
     * @param string|null $theme
71
     * @return void
72
     */
73
    public function makeFromRequest($formRequest, Model $model, $theme = null)
74
    {
75
        // TODO: Implement makeFromRequest() method.
76
    }
77
}