SwapLocationResponse::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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