TDK   A
last analyzed

Complexity

Total Complexity 35

Size/Duplication

Total Lines 466
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 76
c 2
b 1
f 0
dl 0
loc 466
rs 9.6
wmc 35

34 Methods

Rating   Name   Duplication   Size   Complexity  
A comparativeDialectsDictionaryByAzerbaijaniTurkish() 0 3 1
A searchByFrequentlyConfusedWordsGuide() 0 6 1
A suggestions() 0 5 1
A personByManMeaning() 0 3 1
A comparativeDialectsDictionaryByBashkirTurkish() 0 3 1
A comparativeDialectsDictionaryByTatarTurkish() 0 3 1
A searchByCompilationDictionary() 0 5 1
A personByMeaning() 0 3 1
A __construct() 0 5 1
A sound() 0 3 1
A comparativeDialectsDictionaryByRussian() 0 3 1
A personByWomanMeaning() 0 3 1
A comparativeDialectsDictionaryByKyrgyzTurkish() 0 3 1
A personByWomanName() 0 3 1
A searchByProverbDictionary() 0 5 1
A person() 0 7 1
A comparativeDialectsDictionaryByUzbekTurkish() 0 3 1
A comparativeDialectsDictionary() 0 5 2
A searchByForeignWordProvisionsGuide() 0 6 1
A personByManName() 0 3 1
A spelling() 0 5 1
A searchByCurrentTurkishDictionary() 0 5 1
A comparativeDialectsDictionaryByUighurTurkish() 0 3 1
A searchByNursingTermsDictionary() 0 5 1
A comparativeDialectsDictionaryByTurkmenTurkish() 0 3 1
A searchByInternationalMetrologyDictionary() 0 5 1
A searchByMedicineAndPharmacyTermsDictionary() 0 5 1
A personByName() 0 3 1
A searchByScienceAndArtTermsDictionary() 0 6 1
A searchByScanDictionary() 0 5 1
A comparativeDialectsDictionaryByKazakhTurkish() 0 3 1
A searchByWesternOriginDictionary() 0 5 1
A comparativeDialectsDictionaryByTurkeyTurkish() 0 3 1
A searchByCommonMistakesGuide() 0 6 1
1
<?php
2
3
namespace TheCaliskan\TDK;
4
5
use Illuminate\Contracts\Foundation\Application;
6
use Illuminate\Http\Client\PendingRequest;
7
use Illuminate\Http\Client\RequestException;
8
use Illuminate\Support\Facades\Http;
9
10
class TDK
11
{
12
    /**
13
     * The application instance.
14
     *
15
     * @var Application
16
     */
17
    protected $app;
18
19
    /**
20
     * The Laravel HTTP Client.
21
     *
22
     * @var PendingRequest
23
     */
24
    protected $client;
25
26
    /**
27
     * Create a new Payment instance.
28
     *
29
     * @param Application $app
30
     *
31
     * @return void
32
     */
33
    public function __construct(Application $app)
34
    {
35
        $this->app = $app;
36
37
        $this->client = Http::baseUrl('https://sozluk.gov.tr');
38
    }
39
40
    /**
41
     * @param string $word
42
     *
43
     * @throws TDKException|RequestException
44
     *
45
     * @return array
46
     */
47
    public function searchByCurrentTurkishDictionary(string $word)
48
    {
49
        return $this->client->get('/gts', [
50
            'ara' => $word,
51
        ])->tdkThrow()->json();
52
    }
53
54
    /**
55
     * @param string $word
56
     *
57
     * @throws TDKException|RequestException
58
     *
59
     * @return array
60
     */
61
    public function searchByWesternOriginDictionary(string $word)
62
    {
63
        return $this->client->get('/bati', [
64
            'ara' => $word,
65
        ])->tdkThrow()->json();
66
    }
67
68
    /**
69
     * @param string $word
70
     *
71
     * @throws TDKException|RequestException
72
     *
73
     * @return array
74
     */
75
    public function searchByScanDictionary(string $word)
76
    {
77
        return $this->client->get('/tarama', [
78
            'ara' => $word,
79
        ])->tdkThrow()->json();
80
    }
81
82
    /**
83
     * @param string $word
84
     *
85
     * @throws TDKException|RequestException
86
     *
87
     * @return array
88
     */
89
    public function searchByCompilationDictionary(string $word)
90
    {
91
        return $this->client->get('/derleme', [
92
            'ara' => $word,
93
        ])->tdkThrow()->json();
94
    }
95
96
    /**
97
     * @param string $word
98
     *
99
     * @throws TDKException|RequestException
100
     *
101
     * @return array
102
     */
103
    public function searchByProverbDictionary(string $word)
104
    {
105
        return $this->client->get('/atasozu', [
106
            'ara' => $word,
107
        ])->tdkThrow()->json();
108
    }
109
110
    /**
111
     * @param string $word
112
     *
113
     * @throws TDKException|RequestException
114
     *
115
     * @return array
116
     */
117
    public function searchByForeignWordProvisionsGuide(string $word)
118
    {
119
        return $this->client->get('/kilavuz', [
120
            'ara' => $word,
121
            'prm' => 'ysk',
122
        ])->tdkThrow()->json();
123
    }
124
125
    /**
126
     * @param string $word
127
     *
128
     * @throws TDKException|RequestException
129
     *
130
     * @return array
131
     */
132
    public function searchByFrequentlyConfusedWordsGuide(string $word)
133
    {
134
        return $this->client->get('/kilavuz', [
135
            'ara' => $word,
136
            'prm' => 'sks',
137
        ])->tdkThrow()->json();
138
    }
139
140
    /**
141
     * @param string $word
142
     *
143
     * @throws TDKException|RequestException
144
     *
145
     * @return array
146
     */
147
    public function searchByCommonMistakesGuide(string $word)
148
    {
149
        return $this->client->get('/kilavuz', [
150
            'ara' => $word,
151
            'prm' => 'syyd',
152
        ])->tdkThrow()->json();
153
    }
154
155
    /**
156
     * @param string $word
157
     * @param string $science
158
     *
159
     * @throws TDKException|RequestException
160
     *
161
     * @return array
162
     */
163
    public function searchByScienceAndArtTermsDictionary(string $word, string $science = 'tümü')
164
    {
165
        return $this->client->get('/terim', [
166
            'ara'     => $word,
167
            'eser_ad' => $science,
168
        ])->tdkThrow()->json();
169
    }
170
171
    /**
172
     * @param string $word
173
     *
174
     * @throws TDKException|RequestException
175
     *
176
     * @return array
177
     */
178
    public function searchByNursingTermsDictionary(string $word)
179
    {
180
        return $this->client->get('/hemsirelik', [
181
            'ara' => $word,
182
        ])->tdkThrow()->json();
183
    }
184
185
    /**
186
     * @param string $word
187
     *
188
     * @throws TDKException|RequestException
189
     *
190
     * @return array
191
     */
192
    public function searchByMedicineAndPharmacyTermsDictionary(string $word)
193
    {
194
        return $this->client->get('/eczacilik', [
195
            'ara' => $word,
196
        ])->tdkThrow()->json();
197
    }
198
199
    /**
200
     * @param string $word
201
     *
202
     * @throws TDKException|RequestException
203
     *
204
     * @return array
205
     */
206
    public function searchByInternationalMetrologyDictionary(string $word)
207
    {
208
        return $this->client->get('/metroloji', [
209
            'ara' => $word,
210
        ])->tdkThrow()->json();
211
    }
212
213
    /**
214
     * @param string $word
215
     * @param int    $by
216
     * @param int    $gender
217
     *
218
     * @throws TDKException|RequestException
219
     *
220
     * @return array
221
     */
222
    public function person(string $word, int $by, int $gender)
223
    {
224
        return $this->client->get('/adlar', [
225
            'ara'  => $word,
226
            'gore' => $by,
227
            'cins' => $gender,
228
        ])->tdkThrow()->json();
229
    }
230
231
    /**
232
     * @param string $word
233
     *
234
     * @throws TDKException|RequestException
235
     *
236
     * @return array
237
     */
238
    public function personByName(string $word)
239
    {
240
        return $this->person($word, 1, 4);
241
    }
242
243
    /**
244
     * @param string $word
245
     *
246
     * @throws TDKException|RequestException
247
     *
248
     * @return array
249
     */
250
    public function personByWomanName(string $word)
251
    {
252
        return $this->person($word, 1, 1);
253
    }
254
255
    /**
256
     * @param string $word
257
     *
258
     * @throws TDKException|RequestException
259
     *
260
     * @return array
261
     */
262
    public function personByManName(string $word)
263
    {
264
        return $this->person($word, 1, 2);
265
    }
266
267
    /**
268
     * @param string $word
269
     *
270
     * @throws TDKException|RequestException
271
     *
272
     * @return array
273
     */
274
    public function personByMeaning(string $word)
275
    {
276
        return $this->person($word, 2, 4);
277
    }
278
279
    /**
280
     * @param string $word
281
     *
282
     * @throws TDKException|RequestException
283
     *
284
     * @return array
285
     */
286
    public function personByWomanMeaning(string $word)
287
    {
288
        return $this->person($word, 2, 1);
289
    }
290
291
    /**
292
     * @param string $word
293
     *
294
     * @throws TDKException|RequestException
295
     *
296
     * @return array
297
     */
298
    public function personByManMeaning(string $word)
299
    {
300
        return $this->person($word, 2, 2);
301
    }
302
303
    /**
304
     * @param string $word
305
     * @param int    $dialect
306
     *
307
     * @throws TDKException|RequestException
308
     *
309
     * @return array
310
     */
311
    public function comparativeDialectsDictionary(string $word, int $dialect = 0)
312
    {
313
        return $this->client->get('/lehceler', [
314
            'ara' => $word,
315
        ] + ($dialect ? ['lehce' => $dialect] : []))->tdkThrow()->json();
316
    }
317
318
    /**
319
     * @param string $word
320
     *
321
     * @throws TDKException|RequestException
322
     *
323
     * @return array
324
     */
325
    public function comparativeDialectsDictionaryByTurkeyTurkish(string $word)
326
    {
327
        return $this->comparativeDialectsDictionary($word, 1);
328
    }
329
330
    /**
331
     * @param string $word
332
     *
333
     * @throws TDKException|RequestException
334
     *
335
     * @return array
336
     */
337
    public function comparativeDialectsDictionaryByKazakhTurkish(string $word)
338
    {
339
        return $this->comparativeDialectsDictionary($word, 2);
340
    }
341
342
    /**
343
     * @param string $word
344
     *
345
     * @throws TDKException|RequestException
346
     *
347
     * @return array
348
     */
349
    public function comparativeDialectsDictionaryByUzbekTurkish(string $word)
350
    {
351
        return $this->comparativeDialectsDictionary($word, 3);
352
    }
353
354
    /**
355
     * @param string $word
356
     *
357
     * @throws TDKException|RequestException
358
     *
359
     * @return array
360
     */
361
    public function comparativeDialectsDictionaryByAzerbaijaniTurkish(string $word)
362
    {
363
        return $this->comparativeDialectsDictionary($word, 4);
364
    }
365
366
    /**
367
     * @param string $word
368
     *
369
     * @throws TDKException|RequestException
370
     *
371
     * @return array
372
     */
373
    public function comparativeDialectsDictionaryByUighurTurkish(string $word)
374
    {
375
        return $this->comparativeDialectsDictionary($word, 5);
376
    }
377
378
    /**
379
     * @param string $word
380
     *
381
     * @throws TDKException|RequestException
382
     *
383
     * @return array
384
     */
385
    public function comparativeDialectsDictionaryByBashkirTurkish(string $word)
386
    {
387
        return $this->comparativeDialectsDictionary($word, 6);
388
    }
389
390
    /**
391
     * @param string $word
392
     *
393
     * @throws TDKException|RequestException
394
     *
395
     * @return array
396
     */
397
    public function comparativeDialectsDictionaryByTatarTurkish(string $word)
398
    {
399
        return $this->comparativeDialectsDictionary($word, 7);
400
    }
401
402
    /**
403
     * @param string $word
404
     *
405
     * @throws TDKException|RequestException
406
     *
407
     * @return array
408
     */
409
    public function comparativeDialectsDictionaryByTurkmenTurkish(string $word)
410
    {
411
        return $this->comparativeDialectsDictionary($word, 8);
412
    }
413
414
    /**
415
     * @param string $word
416
     *
417
     * @throws TDKException|RequestException
418
     *
419
     * @return array
420
     */
421
    public function comparativeDialectsDictionaryByKyrgyzTurkish(string $word)
422
    {
423
        return $this->comparativeDialectsDictionary($word, 9);
424
    }
425
426
    /**
427
     * @param string $word
428
     *
429
     * @throws TDKException|RequestException
430
     *
431
     * @return array
432
     */
433
    public function comparativeDialectsDictionaryByRussian(string $word)
434
    {
435
        return $this->comparativeDialectsDictionary($word, 10);
436
    }
437
438
    /**
439
     * @param string $word
440
     *
441
     * @throws TDKException|RequestException
442
     *
443
     * @return array
444
     */
445
    public function suggestions(string $word)
446
    {
447
        return $this->client->get('/oneri', [
448
            'soz' => $word,
449
        ])->tdkThrow()->json();
450
    }
451
452
    /**
453
     * @param string $word
454
     *
455
     * @throws TDKException|RequestException
456
     *
457
     * @return array
458
     */
459
    public function spelling(string $word)
460
    {
461
        return $this->client->get('/yazim', [
462
            'ara' => $word,
463
        ])->tdkThrow()->json();
464
    }
465
466
    /**
467
     * @param string $soundID
468
     *
469
     * @throws RequestException
470
     *
471
     * @return string
472
     */
473
    public function sound(string $soundID)
474
    {
475
        return $this->client->get("/ses/$soundID.wav")->throw()->body();
476
    }
477
}
478