Controller   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 28 6
1
<?php
2
3
// Composer autoloading
4
require __DIR__.'/../../vendor/autoload.php';
5
6
use Escopecz\MauticFormSubmit\Mautic;
7
use Escopecz\MauticFormSubmit\Mautic\Config;
8
9
class Controller
10
{
11
    public function __construct()
12
    {
13
        foreach ($_POST as $key => $val) {
14
            $_SESSION[$key] = $val;
15
        }
16
17
	if (isset($_POST['email_label']) && isset($_POST[$_POST['email_label']]) && isset($_POST['mautic_base_url']) && isset($_POST['form_id'])) {
18
		
19
	    // It's optional to create a Config DTO object and pass it to the Mautic object.
20
	    // For example to set Curl verbose logging to true.
21
	    $config = new Config;
22
	    $config->setCurlVerbose(true);
23
24
            $mautic = new Mautic($_POST['mautic_base_url'], $config);
25
            $form = $mautic->getForm($_POST['form_id']);
26
27
            $info = $form->submit(
28
                [
29
                    $_POST['email_label'] => $_POST[$_POST['email_label']],
30
                ]
31
            );
32
33
            $_SESSION['info'] = $info;
34
        }
35
36
        header(rtrim('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], '/controller.php'));
37
        die();
38
    }
39
}
40
41
session_start();
42
new Controller;
43