Accounts::validate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace JeroenBoesten\ShopsUnitedLaravel\Modules;
4
5
use JeroenBoesten\ShopsUnitedLaravel\ShopsUnitedLaravel;
6
7
class Accounts extends ShopsUnitedLaravel
8
{
9
    /**
10
     * Check if the API key in the config is valid.
11
     * @return bool
12
     */
13
    public function validate(): bool
14
    {
15
        $data = $this
16
            ->setParams([
17
                'GebruikerId' => config('shops-united-laravel.account-id'),
18
                'Datum' => date('Y-m-d H:i:s'),
19
                'HmacSha256' => hash_hmac('sha256', config('shops-united-laravel.account-id').date('Y-m-d H:i:s'), config('shops-united-laravel.api-key')),
20
            ])
21
            ->setPostUrl('validate_apikey.php')
22
            ->call();
23
24
        return array_get($data, 'valid');
0 ignored issues
show
Deprecated Code introduced by
The function array_get() has been deprecated with message: Arr::get() should be used directly instead. Will be removed in Laravel 6.0.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
25
    }
26
27
    /**
28
     * Checks whether a account with the given email exists or not.
29
     * @param string $email
30
     * @return bool
31
     */
32
    public function exists($email = null): bool
33
    {
34
        $data = $this
35
            ->addQuery([
36
                'GebruikerId' => config('shops-united-laravel.account-id'),
37
                'Email' => $email,
38
                'HmacSha256' => hash_hmac('sha256', config('shops-united-laravel.account-id').$email, config('shops-united-laravel.api-key')),
39
            ])
40
            ->setGetUrl('account_exists.php')
41
            ->call();
42
43
        return array_get($data, 'exists');
0 ignored issues
show
Deprecated Code introduced by
The function array_get() has been deprecated with message: Arr::get() should be used directly instead. Will be removed in Laravel 6.0.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
44
    }
45
}
46