Completed
Push — master ( cb1113...b09b3a )
by Maarten
16s queued 11s
created

RelationsController::createOptional()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Mtolhuys\LaravelSchematics\Http\Controllers;
4
5
use Illuminate\Contracts\Routing\ResponseFactory;
6
use Mtolhuys\LaravelSchematics\Actions\Migration\CreateRelationMigrationAction;
7
use Mtolhuys\LaravelSchematics\Actions\Relation\DeleteRelationAction;
8
use Mtolhuys\LaravelSchematics\Actions\Relation\CreateRelationAction;
9
use Mtolhuys\LaravelSchematics\Actions\Migration\DeleteMigrationAction;
10
use Mtolhuys\LaravelSchematics\Http\Requests\CreateRelationRequest;
11
use Mtolhuys\LaravelSchematics\Http\Requests\DeleteRelationRequest;
12
use Symfony\Component\HttpFoundation\Response;
13
use Illuminate\Support\Facades\Cache;
14
use Illuminate\Routing\Controller;
15
use ReflectionException;
16
17
class RelationsController extends Controller
18
{
19
    /**
20
     * @param CreateRelationRequest $request
21
     * @return array
22
     * @throws ReflectionException
23
     */
24
    public function create(CreateRelationRequest $request)
25
    {
26
        Cache::forget('schematics');
27
28
        $result = (new CreateRelationAction())->execute($request);
0 ignored issues
show
Documentation introduced by
$request is of type object<Mtolhuys\LaravelS...\CreateRelationRequest>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
29
        (new CreateRelationMigrationAction())->execute($request);
30
31
        $relation = $request->all();
32
        $relation['method']['file'] = $result->file;
33
        $relation['method']['line'] = $result->line;
34
35
        return $relation;
36
    }
37
38
    /**
39
     * @param DeleteRelationRequest $request
40
     * @return ResponseFactory|\Illuminate\Http\Response|Response
41
     */
42
    public function delete(DeleteRelationRequest $request)
43
    {
44
        Cache::forget('schematics');
45
46
        (new DeleteRelationAction())->execute($request);
47
        (new DeleteMigrationAction())->execute($request);
48
49
        return response('Relation removed', 200);
50
    }
51
}
52