jn-devops / common
Homeful Common Package
Fund package maintenance!
Homeful
Installs: 7 231
Dependents: 9
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- propaganistas/laravel-phone: ^5.3
- spatie/laravel-data: ^4.13
- spatie/laravel-package-tools: ^1.16
- spatie/laravel-schemaless-attributes: ^2.5
- whitecube/php-prices: ^3.1
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- spatie/laravel-ray: ^1.35
- dev-main
- v1.5.95
- v1.5.94
- v1.5.93
- v1.5.92
- v1.5.9
- v1.5.8
- v1.5.7
- v1.5.6
- v1.5.5
- v1.5.4
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.93
- v1.4.92
- v1.4.91
- v1.4.9
- v1.4.8
- v1.4.7
- v1.4.6
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.9
- v1.3.8
- v1.3.7
- v1.3.6
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.15
- v1.2.14
- v1.2.13
- v1.2.12
- v1.2.11
- v1.2.10
- v1.2.9
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.0
This package is auto-updated.
Last update: 2025-03-21 01:45:55 UTC
README
The Homeful\Common
package is a utility package that contains reusable helpers, constants, enumerations, and abstract types used across the Homeful system. It aims to promote consistency and reduce duplication of logic in other domain-specific packages such as Mortgage, Payment, Property, and Borrower.
๐ฆ Contents
- Utilities
- Classes
- Enumerations
๐งฐ Utilities
documents_path(?string $path = null): string
Returns the path to the /resources/documents
directory.
documents_path(); // /resources/documents documents_path('legal/contract.pdf'); // /resources/documents/legal/contract.pdf
formatted_age(DateTime $born, ?DateTime $reference = null): string
Returns a human-readable age string based on birthdate.
formatted_age(new DateTime('1990-05-23')); // "33 years, 10 months and 3 days old"
doc_stamps(mixed $value): float
Returns the documentary stamp fee based on property value.
doc_stamps(450000); // 50.0
filter_trim_recursive_array(array $array): array
Trims strings and filters empty values recursively in nested arrays.
dot_shift(&$dot_notation): string
Shifts off the first key in a dot notation string.
$key = dot_shift($dot = "property.name"); // $key = "property", $dot = "name"
titleCase(?string $text, array $exclusions = []): string
Applies Str::title()
but preserves Roman numerals and exceptions.
titleCase('juan dela cruz ii'); // Juan Dela Cruz II
validateJson(string $json): bool
Returns true if a valid JSON string.
resolveOptionalCollection(DataCollection|Optional|null $collection): Collection
Handles resolution of Spatie DataCollection
and Optional
.
array_when(array $array, $condition, callable $callback): array
Conditionally apply a transformation on an array.
array_when([1,2,3], false, fn($arr) => array_map(fn($x) => $x * 2, $arr)); // [1,2,3]
convertNumberToWords(float $value): string
Converts a float value to words.
convertNumberToWords(1500.75); // ONE THOUSAND FIVE HUNDRED AND 75/100
๐ Core Classes
Homeful\Common\Classes\Input
A collection of constants used for data keys in form input and parameter arrays. Examples include:
Input::TCP
- Total Contract PriceInput::PERCENT_DP
- Percent Down PaymentInput::BP_TERM
- Balance Payment Term
Usage:
$params = [ Input::TCP => 2500000, Input::PERCENT_DP => 0.05, ];
Homeful\Common\Classes\Assert
A collection of constants used to assert derived or calculated values in computations:
Assert::LOAN_AMOUNT
Assert::INCOME_REQUIREMENT
Assert::LOAN_AMORTIZATION
Used commonly in unit tests:
expect($mortgage->getLoan()->getPrincipal()->inclusive()->compareTo($params[Assert::LOAN_AMOUNT]))->toBe(Amount::EQUAL);
๐งฎ AmountCollectionItem
Base class representing any item with:
- a name
- a
Price
value - deductible flag
- a tag
Used as a base for:
AddOnFeeToPayment
DeductibleFeeFromPayment
๐ Enumerations
UploadFile
Maps file-related attributes to suffixes for Media Library collections.
UploadFile::Image->suffix(); // 'images' UploadFile::deriveCollectionNameFromAttribute('propertyImage'); // 'property-images'
WorkArea
Represents whether a user operates in a Highly Urbanized City or Region.
WorkArea::fromRegional(true); // WorkArea::REGION WorkArea::default(); // WorkArea::HUC
โ Example Usage
use Homeful\Common\Classes\Input; use Homeful\Common\Classes\Assert; $params = [ Input::TCP => 2500000, Input::PERCENT_DP => 0.05, Assert::LOAN_AMOUNT => 2375000.0, ]; expect($params[Assert::LOAN_AMOUNT])->toBe(2375000.0);
๐ Path Resolution
documents_path('mortgage/terms.pdf'); // => /resources/documents/mortgage/terms.pdf
๐งช Testing Helpers
Used extensively in test scripts to:
- Assert expected results via
Assert
- Pass parameters using
Input
- Use
formatted_age
,doc_stamps
, etc.
Behold, a new you awaits. โจ