Tiqr_DeviceStorage_TokenExchange::getDeviceToken()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 28
ccs 0
cts 19
cp 0
rs 9.6666
cc 3
nc 3
nop 1
crap 12
1
<?php
2
/**
3
 * This file is part of the tiqr project.
4
 * 
5
 * The tiqr project aims to provide an open implementation for 
6
 * authentication using mobile devices. It was initiated by 
7
 * SURFnet and developed by Egeniq.
8
 *
9
 * More information: http://www.tiqr.org
10
 *
11
 * @author Ivo Jansch <[email protected]>
12
 * 
13
 * @package tiqr
14
 *
15
 * @license New BSD License - See LICENSE file for details.
16
 *
17
 * @copyright (C) 2010-2011 SURFnet BV
18
 */
19
20
21
/**
22
 * A DeviceStorage implementation that uses a tokenexhange server to swap
23
 * notificationTokens for deviceTokens.
24
 * 
25
 * The following options can be passed when creating a tokenexchange instance
26
 * (which should be done through the Tiqr_DeviceStorage factory):
27
 * - 'appid' the app identifier of the client app used to exchange tokens, 
28
 *           must match the appid used in the mobile client apps.
29
 * - 'url' the url of the tokenexchange service
30
 * 
31
 * @author ivo
32
 *
33
 */
34
class Tiqr_DeviceStorage_TokenExchange extends Tiqr_DeviceStorage_Abstract
35
{  
36
    /**
37
     * @see Tiqr_DeviceStorage_Abstract::getDeviceToken()
38
     */ 
39
    public function getDeviceToken(string $notificationToken)
40
    {
41
        $url = $this->_options["url"]."?appId=".$this->_options["appid"];
42
        
43
        $url.= "&notificationToken=".$notificationToken;
44
45
        $ch = curl_init();
46
47
        curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
48
        curl_setopt($ch, CURLOPT_HEADER, 0);
49
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
50
        curl_setopt($ch, CURLOPT_URL, $url);
51
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
52
53
        $output = curl_exec($ch);
54
        curl_close($ch);
55
56
        if (stripos($output, "not found")!==false) {
0 ignored issues
show
Bug introduced by
It seems like $output can also be of type true; however, parameter $haystack of stripos() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
        if (stripos(/** @scrutinizer ignore-type */ $output, "not found")!==false) {
Loading history...
57
            $this->logger->error('Token Exchange failed and responded with: not found', ['full output' => $output]);
58
            return false;
59
        }
60
61
        if (stripos($output, "error")!==false) {
62
            $this->logger->error('Token Exchange failed and responded with: error', ['full output' => $output]);
63
            return false;
64
        }
65
        $this->logger->notice(sprintf('Token exchange returned output: %s', $output));
0 ignored issues
show
Bug introduced by
It seems like $output can also be of type true; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
        $this->logger->notice(sprintf('Token exchange returned output: %s', /** @scrutinizer ignore-type */ $output));
Loading history...
66
        return trim($output);
0 ignored issues
show
Bug introduced by
It seems like $output can also be of type true; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
        return trim(/** @scrutinizer ignore-type */ $output);
Loading history...
67
    }
68
}
69