Passed
Push — master ( b2ca99...77b7f1 )
by Gabriel
05:51 queued 13s
created

PurchaseRedirectActionsTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 13
c 1
b 0
f 1
dl 0
loc 27
ccs 0
cts 14
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A redirectToPayment() 0 9 1
A redirectToPaymentPrepareResponse() 0 10 2
1
<?php
2
3
namespace ByTIC\Payments\Controllers\Traits\PurchaseController;
4
5
use ByTIC\Common\Records\Record;
6
use ByTIC\FacebookPixel\FacebookPixel;
7
use ByTIC\Omnipay\Common\Message\Traits\RedirectHtmlTrait;
8
use ByTIC\Payments\Models\Purchase\Traits\IsPurchasableModelTrait;
9
10
/**
11
 * Trait PurchaseRedirectActionsTrait
12
 * @package ByTIC\Payments\Controllers\Traits\PurchaseController
13
 */
14
trait PurchaseRedirectActionsTrait
15
{
16
    public function redirectToPayment()
17
    {
18
        $model = $this->getModelFromRequest();
0 ignored issues
show
Bug introduced by
It seems like getModelFromRequest() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

18
        /** @scrutinizer ignore-call */ 
19
        $model = $this->getModelFromRequest();
Loading history...
19
        $request = $model->getPurchaseRequest();
20
        /** @var RedirectHtmlTrait $response */
21
        $response = $request->send();
22
        $this->redirectToPaymentPrepareResponse($response, $model);
23
        $response->getRedirectResponse()->send();
24
        die();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
25
    }
26
27
    /**
28
     * @param RedirectHtmlTrait $response
29
     * @param Record|IsPurchasableModelTrait $model
30
     */
31
    protected function redirectToPaymentPrepareResponse($response, $model)
32
    {
33
        $response->getView()->set('subtitle', $model->getPurchaseName());
34
        $response->getView()->set('item', $model);
35
        $response->getView()->set('response', $model);
36
37
        if (method_exists($this, 'getFacebookPixelToPaymentResponse')) {
38
            /** @var FacebookPixel $facebookPixel */
39
            $facebookPixel = $this->getFacebookPixelToPaymentResponse($model);
40
            $response->getView()->append('footer_body', $facebookPixel->render());
41
        }
42
    }
43
}
44