GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — new (#864)
by Dave
07:45
created

ManipulatesRequestRelations   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareRequestToBeCopied() 0 11 4
A makeCopyOfRelations() 0 13 2
A copyAfterSave() 0 5 1
1
<?php
2
3
namespace SleepingOwl\Admin\Form\Related;
4
5
use Illuminate\Http\Request;
6
7
trait ManipulatesRequestRelations
8
{
9
    /**
10
     * @var bool
11
     */
12
    protected $copyAfterSave = false;
13
14
    /**
15
     * Marks relations to be able to be copied after form saving.
16
     *
17
     * @return $this
18
     */
19
    public function copyAfterSave()
20
    {
21
        $this->copyAfterSave = true;
22
23
        return $this;
24
    }
25
26
    /**
27
     * Removes relation from request when it's in save_and_create mode.
28
     *
29
     * @param \Illuminate\Http\Request $request
30
     *
31
     * @return \Illuminate\Http\Request
32
     */
33
    protected function prepareRequestToBeCopied(Request $request)
34
    {
35
        $remove = [];
36
        if ($request->method() === 'POST' && $request->input('next_action') === 'save_and_create') {
37
            if (! $this->copyAfterSave) {
38
                $remove[] = $this->relationName;
39
            }
40
            $this->makeCopyOfRelations($request);
41
        }
42
43
        return $request->replace($request->except($remove));
44
    }
45
46
    /**
47
     * Creates a copy of form relations.
48
     *
49
     * @param \Illuminate\Http\Request $request
50
     */
51
    protected function makeCopyOfRelations(\Illuminate\Http\Request $request)
52
    {
53
        $newData = [];
54
        $data = $request->input($this->relationName, []);
55
56
        $counter = 1;
57
58
        foreach ($data as $key => $values) {
59
            $newData["new_{$counter}"] = $values;
60
            $counter++;
61
        }
62
63
        $request->merge([$this->relationName => $newData]);
64
    }
65
}
66