This class seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate
the same code in three or more different places, we strongly encourage you to
look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
9
{
10
/**
11
* @var null|GatewayRegistry
12
*/
13
private static $instance = null;
14
15
/**
16
* @var Gateway[]
17
*/
18
protected $gateways = [];
19
20
/**
21
* @return GatewayRegistry
22
*/
23
public static function instance(): GatewayRegistry
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the getSomeVariable() on that sub-class, you will receive
a runtime error:
classYourSubClassextendsYourClass{}YourSubClass::getSomeVariable();// Will cause an access error.
In the case above, it makes sense to update SomeClass to use self instead:
classSomeClass{privatestatic$someVariable;publicstaticfunctiongetSomeVariable(){returnself::$someVariable;// self works fine with private.}}
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the getSomeVariable() on that sub-class, you will receive
a runtime error:
classYourSubClassextendsYourClass{}YourSubClass::getSomeVariable();// Will cause an access error.
In the case above, it makes sense to update SomeClass to use self instead:
classSomeClass{privatestatic$someVariable;publicstaticfunctiongetSomeVariable(){returnself::$someVariable;// self works fine with private.}}
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the getSomeVariable() on that sub-class, you will receive
a runtime error:
classYourSubClassextendsYourClass{}YourSubClass::getSomeVariable();// Will cause an access error.
In the case above, it makes sense to update SomeClass to use self instead:
classSomeClass{privatestatic$someVariable;publicstaticfunctiongetSomeVariable(){returnself::$someVariable;// self works fine with private.}}
Loading history...
30
}
31
32
/**
33
* @param string $destinationType
34
* @param Gateway $gateway
35
*/
36
4
public function set(string $destinationType, Gateway $gateway): void
37
{
38
4
$this->gateways[$destinationType] = $gateway;
39
4
}
40
41
/**
42
* @param array $gateways
43
*/
44
public function setAll(array $gateways): void
45
{
46
$this->gateways = $gateways;
47
}
48
49
/**
50
* @param Destination $destination
51
* @return Gateway
52
*/
53
5
public function get(Destination $destination): Gateway
54
{
55
5
$destinationType = $destination::type();
56
5
if (!isset($this->gateways[$destinationType])) {
57
1
throw new InvalidArgumentException(
58
1
sprintf(
59
1
'No gateway for destination type (%s) is supported.',
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.