Lines 0.00% 0 / 15
Methods 0.00% 0 / 2
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 process 0.00% 0 / 2 0.00% 0 / 1 2
 readAppointmentUrl 0.00% 0 / 13 0.00% 0 / 1 30
11class AppointmentUrlMiddleware implements MiddlewareInterface
12{
13    #[\Override]
14    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
15    {
16        \App::$templatedefaults['urlAppointments'] = self::readAppointmentUrl();
17
18        return $handler->handle($request);
19    }
20
21    public static function readAppointmentUrl(): string
22    {
23        try {
24            $token = defined('App::CONFIG_SECURE_TOKEN') ? \App::CONFIG_SECURE_TOKEN : null;
25            $entity = \App::$http->readGetResult('/config/', [], $token)->getEntity();
26        } catch (\Throwable $exception) {
27            \App::$log->error('Failed to read the appointment URL', [
28                'error' => $exception->getMessage(),
29            ]);
30            return '';
31        }
32
33        if (!$entity instanceof Config) {
34            return '';
35        }
36
37        $url = $entity->getPreference('appointments', 'urlAppointments');
38        if (!is_string($url)) {
39            return '';
40        }
41
42        return trim($url);
43    }
44}