Destroy::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Http\Controllers\Api\User;
6
7
use App\Contracts\Http\Responses\ResponseFactory;
8
use App\Models\User;
9
use Illuminate\Contracts\Auth\Guard;
10
use Illuminate\Http\Response;
11
12
final class Destroy
13
{
14
    private ResponseFactory $responseFactory;
15 1
16
    public function __construct(ResponseFactory $responseFactory)
17 1
    {
18 1
        $this->responseFactory = $responseFactory;
19
    }
20 1
21
    public function __invoke(Guard $guard, User $user): Response
22 1
    {
23 1
        /** @var User $authenticatedUser */
24
        $authenticatedUser = $guard->user();
25
26
        if ($user->is($authenticatedUser)) {
27
            return $this->responseFactory->noContent(Response::HTTP_CONFLICT);
28
        }
29
30
        $user->delete();
31
32
        return $this->responseFactory->noContent(Response::HTTP_OK);
33
    }
34
}
35