Completed
Push — master ( e2eaf6...d17b9b )
by Mauro
02:27
created

Base::response()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
3
namespace App\Controller;
4
5
/**
6
 * Base Class.
7
 */
8
abstract class Base
9
{
10
    const API_VERSION = '17.04';
11
12
    const USER_NOT_FOUND = 'El usuario solicitado no existe.';
13
    const USER_NAME_NOT_FOUND = 'No se encontraron usuarios con ese nombre.';
14
    const USER_NAME_REQUIRED = 'Ingrese el nombre del usuario.';
15
    const USER_INFO_REQUIRED = 'Ingrese los datos a actualizar del usuario.';
16
    const USER_DELETED = 'El usuario fue eliminado correctamente.';
17
    const USER_EMAIL_INVALID = 'El email ingresado no es correcto.';
18
19
    const TASK_NOT_FOUND = 'La tarea solicitada no existe.';
20
    const TASK_NAME_NOT_FOUND = 'No se encontraron tareas con ese nombre.';
21
    const TASK_NAME_REQUIRED = 'Ingrese el nombre de la tarea.';
22
    const TASK_INFO_REQUIRED = 'Ingrese los datos a actualizar de la tarea.';
23
    const TASK_DELETED = 'La tarea fue eliminada correctamente.';
24
25
    protected $database;
26
27
    protected $request;
28
29
    protected $response;
30
31
    protected $args;
32
33
    /**
34
     * @param type $request
35
     * @param type $response
36
     * @param type $args
37
     */
38
    protected function setParams($request, $response, $args)
39
    {
40
        $this->request = $request;
41
        $this->response = $response;
42
        $this->args = $args;
43
    }
44
45
    /**
46
     * Send response with json as standard format.
47
     *
48
     * @param type $status
49
     * @param type $message
50
     * @param type $code
51
     * @return array
52
     */
53
    protected function jsonResponse($status, $message, $code)
54
    {
55
        $result = [
56
            'code' => $code,
57
            'status' => $status,
58
            'message' => $message,
59
        ];
60
61
        return $this->response->withJson($result, $code, JSON_PRETTY_PRINT);
62
    }
63
}
64