Completed
Pull Request — master (#187)
by Vincent
04:05
created

SmallStringGuesser::fake()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Knp\FriendlyContexts\Guesser;
4
5
class SmallStringGuesser extends AbstractGuesser implements GuesserInterface
6
{
7
    /**
8
     * @param array $mapping
9
     *
10
     * @return boolean
11
     */
12
    public function supports(array $mapping)
13
    {
14
        $mapping = array_merge(['type' => null, 'length' => null], $mapping);
15
16
        return in_array($mapping['type'], ['string', 'text']) && $mapping['length'] !== null;
17
    }
18
19
    /**
20
     * @param string     $str
21
     * @param array|null $mapping
22
     *
23
     * @return string
24
     */
25
    public function transform($str, array $mapping = null)
26
    {
27
        return $str;
28
    }
29
30
    /**
31
     * @param array $mapping
32
     *
33
     * @return string
34
     */
35
    public function fake(array $mapping)
36
    {
37
        return current($this->fakers)->fake('lexify', [str_repeat('?', $mapping['length'])]);
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function getName()
44
    {
45
        return 'smallstring';
46
    }
47
}
48