MethodNameGenerator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace TildBJ\Seeder\Generator;
4
5
/**
6
 * Class MethodNameGenerator
7
 *
8
 * @package TildBJ\Seeder\Generator
9
 */
10
class MethodNameGenerator implements \TildBJ\Seeder\Generator
11
{
12
    /**
13
     * @var \TildBJ\Seeder\Faker $faker
14
     */
15
    protected $faker;
16
17
    /**
18
     * MethodNameGenerator constructor.
19
     */
20 10
    public function __construct(\TildBJ\Seeder\Faker $faker)
21
    {
22 10
        $this->faker = $faker;
23 10
    }
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 7
    public function generate($parameter)
29
    {
30 7
        if (is_numeric($parameter)) {
31 2
            return (int) $parameter;
32
        }
33 5
        if ($this->faker->guessProviderName($parameter)) {
34 3
            $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 5
            $this->faker->get($parameter);
38 4
            return self::PREFIX . ucfirst($parameter) . self::SUFFIX;
39 1
        } catch (\TildBJ\Seeder\Provider\NotFoundException $exception) {
40 1
            return null;
41
        }
42
    }
43
}
44