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

JSONResponse::jsonResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
c 1
b 0
f 1
nc 1
nop 2
dl 0
loc 6
rs 10
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