HasGateway   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 56.67%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 57
ccs 17
cts 30
cp 0.5667
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getGateway() 0 14 3
A setGateway() 0 4 1
A getGatewayToken() 0 14 3
A getGatewayEndpoint() 0 4 1
1
<?php
2
3
namespace Omnipay\Spreedly\Message\Concerns;
4
5
use Omnipay\Common\Exception\InvalidRequestException;
6
use Omnipay\Spreedly\Arr;
7
8
trait HasGateway
9
{
10
    /**
11
     * @return string
12
     */
13 26
    public function getGateway()
14
    {
15 26
        $gateway = $this->getParameter('gateway');
0 ignored issues
show
Bug introduced by
It seems like getParameter() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
16
17 26
        if (is_null($this->getParameter('gateway'))) {
0 ignored issues
show
Bug introduced by
It seems like getParameter() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
18 18
            $gateway = $this->getDefaultGateway();
0 ignored issues
show
Bug introduced by
It seems like getDefaultGateway() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
19 18
        }
20
21 26
        if ($this->getTestMode()) {
0 ignored issues
show
Bug introduced by
It seems like getTestMode() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
22
            $gateway = 'test';
23
        }
24
25 26
        return $gateway;
26
    }
27
28
    /**
29
     * @param $value
30
     * @return $this
31
     */
32 10
    public function setGateway($value)
33
    {
34 10
        return $this->setParameter('gateway', $value);
0 ignored issues
show
Bug introduced by
It seems like setParameter() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
35
    }
36
37
    /**
38
     * @return string
39
     * @throws InvalidRequestException
40
     */
41 18
    public function getGatewayToken()
42
    {
43 18
        $gateway = $this->getGateway();
44
45 18
        $gatewaysTokens = $this->getGatewaysTokens();
0 ignored issues
show
Bug introduced by
The method getGatewaysTokens() does not exist on Omnipay\Spreedly\Message\Concerns\HasGateway. Did you maybe mean getGateway()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
46
47 18
        foreach ($gatewaysTokens as $gatewayToken) {
48 18
            if (Arr::get($gatewayToken, 'type') == $gateway) {
49 18
                return Arr::get($gatewayToken, 'token');
50
            }
51
        }
52
53
        throw new InvalidRequestException("Missing '$gateway' gateway token.");
54
    }
55
56
    /**
57
     * @return string
58
     * @throws InvalidRequestException
59
     */
60 18
    protected function getGatewayEndpoint()
61
    {
62 18
        return $this->endpoint . 'gateways/' . $this->getGatewayToken() . '/';
0 ignored issues
show
Bug introduced by
The property endpoint does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
63
    }
64
}
65