PixelController::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 7
nc 3
nop 1
dl 0
loc 14
c 0
b 0
f 0
cc 3
rs 10
ccs 8
cts 8
cp 1
crap 3
1
<?php
2
3
namespace NotificationTracker\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Routing\Controller;
7
use Illuminate\Support\Facades\Response;
8
use NotificationTracker\Models\TrackedChannel;
9
use NotificationTracker\NotificationTracker;
10
11
class PixelController extends Controller
12
{
13 2
    public function __invoke(Request $request)
14
    {
15 2
        if ($uuid = $request->route('uuid', '')) {
16
            // TODO: move to queue job to speed up updating?
17
            /** @var TrackedChannel $tracker */
18 2
            $tracker = NotificationTracker::modelClass('channel')::query()->uuid($uuid)->first();
19 2
            if ($tracker) {
0 ignored issues
show
introduced by
$tracker is of type NotificationTracker\Models\TrackedChannel, thus it always evaluated to true.
Loading history...
20 1
                $tracker->incrementOpen()->save();
21
            }
22
        }
23
24 2
        return Response::file(NotificationTracker::pixelFilePath(), [
25 2
            'Cache-Control' => 'private, no-cache, no-cache=Set-Cookie, no-store, must-revalidate',
26 2
            'Pragma'        => 'no-cache',
27 2
        ]);
28
    }
29
}
30