PurchaseRedirectActionsTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 16
c 2
b 1
f 1
dl 0
loc 32
ccs 0
cts 15
cp 0
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A redirectToPayment() 0 14 3
A redirectToPaymentPrepareResponse() 0 10 2
1
<?php
2
3
namespace ByTIC\Payments\Controllers\Traits\PurchaseController;
4
5
use ByTIC\FacebookPixel\FacebookPixel;
6
use Paytic\Omnipay\Common\Message\Traits\RedirectHtmlTrait;
7
use ByTIC\Payments\Models\Purchase\Traits\IsPurchasableModelTrait;
8
use Omnipay\Common\Message\RedirectResponseInterface;
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
24
        if ($response instanceof RedirectResponseInterface  && $response->isRedirect()) {
25
            $response->getRedirectResponse()->send();
26
        } else {
27
            $response->send();
28
        }
29
        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...
30
    }
31
32
    /**
33
     * @param RedirectHtmlTrait $response
34
     * @param Record|IsPurchasableModelTrait $model
0 ignored issues
show
Bug introduced by
The type ByTIC\Payments\Controlle...rchaseController\Record was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
     */
36
    protected function redirectToPaymentPrepareResponse($response, $model)
37
    {
38
        $response->getView()->set('subtitle', $model->getPurchaseName());
39
        $response->getView()->set('item', $model);
40
        $response->getView()->set('response', $model);
41
42
        if (method_exists($this, 'getFacebookPixelToPaymentResponse')) {
43
            /** @var FacebookPixel $facebookPixel */
44
            $facebookPixel = $this->getFacebookPixelToPaymentResponse($model);
45
            $response->getView()->append('footer_body', $facebookPixel->render());
46
        }
47
    }
48
}
49