Completed
Branch master (597d40)
by Douglas
02:41 queued 01:20
created

Place::createFromVector()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * (c) 2018 Douglas Reith.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
declare(strict_types=1);
10
11
namespace Reith\ToyRobot\Domain\Robot;
12
13
use Assert\Assert;
14
use MathPHP\LinearAlgebra\Vector;
15
16
/**
17
 * We can treat a placement as a Vector with origin at 0,0,n.
18
 *
19
 * @see Vector
20
 */
21
class Place extends Vector
22
{
23
    /**
24
     * @param array $coordinates
25
     *
26
     * @return Place
27
     *
28
     * @throws Assert\AssertionFailedException
29
     */
30 13
    public static function create(array $coordinates): Place
31
    {
32 13
        Assert::that($coordinates)->notEmpty();
33 12
        Assert::thatAll($coordinates)->integer();
34
35 10
        return new static($coordinates);
36
    }
37
38
    /**
39
     * @param callable $fn
40
     *
41
     * @return array
42
     */
43 6
    public function map(callable $fn): array
44
    {
45 6
        return array_map($fn, $this->getVector());
46
    }
47
48
    /**
49
     * @param Vector $v
50
     *
51
     * @return Place
52
     */
53 4
    public static function createFromVector(Vector $v): Place
54
    {
55 4
        return static::create($v->getVector());
56
    }
57
}
58