iTunesController::viewSong()   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 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace App\Http\Controllers\API;
4
5
use App\Http\Requests\API\ViewSongOnITunesRequest;
6
use App\Models\Album;
7
use App\Services\iTunesService;
8
use Illuminate\Http\RedirectResponse;
9
10
class iTunesController extends Controller
11
{
12
    private $iTunesService;
13
14
    public function __construct(iTunesService $iTunesService)
15
    {
16
        $this->iTunesService = $iTunesService;
17
    }
18
19
    /**
20
     * View a song on iTunes store.
21
     *
22
     * @return RedirectResponse
23
     */
24
    public function viewSong(ViewSongOnITunesRequest $request, Album $album)
25
    {
26
        $url = $this->iTunesService->getTrackUrl($request->q, $album->name, $album->artist->name);
27
        abort_unless($url, 404, "Koel can't find such a song on iTunes Store.");
0 ignored issues
show
Bug introduced by
It seems like $url can also be of type string; however, parameter $boolean of abort_unless() does only seem to accept boolean, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
        abort_unless(/** @scrutinizer ignore-type */ $url, 404, "Koel can't find such a song on iTunes Store.");
Loading history...
28
29
        return redirect($url);
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect($url) also could return the type Illuminate\Routing\Redirector which is incompatible with the documented return type Illuminate\Http\RedirectResponse.
Loading history...
30
    }
31
}
32