Loading coder_sniffer/Drupal/Sniffs/Commenting/HookCommentSniff.php +4 −7 Original line number Diff line number Diff line Loading @@ -48,17 +48,14 @@ class HookCommentSniff implements Sniff public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $find = Tokens::$methodPrefixes; $find[] = T_WHITESPACE; $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG && $tokens[$commentEnd]['code'] !== T_COMMENT ) { // We are only interested in the most outer scope, ignore methods in classes for example. if (empty($tokens[$stackPtr]['conditions']) === false) { return; } if ($tokens[$commentEnd]['code'] === T_COMMENT) { $commentEnd = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG) { return; } Loading coder_sniffer/Drupal/Test/Commenting/HookCommentUnitTest.inc +59 −0 Original line number Diff line number Diff line Loading @@ -10,3 +10,62 @@ */ function example_page_build(&$page) { } /** * Has a method doc comment that is not a hook implementation. */ class Test { /** * Implements a hook bridge for hook_entity_access(). * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to check access for. * @param string $operation * The operation being performed. * @param \Drupal\Core\Session\AccountInterface $account * The user account making the to check access for. * * @return \Drupal\Core\Access\AccessResult * The result of the access check. * * @see hook_entity_access() */ public function entityOperationAccess(EntityInterface $entity, $operation, AccountInterface $account) { // Workspaces themselves are handled by their own access handler and we // should not try to do any access checks for entity types that can not // belong to a workspace. if ($entity->getEntityTypeId() === 'workspace' || !$this->workspaceManager->isEntityTypeSupported($entity->getEntityType())) { return AccessResult::neutral(); } return $this->bypassAccessResult($account); } /** * Implements a hook bridge for hook_entity_access(). * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to check access for. * @param string $operation * The operation being performed. * @param \Drupal\Core\Session\AccountInterface $account * The user account making the to check access for. * * @return \Drupal\Core\Access\AccessResult * The result of the access check. * * @see hook_entity_access() */ function entityOperationAccess2(EntityInterface $entity, $operation, AccountInterface $account) { // Workspaces themselves are handled by their own access handler and we // should not try to do any access checks for entity types that can not // belong to a workspace. if ($entity->getEntityTypeId() === 'workspace' || !$this->workspaceManager->isEntityTypeSupported($entity->getEntityType())) { return AccessResult::neutral(); } return $this->bypassAccessResult($account); } } coder_sniffer/Drupal/Test/Commenting/HookCommentUnitTest.inc.fixed +59 −0 Original line number Diff line number Diff line Loading @@ -10,3 +10,62 @@ */ function example_page_build(&$page) { } /** * Has a method doc comment that is not a hook implementation. */ class Test { /** * Implements a hook bridge for hook_entity_access(). * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to check access for. * @param string $operation * The operation being performed. * @param \Drupal\Core\Session\AccountInterface $account * The user account making the to check access for. * * @return \Drupal\Core\Access\AccessResult * The result of the access check. * * @see hook_entity_access() */ public function entityOperationAccess(EntityInterface $entity, $operation, AccountInterface $account) { // Workspaces themselves are handled by their own access handler and we // should not try to do any access checks for entity types that can not // belong to a workspace. if ($entity->getEntityTypeId() === 'workspace' || !$this->workspaceManager->isEntityTypeSupported($entity->getEntityType())) { return AccessResult::neutral(); } return $this->bypassAccessResult($account); } /** * Implements a hook bridge for hook_entity_access(). * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to check access for. * @param string $operation * The operation being performed. * @param \Drupal\Core\Session\AccountInterface $account * The user account making the to check access for. * * @return \Drupal\Core\Access\AccessResult * The result of the access check. * * @see hook_entity_access() */ public function entityOperationAccess2(EntityInterface $entity, $operation, AccountInterface $account) { // Workspaces themselves are handled by their own access handler and we // should not try to do any access checks for entity types that can not // belong to a workspace. if ($entity->getEntityTypeId() === 'workspace' || !$this->workspaceManager->isEntityTypeSupported($entity->getEntityType())) { return AccessResult::neutral(); } return $this->bypassAccessResult($account); } } Loading
coder_sniffer/Drupal/Sniffs/Commenting/HookCommentSniff.php +4 −7 Original line number Diff line number Diff line Loading @@ -48,17 +48,14 @@ class HookCommentSniff implements Sniff public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $find = Tokens::$methodPrefixes; $find[] = T_WHITESPACE; $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG && $tokens[$commentEnd]['code'] !== T_COMMENT ) { // We are only interested in the most outer scope, ignore methods in classes for example. if (empty($tokens[$stackPtr]['conditions']) === false) { return; } if ($tokens[$commentEnd]['code'] === T_COMMENT) { $commentEnd = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG) { return; } Loading
coder_sniffer/Drupal/Test/Commenting/HookCommentUnitTest.inc +59 −0 Original line number Diff line number Diff line Loading @@ -10,3 +10,62 @@ */ function example_page_build(&$page) { } /** * Has a method doc comment that is not a hook implementation. */ class Test { /** * Implements a hook bridge for hook_entity_access(). * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to check access for. * @param string $operation * The operation being performed. * @param \Drupal\Core\Session\AccountInterface $account * The user account making the to check access for. * * @return \Drupal\Core\Access\AccessResult * The result of the access check. * * @see hook_entity_access() */ public function entityOperationAccess(EntityInterface $entity, $operation, AccountInterface $account) { // Workspaces themselves are handled by their own access handler and we // should not try to do any access checks for entity types that can not // belong to a workspace. if ($entity->getEntityTypeId() === 'workspace' || !$this->workspaceManager->isEntityTypeSupported($entity->getEntityType())) { return AccessResult::neutral(); } return $this->bypassAccessResult($account); } /** * Implements a hook bridge for hook_entity_access(). * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to check access for. * @param string $operation * The operation being performed. * @param \Drupal\Core\Session\AccountInterface $account * The user account making the to check access for. * * @return \Drupal\Core\Access\AccessResult * The result of the access check. * * @see hook_entity_access() */ function entityOperationAccess2(EntityInterface $entity, $operation, AccountInterface $account) { // Workspaces themselves are handled by their own access handler and we // should not try to do any access checks for entity types that can not // belong to a workspace. if ($entity->getEntityTypeId() === 'workspace' || !$this->workspaceManager->isEntityTypeSupported($entity->getEntityType())) { return AccessResult::neutral(); } return $this->bypassAccessResult($account); } }
coder_sniffer/Drupal/Test/Commenting/HookCommentUnitTest.inc.fixed +59 −0 Original line number Diff line number Diff line Loading @@ -10,3 +10,62 @@ */ function example_page_build(&$page) { } /** * Has a method doc comment that is not a hook implementation. */ class Test { /** * Implements a hook bridge for hook_entity_access(). * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to check access for. * @param string $operation * The operation being performed. * @param \Drupal\Core\Session\AccountInterface $account * The user account making the to check access for. * * @return \Drupal\Core\Access\AccessResult * The result of the access check. * * @see hook_entity_access() */ public function entityOperationAccess(EntityInterface $entity, $operation, AccountInterface $account) { // Workspaces themselves are handled by their own access handler and we // should not try to do any access checks for entity types that can not // belong to a workspace. if ($entity->getEntityTypeId() === 'workspace' || !$this->workspaceManager->isEntityTypeSupported($entity->getEntityType())) { return AccessResult::neutral(); } return $this->bypassAccessResult($account); } /** * Implements a hook bridge for hook_entity_access(). * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to check access for. * @param string $operation * The operation being performed. * @param \Drupal\Core\Session\AccountInterface $account * The user account making the to check access for. * * @return \Drupal\Core\Access\AccessResult * The result of the access check. * * @see hook_entity_access() */ public function entityOperationAccess2(EntityInterface $entity, $operation, AccountInterface $account) { // Workspaces themselves are handled by their own access handler and we // should not try to do any access checks for entity types that can not // belong to a workspace. if ($entity->getEntityTypeId() === 'workspace' || !$this->workspaceManager->isEntityTypeSupported($entity->getEntityType())) { return AccessResult::neutral(); } return $this->bypassAccessResult($account); } }