Completed
Push — master ( dad334...685d59 )
by Alberto
02:51
created

StubFactory::fromArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

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