Skip to content

Commit f0dffa6

Browse files
authored
[FEATURE] Allow multiple partner types (#698)
Draft as this needs to be tested with any usages. --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1211138782444277
1 parent c3d4bd1 commit f0dffa6

File tree

6 files changed

+44
-10
lines changed

6 files changed

+44
-10
lines changed

src/Entity/Company.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ class Company implements \JsonSerializable
6666
*/
6767
private array $subscriptions = [];
6868
private ?Address $headquarter = null;
69-
private ?Subscription $partnerProgram = null;
69+
70+
/**
71+
* @var Subscription[]
72+
*/
73+
private array $partnerPrograms = [];
7074
private ?Subscription $membership = null;
7175
private ?string $domain = null;
7276
private ?string $backlink = null;
@@ -427,17 +431,32 @@ public function addSubscription(Subscription $subscription): self
427431
return $this;
428432
}
429433

430-
public function getPartnerProgram(): ?Subscription
434+
/**
435+
* @return Subscription[]
436+
*/
437+
public function getPartnerPrograms(): array
438+
{
439+
return $this->partnerPrograms;
440+
}
441+
442+
/**
443+
* @param Subscription[] $partnerPrograms
444+
*
445+
* @return $this
446+
*/
447+
public function setPartnerPrograms(array $partnerPrograms): self
431448
{
432-
return $this->partnerProgram;
449+
$this->partnerPrograms = $partnerPrograms;
450+
451+
return $this;
433452
}
434453

435454
/**
436455
* @return $this
437456
*/
438-
public function setPartnerProgram(?Subscription $partnerProgram): self
457+
public function addPartnerProgram(Subscription $partnerProgram): self
439458
{
440-
$this->partnerProgram = $partnerProgram;
459+
$this->partnerPrograms[] = $partnerProgram;
441460

442461
return $this;
443462
}

src/Enum/PartnerProgramType.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,19 @@ final class PartnerProgramType extends AbstractEnum
2525
self::TECHNOLOGY => 'Technology',
2626
self::CONSULTANT => 'Consultant',
2727
];
28+
29+
/**
30+
* @var array<string, float>
31+
*/
32+
protected static array $optionWeights = [
33+
self::NONE => 0.0,
34+
self::CONSULTANT => 0.1,
35+
self::SOLUTION => 0.2,
36+
self::TECHNOLOGY => 0.45,
37+
];
38+
39+
public static function getWeight(?string $option): float
40+
{
41+
return self::$optionWeights[$option] ?? 0.0;
42+
}
2843
}

src/Factory/CompanyFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public static function fromArray(array $data): Company
5353
foreach ($data['addresses'] ?? [] as $address) {
5454
$company->addAddress(AddressFactory::fromArray($address));
5555
}
56-
if (isset($data['partnerProgram'])) {
57-
$company->setPartnerProgram(SubscriptionFactory::fromArray($data['partnerProgram']));
56+
foreach ($data['partnerPrograms'] ?? [] as $partnerProgram) {
57+
$company->addPartnerProgram(SubscriptionFactory::fromArray($partnerProgram));
5858
}
5959
if (isset($data['membership'])) {
6060
$company->setMembership(SubscriptionFactory::fromArray($data['membership']));

tests/Api/CompanyApiTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testGetCompany(): void
4747
self::assertEquals([
4848
'isFoundingPartner' => true,
4949
'membership' => 'GOLD',
50-
'partnerType' => 'NONE',
50+
'partnerTypes' => [],
5151
], $response->getStatus());
5252
}
5353

tests/Fixtures/GetCompanyResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
"status": {
162162
"isFoundingPartner": true,
163163
"membership": "GOLD",
164-
"partnerType": "NONE"
164+
"partnerTypes": []
165165
}
166166
}
167167
');

tests/Fixtures/GetUserCompaniesResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"status": {
2727
"isFoundingPartner": false,
2828
"membership": "ACADEMIC_BRONZE",
29-
"partnerType": "NONE"
29+
"partnerTypes": []
3030
}
3131
}
3232
}

0 commit comments

Comments
 (0)