PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0
GiveWP – Donation Plugin and Fundraising Platform v4.18.0
4.18.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 All 257 releases
give / src / Donors / Factories / DonorFactory.php

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

61 lines 2.2 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.18.0 Generate a unique "email", because the donors table does not accept a duplicate.
13 * @since 4.4.0 Add "company", "avatarId", "additionalEmails", and "addresses" properties
14 * @since 3.7.0 Add "phone" property
15 * @since 2.19.6
16 */
17 public function definition(): array
18 {
19 $firstName = $this->faker->firstName;
20 $lastName = $this->faker->lastName;
21
22 // Generate 0-3 additional emails
23 $additionalEmails = [];
24 $additionalEmailCount = $this->faker->numberBetween(0, 3);
25 for ($i = 0; $i < $additionalEmailCount; $i++) {
26 $additionalEmails[] = $this->faker->unique()->email;
27 }
28
29 // Generate 0-3 addresses
30 $addresses = [];
31 $addressCount = $this->faker->numberBetween(0, 3);
32 for ($i = 0; $i < $addressCount; $i++) {
33 $addresses[] = DonorAddress::fromArray([
34 'address1' => $this->faker->streetAddress,
35 'address2' => $this->faker->optional(0.3)->secondaryAddress,
36 'city' => $this->faker->city,
37 'state' => $this->faker->stateAbbr,
38 'country' => $this->faker->countryCode,
39 'zip' => $this->faker->postcode,
40 ]);
41 }
42
43 $data = [
44 'firstName' => $firstName,
45 'lastName' => $lastName,
46 'prefix' => $this->faker->randomElement(give_get_option('title_prefixes', array_values(give_get_default_title_prefixes()))),
47 'name' => trim("$firstName $lastName"),
48 'email' => $this->faker->unique()->email,
49 'phone' => $this->faker->phoneNumber,
50 'company' => $this->faker->company,
51 'avatarId' => $this->faker->optional(0.2)->numberBetween(1, 9999),
52 'additionalEmails' => $additionalEmails,
53 'addresses' => $addresses,
54 'totalAmountDonated' => new Money(0, 'USD'),
55 'totalNumberOfDonations' => 0
56 ];
57
58 return $data;
59 }
60 }
61