-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
This is a thoughtful architectural question. Let me break down feasibility and value:
Feasibility Assessment
Yes, it's technically possible. The Golden Rules Analyzer already does cross-file token analysis. Here's what we could detect:
Detectable Signals via Tokenization
| Signal | Detection Method | Complexity |
|---|---|---|
| Multiple write sites to same option/meta | Track update_option('key'), update_post_meta($id, 'key') across files |
Medium |
| Status-like variable writes | Match keys containing status, state, phase, step, mode |
Low |
| Scattered transition logic | Count functions with names like set_*_status, transition_to_* |
Low |
| Complex status conditionals | Detect switch/if-else chains on status-like variables | Medium-High |
Rough Implementation Sketch
// In golden-rules-analyzer.php
// Track state writes: ['option_key' => ['file:line', 'file:line', ...]]
$state_write_sites = [];
// During token stream processing:
if ($token_is_function_call && in_array($func_name, ['update_option', 'update_post_meta', 'set_transient'])) {
$key = extract_first_string_arg($tokens, $position);
if (preg_match('/status|state|phase|step|mode|stage/i', $key)) {
$state_write_sites[$key][] = "$current_file:$line_number";
}
}
// After processing all files:
foreach ($state_write_sites as $key => $locations) {
if (count($locations) >= 3 && count(array_unique(array_map('dirname', $locations))) >= 2) {
// 3+ writes across 2+ directories = complexity signal
emit_advisory('fsm-complexity-signal', $key, $locations);
}
}Value Assessment
Mixed—here's my honest take:
Arguments For
- Proactive architectural guidance — catches complexity before it becomes unmanageable
- Educational — introduces FSM thinking to developers who may not know the pattern
- Differentiator — no other PHP scanner does architectural recommendations like this
- Fits the "Golden Rules" philosophy — deeper insights beyond simple pattern matching
Arguments Against
- High false positive risk — legitimate multi-path writes are common (settings pages, REST endpoints, CLI commands all updating same option)
- Subjective threshold — when is 3 writes "too many"? 5? Depends entirely on context
- Not actionable without context — unlike "unbounded query" which has a clear fix, this just says "maybe refactor?"
- Scope creep — this is architectural consulting, not code quality scanning
My Recommendation
Worth exploring as a "beta/experimental" advisory feature, but not as a core pattern.
Practical Implementation Path
- Start narrow: Only detect
update_option()/update_post_meta()with explicitly status-like keys - High threshold: Require 4+ distinct write sites across 3+ files before flagging
- Advisory output: Separate from violations—maybe a "Complexity Insights" section in the report
- Link to guidance: Include a brief "What is FSM?" explainer or link to documentation
Output Format Concept
{
"advisory_insights": [
{
"type": "complexity-signal",
"category": "state-management",
"message": "Option 'plugin_sync_status' is written from 5 locations across 4 files",
"recommendation": "Consider centralizing state transitions with a state machine pattern",
"locations": ["sync.php:142", "ajax.php:89", "cron.php:201", "admin.php:55", "rest.php:178"],
"learn_more": "https://docs.wpcode.check/patterns/fsm-recommendation"
}
]
}Bottom Line
| Question | Answer |
|---|---|
| Is it possible? | ✅ Yes, with medium effort |
| Is it worthwhile? | |
| Should you build it now? | 🤔 I'd prioritize it below the Laravel expansion and TypeScript patterns |
If you want to experiment, I'd suggest adding it as a "hidden" feature flag first (--experimental-insights) and collecting real-world data on whether the detections are useful before promoting it to a standard feature.
Want me to draft a more detailed implementation spec, or would you rather focus on the higher-priority roadmap items first?