LoginUrl   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 43
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A loginUrl() 0 7 2
1
<?php
2
/**
3
 * The MIT License (MIT)
4
 *
5
 * Copyright (c) 2016 Haridarshan Gorana
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in all
15
 * copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
 */
25
namespace Haridarshan\Instagram;
26
27
/**
28
 * LoginUrl class
29
 *
30
 * @library			instagram-php
31
 *
32
 * @license 		https://opensource.org/licenses/MIT MIT
33
 *
34
 * @link			http://github.com/haridarshan/instagram-php Class Documentation
35
 * @link			http://instagram.com/developer/ API Documentation
36
 *
37
 * @author			Haridarshan Gorana 	<[email protected]>
38
 *
39
 * @since			September 03, 2016
40
 *
41
 * @copyright		Haridarshan Gorana
42
 *
43
 * @version			2.2.2
44
 */
45
class LoginUrl
46
{
47
    /** @var InstagramApp */
48
    protected $app;
49
50
    /** @var string */
51
    protected $callback;
52
53
    /** @var string */
54
    protected $state;
55
56
    /** @var array */
57
    protected $scopes;
58
59
    /**
60
     * LoginUrl constructor
61
     *
62
     * @param InstagramApp $app
63
     * @param string       $callback
64
     * @param string       $state
65
     * @param array        $scopes
66
     */
67
    public function __construct(InstagramApp $app, $callback, $state, $scopes)
68
    {
69
        $this->app = $app;
70
        $this->callback = $callback;
71
        $this->state = $state;
72
        $this->scopes = $scopes;
73
    }
74
75
    /**
76
     * Creates login url
77
     *
78
     * @return string
79
     */
80
    public function loginUrl()
81
    {
82
        $query = 'client_id=' . $this->app->getId() . '&redirect_uri=' . urlencode($this->callback) . '&response_type=code&state=' . $this->state;
83
        $query .= isset($this->scopes) ? '&scope=' . urlencode(str_replace(',', ' ', implode(',', $this->scopes))) : '';
84
85
        return sprintf('%s%s?%s', Constants::API_HOST, Constants::API_AUTH, $query);
86
    }
87
}
88