HomeController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 48
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 4 1
A helloAction() 0 4 1
A databaseAction() 0 18 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