SwapLocationResponse   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doLocationResponse() 0 9 2
A __construct() 0 3 1
1
<?php
2
3
namespace App\Adventure\ActionResponses;
4
5
use App\Adventure\Location;
6
use App\Adventure\Utils\Connector;
7
8
/**
9
 * SwapLocationResponse implements the LocationResponseInterface.
10
 * It swaps the current location with a new location.
11
 */
12
class SwapLocationResponse implements LocationResponseInterface
13
{
14
    /**
15
     * @var Location The new location to swap with the current location.
16
     */
17
    private $newLocation;
18
19
    /**
20
     * SwapLocationResponse constructor.
21
     *
22
     * @param Location $newLocation The new location to swap with the current location.
23
     */
24 2
    public function __construct(Location $newLocation)
25
    {
26 2
        $this->newLocation = $newLocation;
27
    }
28
29
    /**
30
     * Performs the location response action by swapping the current location with the new location.
31
     *
32
     * @param  Location|null $oldLocation The current location.
33
     * @return Location The resulting location after the swap, will be the new location.
34
     */
35 1
    public function doLocationResponse(?Location $oldLocation): Location
36
    {
37 1
        if ($oldLocation === null) {
38
            return $this->newLocation;
39
        }
40
41 1
        $resultLocation = Connector::swapLocations($oldLocation, $this->newLocation);
42
43 1
        return $resultLocation;
44
    }
45
}
46