A general purpose package containing core PHP utility classes and methods for use by other OceanMoon PHP packages.
License | Changelog | Documentation
This package provides a comprehensive set of utility classes for working with various PHP types and common operations. All utility classes are final with static methods and cannot be instantiated.
Claude Chat and Claude Code were used in the development of this package. The core classes were designed, coded, and commented primarily by the author, with Claude providing substantial assistance with code review, suggesting improvements, debugging, and generating tests and documentation. All code was thoroughly reviewed by the author, and validated using industry-standard tools including PHP_Codesniffer, PHPStan (to level 9), and PHPUnit to ensure full compliance with PSR-12 coding standards and comprehensive unit testing with 100% code coverage. This collaborative approach has produced a well-designed, production-ready package with thorough test coverage and documentation.
- PHP ^8.4
composer require oceanmoon/coreGeneral number-related utility methods including sign operations.
Float-specific utilities for handling IEEE-754 special values (-0.0, ±INF, NAN), approximate comparison, float space navigation (next/previous), random generation, and IEEE-754 component assembly/disassembly.
Integer arithmetic operations with overflow checking (add, subtract, multiply, power), GCD calculation, and Unicode subscript/superscript conversion.
Array utility methods including circular reference detection, value quoting, and first/last element extraction.
Type checking and inspection utilities with methods for identifying numbers, unsigned integers, traits, and generating unique string keys.
String conversion and output utilities. Converts any value to a string, passing strings through as-is and using __toString() for Stringable objects.
Advanced value-to-string conversion with pretty printing, supporting all PHP types with improved readability.
Convenience functions in the OceanMoon\Core namespace, including println() for outputting strings and other values.
Equality and ordering comparison operations for custom types. See ComparisonTraits.md for the trait hierarchy and usage guide.
| Trait | Description |
|---|---|
| Equatable | Base trait for exact equality comparison via equal(). |
| Comparable | Extends Equatable with ordering: lessThan(), greaterThan(), etc. |
| ApproxEquatable | Extends Equatable with tolerance-based approxEqual(). |
| ApproxComparable | Combines Comparable and ApproxEquatable with approxCompare(). |
Custom PHPUnit assertions for test cases. See TestingTraits.md for usage examples.
| Trait | Description |
|---|---|
| FloatAssertions | Provides assertApproxEqual() and assertApproxZero() with informative failure messages. |
Exception thrown when attempting to compare values of incompatible types. Used by the Comparable and ApproxComparable traits. Automatically generates descriptive error messages.
Exception thrown when a string has an invalid format for the desired operation. Extends DomainException. Useful for parse methods or constructors that accept string arguments.
The library includes comprehensive test coverage:
# Run all tests
vendor/bin/phpunit
# Run specific test class
vendor/bin/phpunit tests/NumbersTest.php
# Run with coverage (generates HTML report and clover.xml)
composer testMIT License - see LICENSE for details
- Issues: https://github.com/mossy2100/PHP-Core/issues
- Documentation: See docs/ directory for detailed class documentation
- Examples: See test files for comprehensive usage examples
For questions or suggestions, please open an issue.
See CHANGELOG.md for version history and changes.
