src/DataFixtures/ObjectMother/CustomerMother.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\DataFixtures\ObjectMother;
  3. use App\Entity\City;
  4. use App\Entity\Customer;
  5. use App\Entity\Embeddables\IdentityDocumentEmbeddable;
  6. use Faker\Factory;
  7. final class CustomerMother
  8. {
  9.     public static function create(
  10.         ?string $email null,
  11.         City $city
  12.     ): Customer {
  13.         $faker Factory::create('es_ES');
  14.         $customer = new Customer();
  15.         $customer->setEmail($email ?? $faker->email());
  16.         $customer->setPassword('customer');
  17.         $customer->setName($faker->firstName());
  18.         $customer->setSurname(sprintf('%s %s'$faker->lastName(), $faker->lastName()));
  19.         $customer->setAvatar(sprintf('https://randomuser.me/api/portraits/men/%d.jpg'rand(1,100)));
  20.         $customer->setBirthday($faker->dateTimeBetween('-50 year''-18 year'));
  21.         $customer->getDocument()->setType(rand(12));
  22.         $customer->getDocument()->setNumber($faker->vat());
  23.         switch ($customer->getDocument()->getType()) {
  24.             case IdentityDocumentEmbeddable::TYPE_DNI:
  25.                 $customer->getDocument()->setDateValid($faker->dateTimeBetween('1 year''5 year'));
  26.                 break;
  27.             case IdentityDocumentEmbeddable::TYPE_NIE:
  28.                 $customer->getDocument()->setNumberSupport($faker->vat());
  29.                 break;
  30.         }
  31.         
  32.         $customer->setAddressType(Customer::ADDRESS_TYPE_OTHER);
  33.         $customer->getAddress()->setRegion($city->getRegion()->getName());
  34.         $customer->getAddress()->setCity($city->getName());
  35.         $customer->getAddress()->setStreet($faker->streetAddress());
  36.         $customer->getAddress()->setPostal($faker->postcode());
  37.         $customer->setPhone($faker->phoneNumber());
  38.         $customer->setStatus(Customer::STATUS_PUBLISHED);
  39.         $customer->setCdate($faker->dateTimeBetween('-1 year''-1 month'));
  40.         return $customer;
  41.     }
  42. }