Passed
Pull Request — master (#27)
by Burak
05:50
created

ContactController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 40
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A show() 0 4 1
A __construct() 0 3 1
A index() 0 5 1
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 2
    public function __construct(ContactServiceInterface $service)
23
    {
24 2
        $this->service = $service;
25 2
    }
26
27
    /**
28
     * Returns user by id.
29
     *
30
     * @param string $id
31
     * @return ContactResource
32
     */
33 1
    public function show(string $id)
34
    {
35 1
        return new ContactResource(
36 1
            $this->service->contact($id)
37
        );
38
    }
39
40
    /**
41
     * Returns contacts by user.
42
     *
43
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
44
     */
45 1
    public function index()
46
    {
47 1
        $user = Auth::user();
48
49 1
        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

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