Completed
Push — master ( b97427...e235cc )
by Raffael
30:35 queued 26:08
created

Http::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 14
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
nc 1
nop 2
crap 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A Http.php$0 ➔ preAuthentication() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * balloon
7
 *
8
 * @copyright   Copryright (c) 2012-2019 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPL-3.0 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Balloon\App\Webauthn\Constructor;
13
14
use Balloon\App\Webauthn\Api\v2;
15
use Balloon\Hook;
16
use Balloon\Hook\AbstractHook;
17
use Micro\Auth\Adapter\None as AuthNone;
18
use Micro\Auth\Auth;
19
use Micro\Http\Router;
20
use Micro\Http\Router\Route;
21
22
class Http
23
{
24
    /**
25
     * Router.
26
     *
27
     * @var Router
28
     */
29
    protected $router;
30
31
    /**
32
     * Hook.
33
     *
34
     * @var Hook
35
     */
36
    protected $hook;
37
38
    /**
39
     * Constructor.
40
     */
41
    public function __construct(Router $router, Hook $hook)
42
    {
43
        $router
44
            ->appendRoute(new Route('/api/v2/devices', v2\Devices::class))
45
            ->appendRoute(new Route('/api/v2/users/{id:#([0-9a-z]{24})#}/request-challenges', v2\RequestChallenges::class))
46
            ->appendRoute(new Route('/api/v2/creation-challenges', v2\CreationChallenges::class));
47
48
        $hook->injectHook(new class() extends AbstractHook {
49
            public function preAuthentication(Auth $auth): void
50
            {
51
                if (preg_match('#^/index.php/api/v2/users/([0-9a-z]{24})/request-challenges#', $_SERVER['ORIG_SCRIPT_NAME'])) {
52
                    $auth->injectAdapter(new AuthNone());
53
                }
54
            }
55
        });
56
57
        return true;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
58
    }
59
}
60