thesis/formatter

Thesis Formatter

Maintainers

Package info

github.com/thesis-php/formatter

pkg:composer/thesis/formatter

Fund package maintenance!

www.tinkoff.ru/cf/5MqZQas2dk7

Statistics

Installs: 80

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 1

0.1.0 2026-04-13 19:08 UTC

This package is auto-updated.

Last update: 2026-04-13 19:35:04 UTC


README

PHP Version Requirement GitHub Release Code Coverage Mutation testing badge

A collection of functions for formatting PHP values and code elements into human-readable strings. Useful for error messages, exceptions, and debugging output.

Installation

composer require thesis/formatter

Functions

All functions are in the Thesis\Formatter namespace.

format(mixed $value): string

Formats any PHP value.

format(null);                 // null
format(true);                 // true
format(42);                   // 42
format("it's fine");          // 'it\'s fine'
format([1, 2, 3]);            // list{1, 2, 3}
format(['a' => 1, 'b' => 2]); // array{a: 1, b: 2}
format((object)['x' => 1]);   // object{x: 1}
format(Status::Active);       // Status::Active
format(new MyClass());        // MyClass
format(fn() => null);         // function@src/foo.php:12()

formatClass(string|object $class): string

Formats a class name. Anonymous classes get a readable file:line label.

formatClass(MyClass::class); // MyClass
formatClass(new MyClass());  // MyClass
formatClass(new class {});   // class@src/foo.php:42

formatFunction(callable $function): string

Formats a callable.

formatFunction('strlen');                       // strlen()
formatFunction('MyClass::myMethod');            // MyClass::myMethod()
formatFunction([MyClass::class, 'myMethod']);   // MyClass::myMethod()
formatFunction(fn() => null);                   // function@src/foo.php:12()
formatFunction(new MyInvokable());              // MyInvokable()

formatParameter(callable $function, int|string $parameter): string

Formats a parameter reference by index or name.

formatParameter('myFunction', 'value');  // myFunction($value)
formatParameter('myFunction', 0);        // myFunction($0)

formatProperty(string|object $class, string $property): string

Formats a property reference.

formatProperty(MyClass::class, 'name');  // MyClass::$name
formatProperty(new MyClass(), 'name');   // MyClass::$name

Reflection-based functions

Convenient wrappers around the functions above.

Function Example output
formatReflectedClass(\ReflectionClass $class) MyClass
formatReflectedFunction(\ReflectionFunctionAbstract $function) MyClass::myMethod()
formatReflectedParameter(\ReflectionParameter $parameter) MyClass::myMethod($param)
formatReflectedProperty(\ReflectionProperty $property) MyClass::$name
formatReflectedType(?\ReflectionType $type) string|int, ?Foo, A&B