Completed
Push — master ( 4ab497...db9007 )
by Freek
01:47
created

ArgumentValueProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Spatie\MailableTest;
4
5
use Faker\Generator;
6
7
class ArgumentValueProvider
8
{
9
    /** @var \Faker\Generator  */
10
    protected $faker;
11
12
    public function __construct(Generator $faker)
13
    {
14
        $this->faker = $faker;
15
    }
16
17
    public function getValue(string $argumentName, string $argumentType = '')
0 ignored issues
show
Unused Code introduced by
The parameter $argumentName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
    {
19
        if ($argumentType === 'int') {
20
            return $this->faker->numberBetween(1, 100);
21
        }
22
23
        if ($argumentType === 'string') {
24
            return $this->faker->sentence();
25
        }
26
27
        if ($argumentType === 'bool') {
28
            return $this->faker->boolean(50);
29
        }
30
31
32
        $argumentValue = app($argumentType);
33
34
        if ($argumentValue instanceof Model) {
0 ignored issues
show
Bug introduced by
The class Spatie\MailableTest\Model does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
35
            $argumentValue = $this->getModelInstance($argumentValue);
36
        }
37
38
        return $argumentValue;
39
    }
40
41
    protected function getModelInstance(Model $model)
42
    {
43
        $model = $model->first();
44
45
        if (! $model) {
46
            $modelClass = get_class($model);
47
            throw new Exception("Could not find a model of class `{$modelClass}`.");
48
        }
49
50
        return $model;
51
    }
52
}
53