Completed
Pull Request — master (#44)
by Angelo
02:02
created

buildStubs.php ➔ buildStubs()   A

Complexity

Conditions 4
Paths 7

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 7
nop 1
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 4
rs 9.2
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Factory;
5
use Moka\Exception\InvalidArgumentException;
6
use Moka\Stub\MethodStub;
7
use Moka\Stub\PropertyStub;
8
use Moka\Stub\StubHelper;
9
use Moka\Stub\StubInterface;
10
use Moka\Stub\StubSet;
11
12
/**
13
 * @param array $namesWithValues
14
 * @return StubSet|StubInterface[]
15
 *
16
 * @throws InvalidArgumentException
17
 * @throws \LogicException
18
 */
19
function buildStubs(array $namesWithValues): StubSet
20
{
21 81
    $stubSet = new StubSet();
22 81
    foreach ($namesWithValues as $name => $value) {
23
        try {
24 81
            $stub = StubHelper::isPropertyName($name)
25 80
                ? new PropertyStub($name, $value)
26 80
                : new MethodStub($name, $value);
27
28 80
            $stubSet->add($stub);
29 1
        } catch (\Error $error) {
30 81
            throw new InvalidArgumentException($error->getMessage());
31
        }
32
    }
33
34 80
    return $stubSet;
35
}
36