Files
Mangarr/src/Factory/MangaFactory.php
ext.jeremy.guillot@maxicoffee.domains 55945adc53 feat: Reader beginning
2025-02-16 16:15:42 +01:00

85 lines
3.4 KiB
PHP

<?php
namespace App\Factory;
use App\Entity\Manga;
use App\Repository\MangaRepository;
use Symfony\Component\String\Slugger\SluggerInterface;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Proxy;
use Zenstruck\Foundry\RepositoryProxy;
/**
* @extends ModelFactory<Manga>
*
* @method Manga|Proxy create(array|callable $attributes = [])
* @method static Manga|Proxy createOne(array $attributes = [])
* @method static Manga|Proxy find(object|array|mixed $criteria)
* @method static Manga|Proxy findOrCreate(array $attributes)
* @method static Manga|Proxy first(string $sortedField = 'id')
* @method static Manga|Proxy last(string $sortedField = 'id')
* @method static Manga|Proxy random(array $attributes = [])
* @method static Manga|Proxy randomOrCreate(array $attributes = [])
* @method static MangaRepository|RepositoryProxy repository()
* @method static Manga[]|Proxy[] all()
* @method static Manga[]|Proxy[] createMany(int $number, array|callable $attributes = [])
* @method static Manga[]|Proxy[] createSequence(iterable|callable $sequence)
* @method static Manga[]|Proxy[] findBy(array $attributes)
* @method static Manga[]|Proxy[] randomRange(int $min, int $max, array $attributes = [])
* @method static Manga[]|Proxy[] randomSet(int $number, array $attributes = [])
*/
final class MangaFactory extends ModelFactory
{
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services
*
* @todo inject services if required
*/
public function __construct(private SluggerInterface $slugger)
{
parent::__construct();
}
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories
*
* @todo add your default values here
*/
protected function getDefaults(): array
{
$title = self::faker()->words(rand(1, 3), true);
return [
'title' => $title,
'slug' => $this->slugger->slug($title)->lower(),
'imageUrl' => self::faker()->optional()->imageUrl(),
'publicationYear' => self::faker()->optional()->year(),
'description' => self::faker()->optional()->text(),
'genres' => self::faker()->optional()->words(rand(1, 5)),
'createdAt' => \DateTimeImmutable::createFromMutable(self::faker()->dateTime()),
'rating' => self::faker()->optional()->randomFloat(1, 0, 10),
'author' => self::faker()->optional()->name(),
'externalId' => self::faker()->optional()->uuid(),
'status' => self::faker()->optional()->randomElement(['ongoing', 'completed', 'hiatus']),
'thumbnailUrl' => self::faker()->optional()->imageUrl(150, 150),
'monitored' => self::faker()->boolean(),
'AlternativeSlugs' => self::faker()->optional()->words(3),
];
}
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
*/
protected function initialize(): self
{
return $this
// ->afterInstantiate(function(Manga $manga): void {})
;
}
protected static function getClass(): string
{
return Manga::class;
}
}