Test Failed
Push — master ( 7405ac...f937f1 )
by Burak
05:02
created

ContactController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Resources\ContactResource;
6
use App\Interfaces\ContactServiceInterface;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\Auth;
9
10
class ContactController extends Controller
11
{
12
    /**
13
     * @var ContactServiceInterface
14
     */
15
    private ContactServiceInterface $service;
16
17
    /**
18
     * ContactController constructor.
19
     *
20
     * @param ContactServiceInterface $service
21
     */
22
    public function __construct(ContactServiceInterface $service)
23
    {
24
        $this->service = $service;
25
    }
26
27
    /**
28
     * Returns user by id.
29
     *
30
     * @param string $id
31
     * @return ContactResource
32
     */
33
    public function show(string $id)
34
    {
35
        return new ContactResource(
36
            $this->service->contact($id)
37
        );
38
    }
39
40
    /**
41
     * Returns contacts by user.
42
     *
43
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
44
     */
45
    public function index()
46
    {
47
        $user = Auth::user();
48
        return ContactResource::collection($this->service->contacts($user));
0 ignored issues
show
Bug introduced by
It seems like $user can also be of type null; however, parameter $user of App\Interfaces\ContactServiceInterface::contacts() does only seem to accept App\Models\User, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
        return ContactResource::collection($this->service->contacts(/** @scrutinizer ignore-type */ $user));
Loading history...
49
    }
50
}
51