You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CLAUDE.md
+73-5Lines changed: 73 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,10 @@ user to resolve it.
9
9
10
10
Rules:
11
11
12
-
- Ask all foreseeable clarifying questions upfront in a single batch before work begins.
12
+
- When there are multiple clarifying questions to ask, ask them **one at a time**, in order of
13
+
dependency (earlier answers may resolve later questions). Wait for the answer before asking the
14
+
next question. This allows the user to discuss each point in depth without being overwhelmed by
15
+
a wall of questions.
13
16
- If new ambiguities emerge during execution that were not foreseeable upfront, pause and ask
14
17
follow-up questions before proceeding past that decision point.
15
18
- For high-stakes decisions (architecture, scope, data model, API shape, behaviour changes) always
@@ -19,6 +22,9 @@ Rules:
19
22
visible so the user can correct it.
20
23
- There must be no silent interpretation or interpolation of under-specified tasks. If something is
21
24
unclear, ask. Do not guess and proceed.
25
+
- For multi-phase implementations, **never start the next phase without an explicit go-ahead from
26
+
the user**. After completing a phase, summarise what was done and wait for confirmation before
27
+
proceeding.
22
28
23
29
When generating a new CLAUDE.md for a repository, include this clarification policy verbatim as a
24
30
preamble before all other content.
@@ -48,6 +54,20 @@ composer update
48
54
49
55
Tests write generated PHP classes to `sys_get_temp_dir()/PHPModelGeneratorTest/Models/` and dump failed classes to `./failed-classes/` (auto-cleaned on bootstrap).
50
56
57
+
### Running the full test suite
58
+
59
+
When running the full test suite, always save output to a file so the complete
60
+
output is available for analysis without re-running. Use `--display-warnings` to capture warning
61
+
details and `--no-coverage` to skip slow coverage collection:
- Uses `PropertyProcessorFactory` to instantiate the correct processor by JSON type (String, Integer, Number, Boolean, Array, Object, Null, Const, Any, Reference)
76
-
-Convention: processor class name is `PHPModelGenerator\PropertyProcessor\Property\{Type}Processor`
95
+
- Uses `PropertyFactory` (`src/PropertyProcessor/PropertyFactory.php`) to create and configure each property
96
+
-`PropertyFactory` resolves `$ref` references, delegates `object` types to `processSchema`, and for all other types constructs a `Property` directly and applies Draft modifiers
-**`Model/Validator/Factory/`** — `AbstractValidatorFactory` subclasses keyed to schema keywords (e.g. `MinLengthPropertyValidatorFactory` for `minLength`); run as modifiers when a matching key exists in the schema
108
+
109
+
`PropertyFactory::applyDraftModifiers` resolves `getCoveredTypes($type)` (which always includes `'any'`) and runs every modifier for each covered type in order.
@@ -104,6 +134,17 @@ Implement `SchemaProviderInterface` to supply schemas from custom sources. Built
104
134
105
135
`AbstractPHPModelGeneratorTestCase` is the base class for all tests. Tests generate model classes into a temp directory and then instantiate/exercise them to verify validation behavior. The `tests/manual/` directory contains standalone scripts excluded from the test suite.
106
136
137
+
#### Test case consolidation
138
+
139
+
Each call to `generateClassFromFile` triggers a code generation pass, which is the dominant cost in the test suite. **Minimise the number of distinct `generateClassFromFile` calls** by combining assertions that share the same schema file and `GeneratorConfiguration` into a single test method.
140
+
141
+
Rules:
142
+
143
+
- Group assertions by `(schema file, GeneratorConfiguration)` pair. All assertions that can use the same generated class belong in one test method.
144
+
- A single test method may cover multiple behaviours (e.g. key naming, round-trip, `$except`, custom serializer) as long as they all operate on the same generated class. Use clear inline comments to separate the logical sections.
145
+
- Only split into separate test methods when the behaviours require genuinely different configurations, or when combining them would make the test too complex to understand at a glance.
146
+
- The goal is the balance between runtime efficiency (fewer generations) and readability (each method remains comprehensible). Avoid both extremes: a single monolithic test and a proliferation of single-assertion tests.
147
+
107
148
### JSON Schema style
108
149
109
150
In test schema files (`tests/Schema/**/*.json`), every object value must be expanded across multiple lines — never written inline. Use this style:
@@ -131,6 +172,33 @@ property, duplicate property names with unresolvable type conflicts, and any oth
131
172
that cannot produce a correct PHP model. Fail loudly at generation time so the developer sees the
132
173
problem immediately rather than receiving silently incorrect generated code.
133
174
175
+
### Filter callable classes must be in the production library
176
+
177
+
A `FilterInterface::getFilter()` callable is embedded verbatim in generated PHP code and is
178
+
called at runtime — without the generator package being present. Any class referenced in
179
+
`getFilter()` must therefore live in `php-json-schema-model-generator-production`, not in this
180
+
generator package. Using a generator-package class as a filter callable will produce generated
181
+
code that fails at runtime whenever the generator is not installed.
182
+
183
+
If a production-library class lacks the required type hints (needed for reflection-based type
184
+
derivation), the fix is to add or update the callable in the production library, not to create
185
+
a wrapper class here.
186
+
187
+
### Staging changes
188
+
189
+
After finishing an implementation task, always stage all relevant changed files for commit using
190
+
`git add`. Do not wait for the user to ask — stage immediately when the work is done.
191
+
192
+
### Reading files
193
+
194
+
Always use the dedicated `Read` tool to read file contents. Never use `sed`, `head`, `tail`, `cat`, or `awk` to read or extract portions of files. The `Read` tool supports `offset` and `limit` parameters for reading partial files when needed.
195
+
196
+
### Variable naming
197
+
198
+
Never use single-character variable names. All variables must have meaningful, descriptive names
199
+
that convey their purpose. For example, use `$typeName` instead of `$t`, `$validator` instead of
200
+
`$v`, `$property` instead of `$p`.
201
+
134
202
### PHP import style
135
203
136
204
Always add `use` imports for every class referenced in a file, including global PHP classes such as
0 commit comments