Test Failed
Pull Request — master (#9)
by Maximo
03:33 queued 10s
created

IndexController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 35.29%

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 73
ccs 12
cts 34
cp 0.3529
rs 10
c 0
b 0
f 0
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 3 1
C status() 0 50 8
1
<?php
0 ignored issues
show
Coding Style introduced by
End of line character is invalid; expected "\n" but found "\r\n"
Loading history...
2
declare(strict_types=1);
3
4
namespace Gewaer\Api\Controllers;
5
6
use Exception;
7
use PDOException;
8
use Phalcon\Http\Response;
9
use Phalcon\Queue\Beanstalk\Exception as BeanstalkException;
10
use Gewaer\Exception\ServerErrorHttpException;
11
use RedisException;
12
13
/**
14
 * Base controller
15
 *
16
 */
17
class IndexController extends BaseController
18
{
19
    /**
20
     * Index
21
     *
22
     * @method GET
23
     * @url /
24
     *
25
     * @return Phalcon\Http\Response
0 ignored issues
show
Bug introduced by
The type Gewaer\Api\Controllers\Phalcon\Http\Response was not found. Did you mean Phalcon\Http\Response? If so, make sure to prefix the type with \.
Loading history...
26
     */
27
    public function index($id = null) : Response
28
    {
29
        return $this->response(['Woot Baka']);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->response(array('Woot Baka')) returns the type Phalcon\Http\Response which is incompatible with the documented return type Gewaer\Api\Controllers\Phalcon\Http\Response.
Loading history...
30
    }
31
32
    /**
33
     * Show the status of the diferent services
34
     *
35
     * @method GET
36
     * @url /status
37
     *
38
     * @return Phalcon\Http\Response
39
     */
40 1
    public function status() : Response
41
    {
42 1
        $response = [];
43
44
        //Try to connect to Redis
45
        try {
46 1
            $this->redis->hSet('htest', 'a', 'x');
0 ignored issues
show
Bug Best Practice introduced by
The property redis does not exist on Gewaer\Api\Controllers\IndexController. Since you implemented __get, consider adding a @property annotation.
Loading history...
47
            $this->redis->hSet('htest', 'b', 'y');
48
            $this->redis->hSet('htest', 'c', 'z');
49
            $this->redis->hSet('htest', 'd', 't');
50
            $this->redis->hGetAll('htest');
51
52
            //$this->redis->ping();
53 1
        } catch (RedisException $e) {
54 1
            $this->log->error($e->getMessage(), $e->getTrace());
0 ignored issues
show
Bug Best Practice introduced by
The property log does not exist on Gewaer\Api\Controllers\IndexController. Since you implemented __get, consider adding a @property annotation.
Loading history...
55 1
            $response['errors']['redis'] = $e->getMessage();
56
        } catch (Exception $e) {
57
            $this->log->error("Redis isn't working. {$e->getMessage()}", $e->getTrace());
58
            $response['errors']['redis'] = "Redis isn't working.";
59
        }
60
61
        //Try to connect to Beanstalk
62
        try {
63 1
            $this->queue->connect();
0 ignored issues
show
Bug Best Practice introduced by
The property queue does not exist on Gewaer\Api\Controllers\IndexController. Since you implemented __get, consider adding a @property annotation.
Loading history...
64
        } catch (BeanstalkException $e) {
65
            $this->log->error($e->getMessage(), $e->getTrace());
66
            $response['errors']['beanstalk'] = $e->getMessage();
67
        } catch (Exception $e) {
68
            $this->log->error("Beanstalk isn't working. {$e->getMessage()}", $e->getTrace());
69
            $response['errors']['beanstalk'] = "Beanstalk isn't working.";
70 1
        } finally {
71 1
            $this->queue->disconnect();
72
        }
73
74
        //Try to connect to db
75
        try {
76 1
            $this->db->connect();
77
        } catch (PDOException $e) {
78
            $this->log->error($e->getMessage(), $e->getTrace());
79
            $response['errors']['db'] = $e->getMessage();
80
        } catch (Exception $e) {
81
            $this->log->error("The database isn't working. {$e->getMessage()}", $e->getTrace());
82
            $response['errors']['db'] = "The database isn't working.";
83
        }
84
85 1
        if (!count($response)) {
86
            return $this->response(['OK']);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->response(array('OK')) returns the type Phalcon\Http\Response which is incompatible with the documented return type Gewaer\Api\Controllers\Phalcon\Http\Response.
Loading history...
87
        }
88
89 1
        throw new ServerErrorHttpException(json_encode($response));
90
    }
91
}
92