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

RestAPI   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setup() 0 4 1
A validateLoggedIn() 0 8 2
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