Issues (85)

app/Http/Controllers/ContactController.php (5 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Requests\ContactStoreRequest;
0 ignored issues
show
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\Http\Request;
10
use Illuminate\Support\Facades\Auth;
11
12
class ContactController extends Controller
13
{
14
    /**
15
     * @var ContactServiceInterface
16
     */
17
    private ContactServiceInterface $service;
18
19
    /**
20
     * @var UserServiceInterface
21
     */
22
    private UserServiceInterface $userService;
23
24
    /**
25
     * ContactController constructor.
26
     *
27
     * @param  ContactServiceInterface  $service
28
     * @param  UserServiceInterface  $userService
29
     */
30
    public function __construct(ContactServiceInterface $service, UserServiceInterface $userService)
31
    {
32
        $this->service = $service;
33
        $this->userService = $userService;
34
    }
35
36
    /**
37
     * Returns user by id.
38
     *
39
     * @param  string  $id
40
     * @return ContactResource
41
     */
42
    public function show(string $id)
43
    {
44
        $user = Auth::user();
45
46
        return new ContactResource(
47
            $this->service->contact($id, $user)
0 ignored issues
show
It seems like $user can also be of type null; however, parameter $user of App\Interfaces\ContactServiceInterface::contact() 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

47
            $this->service->contact($id, /** @scrutinizer ignore-type */ $user)
Loading history...
48
        );
49
    }
50
51
    /**
52
     * Returns contacts by user.
53
     *
54
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
55
     */
56
    public function index()
57
    {
58
        $user = Auth::user();
59
60
        return ContactResource::collection($this->service->contacts($user));
0 ignored issues
show
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

60
        return ContactResource::collection($this->service->contacts(/** @scrutinizer ignore-type */ $user));
Loading history...
61
    }
62
63
    /**
64
     * Store a contact.
65
     *
66
     * @param  string  $user_id
67
     * @return ContactResource
68
     */
69
    public function store(string $user_id): ContactResource
70
    {
71
        $user = Auth::user();
72
        $contact = $this->userService->find($user_id);
73
74
        return new ContactResource(
75
            $this->service->addContact($user, $contact)
0 ignored issues
show
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

75
            $this->service->addContact(/** @scrutinizer ignore-type */ $user, $contact)
Loading history...
76
        );
77
    }
78
79
    /**
80
     * Redirects to URI.
81
     *
82
     * @param  Request  $request
83
     * @param  string  $id
84
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
85
     */
86
    public function redirect(Request $request, string $id)
87
    {
88
        $user = Auth::user();
89
        $contact = $this->service->contact($id, $user);
0 ignored issues
show
It seems like $user can also be of type null; however, parameter $user of App\Interfaces\ContactServiceInterface::contact() 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

89
        $contact = $this->service->contact($id, /** @scrutinizer ignore-type */ $user);
Loading history...
90
91
        if (null === $contact) {
92
            abort(404);
93
        }
94
95
        $URI = $request->get('redirect_uri', config('app.uri'));
96
97
        return redirect($URI ?? '/');
98
    }
99
}
100