BantenprovSso::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 9.4285
1
<?php
2
3
/**
4
 * @Author: jdi-juma
5
 * @Date:   2017-12-09 16:45:17
6
 * @Last Modified by:   jdi-juma
7
 * @Last Modified time: 2017-12-09 23:19:33
8
 */
9
10
11
namespace Bantenprov\BantenprovSso;
12
13
14
class BantenprovSso 
15
{
16
17
	public static $result;
18
	public static $profile_result;
19
	public static $status;
20
	public static $request;
21
	public static $fails;
22
	public static $check_login;
23
	public static $token_access;
24
25
	public function __construct()
26
	{
27
		Self::$fails   			= false;
28
		Self::$profile_fails   	= false;
0 ignored issues
show
Bug Best Practice introduced by
The property profile_fails does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
29
		Self::$token_access     = false;
30
		$this->profile = '';
0 ignored issues
show
Bug Best Practice introduced by
The property profile does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31
	}
32
33
34
	static function Attempt($post)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
35
	{
36
		$post['appid']		= env('APPID');
0 ignored issues
show
Bug introduced by
The function env was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

36
		$post['appid']		= /** @scrutinizer ignore-call */ env('APPID');
Loading history...
37
		$post['token']		= env('TOKEN');
38
		$curl=curl_init();
39
		curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
40
		curl_setopt($curl,CURLOPT_URL,env('SSO_LOGIN'));
41
		curl_setopt($curl,CURLOPT_POST,1);
42
		curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($post));
43
		curl_setopt($curl,CURLOPT_TIMEOUT,20);
44
		curl_setopt($curl,CURLOPT_HTTPHEADER, array(
45
		    'Accept: application/json')
46
		);
47
		$exec=curl_exec($curl);
48
		if(!$exec)
49
		{
50
			return BantenprovSso::$fails = true;
51
		}
52
		curl_close($curl);
53
		$result = json_decode($exec);
54
		BantenprovSso::$result = $result;
55
		return $result->status;
56
	}
57
58
	static function message()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
59
	{
60
		return BantenprovSso::$result->message;
61
	}
62
63 View Code Duplication
	static function check_logout($post)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method 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...
64
	{
65
		$post['appid']		= env('APPID');
0 ignored issues
show
Bug introduced by
The function env was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

65
		$post['appid']		= /** @scrutinizer ignore-call */ env('APPID');
Loading history...
66
		$post['token']		= env('TOKEN');
67
		$curl=curl_init();
68
		curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
69
		curl_setopt($curl,CURLOPT_URL,env('CHECK_LOGOUT'));
70
		curl_setopt($curl,CURLOPT_POST,1);
71
		curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($post));
72
		curl_setopt($curl,CURLOPT_TIMEOUT,20);
73
		curl_setopt($curl,CURLOPT_HTTPHEADER, array(
74
		    'Accept: application/json')
75
		);
76
		$exec=curl_exec($curl);
77
		if(!$exec)
78
		{
79
			return false;
80
		}
81
		curl_close($curl);
82
		$result = json_decode($exec);
83
		return $result->status;
84
	}
85
86 View Code Duplication
	static function check_login($post)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method 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...
87
	{
88
		$post['appid']		= env('APPID');
0 ignored issues
show
Bug introduced by
The function env was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

88
		$post['appid']		= /** @scrutinizer ignore-call */ env('APPID');
Loading history...
89
		$post['token']		= env('TOKEN');
90
		$curl=curl_init();
91
		curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
92
		curl_setopt($curl,CURLOPT_URL,env('CHECK_LOGIN'));
93
		curl_setopt($curl,CURLOPT_POST,1);
94
		curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($post));
95
		curl_setopt($curl,CURLOPT_TIMEOUT,20);
96
		curl_setopt($curl,CURLOPT_HTTPHEADER, array(
97
		    'Accept: application/json')
98
		);
99
		$exec=curl_exec($curl);
100
101
		//dd($exec);
102
103
		if(!$exec)
104
		{
105
			return false;
106
		}
107
		curl_close($curl);
108
		$result = json_decode($exec);
109
		BantenprovSso::$check_login = $result;
110
		return $result->status;
111
	}
112
113
	static function check_login_data()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
114
	{
115
		return BantenprovSso::$check_login->data;
116
	}
117
118
	static function data()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
119
	{
120
		if( BantenprovSso::$result->status == false)
121
		{
122
			return BantenprovSso::$result->message;
123
		}
124
		return BantenprovSso::$result->data;
125
126
	}
127
128 View Code Duplication
	static function Logout($post)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method 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...
129
	{
130
		$post['appid']		= env('APPID');
0 ignored issues
show
Bug introduced by
The function env was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

130
		$post['appid']		= /** @scrutinizer ignore-call */ env('APPID');
Loading history...
131
		$post['token']		= env('TOKEN');
132
		$curl=curl_init();
133
		curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
134
		curl_setopt($curl,CURLOPT_URL,env('SSO_LOGOUT'));
135
		curl_setopt($curl,CURLOPT_POST,1);
136
		curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($post));
137
		curl_setopt($curl,CURLOPT_TIMEOUT,20);
138
		curl_setopt($curl,CURLOPT_HTTPHEADER, array(
139
		    'Accept: application/json')
140
		);
141
		$exec=curl_exec($curl);
142
		//dd($exec);
143
		if(!$exec)
144
		{
145
			return false;
146
		}
147
		curl_close($curl);
148
		$result = json_decode($exec);
149
		BantenprovSso::$check_login = $result;
150
		return $result->status;
151
	}
152
153
	static function InitAddress()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
154
	{
155
		$ipaddress = '';
156
	    if (getenv('HTTP_CLIENT_IP'))
157
	        $ipaddress = getenv('HTTP_CLIENT_IP');
158
	    else if(getenv('HTTP_X_FORWARDED_FOR'))
159
	        $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
160
	    else if(getenv('HTTP_X_FORWARDED'))
161
	        $ipaddress = getenv('HTTP_X_FORWARDED');
162
	    else if(getenv('HTTP_FORWARDED_FOR'))
163
	        $ipaddress = getenv('HTTP_FORWARDED_FOR');
164
	    else if(getenv('HTTP_FORWARDED'))
165
	       $ipaddress = getenv('HTTP_FORWARDED');
166
	    else if(getenv('REMOTE_ADDR'))
167
	        $ipaddress = getenv('REMOTE_ADDR');
168
	    else
169
	        $ipaddress = 'UNKNOWN';
170
	    return $ipaddress;
171
	}
172
173
	static function init()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
174
	{
175
		return 'package loaded';
176
	}
177
178
}