Skip to content

Repository files navigation

OceanMoon PHP Core

A general purpose package containing core PHP utility classes and methods for use by other OceanMoon PHP packages.

License | Changelog | Documentation

PHP 8.4


Description

This package provides a comprehensive set of utility classes for working with various PHP types and common operations. Most utility classes are final with static methods and cannot be instantiated directly. Console is the exception — an instantiable class with instance methods and internal style state, since its fluent -> chaining API needs a real object to chain off.


Development and Quality Assurance

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.

Code Coverage


Requirements

  • PHP ^8.4

Installation

composer require oceanmoon/core

Classes

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.

Number-related utilities for type checking (distinguishing actual numbers from numeric strings), exact equality that correctly handles mixed int/float comparisons, and sign operations with IEEE-754 signed zero support.

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.

Advanced value-to-string conversion with pretty printing, supporting all PHP types with improved readability. This class serves as the basis of the Console::dump() method.

Runtime environment detection: 64-bit architecture checks, and locale detection from the HTTP Accept-Language header.

ANSI/SGR-styled console output: 16-color foreground/background, text attributes (bold, italic, underline, etc.), method chaining, style snapshot/restore, and higher-level helpers like dump() and severity-colored messages (success(), error(), warn(), info()).


Useful constants (M_TAU, RECURSION) that are more convenient to use as globals (namespaced to OceanMoon\Core) than as class members.


Traits

Comparison Traits

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().

Assert Traits

Custom PHPUnit assertions for test cases. See TestingTraits.md for usage examples.

Trait Description
FloatAssertions Provides assertApproxEqual() with informative failure messages.

Enums

Notation styles for Floats::format() — fixed-point, scientific, or automatic selection between the two.

Rendering styles for the exponent portion of scientific-notation float output, from plain ASCII e/E through to Unicode and HTML mathematical notation.


Exceptions

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.

Exception thrown when an arithmetic operation has no defined result for the given operands, such as division by zero or a logarithm of a non-positive number. Extends DomainException. Displaces DivisionByZeroError for userland arithmetic code in value types like Complex, Rational, Vector, and Matrix.


Testing

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 test

License

MIT License - see LICENSE for details


Support

For questions or suggestions, please open an issue.


Changelog

See CHANGELOG.md for version history and changes.

About

Base package containing general purpose utility classes and methods.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages