Factory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 10
c 0
b 0
f 0
ccs 13
cts 13
cp 1
wmc 6
lcom 0
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 4 1
A get() 0 4 1
A translator() 0 4 1
A inputModel() 0 11 2
A formModel() 0 4 1
1
<?php
2
3
namespace LaravelPlus\Extension\Specs;
4
5
class Factory
6
{
7
    /**
8
     * rule string or array.
9
     *
10
     * @param string $path
11
     *
12
     * @return \LaravelPlus\Extension\Specs\InputSpec
13
     */
14 3
    public function make($path)
15
    {
16 3
        return new InputSpec(app('specs'), app('translator'), $path);
17
    }
18
19
    /**
20
     * Get the specified spec value.
21
     *
22
     * @param string $key
23
     * @param mixed  $default
24
     *
25
     * @return \LaravelPlus\Extension\Repository\NamespacedRepository|string
26
     */
27 2
    function get($key, $default = null)
28
    {
29 2
        return app('specs')->get($key, $default);
30
    }
31
32
    /**
33
     * @param string $namespace
34
     *
35
     * @return \LaravelPlus\Extension\Specs\Translator
36
     */
37 1
    public function translator($namespace)
38
    {
39 1
        return new Translator(app('translator'), $namespace);
40
    }
41
42
    /**
43
     * @param string | \LaravelPlus\Extension\Specs\InputSpec $pathOrSpec
44
     * @param array                                           $in
45
     *
46
     * @return \LaravelPlus\Extension\Specs\InputModel
47
     */
48 1
    public function inputModel($pathOrSpec, array $in = null)
49
    {
50 1
        if (is_string($pathOrSpec)) {
51 1
            $spec = $this->make($pathOrSpec);
52
        }
53
        else {
54 1
            $spec = $pathOrSpec;
55
        }
56
57 1
        return new InputModel($spec, $in);
58
    }
59
60
    /**
61
     * @param string $id
62
     * @param string $path
63
     *
64
     * @return \LaravelPlus\Extension\Specs\FormModel
65
     */
66 1
    public function formModel($id, $path)
67
    {
68 1
        return new FormModel($id, $this->make($path));
69
    }
70
71
}
72