Mock   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B create() 0 25 4
1
<?php
2
3
namespace GFG\DTOContext\DataWrapper;
4
5
class Mock
6
{
7
    /**
8
     * Creates a mock for a given transfer (because of dynamic getters and setters)
9
     */
10
    public static function create($name, \PHPUnit_Framework_TestCase $phpunit)
11
    {
12
        $methods = array();
13
14
        $ref = new \ReflectionClass($name);
15
        foreach ($ref->getProperties() as $property) {
16
            $methods[] = 'get' . ucfirst($property->name);
17
            $methods[] = 'set' . ucfirst($property->name);
18
        }
19
20
        foreach ($ref->getMethods() as $method) {
21
22
            // do not mock array object methods to we can iterate these mocks
23
            if ($method->class === 'ArrayObject') {
24
                continue;
25
            }
26
27
            $methods[] = $method->name;
28
        }
29
30
        return $phpunit->getMockBuilder($name)
31
            ->disableOriginalConstructor()
32
            ->setMethods($methods)
33
            ->getMock();
34
    }
35
}
36