Completed
Push — master ( 0d5c20...3309bb )
by Changwan
09:19
created

functions.php ➔ validator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Foundation
3
{
4
    use function Wandu\DI\container;
5
6
    /**
7
     * @deprecated use function Wandu\DI\container
8
     * @return \Wandu\DI\ContainerInterface
9
     */
10
    function app()
11
    {
12
        return container();
13
    }
14
15
    /**
16
     * @param string $name
17
     * @param mixed $default
18
     * @return mixed
19
     */
20
    function config($name, $default = null)
21
    {
22 1
        return container()->get('config')->get($name, $default);
23
    }
24
25
    /**
26
     * @deprecated
27
     * @param string|array $path
28
     * @return string|array
29
     */
30
    function path($path)
31
    {
32
        if (is_array($path)) {
33
            return array_map(function ($path) {
34
                return path($path);
35
            }, $path);
36
        }
37
        if ($path[0] !== '/' && container()->has('base_path')) {
38
            return container()->get('base_path') . '/' . $path;
39
        }
40
        return $path;
41
    }
42
}
43
44
namespace Wandu\View
45
{
46
    use Wandu\View\Contracts\RenderInterface;
0 ignored issues
show
Coding Style introduced by
USE declarations must go after the first namespace declaration
Loading history...
47
    use function Wandu\DI\container;
0 ignored issues
show
Coding Style introduced by
USE declarations must go after the first namespace declaration
Loading history...
48
49
    /**
50
     * @param string $template
51
     * @param array $attributes
52
     * @param string $basePath
53
     * @return string
54
     */
55
    function render($template, array $attributes = [], $basePath = null)
56
    {
57
        return container()->get(RenderInterface::class)->render($template, $attributes, $basePath);
58
    }
59
}
60
61
namespace Wandu\Router
62
{
63
    use function Wandu\DI\container;
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
USE declarations must go after the first namespace declaration
Loading history...
64
65
    /**
66
     * @return \Wandu\Router\Dispatcher
67
     */
68
    function dispatcher()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
69
    {
70
        return container()->get(Dispatcher::class);
71
    }
72
    
73
    /**
74
     * @param string $name
75
     * @param array $attributes
76
     * @return string
77
     */
78
    function route(string $name, array $attributes = [])
79
    {
80
        return dispatcher()->getPath($name, $attributes);
81
    }
82
}
83
84
namespace Wandu\Validator
85
{
86
    use Wandu\Validator\Contracts\Tester;
0 ignored issues
show
Coding Style introduced by
USE declarations must go after the first namespace declaration
Loading history...
87
    use function Wandu\DI\container;
0 ignored issues
show
Coding Style introduced by
USE declarations must go after the first namespace declaration
Loading history...
88
89
    /**
90
     * @param string $tester
91
     * @param array $arguments
92
     * @return \Wandu\Validator\Contracts\Tester
93
     */
94
    function tester(string $tester, array $arguments = []): Tester
95
    {
96
        $factory = container()->get(TesterFactory::class);
97
        if (count($arguments)) {
98
            return $factory->create($tester, $arguments);
99
        }
100
        return $factory->parse($tester);
101
    }
102
103
    /**
104
     * @param string|\Wandu\Validator\Contracts\Rule $rule
105
     * @return \Wandu\Validator\Validator
106
     */
107
    function validator($rule): Validator
108
    {
109
        return container()->get(ValidatorFactory::class)->create($rule);
110
    }
111
}
112