All rules

Sheath rule

native-callback-exists

NativePHP event callbacks must call an accessible owning-component method with enough arguments.
Package
NativePHP
Category
Native
Default severity
error by default
Auto-fix
Manual fix

#Why

Native events dispatch method names through the component that owns the view. A missing or private method, inline expression, or undersupplied method cannot handle the event as authored.

#Examples

#Bad

{{-- Inline assignments are not component method callbacks. --}}
<native:button @press="$saved = true">Save</native:button>

#Good

{{-- save names an accessible component method. --}}
<native:button @press="save">Save</native:button>
{{-- Bound arguments count toward the method's required parameters. --}}
<native:toggle @change="updatePreference('email')" />

#Component Resolution

A view has an owning component when exactly one configured component returns it from render(). For that view, public and protected methods are accepted, private methods are reported, and required parameter counts are checked.

If ownership is absent or ambiguous, empty method names, expressions, and unsupported directive syntax are still reported. Component-specific method existence cannot be checked.

#Options

componentPaths sets the directories scanned for owning component classes. Its default is ['app/NativeComponents']:

<?php
return [
'rules' => [
'native-callback-exists' => ['error', [
'componentPaths' => ['app/NativeComponents', 'modules/Native'],
]],
],
];

The rule also accepts nativeViewPaths, which defaults to ['views/native/']. See Native View Detection for path configuration.

#Notes

Event payload sizes follow the installed NativePHP version. Press, dismiss, refresh, end-reached, and swipe-delete events supply no arguments. Change, submit, swipe, and pinch-end supply one. Selection change supplies three.

The rule validates callbacks only for an event the target can dispatch. Custom child-component events are supported.

#See Also

Related rules validate event support and component state: