PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / src / Donors / Factories / DonorFactory.php

DonorFactory.php in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at src/Donors/Factories/DonorFactory.php

60 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Donors\Factories;
4
5 use Give\Donors\ValueObjects\DonorAddress;
6 use Give\Framework\Models\Factories\ModelFactory;
7 use Give\Framework\Support\ValueObjects\Money;
8
9 class DonorFactory extends ModelFactory
10 {
11 /**
12 * @since 4.4.0 Add "company", "avatarId", "additionalEmails", and "addresses" properties
13 * @since 3.7.0 Add "phone" property
14 * @since 2.19.6
15 */
16 public function definition(): array
17 {
18 $firstName = $this->faker->firstName;
19 $lastName = $this->faker->lastName;
20
21 // Generate 0-3 additional emails
22 $additionalEmails = [];
23 $additionalEmailCount = $this->faker->numberBetween(0, 3);
24 for ($i = 0; $i < $additionalEmailCount; $i++) {
25 $additionalEmails[] = $this->faker->unique()->email;
26 }
27
28 // Generate 0-3 addresses
29 $addresses = [];
30 $addressCount = $this->faker->numberBetween(0, 3);
31 for ($i = 0; $i < $addressCount; $i++) {
32 $addresses[] = DonorAddress::fromArray([
33 'address1' => $this->faker->streetAddress,
34 'address2' => $this->faker->optional(0.3)->secondaryAddress,
35 'city' => $this->faker->city,
36 'state' => $this->faker->stateAbbr,
37 'country' => $this->faker->countryCode,
38 'zip' => $this->faker->postcode,
39 ]);
40 }
41
42 $data = [
43 'firstName' => $firstName,
44 'lastName' => $lastName,
45 'prefix' => $this->faker->randomElement(give_get_option('title_prefixes', array_values(give_get_default_title_prefixes()))),
46 'name' => trim("$firstName $lastName"),
47 'email' => $this->faker->email,
48 'phone' => $this->faker->phoneNumber,
49 'company' => $this->faker->company,
50 'avatarId' => $this->faker->optional(0.2)->numberBetween(1, 9999),
51 'additionalEmails' => $additionalEmails,
52 'addresses' => $addresses,
53 'totalAmountDonated' => new Money(0, 'USD'),
54 'totalNumberOfDonations' => 0
55 ];
56
57 return $data;
58 }
59 }
60