Passed
Pull Request — master (#127)
by Garion
03:26
created

JSONResponse::jsonResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php declare(strict_types=1);
2
3
namespace SilverStripe\MFA;
4
5
use SilverStripe\Control\HTTPResponse;
6
7
/**
8
 * Provides a simplified method for creating JSON-based HTTPResponses.
9
 *
10
 * @package SilverStripe\MFA
11
 */
12
trait JSONResponse
13
{
14
    public function jsonResponse(array $body, int $status = 200): HTTPResponse
15
    {
16
        return HTTPResponse::create()
17
            ->setStatusCode($status)
18
            ->addHeader('Content-Type', 'application/json')
19
            ->setBody(json_encode($body));
20
    }
21
}
22