Completed
Push — master ( 8f8221...a2309d )
by Haridarshan
02:33
created

LoginUrl   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A loginUrl() 0 6 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
 */
26
namespace Haridarshan\Instagram;
27
28
/**
29
 * LoginUrl class
30
 * 
31
 * @library			instagram-php
32
 * @license 		https://opensource.org/licenses/MIT MIT
33
 * @link			http://github.com/haridarshan/instagram-php Class Documentation
34
 * @link			http://instagram.com/developer/ API Documentation
35
 * @author			Haridarshan Gorana 	<[email protected]>
36
 * @since			September 03, 2016
37
 * @copyright		Haridarshan Gorana
38
 * @version			2.2.2
39
 */
40
class LoginUrl
41
{
42
	/** @var InstagramApp */
43
	protected $app;
44
	
45
	/** @var string */
46
	protected $callback;
47
	
48
	/** @var string */
49
	protected $state; 
50
	
51
	/** @var array */
52
	protected $scopes;
53
	
54
	/**
55
     * LoginUrl constructor
56
	 * 
57
     * @param InstagramApp $app
58
     * @param string $callback
59
     * @param string $state
60
     * @param array $scopes
61
     */
62
	public function __construct(InstagramApp $app, $callback, $state, $scopes)
63
	{
64
		$this->app = $app;	
65
		$this->callback = $callback;	
66
		$this->state = $state;	
67
		$this->scopes = $scopes;	
68
	}
69
	
70
	/**
71
     * Creates login url
72
	 * 
73
	 * @return string
74
     */
75
	public function loginUrl()
76
	{
77
		$query = 'client_id='.$this->app->getId().'&redirect_uri='.urlencode($this->callback).'&response_type=code&state='.$this->state;
78
        $query .= isset($this->scopes) ? '&scope='.urlencode(str_replace(",", " ", implode(",", $this->scopes))) : '';
79
        return sprintf('%s%s?%s', Constants::API_HOST, Constants::API_AUTH, $query);
80
	}
81
}
82