Completed
Push — master ( b74cd0...088e4f )
by Dennis
11:47
created

MethodNameGenerator::generate()   A

Complexity

Conditions 4
Paths 7

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.2
cc 4
eloc 10
nc 7
nop 1
1
<?php
2
3
namespace Dennis\Seeder\Generator;
4
5
/**
6
 * Class MethodNameGenerator
7
 *
8
 * @package Dennis\Seeder\Generator
9
 */
10
class MethodNameGenerator implements \Dennis\Seeder\Generator
11
{
12
    /**
13
     * @var \Dennis\Seeder\Faker $faker
14
     */
15
    protected $faker;
16
17
    /**
18
     * MethodNameGenerator constructor.
19
     */
20
    public function __construct(\Dennis\Seeder\Faker $faker)
21
    {
22
        $this->faker = $faker;
23
    }
24
25
    /**
26
     * @return mixed|void
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use integer|string|null.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
27
     */
28
    public function generate($parameter)
29
    {
30
        if (is_numeric($parameter)) {
31
            return (int) $parameter;
32
        }
33
        if ($this->faker->guessProviderName($parameter)) {
34
            $parameter = $this->faker->guessProviderName($parameter);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $parameter. This often makes code more readable.
Loading history...
35
        }
36
        try {
37
            $this->faker->get($parameter);
38
            return self::PREFIX . ucfirst($parameter) . self::SUFFIX;
39
        } catch (\Dennis\Seeder\Provider\NotFoundException $exception) {
40
            return null;
41
        }
42
    }
43
}
44