Valinor/docs/pages/index.md
2022-06-11 12:48:35 +02:00

44 lines
1.6 KiB
Markdown

---
hide:
- toc
---
Valinor • PHP object mapper with strong type support
====================================================
<img src="img/valinor-logo.svg" align="left" width="100"/>
Valinor is a PHP library that helps to map any input into a strongly-typed value
object structure.
The conversion can handle native PHP types as well as other well-known advanced
type annotations like array shapes, generics and more.
## Why?
There are many benefits of using value objects instead of plain arrays and
scalar values in a modern codebase, among which:
1. **Data and behaviour encapsulation** — locks an object's behaviour inside its
class, preventing it from being scattered across the codebase.
2. **Data validation** — guarantees the valid state of an object.
3. **Immutability** — ensures the state of an object cannot be changed during
runtime.
When mapping any source to an object structure, this library will ensure that
all input values are properly converted to match the types of the nodes — class
properties or method parameters. Any value that cannot be converted to the
correct type will trigger an error and prevent the mapping from completing.
These checks guarantee that if the mapping succeeds, the object structure is
perfectly valid, hence there is no need for further validation nor type
conversion: the objects are ready to be used.
### Static analysis
A strongly-typed codebase allows the usage of static analysis tools like
[PHPStan] and [Psalm] that can identify issues in a codebase without running it.
Moreover, static analysis can help during a refactoring of a codebase with tools
like an IDE or [Rector].