Passed
Push — release-11.2.x ( 8442ea...708df0 )
by Markus
22:42 queued 18:28
created

ApiEid::main()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 23
ccs 0
cts 21
cp 0
rs 9.7
cc 3
nc 3
nop 1
crap 12
1
<?php
2
3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
 * It is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License, either version 2
8
 * of the License, or any later version.
9
 *
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
 * The TYPO3 project - inspiring people to share!
14
 */
15
16
namespace ApacheSolrForTypo3\Solr\Eid;
17
18
use ApacheSolrForTypo3\Solr\Api;
19
use Psr\Http\Message\ResponseInterface;
20
use Psr\Http\Message\ServerRequestInterface;
21
use TYPO3\CMS\Core\Http\Response;
22
use TYPO3\CMS\Core\Utility\GeneralUtility;
23
use TYPO3\CMS\Core\Utility\HttpUtility;
24
25
class ApiEid
26
{
27
    public function main(ServerRequestInterface $request): ResponseInterface
28
    {
29
        $api = GeneralUtility::_GP('api');
30
        $apiKey = trim(GeneralUtility::_GP('apiKey'));
31
32
        if (!Api::isValidApiKey($apiKey)) {
33
            header(HttpUtility::HTTP_STATUS_403);
34
            header('Content-Type: application/json; charset=utf-8');
35
            echo json_encode(['errorMessage' => 'Invalid API key']);
36
        } else {
37
            switch ($api) {
38
                case 'siteHash':
39
                    include('SiteHash.php');
40
                    break;
41
42
                default:
43
                    header(HttpUtility::HTTP_STATUS_400);
44
                    header('Content-Type: application/json; charset=utf-8');
45
                    echo json_encode(['errorMessage' => 'You must provide an available API method, e.g. siteHash.']);
46
                    break;
47
            }
48
        }
49
        return new Response();
50
    }
51
}
52