HomeController::databaseAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 10
cts 10
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 1
crap 1
1
<?php
2
namespace App\Http\Controllers;
3
4
use Fyuze\Database\Db;
5
use Fyuze\Http\Message\Stream;
6
use Fyuze\Http\Response;
7
8
class HomeController
9
{
10
    /**
11
     * Basic GET route action
12
     *
13
     * @return Response
14
     */
15 1
    public function indexAction()
16
    {
17 1
        return '<body>Welcome to Fyuze!</body>';
18
    }
19
20
    /**
21
     * Basic greeting example with parameters
22
     *
23
     * @param $name
24
     * @return Response
25
     */
26 1
    public function helloAction($name)
27
    {
28 1
        return Response::create(sprintf('<body>Hello, %s!</body>', $name));
29
    }
30
31
    /**
32
     * Temporary method for db interaction
33
     *
34
     * @param Db $db
35
     * @return Response
36
     */
37 1
    public function databaseAction(Db $db)
38
    {
39 1
        $db->query('CREATE TABLE users(name varchar(255));');
40 1
        $db->query('INSERT INTO users VALUES (?)', ['matthew']);
41
42 1
        $results = $db->first("SELECT * FROM users WHERE name = ?", ['matthew']);
43
44
        /** Psr7 example */
45
46 1
        $stream = new Stream('php://memory', 'wb+');
47 1
        $stream->write(json_encode($results));
48
49 1
        return (new Response)
50 1
                ->withStatus(200)
51 1
                ->withBody($stream)
52 1
                ->withHeader('Content-Type', 'application/json');
53
54
    }
55
}
56