ComicController::show()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: famoser
5
 * Date: 07/06/2016
6
 * Time: 17:54
7
 */
8
9
namespace Famoser\XKCDCache\Controllers;
10
11
12
use Famoser\XKCDCache\Controllers\Base\FrontendController;
13
use Famoser\XKCDCache\Entities\Comic;
14
use Famoser\XKCDCache\Types\DownloadStatus;
15
use Slim\Exception\NotFoundException;
16
use Slim\Http\Request;
17
use Slim\Http\Response;
18
19
/**
20
 * the comic controller allows to inspect all cached files, and allows to analyze errors
21
 *
22
 * @package Famoser\XKCDCache\Controllers
23
 */
24
class ComicController extends FrontendController
25
{
26
    /**
27
     * show all comics
28
     *
29
     * @param Request $request
30
     * @param Response $response
31
     * @return mixed
32
     */
33 2
    public function index(/** @scrutinizer ignore-unused */ Request $request, Response $response)
34
    {
35 2
        $comics = $this->getDatabaseService()->getFromDatabase(new Comic(), null, null, "num");
36 2
        return $this->renderTemplate($response, 'comics/list', ["comics" => $comics]);
37
    }
38
39
    /**
40
     * show all comics
41
     *
42
     * @param Request $request
43
     * @param Response $response
44
     * @return mixed
45
     */
46 2
    public function failed(/** @scrutinizer ignore-unused */ Request $request, Response $response)
47
    {
48 2
        $comics = $this->getDatabaseService()->getFromDatabase(new Comic(), "status <> " . DownloadStatus::SUCCESSFUL, [], "num");
49 2
        return $this->renderTemplate($response, 'comics/list', ["comics" => $comics]);
50
    }
51
52
    /**
53
     * show all comics
54
     *
55
     * @param Request $request
56
     * @param Response $response
57
     * @param $args
58
     * @return mixed
59
     * @throws NotFoundException
60
     */
61 2
    public function show(Request $request, Response $response, $args)
62
    {
63 2
        $comic = $this->getDatabaseService()->getSingleByIdFromDatabase(new Comic(), $args["id"]);
64 2
        if (!$comic instanceof Comic) {
65 1
            throw new NotFoundException($request, $response);
66
        }
67 2
        $imagePublicPath = $this->getSettingService()->getImagePublicBasePath() . "/" . $comic->filename;
68 2
        return $this->renderTemplate($response, 'comics/show', $args + ["comic" => $comic, "image_public_path" => $imagePublicPath]);
69
    }
70
}
71