Skip to content

Commit 960cc43

Browse files
committed
Add typehint to fn args
1 parent 6ab30cc commit 960cc43

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/lib/CustomSpecAttr.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@ class CustomSpecAttr
4040
* Foreign key column name. See README for usage docs
4141
*/
4242
public const FK_COLUMN_NAME = 'x-fk-column-name';
43+
44+
/**
45+
* Foreign key column name. See README for usage docs
46+
*/
47+
// public const FK_COLUMN_NAME = 'x-fk-column-name';
4348
}

src/lib/FakerStubResolver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ public function fakeForObject(SpecObjectInterface $items): string
355355
* @return string
356356
* @internal
357357
*/
358-
public function handleOneOf($items, $count): string
358+
public function handleOneOf(SpecObjectInterface $items, int $count): string
359359
{
360360
$result = 'array_map(function () use ($faker, $uniqueFaker) {';
361361
foreach ($items->oneOf as $key => $aDataType) {
@@ -370,7 +370,7 @@ public function handleOneOf($items, $count): string
370370
return $result;
371371
}
372372

373-
public function wrapInArray($aFaker, $uniqueItems, $count): string
373+
public function wrapInArray(string $aFaker, bool $uniqueItems, int $count): string
374374
{
375375
return 'array_map(function () use ($faker, $uniqueFaker) {
376376
return ' . ($uniqueItems ? str_replace('$faker->', '$uniqueFaker->', $aFaker) : $aFaker) . ';
@@ -385,7 +385,7 @@ public function arbitraryArray(): string
385385
/**
386386
* This method is only for `fakeForArray()` or methods only used inside `fakeForArray()`. If needed to use outside `fakeForArray()` context then some changes might be required.
387387
* Also see OpenAPI extension `x-no-relation` in README.md
388-
* @param $data
388+
* @param $data object|array
389389
* @return string|null
390390
* @throws ExceptionInterface
391391
* @throws InvalidConfigException
@@ -397,7 +397,7 @@ public function arbitraryArray(): string
397397
*/
398398
public function aElementFaker($data): ?string
399399
{
400-
$aElementData = Json::decode(Json::encode($data)); // object of stdClass -> array
400+
$aElementData = Json::decode(Json::encode($data)); // element object of stdClass -> array
401401
$compoSchemaData = [
402402
'properties' => [
403403
'unnamedProp' => $aElementData['items']

tests/specs/issue_fix/20_consider_openapi_spec_examples_in_faker_code_generation/index.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ components:
126126
type: array
127127
items:
128128
type: array
129+
minItems: 11
129130
items:
130131
type: integer
131-
132132
appearance:
133133
type: object
134134
properties:
@@ -171,7 +171,7 @@ components:
171171

172172
one_of_arr_complex:
173173
type: array
174-
maxItems: 8
174+
minItems: 8
175175
items:
176176
oneOf:
177177
- type: integer

tests/unit/IssueFixTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,12 @@ public function test158BugGiiapiGeneratedRulesEnumWithTrim()
364364
// https://github.com/php-openapi/yii2-openapi/issues/20
365365
public function test20ConsiderOpenApiSpecExamplesInFakeCodeGeneration()
366366
{
367+
// $faker = \Faker\Factory::create();
368+
// $uniqueFaker = $faker->unique();
369+
//
370+
// var_dump();
371+
// return;
372+
367373
$testFile = Yii::getAlias("@specs/issue_fix/20_consider_openapi_spec_examples_in_faker_code_generation/index.php");
368374
$this->runGenerator($testFile);
369375
// $actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [

0 commit comments

Comments
 (0)