Completed
Pull Request — master (#20)
by Harry
03:01
created

HttpsAuth   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 83
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 3
dl 83
loc 83
ccs 22
cts 22
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A getEvents() 4 4 1
A getApiKey() 4 4 1
A getSecret() 4 4 1
A getUserKey() 4 4 1
A sign() 12 12 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * This file is part of graze/gigya-client
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/gigya-client/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/gigya-client
12
 */
13
14
namespace Graze\Gigya\Auth;
15
16
use GuzzleHttp\Event\BeforeEvent;
17
use GuzzleHttp\Event\RequestEvents;
18
use GuzzleHttp\Event\SubscriberInterface;
19
20 View Code Duplication
class HttpsAuth implements SubscriberInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
{
22
    const AUTH_NAME = 'gigya';
23
24
    /**
25
     * @var string
26
     */
27
    private $apiKey;
28
29
    /**
30
     * @var string
31
     */
32
    private $secret;
33
34
    /**
35
     * @var null|string
36
     */
37
    private $userKey;
38
39
    /**
40
     * @param string      $apiKey
41
     * @param string      $secret
42
     * @param string|null $userKey
43
     */
44 55
    public function __construct($apiKey, $secret, $userKey = null)
45
    {
46 55
        $this->apiKey = $apiKey;
47 55
        $this->secret = $secret;
48 55
        $this->userKey = $userKey;
49 55
    }
50
51
    /**
52
     * Returns an array of event names this subscriber wants to listen to.
53
     *
54
     * @return array
55
     */
56 8
    public function getEvents()
57
    {
58 8
        return ['before' => ['sign', RequestEvents::SIGN_REQUEST]];
59
    }
60
61
    /**
62
     * Add the authentication params to the request.
63
     *
64
     * @param BeforeEvent $event
65
     */
66 11
    public function sign(BeforeEvent $event)
67
    {
68 11
        $request = $event->getRequest();
69 11
        if ($request->getScheme() == 'https' && $request->getConfig()->get('auth') == static::AUTH_NAME) {
70 9
            $query = $request->getQuery();
71 9
            $query['apiKey'] = $this->apiKey;
72 9
            $query['secret'] = $this->secret;
73 9
            if ((bool) $this->userKey) {
74 2
                $query['userKey'] = $this->userKey;
75
            }
76
        }
77 11
    }
78
79
    /**
80
     * @return string
81
     */
82 39
    public function getApiKey()
83
    {
84 39
        return $this->apiKey;
85
    }
86
87
    /**
88
     * @return string
89
     */
90 39
    public function getSecret()
91
    {
92 39
        return $this->secret;
93
    }
94
95
    /**
96
     * @return string|null
97
     */
98 39
    public function getUserKey()
99
    {
100 39
        return $this->userKey;
101
    }
102
}
103