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

StubFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 22
c 0
b 0
f 0
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 13 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