Completed
Push — master ( ab2960...44d5ac )
by Patrick
03:26
created

RestAPI::setup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Http\Rest;
3
4
use \Psr\Http\Message\ServerRequestInterface as Request;
5
use \Psr\Http\Message\ResponseInterface as Response;
6
7
require 'vendor/autoload.php';
8
9
const SUCCESS = 0;
10
const UNRECOGNIZED_METHOD = 1;
11
const INVALID_PARAM = 2;
12
const ALREADY_LOGGED_IN = 3;
13
const INVALID_LOGIN = 4;
14
const ACCESS_DENIED = 5;
15
const INTERNAL_ERROR = 6;
16
const UNKNOWN_ERROR = 255;
17
18
class RestAPI
19
{
20
    public function setup($app)
21
    {
22
        return $app->any('[/]', $this);
23
    }
24
25
    public function validateLoggedIn($request)
26
    {
27
        $this->user = $request->getAttribute('user');
0 ignored issues
show
Bug introduced by
The property user does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28
        if($this->user === false)
29
        {
30
            throw new Exception('Must be logged in', \Http\Rest\ACCESS_DENIED);
31
        }
32
    }
33
}
34