Completed
Push — test-coverage ( 951e01...59b971 )
by Tomas Norre
05:18
created

AuthenticationService::authUser()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace AOE\Crawler\Service;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2016 AOE GmbH <[email protected]>
8
 *
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use TYPO3\CMS\Sv\AbstractAuthenticationService;
29
30
/**
31
 * Class AuthenticationService
32
 *
33
 * @package AOE\Crawler\Service
34
 */
35
class AuthenticationService extends AbstractAuthenticationService
36
{
37
38
    /**
39
     * Find user by HTTP_X_T3CRAWLER Header
40
     *
41
     * @return mixed user array or false
42
     */
43 2
    public function getUser()
44
    {
45 2
        $user = false;
46 2
        if (isset($_SERVER['HTTP_X_T3CRAWLER'])) {
47 1
            $user = $this->fetchUserRecord('_cli_crawler');
48
        }
49
50 2
        return $user;
51
    }
52
53
    /**
54
     * Authenticate user
55
     *
56
     * @param array user
57
     *
58
     * @return int 100="don't know", 0="no", 200="yes"
59
     */
60 3
    public function authUser(array $user)
61
    {
62 3
        if (isset($_SERVER['HTTP_X_T3CRAWLER'])) {
63 2
            return ($user['username'] == '_cli_crawler') ? 200 : 100;
64
        }
65
66 1
        return 100;
67
    }
68
}
69