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.

PlatformController::removeConfiguration()   B
last analyzed

Complexity

Conditions 3
Paths 10

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 16
nc 10
nop 2
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Ad;
6
use App\Platform;
7
use App\Platforms\Traits\GetHelperClassFromPlatform;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Crypt;
10
11
class PlatformController extends Controller
12
{
13
    use GetHelperClassFromPlatform;
0 ignored issues
show
Bug introduced by
The trait App\Platforms\Traits\GetHelperClassFromPlatform requires the property $type which is not provided by App\Http\Controllers\PlatformController.
Loading history...
14
15
    /**
16
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
17
     */
18
    public function index()
19
    {
20
        $platforms = Platform::with('ads')->get();
21
        return view('pages.platforms.list', compact('platforms'));
22
    }
23
24
    /**
25
     * @param Platform $platform
26
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
27
     */
28
    public function edit(Platform $platform)
29
    {
30
        $helper = $this->getHelperClassFromPlatform($platform);
31
        $formFields = $helper->getFormFields();
32
33
        return view('pages.platforms.edit', compact('platform', 'formFields'));
34
    }
35
36
    /**
37
     * @param Request $request
38
     * @param Platform $platform
39
     * @return \Illuminate\Http\RedirectResponse
40
     */
41
    public function update(Request $request, Platform $platform)
42
    {
43
        $helper = $this->getHelperClassFromPlatform($platform);
44
        $validatedData = $request->validate($helper->getFormFieldsValidationRules());
45
46
        if (array_key_exists('password', $validatedData)) {
47
            $validatedData['password'] = Crypt::encrypt($validatedData['password']);
48
        }
49
50
        $updatedConfig = array_merge(/** @scrutinizer ignore-type */  $platform->config, $validatedData);
51
        $platform->config = $updatedConfig;
52
        $platform->save();
53
54
        $request->session()->flash('success', 'Plateforme mise à jour');
55
56
        return redirect()->route('platforms.list');
57
    }
58
59
    /**
60
     * @param Request $request
61
     * @param Platform $platform
62
     * @return \Illuminate\Http\RedirectResponse
63
     */
64
    public function removeConfiguration(Request $request, Platform $platform)
65
    {
66
        $adsPublishedOnPlatform = $platform->ads;
67
        $helper = $this->getHelperClassFromPlatform($platform);
68
69
        try {
70
            if (count($adsPublishedOnPlatform) > 0) {
71
                $adsPublishedOnPlatform->each(function(Ad $ad) use ($platform, $helper) {
72
                    $helper->unpublish($ad, $platform);
73
                    $ad->platforms()->detach($platform->id);
74
                });
75
            }
76
77
            $emptyConfig = collect($helper->getFormFields())->reduce(function($emptyConfig, $field) {
78
                $emptyConfig[$field['name']] = '';
79
                return $emptyConfig;
80
            }, []);
81
82
            $platform->config = $emptyConfig;
83
            $platform->save();
84
85
            $request->session()->flash('success', 'Configuration de la plateforme supprimée');
86
        } catch (\Exception $e) {
87
            $request->session()->flash('danger', $e->getMessage());
88
        }
89
90
        return redirect()->route('platforms.list');
91
    }
92
}
93