__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 4
cp 0
crap 2
1
<?php
2
class Intraface_Controller_ModulePackage_Process extends k_Component
3
{
4
    protected $kernel;
5
    protected $mdb2;
6
7
    function __construct(MDB2_Driver_Common $mdb2)
8
    {
9
        $this->mdb2 = $mdb2;
10
    }
11
12
    function postForm()
0 ignored issues
show
Coding Style introduced by
postForm uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
postForm uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
postForm uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
13
    {
14
        // When we recieve from Quickpay payment not being logged in
15
        $action = Intraface_modules_modulepackage_ActionStore::restoreFromIdentifier($this->mdb2, $_GET['action_store_identifier']);
16
        if (!$action) {
17
            throw new Exception('Unable to restore action from identifier '. $_GET['action_store_identifier']);
18
        }
19
20
        // We login to the intranet with the private key
21
        $adapter = new Intraface_Auth_PrivateKeyLogin($this->mdb2, uniqid(), $action->getIntranetPrivateKey());
22
        $weblogin = $adapter->auth();
23
        if (!$intranet_id = $weblogin->getActiveIntranetId()) {
24
            throw new Exception("Unable to log in to the intranet with public key: ".$action->getIntranetPrivateKey());
25
        }
26
27
        $this->getKernel()->weblogin = $weblogin;
28
        $this->getKernel()->intranet = new Intraface_Intranet($intranet_id);
29
        $this->getKernel()->setting = new Intraface_Setting($this->getKernel()->intranet->get('id'));
30
31
        $module = $this->getKernel()->module('modulepackage');
32
        $module->includeFile('Manager.php');
33
        $module->includeFile('ShopExtension.php');
34
        $module->includeFile('ActionStore.php');
35
        $module->includeFile('AccessUpdate.php');
36
37
        $shop = new Intraface_modules_modulepackage_ShopExtension();
38
        $order = $shop->getOrderDetails($action->getOrderIdentifier());
39
40
        if (empty($order)) {
41
            throw new Exception('Unable to restore order from identifier '.$action->getOrderIdentifier());
42
        }
43
44
        $payment_provider = 'Ilib_Payment_Authorize_Provider_'.INTRAFACE_ONLINEPAYMENT_PROVIDER;
45
        $payment_authorize = new $payment_provider(INTRAFACE_ONLINEPAYMENT_MERCHANT, INTRAFACE_ONLINEPAYMENT_MD5SECRET);
46
        $payment_postprocess = $payment_authorize->getPostProcess($_GET, $_POST, $_SESSION, $order);
47
48
        $amount = $payment_postprocess->getAmount();
49
50
        $shop->addPaymentToOrder($action->getOrderIdentifier(), $payment_postprocess);
51
52
        if ($payment_postprocess->getPbsStatus() == '000') {
53
            if ($amount >= $action->getTotalPrice()) {
54
                if ($action->execute($this->getKernel()->intranet)) {
55
                    // we delete the action from the store
56
                    $action_store = new Intraface_modules_modulepackage_ActionStore($this->getKernel()->intranet->get('id'));
57
                    $action_store->restore($_GET['action_store_identifier']);
58
                    $action_store->delete();
59
60
                    // TODO: do we maybe want to send an email to the customer?
61
62
                    $access_update = new Intraface_modules_modulepackage_AccessUpdate();
63
                    $access_update->run($this->getKernel()->intranet->get('id'));
64
                    return new k_TextResponse('SUCCESS!');
65
                } else {
66
                    $response = new k_TextResponse('Failure:'.$action->error->view());
67
                    $response->setStatus(400);
68
                    return $response;
69
                }
70
            } else {
71
                // TODO: Here we can send an e-mail that says they still need to pay some more OR?
72
                throw new Exception('Failure: Not sufficient payment');
73
            }
74
        } else {
75
            // @todo should throw a 401
76
            $response = new k_TextResponse('Payment attempt registered. Not authorized');
77
            $response->setStatus(401);
78
            return $response;
79
        }
80
        $response = new k_TextResponse('Unknown failure');
0 ignored issues
show
Unused Code introduced by
$response = new \k_TextR...nse('Unknown failure'); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
81
        $response->setStatus(400);
82
        return $response;
83
    }
84
85
    function getKernel()
86
    {
87
        if (is_object($this->kernel)) {
88
            return $this->kernel;
89
        }
90
        return $this->kernel = new Intraface_Kernel();
91
    }
92
}
93