Assasz /
gorynych
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Copyright (c) 2020. |
||
| 4 | * @author Paweł Antosiak <[email protected]> |
||
| 5 | */ |
||
| 6 | |||
| 7 | declare(strict_types=1); |
||
| 8 | |||
| 9 | namespace Gorynych\Testing; |
||
| 10 | |||
| 11 | use Faker\Generator; |
||
| 12 | use Webmozart\Assert\Assert; |
||
| 13 | |||
| 14 | final class FakerValueResolver |
||
| 15 | { |
||
| 16 | private Generator $faker; |
||
| 17 | |||
| 18 | 5 | public function __construct(Generator $faker) |
|
| 19 | { |
||
| 20 | 5 | $this->faker = $faker; |
|
| 21 | 5 | } |
|
| 22 | |||
| 23 | /** |
||
| 24 | * @return bool|int|string|null |
||
| 25 | */ |
||
| 26 | 5 | public function resolvePropertyValue(\ReflectionProperty $property) |
|
| 27 | { |
||
| 28 | 5 | $propertyType = $property->getType(); |
|
|
0 ignored issues
–
show
|
|||
| 29 | 5 | Assert::isInstanceOf($propertyType, \ReflectionNamedType::class); |
|
| 30 | |||
| 31 | 5 | switch ($propertyType->getName()) { |
|
| 32 | 5 | case 'string': |
|
| 33 | try { |
||
| 34 | 2 | $value = $this->faker->{$property->getName()}; |
|
| 35 | 2 | } catch (\Throwable $t) { |
|
| 36 | 2 | $value = $this->faker->word; |
|
| 37 | } |
||
| 38 | 2 | break; |
|
| 39 | 4 | case 'int': |
|
| 40 | 2 | $value = $this->faker->randomDigit; |
|
| 41 | 2 | break; |
|
| 42 | 3 | case 'bool': |
|
| 43 | 2 | $value = $this->faker->boolean; |
|
| 44 | 2 | break; |
|
| 45 | 2 | case 'DateTime': |
|
| 46 | 2 | $value = $this->faker->dateTime->format('Y-m-d H:i'); |
|
| 47 | 2 | break; |
|
| 48 | default: |
||
| 49 | $value = null; |
||
| 50 | } |
||
| 51 | |||
| 52 | 5 | return $value; |
|
| 53 | } |
||
| 54 | } |
||
| 55 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.