SuccessExample   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
eloc 16
c 3
b 0
f 0
dl 0
loc 59
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A successReturn() 0 11 1
A __construct() 0 3 1
A emptyDataReturn() 0 3 1
A otherReturn() 0 9 1
1
<?php
2
3
use MelquesPaiva\RestResponse\HttpResponse\Success;
4
use MelquesPaiva\RestResponse\Response;
5
6
require __DIR__ . '/../vendor/autoload.php';
7
8
/**
9
 * Class SuccessExample
10
 */
11
class SuccessExample
12
{
13
    /** @var Response $response */
14
    protected Response $response;
15
16
    /**
17
     * SuccessExample Constructor
18
     */
19
    public function __construct()
20
    {
21
        $this->response = new Response();
22
    }
23
24
    /**
25
     * Method to simulate a succesfull response (statusCode = 200)
26
     *
27
     * @return void
28
     */
29
    public function successReturn(): void
30
    {
31
        $data = [
32
            "user" => [
33
                "name" => "Melques",
34
                "last_name" => "Paiva",
35
                "document" => "123456456"                
36
            ]
37
        ];
38
39
        $this->response->successful("The request was finish with success", $data);
40
    }
41
42
    /**
43
     * Method to simulate a successfull response with empty data to return (statusCode = 204)
44
     *
45
     * @return void
46
     */
47
    public function emptyDataReturn(): void
48
    {
49
        $this->response->noContent();
50
    }
51
52
    /**
53
     * Method to simulate other response int the 200 range
54
     *
55
     * @param integer $statusCode
56
     * @param string $message
57
     * @param string $type
58
     * @param array $data
59
     * @return void
60
     */
61
    public function otherReturn(int $statusCode, string $message, string $type, array $data = []): void
62
    {
63
        $success = new Success();
64
        $success->setStatusCode($statusCode)
65
            ->setMessage($message)
66
            ->setType($type)
67
            ->setData($data);
68
69
        echo $this->response->successfullResponse($success);
70
    }
71
}
72
73
// $param = $_GET['param'];
74
// switch($param) {
75
//     case "success":
76
//         (new SuccessExample())->successReturn();
77
//         return;
78
//     case "no_content":
79
//         (new SuccessExample())->emptyDataReturn();
80
//         return;
81
//     default:
82
//         (new SuccessExample())->otherReturn(203, "message", "type",["user" => "test"]);
83
//         return;
84
// }
85