Users::getUser()   A
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 3
nop 2
dl 0
loc 14
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Osnova\Services\Users;
4
5
use GuzzleHttp\Exception\RequestException;
6
use Osnova\OsnovaResource;
7
use Osnova\Services\AbstractService;
8
9
class Users extends AbstractService
10
{
11
    /**
12
     * Get user by the given ID.
13
     *
14
     * @param integer        $id       User ID.
15
     * @param OsnovaResource $resource = null Osnova resource that will be bound to entry.
16
     *
17
     * @return User|null
18
     */
19
    public function getUser($id, OsnovaResource $resource = null)
20
    {
21
        try {
22
            $response = $this->getApiProvider()->getClient()->request('GET', 'users/'.$id);
23
24
            return $this->getEntitiesBuilder(User::class)
25
                ->fromResponse($response)
26
                ->with($this->getApiProvider(), $resource)
27
                ->item();
28
        } catch (RequestException $e) {
29
            //
30
        }
31
32
        return [];
0 ignored issues
show
Bug Best Practice introduced by
The expression return array() returns the type array which is incompatible with the documented return type Osnova\Services\Users\User|null.
Loading history...
33
    }
34
}
35