• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pixelpeter / laravel-genderize-api-client / 16567649557

28 Jul 2025 11:20AM UTC coverage: 100.0%. Remained the same
16567649557

Pull #34

github

web-flow
Merge 88ea5c63d into 8a0d5467f
Pull Request #34: Bump aglipanci/laravel-pint-action from 2.5 to 2.6

92 of 92 relevant lines covered (100.0%)

43.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/GenderizeClient.php
1
<?php
2

3
namespace Pixelpeter\Genderize;
4

5
use Pixelpeter\Genderize\Models\GenderizeResponse;
6
use Unirest\Request;
7

8
class GenderizeClient
9
{
10
    /**
11
     * @var array Holds one or more names to check
12
     */
13
    protected $names;
14

15
    /**
16
     * @var string | null The language used for the check
17
     */
18
    protected $lang;
19

20
    /**
21
     * @var string | null The country used for the check
22
     */
23
    protected $country;
24

25
    /**
26
     * @var string The api key used for the request
27
     */
28
    protected $apikey;
29

30
    /**
31
     * @var \Unirest\Request
32
     */
33
    protected $request;
34

35
    /**
36
     * @const API_URL The URL of the api endpoint
37
     */
38
    const API_URL = 'https://api.genderize.io';
39

40
    /**
41
     * Create new instance of Pixelpeter\Genderize\GenderizeClient
42
     */
43
    public function __construct(Request $request)
80✔
44
    {
45
        $this->apikey = config('genderize.apikey');
80✔
46
        $this->request = $request;
80✔
47
    }
48

49
    /**
50
     * Fluent setter for names given as string
51
     *
52
     * @param  string | array  $name
53
     * @return $this|GenderizeClient
54
     */
55
    public function name($name = '')
70✔
56
    {
57
        if (is_array($name)) {
70✔
58
            return $this->names($name);
10✔
59
        }
60

61
        $this->names = [$name];
60✔
62

63
        return $this;
60✔
64
    }
65

66
    /**
67
     * Fluent setter for names given as array
68
     *
69
     * @return $this
70
     */
71
    public function names(array $names)
20✔
72
    {
73
        $this->names = $names;
20✔
74

75
        return $this;
20✔
76
    }
77

78
    /**
79
     * Fluent setter for language
80
     *
81
     * @param  string | null  $lang
82
     * @return $this
83
     */
84
    public function lang($lang = null)
20✔
85
    {
86
        $this->lang = $lang;
20✔
87

88
        return $this;
20✔
89
    }
90

91
    /**
92
     * Fluent setter for country
93
     *
94
     * @param  string | null  $country
95
     * @return $this
96
     */
97
    public function country($country = null)
20✔
98
    {
99
        $this->country = $country;
20✔
100

101
        return $this;
20✔
102
    }
103

104
    /**
105
     * Send the request
106
     *
107
     * @return GenderizeResponse
108
     */
109
    public function get()
10✔
110
    {
111
        $headers = ['Accept' => 'application/json'];
10✔
112

113
        $response = $this->request->get(self::API_URL, $headers, $this->buildQuery());
10✔
114

115
        return new GenderizeResponse($response);
10✔
116
    }
117

118
    /**
119
     * Build the query
120
     *
121
     * @return array
122
     */
123
    protected function buildQuery()
10✔
124
    {
125
        $query = [
10✔
126
            'name' => $this->names,
10✔
127
            'country_id' => $this->country,
10✔
128
            'language_id' => $this->lang,
10✔
129
            'apikey' => $this->apikey,
10✔
130
        ];
10✔
131

132
        return array_filter($query);
10✔
133
    }
134
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc