Failed Conditions
Push — master ( 1156ed...624507 )
by Florent
05:39
created

JWKSetController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 35
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getAction() 0 12 2
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace SpomkyLabs\JoseBundle\Controller;
13
14
use Jose\Object\JWKSetInterface;
15
use Symfony\Component\HttpFoundation\Response;
16
17
final class JWKSetController
18
{
19
    /**
20
     * @var \Jose\Object\JWKSetInterface
21
     */
22
    private $jwkset;
23
24
    /**
25
     * JWKSetController constructor.
26
     *
27
     * @param \Jose\Object\JWKSetInterface $jwkset
28
     */
29
    public function __construct(JWKSetInterface $jwkset)
30
    {
31
        $this->jwkset = $jwkset;
32
    }
33
34
    /**
35
     * @param string $_format
36
     *
37
     * @return \Symfony\Component\HttpFoundation\Response
38
     */
39
    public function getAction($_format)
40
    {
41
        if ('json' === $_format) {
42
            $value = json_encode($this->jwkset);
43
            $ct = 'application/jwk-set+json; charset=UTF-8';
44
        } else {
45
            $value = json_encode($this->jwkset->toPEM());
46
            $ct = 'application/json; charset=UTF-8';
47
        }
48
49
        return new Response($value, Response::HTTP_OK, ['content-type' => $ct]);
50
    }
51
}
52