QuoteController::destroy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
ccs 0
cts 2
cp 0
crap 2
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Helpers\Helper;
6
use App\Http\Requests\QuoteSearchRequest;
7
use App\Http\Requests\QuoteStoreRequest;
8
use App\Models\Quote;
9
use App\Services\QuoteService;
10
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
11
12
class QuoteController extends Controller
13
{
14
    private QuoteService $quoteService;
15
16
    public function __construct(
17
        QuoteService $quoteService
18
    ) {
19
        $this->quoteService = $quoteService;
20
    }
21
22
23
    /**
24
     * Display a listing of the resource.
25
     *
26
     * @param \App\Http\Requests\QuoteSearchRequest $request
27
     *
28
     * @return \Illuminate\Contracts\View\View
29
     */
30
    public function index(QuoteSearchRequest $request)
31
    {
32
        $searchParameters = Helper::getSearchParameters($request, Quote::SEARCH_PARAMETERS);
33
34
        $quotes = $this->quoteService->getQuotes(20, $searchParameters);
35
        $statuses = Quote::PUBLISHING_STATUS;
36
        $showWhereOptions = Quote::SHOW_WHERE_OPTIONS;
37
38
        return view('quotes.index', [
39
            'quotes' => $quotes,
40
            'searchParameters' => $searchParameters,
41
            'statuses' => $statuses,
42
            'showWhereOptions' => $showWhereOptions,
43
        ]);
44
    }
45
46
    /**
47
     * Show the form for creating a new resource.
48
     *
49
     * @return \Illuminate\Contracts\View\View
50
     */
51
    public function create()
52
    {
53
        $countriesAvailableForTranslations = LaravelLocalization::getSupportedLocales();
54
        return view('quotes.create', [
55
            'countriesAvailableForTranslations' => $countriesAvailableForTranslations,
56
        ]);
57
    }
58
59
    /**
60
     * Store a newly created resource in storage.
61
     *
62
     * @param \App\Http\Requests\QuoteStoreRequest $request
63
     *
64
     * @return \Illuminate\Http\RedirectResponse
65
     */
66
    public function store(QuoteStoreRequest $request)
67
    {
68
        $quote = $this->quoteService->createQuote($request);
0 ignored issues
show
Unused Code introduced by
The assignment to $quote is dead and can be removed.
Loading history...
69
70
        return redirect()->route('quotes.index')
71
            ->with('success', 'Quote created successfully');
72
    }
73
74
    /**
75
     * Show the form for editing the specified resource.
76
     *
77
     * @param int $quoteId
78
     *
79
     * @return \Illuminate\Contracts\View\View
80
     */
81
    public function edit(int $quoteId)
82
    {
83
        $quote = $this->quoteService->getById($quoteId);
84
        $countriesAvailableForTranslations = LaravelLocalization::getSupportedLocales();
85
86
        return view('quotes.edit', [
87
            'quote' => $quote,
88
            'countriesAvailableForTranslations' => $countriesAvailableForTranslations,
89
        ]);
90
    }
91
92
    /**
93
     * Update the specified resource in storage.
94
     *
95
     * @param \App\Http\Requests\QuoteStoreRequest $request
96
     * @param int $quoteId
97
     *
98
     * @return \Illuminate\Http\RedirectResponse
99
     */
100
    public function update(QuoteStoreRequest $request, int $quoteId)
101
    {
102
        $quote = $this->quoteService->updateQuote($request, $quoteId);
0 ignored issues
show
Unused Code introduced by
The assignment to $quote is dead and can be removed.
Loading history...
103
104
        return redirect()->route('quotes.index')
105
            ->with('success', 'Quote updated successfully');
106
    }
107
108
    /**
109
     * Remove the specified resource from storage.
110
     *
111
     * @param int $quoteId
112
     *
113
     * @return \Illuminate\Http\RedirectResponse
114
     */
115
    public function destroy(int $quoteId)
116
    {
117
        $this->quoteService->deleteQuote($quoteId);
118
119
        return redirect()->route('quotes.index')
120
            ->with('success', 'Quote deleted successfully');
121
    }
122
123
124
125
}
126