Code Duplication    Length = 38-38 lines in 2 locations

src/app/Balloon.App.Webauthn/Api/v2/CreationChallenges.php 1 location

@@ 18-55 (lines=38) @@
15
use Balloon\Server;
16
use Micro\Http\Response;
17
18
class CreationChallenges
19
{
20
    /**
21
     * CreationChallengeFactory.
22
     *
23
     * @var CreationChallengeFactory
24
     */
25
    protected $creation_challenge_factory;
26
27
    /**
28
     * Server.
29
     *
30
     * @var Server
31
     */
32
    protected $server;
33
34
    /**
35
     * Initialize.
36
     */
37
    public function __construct(CreationChallengeFactory $creation_challenge_factory, Server $server)
38
    {
39
        $this->creation_challenge_factory = $creation_challenge_factory;
40
        $this->server = $server;
41
    }
42
43
    /**
44
     * Challenge endpoint.
45
     */
46
    public function post(string $domain): Response
47
    {
48
        $resource = $this->creation_challenge_factory->create($this->server->getIdentity(), $domain);
49
50
        return (new Response())->setCode(201)->setBody([
51
            'id' => (string) $resource['id'],
52
            'key' => $resource['key'],
53
        ]);
54
    }
55
}
56

src/app/Balloon.App.Webauthn/Api/v2/RequestChallenges.php 1 location

@@ 19-56 (lines=38) @@
16
use Micro\Http\Response;
17
use MongoDB\BSON\ObjectId;
18
19
class RequestChallenges
20
{
21
    /**
22
     * RequestChallengeFactory.
23
     *
24
     * @var RequestChallengeFactory
25
     */
26
    protected $request_challenge_factory;
27
28
    /**
29
     * Server.
30
     *
31
     * @var Server
32
     */
33
    protected $server;
34
35
    /**
36
     * Initialize.
37
     */
38
    public function __construct(RequestChallengeFactory $request_challenge_factory, Server $server)
39
    {
40
        $this->request_challenge_factory = $request_challenge_factory;
41
        $this->server = $server;
42
    }
43
44
    /**
45
     * Challenge endpoint.
46
     */
47
    public function post(ObjectId $id, string $domain): Response
48
    {
49
        $resource = $this->request_challenge_factory->create($id, $domain);
50
51
        return (new Response())->setCode(201)->setBody([
52
            'id' => (string) $resource['id'],
53
            'key' => $resource['key'],
54
        ]);
55
    }
56
}
57