Passed
Push — master ( ec9982...23e9a9 )
by Zing
06:03
created

SampleCollector   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 162
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 91
c 1
b 0
f 0
dl 0
loc 162
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B samples() 0 157 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zing\QueryBuilder\Samples;
6
7
class SampleCollector
8
{
9
    /**
10
     * @return \Zing\QueryBuilder\Samples\Sample[]
11
     */
12
    public function samples(): array
13
    {
14
        return [
15
            new Sample('Basic usage', '', [new CodeSample(
16
                __DIR__ . '/basic/basic.php',
17
                [
18
                    new IOSample(
19
                        '/api/users?search=Harry&status=1,2,3&desc=created_at&per_page=10',
20
                        'select * from "users" where ("name" like "%Harry%") and "status" in ("1", "2", "3") order by "created_at" desc limit 11 offset 0'
21
                    ),
22
                ]
23
            ),
24
            ]),
25
26
            new Sample(
27
                'Search',
28
                '',
29
                [new CodeSample(
30
                    __DIR__ . '/search/search.php',
31
                    [
32
                        new IOSample(
33
                            '/api/users?search=Harry',
34
                            'select * from "users" where ("name" like "%Harry%" or "email" like "%Harry%") limit 16 offset 0'
35
                        ),
36
                    ]
37
                ),
38
                ]
39
            ),
40
41
            (new Sample(
42
                'Search',
43
                'Composite search',
44
                [new CodeSample(
45
                    __DIR__ . '/search/composite_search.php',
46
                    [
47
                        new IOSample(
48
                            '/api/users?search=2021',
49
                            'select * from "users" where ("number" like "%2021%" or ("id" = "2021")) limit 16 offset 0'
50
                        ),
51
                    ]
52
                ),
53
                ]
54
            ))->description('⚠️ The filter with default value is not supported yet.'),
55
            new Sample(
56
                'Filter',
57
                '',
58
                [
59
                    new CodeSample(
60
                        __DIR__ . '/filter/filter_column_contains_property_value.php',
61
                        [
62
                            new IOSample(
63
                                '/api/users?name=Harry',
64
                                'select * from "users" where "name" like "%Harry%" limit 16 offset 0'
65
                            ),
66
                        ]
67
                    ),
68
                    new CodeSample(
69
                        __DIR__ . '/filter/filter_column_equals_to_property_value.php',
70
                        [
71
                            new IOSample(
72
                                '/api/users?status=1,2,3',
73
                                'select * from "users" where "status" in ("1", "2", "3") limit 16 offset 0'
74
                            ),
75
                        ]
76
                    ),
77
                    new CodeSample(
78
                        __DIR__ . '/filter/filter_with_scope_and_default.php',
79
                        [
80
                            new IOSample(
81
                                '/api/users?visible=1',
82
                                'select * from "users" where "is_visible" = true limit 16 offset 0'
83
                            ),
84
                            new IOSample(
85
                                '/api/users',
86
                                'select * from "users" where "is_visible" = true limit 16 offset 0'
87
                            ),
88
                        ]
89
                    ),
90
                ]
91
            ),
92
            (new Sample(
93
                'Filter',
94
                'Typed filter',
95
                [
96
                    new CodeSample(
97
                        __DIR__ . '/filter/filter_orders_with_type_and_value.php',
98
                        [
99
                            new IOSample(
100
                                '/api/users?search_type=number&search_value=2021',
101
                                'select * from "orders" where "number" like "%2021%" limit 16 offset 0'
102
                            ),
103
                        ]
104
                    ),
105
                ]
106
            ))->description('⚠️ The filter with default value is not supported yet.'),
107
            (new Sample(
108
                'Filter',
109
                'Flagged filter',
110
                [
111
                    new CodeSample(
112
                        __DIR__ . '/filter/filter_orders_match_any_filters.php',
113
                        [
114
                            new IOSample(
115
                                '/api/users?number=2021&user_name=Jone',
116
                                'select * from "orders" where (("number" like "%2021%") or (exists (select * from "users" where "orders"."user_id" = "users"."id" and "users"."name" like "%Jone%"))) limit 16 offset 0'
117
                            ),
118
                        ]
119
                    ),
120
                ]
121
            )),
122
            new Sample(
123
                'Filter',
124
                'Cast Input(Skip auto cast)',
125
                [
126
                    new CodeSample(
127
                        __DIR__ . '/filter/cast_value_to_boolean.php',
128
                        [
129
                            new IOSample(
130
                                '/api/users?is_visible=true',
131
                                'select * from "users" where "is_visible" = true limit 16 offset 0'
132
                            ),
133
                        ]
134
                    ),
135
                    new CodeSample(
136
                        __DIR__ . '/filter/cast_value_force_to_string.php',
137
                        [
138
                            new IOSample(
139
                                '/api/orders?content=code,and',
140
                                'select * from "orders" where "content" like "%code,and%" limit 16 offset 0'
141
                            ),
142
                        ]
143
                    ),
144
                ]
145
            ),
146
            new Sample(
147
                'Sort',
148
                '',
149
                [
150
                    new CodeSample(__DIR__ . '/sort/sort_users_by_created_date.php', [
151
                        new IOSample(
152
                            '/api/users?desc=created_date',
153
                            'select * from "orders" order by "created_at" desc limit 16 offset 0'
154
                        ),
155
                    ]),
156
                ]
157
            ),
158
            new Sample(
159
                'Paginator',
160
                '',
161
                [
162
                    new CodeSample(
163
                        __DIR__ . '/paginator/paginate_by_size_per_page.php',
164
                        [new IOSample('/api/users?size=5', 'select * from "users" limit 6 offset 0')]
165
                    ),
166
                    new CodeSample(
167
                        __DIR__ . '/paginator/paginate_by_size_per_page_with_default.php',
168
                        [new IOSample('/api/users?size=', 'select * from "users" limit 6 offset 0')]
169
                    ),
170
                ]
171
            ),
172
        ];
173
    }
174
}
175