|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Factory\Model; |
| 4 | + |
| 5 | +use App\Model\GitHubUrlData; |
| 6 | +use App\Util\TypeEnum; |
| 7 | +use Zenstruck\Foundry\ModelFactory; |
| 8 | +use Zenstruck\Foundry\Proxy; |
| 9 | + |
| 10 | +/** |
| 11 | + * @extends ModelFactory<GitHubUrlData> |
| 12 | + * |
| 13 | + * @method GitHubUrlData|Proxy create(array|callable $attributes = []) |
| 14 | + * @method static GitHubUrlData|Proxy createOne(array $attributes = []) |
| 15 | + * @method static GitHubUrlData|Proxy find(object|array|mixed $criteria) |
| 16 | + * @method static GitHubUrlData|Proxy findOrCreate(array $attributes) |
| 17 | + * @method static GitHubUrlData|Proxy first(string $sortedField = 'id') |
| 18 | + * @method static GitHubUrlData|Proxy last(string $sortedField = 'id') |
| 19 | + * @method static GitHubUrlData|Proxy random(array $attributes = []) |
| 20 | + * @method static GitHubUrlData|Proxy randomOrCreate(array $attributes = []) |
| 21 | + * @method static GitHubUrlData[]|Proxy[] all() |
| 22 | + * @method static GitHubUrlData[]|Proxy[] createMany(int $number, array|callable $attributes = []) |
| 23 | + * @method static GitHubUrlData[]|Proxy[] createSequence(iterable|callable $sequence) |
| 24 | + * @method static GitHubUrlData[]|Proxy[] findBy(array $attributes) |
| 25 | + * @method static GitHubUrlData[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) |
| 26 | + * @method static GitHubUrlData[]|Proxy[] randomSet(int $number, array $attributes = []) |
| 27 | + * |
| 28 | + * @psalm-method GitHubUrlData&Proxy create(array|callable $attributes = []) |
| 29 | + * @psalm-method static GitHubUrlData&Proxy createOne(array $attributes = []) |
| 30 | + * @psalm-method static GitHubUrlData&Proxy find(object|array|mixed $criteria) |
| 31 | + * @psalm-method static GitHubUrlData&Proxy findOrCreate(array $attributes) |
| 32 | + * @psalm-method static GitHubUrlData&Proxy first(string $sortedField = 'id') |
| 33 | + * @psalm-method static GitHubUrlData&Proxy last(string $sortedField = 'id') |
| 34 | + * @psalm-method static GitHubUrlData&Proxy random(array $attributes = []) |
| 35 | + * @psalm-method static GitHubUrlData&Proxy randomOrCreate(array $attributes = []) |
| 36 | + * @psalm-method static GitHubUrlData[]&Proxy[] all() |
| 37 | + * @psalm-method static GitHubUrlData[]&Proxy[] createMany(int $number, array|callable $attributes = []) |
| 38 | + * @psalm-method static GitHubUrlData[]&Proxy[] createSequence(iterable|callable $sequence) |
| 39 | + * @psalm-method static GitHubUrlData[]&Proxy[] findBy(array $attributes) |
| 40 | + * @psalm-method static GitHubUrlData[]&Proxy[] randomRange(int $min, int $max, array $attributes = []) |
| 41 | + * @psalm-method static GitHubUrlData[]&Proxy[] randomSet(int $number, array $attributes = []) |
| 42 | + */ |
| 43 | +class GitHubUrlDataFactory extends ModelFactory |
| 44 | +{ |
| 45 | + #[\Override] |
| 46 | + protected function getDefaults(): array |
| 47 | + { |
| 48 | + return [ |
| 49 | + 'owner' => $owner = self::faker()->slug(), |
| 50 | + 'repository' => $repository = self::faker()->slug(), |
| 51 | + 'type' => $type = TypeEnum::PULL_REQUEST, |
| 52 | + 'identifier' => $id = self::faker()->randomNumber(), |
| 53 | + 'uri' => sprintf('https://github.com/%s/%s/%s/%s', |
| 54 | + $owner, |
| 55 | + $repository, |
| 56 | + TypeEnum::PULL_REQUEST === $type ? 'pulls' : 'issues', |
| 57 | + $id |
| 58 | + ), |
| 59 | + ]; |
| 60 | + } |
| 61 | + |
| 62 | + public function asIssue(): self |
| 63 | + { |
| 64 | + $uri = $this->getDefaults()['uri']; |
| 65 | + |
| 66 | + return $this->addState([ |
| 67 | + 'type' => TypeEnum::ISSUE, |
| 68 | + 'uri' => str_replace(TypeEnum::PULL_REQUEST->value, TypeEnum::ISSUE->value, (string) $uri), |
| 69 | + ]); |
| 70 | + } |
| 71 | + |
| 72 | + public function forResponse(): self |
| 73 | + { |
| 74 | + return $this->addState([ |
| 75 | + 'owner' => 'rushlow-development', |
| 76 | + 'repository' => 'big-desk', |
| 77 | + 'type' => TypeEnum::PULL_REQUEST, |
| 78 | + 'identifier' => 100, |
| 79 | + 'uri' => 'https://github.com/rushlow-development/big-desk/pulls/100', |
| 80 | + ]); |
| 81 | + } |
| 82 | + |
| 83 | + #[\Override] |
| 84 | + protected function initialize(): self |
| 85 | + { |
| 86 | + return $this |
| 87 | + ->withoutPersisting() |
| 88 | + ; |
| 89 | + } |
| 90 | + |
| 91 | + #[\Override] |
| 92 | + protected static function getClass(): string |
| 93 | + { |
| 94 | + return GitHubUrlData::class; |
| 95 | + } |
| 96 | +} |
0 commit comments