MoipController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 10
Bugs 1 Features 1
Metric Value
wmc 8
c 10
b 1
f 1
lcom 2
cbo 1
dl 0
loc 115
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A response() 0 6 1
A initialize() 0 10 2
A token() 0 4 2
A transparent() 0 5 1
A environment() 0 12 2
1
<?php namespace SOSTheBlack\Moip\Controllers;
2
3
use View;
4
use Moip;
5
use Input;
6
use Config;
7
use Session;
8
use BaseController;
9
10
class MoipController extends BaseController
11
{
12
	/**
13
	 * data of configuration of the MoIP
14
	 *
15
	 * @var []
16
	 **/
17
18
	private $moip;
19
20
	/**
21
	 * array
22
	 *
23
	 * @var []
24
	 **/
25
26
	private $data = [
27
		"Forma" 		=> "",
28
		"Instituicao" 	=> "",
29
	    "Parcelas"		=> "",
30
	    "CartaoCredito" => [
31
	        "Numero" 		 => "",
32
	        "Expiracao" 	 => "",
33
	        "Cofre"			 => "",
34
	        "CodigoSeguranca"=> "",
35
	        "Portador" 		 => [
36
	        	"Nome" 			=> "",
37
	            "DataNascimento"=> "",
38
	            "Telefone" 		=> "",
39
	            "Identidade" 	=> ""
40
	        ]
41
	    ]
42
	];
43
44
	/**
45
	 * callback do js de pagamento do moip
46
	 *
47
	 * @var array
48
	 **/
49
	protected $response;
50
51
	/**
52
	 * response
53
	 * Recebe o callback do js de pagamento do moip
54
	 * e grava os dados em uma session
55
	 * 
56
	 * @return type
57
	 */
58
	public function response()
59
	{
60
		$this->response = Input::all();
61
		Session::put(Config::get('sostheblack::moip.array_session').'.callback', $this->response['moip']);
62
		return $this->response;
63
	}
64
65
	/**
66
	 * initialize
67
	 * 
68
	 * @param string|null $token
69
	 * @return void
70
	 */
71
	private function initialize(array $data, $token)
72
	{
73
		$this->moip = Moip::firstOrFail();
74
		$this->data = array_replace_recursive($this->data, $data);
75
		if (empty($this->data['CartaoCredito']['Cofre'])) {
76
			unset($this->data['CartaoCredito']['Cofre']);
77
		}
78
		$this->data['token'] 		= $this->token($token);
79
		$this->data['environment'] 	= $this->environment();
80
	}
81
82
	/**
83
	 * token
84
	 * Define o token que será pago
85
	 * 
86
	 * @param  string $token
87
	 * @return string
88
	 */
89
	private function token($token)
90
	{
91
		return $token ? $token : Session::get('pagamento.response.token');
92
	}
93
94
	/**
95
	 * transparent
96
	 * 
97
	 * @param array $data 
98
	 * @param string $token
99
	 * @return Illuminate\View\Factory
100
	 */
101
	public function transparent(array $data, $token = null)
102
	{
103
		$this->initialize($data, $token);
104
		return View::make('sostheblack::moip')->withMoip($this->data);
105
	}
106
107
	/**
108
	 * environment
109
	 * 
110
	 * @return string
111
	 */
112
	private function environment()
113
	{
114
		$environment = "";
0 ignored issues
show
Unused Code introduced by
$environment is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
115
116
		if ((boolean) $this->moip->environment === true) {
117
			$environment = "https://www.moip.com.br/transparente/MoipWidget-v2.js";
118
		} else {
119
			$environment = "https://desenvolvedor.moip.com.br/sandbox/transparente/MoipWidget-v2.js";
120
		}
121
122
		return $environment;
123
	}
124
}