Learn-skills.dev valinor-php
Write and fix PHP code using `cuyz/valinor`. Use this skill whenever the user mentions Valinor, `MapperBuilder`, `NormalizerBuilder`, `MappingError`, mapping arrays, JSON, YAML, or HTTP requests into typed PHP objects, normalizing objects back to arrays or JSON, custom converters, constructors, transformers, or advanced PHPStan or Psalm type signatures with Valinor.
install
source · Clone the upstream repo
git clone https://github.com/NeverSight/learn-skills.dev
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/NeverSight/learn-skills.dev "$T" && mkdir -p ~/.claude/skills && cp -r "$T/data/skills-md/aaronflorey/agent-skills/valinor-php" ~/.claude/skills/neversight-learn-skills-dev-valinor-php && rm -rf "$T"
manifest:
data/skills-md/aaronflorey/agent-skills/valinor-php/SKILL.mdsource content
Valinor PHP
Use this skill to write production-quality code against Valinor's public API. Favor the smallest correct Valinor configuration and keep the code on the public surface.
Core stance
- Default to strict mapping. Relax rules only when the input contract actually requires it.
- Prefer precise PHP and PHPDoc types over
ormixed
.object - Prefer public entrypoints such as
,MapperBuilder
,NormalizerBuilder
,Mapper\Source\Source
,Normalizer\Format
,HttpRequest
,AsConverter
, andAsTransformer
.Object\Constructor - Treat builders as immutable configuration objects. Chain or reassign them; do not assume in-place mutation.
- Prefer reusable configurators for shared application policy.
- Avoid internal classes under areas like
,Library
,Compiler
, or concrete mapper internals.Definition
Read only what you need
| Task | Read |
|---|---|
| General mapping, builder setup, cache, public API | |
| Choosing exact types and signatures | |
| JSON/YAML/file sources, path mapping, and custom iterable sources | |
| Converters, key remapping, constructors, interface inference, custom errors | |
| HTTP request mapping, PSR-7 integration, source-binding attributes | |
| Array or JSON normalization and transformers | |
| Formatting, translating, and remapping validation messages | |
| Static-analysis plugins, purity, framework integration, and upgrade notes | |
| Picking an implementation pattern from a user request | |
| Debugging mapping failures or weird behavior | |
| Fast starter snippets | |
| HTTP-specific starter snippets | |
| Message-formatting snippets | |
| Production-safe baseline | |
| Smells and corrected versions | |
Workflow
- Identify the boundary: object mapping, callable arguments, HTTP request mapping, normalization, or customization.
- Load the one or two reference files that match the task.
- Use the narrowest correct target type.
- Start with strict defaults; only add toggles like
orallowScalarValueCasting()
when justified by the input contract.allowSuperfluousKeys() - Catch
at the application boundary when invalid external input is expected.CuyZ\Valinor\Mapper\MappingError - If the same Valinor policy will be reused, extract it into a builder configurator instead of repeating chained calls.
- If code is production-facing, add cache usage when appropriate.
Preferred defaults
- For JSON, YAML, and files, prefer
,Mapper\Source\Source::json()
, andSource::yaml()
.Source::file() - For new code, prefer provided key-case configurators over deprecated source
modifiers like
.Source::camelCaseKeys()
path mapping is still valid when reshaping inbound payloads; only the deprecated key-case source modifier should be avoided in new code.Source::map()- Use direct type signatures like
or'list<Foo>'
when a dedicated DTO would be unnecessary.'array{status: non-empty-string, page?: positive-int}' - Use DTOs or value objects when the structure is reused, domain-bearing, or deserves constructor validation.
- Use
for interface or abstract-class polymorphism when the concrete implementation depends on input data.infer() - Use
orregisterConstructor()
when object creation is not a plain constructor mapping problem.#[Object\Constructor] - Use
for input value transformation andregisterConverter()
for output normalization.registerTransformer() - For HTTP request mapping, remember route and query parameters already support
scalar casting without enabling global
.allowScalarValueCasting()
Hard rules
- Do not recommend internal Valinor classes for application code.
- Do not silently widen types just to make mapping pass.
- Do not enable permissive behavior globally without an explicit reason.
- Do not forget that custom constructors, converters, transformers, and infer callbacks must stay pure and deterministic.
Delivery checklist
Before finishing, make sure the code:
- Uses public Valinor APIs only.
- Uses the exact type signature the boundary needs.
- Explains any non-default flexibility setting by the input contract.
- Handles
where invalid external input can occur.MappingError - Avoids deprecated patterns unless maintaining existing code.
This skill is self-contained and should be sufficient at runtime.