FamilySearchController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A searchPerson() 0 38 2
A __construct() 0 3 1
1
<?php
2
3
namespace App\Http\Controllers\FamilySearch;
4
5
use App\Http\Controllers\Controller;
6
use Illuminate\Http\Request;
7
8
class FamilySearchController extends Controller
9
{
10
    private $familySearchRecordsApi;
11
12
    public function __construct()
13
    {
14
        $this->familySearchRecordsApi = config('services.familysearch.api.records');
15
    }
16
17
    public function searchPerson(Request $request)
18
    {
19
        $apiToken = $request->apiToken;
20
21
        $client = new \GuzzleHttp\Client();
22
23
        try {
24
            $response = $client->request('GET', $this->familySearchRecordsApi.'/search', [
25
                'headers' => [
26
                    'Authorization' => 'Bearer '.$apiToken,
27
                    'Accept' => 'application/x-gedcomx-atom+json',
28
                ],
29
                'query' => [
30
                    'q.givenName' => $request->givenName,
31
                    'q.surname' => $request->surname,
32
                    'q.sex' => $request->sex,
33
                    'q.deathLikeDate.from' => $request->deathLikeDate_from,
34
                    'q.deathLikeDate.to' => $request->deathLikeDate_to,
35
                    'q.fatherGivenName' => $request->fatherGivenName,
36
                    'q.fatherSurname' => $request->fatherSurname,
37
                    'q.motherGivenName' => $request->motherGivenName,
38
                    'q.motherSurname' => $request->motherSurname,
39
                    'q.motherBirthLikePlace' => $request->motherBirthLikePlace,
40
                    'offset' => $request->offest,
41
                    'count' => $request->count,
42
                ],
43
            ]);
44
45
            $statusCode = $response->getStatusCode();
0 ignored issues
show
Unused Code introduced by
The assignment to $statusCode is dead and can be removed.
Loading history...
46
            $content = $response->getBody();
0 ignored issues
show
Unused Code introduced by
The assignment to $content is dead and can be removed.
Loading history...
47
            $result = json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);
48
49
            return response()->json($result);
50
        } catch (\GuzzleHttp\Exception\ClientException $e) {
51
            $response = $e->getResponse();
52
            $result = json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);
53
54
            return response()->json($result);
55
        }
56
    }
57
}
58