Completed
Pull Request — master (#63)
by
unknown
04:39
created

JSONResponse   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 8
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 8
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A jsonResponse() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SilverStripe\MFA;
6
7
use SilverStripe\Control\HTTPResponse;
8
9
/**
10
 * Provides a simplified method for creating JSON-based HTTPResponses.
11
 *
12
 * @package SilverStripe\MFA
13
 */
14
trait JSONResponse
15
{
16
    public function jsonResponse(array $body, int $status = 200): HTTPResponse
17
    {
18
        return HTTPResponse::create()
19
            ->setStatusCode($status)
20
            ->addHeader('Content-Type', 'application/json')
21
            ->setBody(json_encode($body));
22
    }
23
}
24