Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ jobs:
- name: Run unit tests
run: vendor/bin/phpunit --testsuite unit

phpcs:
name: phpcs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: none
tools: composer:v2

- name: Install dependencies
uses: ramsey/composer-install@v3
with:
composer-options: '--no-interaction --no-progress --prefer-dist'

- name: Run phpcs
run: vendor/bin/phpcs --standard=vendor/rentpost/coding-standard-php/phpcs.xml src/ test/

# Integration tests hit the real TransUnion ShareAble sandbox API and require
# credentials. They run only on manual maintainer trigger so PR validation
# never burns sandbox quota and so secrets are never exposed to fork PRs.
Expand Down
3 changes: 2 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,10 @@ public function addRenterToScreeningRequest(
ScreeningRequestRenter $screeningRequestRenter,
): ScreeningRequestRenter
{
$renterId = $screeningRequestRenter->getRenterId();
$response = $this->requestJson(
'POST',
"ScreeningRequests/$screeningRequestId/Renters/{$screeningRequestRenter->getRenterId()}/ScreeningRequestRenters",
"ScreeningRequests/$screeningRequestId/Renters/$renterId/ScreeningRequestRenters",
$screeningRequestRenter->toArray(), // No clue on this - docs don't say it's needed, but it is
);

Expand Down
1 change: 1 addition & 0 deletions src/ClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
class ClientException extends \Exception
{

// Marker exception for ShareAble client errors.
}
1 change: 0 additions & 1 deletion src/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Rentpost\TUShareable;

use Rentpost\TUShareable\Model\Attestation;
use Rentpost\TUShareable\Model\AttestationGroup;
use Rentpost\TUShareable\Model\Bundle;
use Rentpost\TUShareable\Model\CultureCode;
Expand Down
61 changes: 29 additions & 32 deletions src/Model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Symfony\Component\Validator\Constraints as Assert;

// addressLine1..4 are TU API field names; renaming would break the wire contract.
// phpcs:disable Zend.NamingConventions.ValidVariableName.ContainsNumbers

/**
* Class that represents an address.
*/
Expand All @@ -15,34 +18,44 @@ class Address
use Validate;


private const ADDRESS_PATTERN = '/^[a-zA-Z0-9 #()&.,\'\-_\+~\/\*]*$/';
private const ADDRESS_PATTERN_MESSAGE = 'Address field must only contain letters, numbers, spaces, hashes, '
. 'parentheses, ampersands, commas, periods, single quotes, hyphens, underscores, pluses, tildes, '
. 'forward slashes and asterisks.';


/** @param array<string, mixed> $data */
public static function fromArray(array $data): self
{
return new self(
$data['addressLine1'],
$data['addressLine2'] ?? null,
$data['addressLine3'] ?? null,
$data['addressLine4'] ?? null,
$data['locality'],
$data['region'],
$data['postalCode'],
$data['country'],
);
}


public function __construct(
#[Assert\NotBlank]
#[Assert\Length(min: 1, max: 50)]
#[Assert\Regex(
pattern: '/^[a-zA-Z0-9 #()&.,\'\-_\+~\/\*]*$/',
message: 'Address field must only contain letters, numbers, spaces, hashes, parentheses, ampersands, commas, periods, single quotes, hyphens, underscores, pluses, tildes, forward slashes and asterisks.',
)]
#[Assert\Regex(pattern: self::ADDRESS_PATTERN, message: self::ADDRESS_PATTERN_MESSAGE)]
private string $addressLine1,

#[Assert\Length(max: 100)]
#[Assert\Regex(
pattern: '/^[a-zA-Z0-9 #()&.,\'\-_\+~\/\*]*$/',
message: 'Address field must only contain letters, numbers, spaces, hashes, parentheses, ampersands, commas, periods, single quotes, hyphens, underscores, pluses, tildes, forward slashes and asterisks.',
)]
#[Assert\Regex(pattern: self::ADDRESS_PATTERN, message: self::ADDRESS_PATTERN_MESSAGE)]
private ?string $addressLine2,

#[Assert\Length(max: 100)]
#[Assert\Regex(
pattern: '/^[a-zA-Z0-9 #()&.,\'\-_\+~\/\*]*$/',
message: 'Address field must only contain letters, numbers, spaces, hashes, parentheses, ampersands, commas, periods, single quotes, hyphens, underscores, pluses, tildes, forward slashes and asterisks.',
)]
#[Assert\Regex(pattern: self::ADDRESS_PATTERN, message: self::ADDRESS_PATTERN_MESSAGE)]
private ?string $addressLine3,

#[Assert\Length(max: 100)]
#[Assert\Regex(
pattern: '/^[a-zA-Z0-9 #()&.,\'\-_\+~\/\*]*$/',
message: 'Address field must only contain letters, numbers, spaces, hashes, parentheses, ampersands, commas, periods, single quotes, hyphens, underscores, pluses, tildes, forward slashes and asterisks.',
)]
#[Assert\Regex(pattern: self::ADDRESS_PATTERN, message: self::ADDRESS_PATTERN_MESSAGE)]
private ?string $addressLine4,

#[Assert\NotBlank]
Expand Down Expand Up @@ -253,20 +266,4 @@ public function toArray(): array

return $array;
}


/** @param array<string, mixed> $data */
public static function fromArray(array $data): self
{
return new self(
$data['addressLine1'],
$data['addressLine2'] ?? null,
$data['addressLine3'] ?? null,
$data['addressLine4'] ?? null,
$data['locality'],
$data['region'],
$data['postalCode'],
$data['country'],
);
}
}
28 changes: 14 additions & 14 deletions src/Model/Attestation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ class Attestation
use Validate;


/** @param array<string, mixed> $data */
public static function fromArray(array $data): self
{
return new self(
$data['attestationId'],
$data['attestationTypeId'],
$data['name'],
$data['legalText'],
$data['affirmativeRequired'],
$data['additionalInformation'],
);
}


public function __construct(
private int $attestationId,
private int $attestationTypeId,
Expand Down Expand Up @@ -73,18 +87,4 @@ public function toArray(): array
'additionalInformation' => $this->additionalInformation,
];
}


/** @param array<string, mixed> $data */
public static function fromArray(array $data): self
{
return new self(
$data['attestationId'],
$data['attestationTypeId'],
$data['name'],
$data['legalText'],
$data['affirmativeRequired'],
$data['additionalInformation'],
);
}
}
42 changes: 21 additions & 21 deletions src/Model/AttestationGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ class AttestationGroup
private ?array $attestationResponses = null;


/** @param array<string, int|array<string, mixed>|null> $data */
public static function fromArray(array $data): self
{
$attestationGroupId = $data['attestationGroupId'];

$attestations = [];
foreach (($data['attestations'] ?? []) as $attestation) {
$attestations[] = new Attestation(
$attestation['attestationId'],
$attestation['attestationTypeId'],
$attestation['name'] ?? null,
$attestation['legalText'] ?? null,
$attestation['affirmativeRequired'],
$attestation['additionalInformation'] ?? null,
);
}

return new self($attestationGroupId, $attestations);
}


public function __construct(
private readonly int $attestationGroupId,

Expand Down Expand Up @@ -55,27 +76,6 @@ public function addAttestationResponse(int $attestationId, bool $isAffirmative):
}


/** @param array<string, int|array<string, mixed>|null> $data */
public static function fromArray(array $data): self
{
$attestationGroupId = $data['attestationGroupId'];

$attestations = [];
foreach (($data['attestations'] ?? []) as $attestation) {
$attestations[] = new Attestation(
$attestation['attestationId'],
$attestation['attestationTypeId'],
$attestation['name'] ?? null,
$attestation['legalText'] ?? null,
$attestation['affirmativeRequired'],
$attestation['additionalInformation'] ?? null,
);
}

return new self($attestationGroupId, $attestations);
}


/** @return array<string, int|array<string, mixed>> */
public function toArray(): array
{
Expand Down
20 changes: 10 additions & 10 deletions src/Model/Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ class Bundle
use Validate;


/** @param array<string, mixed> $data */
public static function fromArray(array $data): self
{
return new self(
$data['bundleId'],
$data['name'],
);
}


public function __construct(
#[Assert\NotBlank]
private int $bundleId,
Expand Down Expand Up @@ -45,14 +55,4 @@ public function toArray(): array
'name' => $this->name,
];
}


/** @param array<string, mixed> $data */
public static function fromArray(array $data): self
{
return new self(
$data['bundleId'],
$data['name'],
);
}
}
2 changes: 2 additions & 0 deletions src/Model/EmploymentStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

enum EmploymentStatus: string
{

use From;


case NotEmployed = 'NotEmployed';
case Employed = 'Employed';
case SelfEmployed = 'SelfEmployed';
Expand Down
44 changes: 22 additions & 22 deletions src/Model/Exam.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@ class Exam
private ?string $externalReferenceNumber = null;


/** @param array<string, mixed> $data */
public static function fromArray(array $data): self
{
$exam = new self($data['examId'], $data['result']);
$exam->setExternalReferenceNumber($data['setExternalReferenceNumber'] ?? null);

foreach ($data['authenticationQuestions'] as $qInfo) {
$question = new ExamQuestion($qInfo['questionKeyName'], $qInfo['questionDisplayName'], $qInfo['type']);

foreach ($qInfo['choices'] as $choice) {
$answer = new ExamQuestionAnswer($choice['choiceKeyName'], $choice['choiceDisplayName']);

$question->addChoice($answer);
}

$exam->addQuestion($question);
}

return $exam;
}


public function __construct(private int $examId, private string $result) {}


Expand Down Expand Up @@ -55,26 +77,4 @@ public function setExternalReferenceNumber(?string $val): void
{
$this->externalReferenceNumber = $val;
}


/** @param array<string, mixed> $data */
public static function fromArray(array $data): self
{
$exam = new self($data['examId'], $data['result']);
$exam->setExternalReferenceNumber($data['setExternalReferenceNumber'] ?? null);

foreach ($data['authenticationQuestions'] as $qInfo) {
$question = new ExamQuestion($qInfo['questionKeyName'], $qInfo['questionDisplayName'], $qInfo['type']);

foreach ($qInfo['choices'] as $choice) {
$answer = new ExamQuestionAnswer($choice['choiceKeyName'], $choice['choiceDisplayName']);

$question->addChoice($answer);
}

$exam->addQuestion($question);
}

return $exam;
}
}
38 changes: 19 additions & 19 deletions src/Model/Landlord.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ class Landlord
private ?int $landlordId = null;


/** @param array<string, mixed> $data */
public static function fromArray(array $data): self
{
$landlord = new self(
new Email($data['emailAddress']),
$data['firstName'],
$data['lastName'],
new Phone($data['phoneNumber'], $data['phoneType']),
$data['businessName'] ?? null,
Address::fromArray($data['businessAddress']),
boolval($data['acceptedTermsAndConditions']),
);

$landlord->setLandlordId($data['landlordId'] ?? null);

return $landlord;
}


public function __construct(
#[Assert\NotBlank]
private Email $emailAddress,
Expand Down Expand Up @@ -167,23 +186,4 @@ public function toArray(): array

return $array;
}


/** @param array<string, mixed> $data */
public static function fromArray(array $data): self
{
$landlord = new self(
new Email($data['emailAddress']),
$data['firstName'],
$data['lastName'],
new Phone($data['phoneNumber'], $data['phoneType']),
$data['businessName'] ?? null,
Address::fromArray($data['businessAddress']),
boolval($data['acceptedTermsAndConditions']),
);

$landlord->setLandlordId($data['landlordId'] ?? null);

return $landlord;
}
}
Loading
Loading