ApiKeysController::store()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace TaskManager\Http\Controllers;
4
5
use TaskManager\Services\ApiService;
6
7
class ApiKeysController extends Controller
8
{
9
    protected $api;
10
    function __construct(ApiService $api)
11
    {
12
        $this->api = $api;
13
    }
14
15
    /**
16
     * Store a newly created resource in storage.
17
     * @return \Illuminate\Http\RedirectResponse
18
     * @internal param Request $request
19
     */
20
    public function store()
21
    {
22
        if(!$this->api->exists()) {
23
            $this->api->generateKey();
24
            session()->flash('suc_key', 'API key added successfully');
25
            return redirect()->back();
26
        }
27
        return redirect()->back()->withErrors('Key already exists');
28
    }
29
}
30