feat(sniffs): close bypass loopholes in Service and ValueObject sniffs#54
Merged
Merged
Conversation
- ServiceStructureSniff: detect classes implementing Domain\Service\ interface outside Service/ directory (DomainServiceImplOutsideServiceDirectory error). Prevents bypass by removing Service\ segment from namespace path. - ValueObjectStructureSniff: require Vo suffix for classes in ValueObject/Vo namespace (MissingVoSuffix error). Prevents creating VO without proper naming convention like RuntimeContext instead of RuntimeContextVo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Проблема
Обнаружены два способа обойти существующие сниффы:
1. ServiceStructureSniff — обход через удаление
Service\из путиКласс
NullNotificationBroadcasterреализует интерфейс изDomain\Service\, но лежит вIntegration\Broadcaster\(безService\в пути). Sniff его пропускал, потому что:inServiceDir = false(нетServiceв пути)hasSuffix = false(нет суффиксаService)Оба условия false → sniff молчал.
2. ValueObjectStructureSniff — VO без суффикса
VoКласс
RuntimeContextв namespaceDomain\ValueObject\— без суффиксаVo. Sniff проверял только классы с суффиксомVo, остальные полностью пропускал.Решение
ServiceStructureSniff
Новое правило
DomainServiceImplOutsideServiceDirectory: если класс реализует интерфейс изDomain\Service\(черезuseили FQCN) — он обязан лежать в директорииService/.Sniff парсит
use-statements для определения FQCN интерфейсов изimplements.ValueObjectStructureSniff
Новое правило
MissingVoSuffix: если класс находится в namespace\ValueObject\или\Vo\, но не имеет суффиксаVo— ошибка.Тесты
NullNotificationBroadcaster.inc—implementsчерезuse, внеService/FqcnBroadcaster.inc—implementsчерез FQCN, внеService/LogOnSomethingListener.inc— внеService/, интерфейс не изDomain\Service\RuntimeContext.inc— вValueObject\namespace без суффиксаVoEmailVo.inc— вValueObject\namespace с суффиксомVoЧек-лист
composer checkпройден