Test Failed
Push — master ( 531d97...f6cf4d )
by Burak
08:08
created

ContactController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Requests\ContactStoreRequest;
0 ignored issues
show
Bug introduced by
The type App\Http\Requests\ContactStoreRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use App\Http\Resources\ContactResource;
7
use App\Interfaces\ContactServiceInterface;
8
use App\Interfaces\UserServiceInterface;
9
use Illuminate\Support\Facades\Auth;
10
11
class ContactController extends Controller
12
{
13
    /**
14
     * @var ContactServiceInterface
15
     */
16
    private ContactServiceInterface $service;
17
18
    /**
19
     * @var UserServiceInterface
20
     */
21
    private UserServiceInterface $userService;
22
23
    /**
24
     * ContactController constructor.
25
     *
26
     * @param ContactServiceInterface $service
27
     * @param UserServiceInterface $userService
28
     */
29 3
    public function __construct(ContactServiceInterface $service, UserServiceInterface $userService)
30
    {
31 3
        $this->service = $service;
32 3
        $this->userService = $userService;
33 3
    }
34
35
    /**
36
     * Returns user by id.
37
     *
38
     * @param string $id
39
     * @return ContactResource
40
     */
41 1
    public function show(string $id)
42
    {
43 1
        return new ContactResource(
44 1
            $this->service->contact($id)
45
        );
46
    }
47
48
    /**
49
     * Returns contacts by user.
50
     *
51
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
52
     */
53 1
    public function index()
54
    {
55 1
        $user = Auth::user();
56
57 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

57
        return ContactResource::collection($this->service->contacts(/** @scrutinizer ignore-type */ $user));
Loading history...
58
    }
59
60
    /**
61
     * Store a contact.
62
     *
63
     * @param string $user_id
64
     * @return ContactResource
65
     */
66 1
    public function store(string $user_id): ContactResource
67
    {
68 1
        $user = Auth::user();
69 1
        $contact = $this->userService->find($user_id);
70
71 1
        return new ContactResource(
72 1
            $this->service->addContact($user, $contact)
0 ignored issues
show
Bug introduced by
It seems like $user can also be of type null; however, parameter $user of App\Interfaces\ContactSe...Interface::addContact() 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

72
            $this->service->addContact(/** @scrutinizer ignore-type */ $user, $contact)
Loading history...
73
        );
74
    }
75
}
76