StringGuesser::fake()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 3
nop 1
1
<?php
2
3
namespace Knp\FriendlyContexts\Guesser;
4
5
class StringGuesser extends AbstractGuesser implements GuesserInterface
6
{
7
    public function supports(array $mapping)
8
    {
9
        $mapping = array_merge([ 'type' => null ], $mapping);
10
11
        return in_array($mapping['type'], ['string', 'text']);
12
    }
13
14
    public function transform($str, array $mapping = null)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
15
    {
16
        return $str;
17
    }
18
19
    public function fake(array $mapping)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
20
    {
21
        $mapping = array_merge(
22
            ['fieldName' => null, 'type' => null],
23
            $mapping
24
        );
25
26
        $name = $mapping['fieldName'];
27
28
        foreach ($this->fakers as $faker) {
29
            if ($faker->isFakable($name)) {
30
                return $faker->fake($name);
31
            }
32
        }
33
34
        return $this->fake(['fieldName' => 'text' === $mapping['type'] ? 'paragraph' : 'word']);
35
    }
36
37
    public function getName()
38
    {
39
        return 'string';
40
    }
41
}
42