Repository navigation
Description
Context
Principle 9: values a view reads as properties are escaped by default (src/Infrastructure/View/SimpleView.php:230-250); a value fetched with raw() must be escaped by the template for where it is printed. views/test-backend-service.php:9 prints <?= $this->raw( 'plugin' ) ?> with no escaping, and vendor/bin/phpcs views/test-backend-service.php reports nothing (checked 2026-10-23), so WordPress Coding Standards do not see it. views/test-loop-service.php:7-17 shows the correct pattern: the raw WP_Post is printed field by field through esc_html(). Principle 14 makes a shortcut in a sample a defect.
Scope
- A PHPStan rule
architecture.rawIsEscapedover the production view directories (dependencyDirection.views): every expression printed withecho,printor<?=that contains a$this->raw( … )call, or a variable assigned from one, must be the argument of a function inrawIsEscaped.escapingFunctions(default:esc_html,esc_attr,esc_url,esc_js,esc_textarea,esc_xml,wp_kses,wp_kses_post,wp_kses_data,absint,intval). - Fix
views/test-backend-service.php:9to escape the raw value withesc_html(), keeping it a demonstration ofraw()with a comment saying why it is escaped. - The message names the template, the line and the escaping function family to use.
Out of scope
- Property access (
$this->plugin), whichSimpleViewalready escapes. - Fixes to the view escaping itself (views: escaping misses single quotes and view paths are not confined #28).
- Data flow beyond a direct assignment from
raw()within the template.
Acceptance criteria
- A fixture template that prints
$this->raw( 'x' )unescaped, and one that prints a variable assigned from it, fail with the full message asserted;esc_html( $this->raw( 'x' ) )and the property form pass. -
views/test-backend-service.phpescapes its raw value and both views pass. - The integration test for the backend sample still passes.
Verification
composer test
composer lintImpact on generated plugins
Tests and tool configuration only; no interface or convention generated plugins rely on changes. Settings read the plugin's namespace and prefixes from configuration, so a generated plugin keeps the check after renaming.
Activity
schlessera commentedon Oct 23, 2026
Claiming this. Branch:
test/79-raw-is-escaped.