DetectFromHttpRequestTrait   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 14
c 1
b 0
f 0
dl 0
loc 32
ccs 12
cts 14
cp 0.8571
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B detectFromHttpRequestTrait() 0 22 7
1
<?php
2
3
namespace ByTIC\Payments\Gateways\Providers\AbstractGateway\Traits;
4
5
use Omnipay\Common\Message\AbstractRequest;
6
use Symfony\Component\HttpFoundation\Request as HttpRequest;
7
8
/**
9
 * Trait DetectFromHttpRequestTrait
10
 * @package ByTIC\Payments\Gateways\Providers\AbstractGateway\Traits
11
 */
12
trait DetectFromHttpRequestTrait
13
{
14
    /**
15
     * @param $modelManager
16
     * @param null $callback
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $callback is correct as it would always require null to be passed?
Loading history...
17
     * @param HttpRequest $httpRequest
18
     *
19
     * @return AbstractRequest|false
20
     * @throws \Exception
21
     */
22 14
    public function detectFromHttpRequestTrait($modelManager, $callback = null, $httpRequest = null)
23
    {
24 14
        $callback = $callback ? $callback : 'completePurchase';
0 ignored issues
show
introduced by
$callback is of type null, thus it always evaluated to false.
Loading history...
25 14
        if ($httpRequest) {
26 13
            $this->setHttpRequest($httpRequest);
0 ignored issues
show
Bug introduced by
It seems like setHttpRequest() 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

26
            $this->/** @scrutinizer ignore-call */ 
27
                   setHttpRequest($httpRequest);
Loading history...
27
        }
28 14
        if (!method_exists($this, $callback)) {
29 1
            return false;
30
        }
31
        /** @var AbstractRequest $request */
32 13
        $request = $this->$callback(['modelManager' => $modelManager]);
33 13
        if (!is_object($request)) {
34
            return false;
35
        }
36 13
        if (!method_exists($request, 'isValidNotification')) {
37
            throw new \Exception("Request must have a isValidNotification public method");
38
        }
39 13
        if (!$request->isValidNotification()) {
40 10
            return false;
41
        }
42
43 13
        return $request;
44
    }
45
}
46