Loading coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php +5 −5 Original line number Diff line number Diff line Loading @@ -93,7 +93,7 @@ class ScopeIndentSniff implements Sniff * * @var int[] */ private $_ignoreIndentationTokens = []; private $ignoreIndentation = []; /** * Any scope openers that should not cause an indent. Loading Loading @@ -175,8 +175,8 @@ class ScopeIndentSniff implements Sniff echo "Start with token $stackPtr on line $line with indent $currentIndent".PHP_EOL; } if (empty($this->_ignoreIndentationTokens) === true) { $this->_ignoreIndentationTokens = [T_INLINE_HTML => true]; if (empty($this->ignoreIndentation) === true) { $this->ignoreIndentation = [T_INLINE_HTML => true]; foreach ($this->ignoreIndentationTokens as $token) { if (is_int($token) === false) { if (defined($token) === false) { Loading @@ -186,7 +186,7 @@ class ScopeIndentSniff implements Sniff $token = constant($token); } $this->_ignoreIndentationTokens[$token] = true; $this->ignoreIndentation[$token] = true; } }//end if Loading Loading @@ -823,7 +823,7 @@ class ScopeIndentSniff implements Sniff $adjusted = false; if ($checkToken !== null && isset($this->_ignoreIndentationTokens[$tokens[$checkToken]['code']]) === false && isset($this->ignoreIndentation[$tokens[$checkToken]['code']]) === false && (($tokenIndent !== $checkIndent && $exact === true) || ($tokenIndent < $checkIndent && $exact === false)) ) { Loading coder_sniffer/Drupal/Test/WhiteSpace/ScopeIndentUnitTest.inc +88 −0 Original line number Diff line number Diff line Loading @@ -37,3 +37,91 @@ function example_field_formatter_view($entity_type, $entity, $field, $instance, return $element; } /** * A test function. */ function test_form() { /* * Here is some long form comment which is discouraged but not forbidden, * I think? It goes over multiple lines in this pseudo doc comment style. * And even more text now. */ $form['submit_connection'] = [ '#prefix' => "<br style='clear:both'/>", '#name' => 'enter_connection_settings', '#type' => 'submit', '#value' => t('Enter connection settings'), '#weight' => 100, ]; } /** * Provides the necessary user permissions for entity operations. * * @param string $entity_type_id * The entity type. * @param string $operation * The operation, one of 'view', 'create', 'update' or 'delete'. * * @return array * The set of user permission strings. */ function entity_permissions($entity_type_id, $operation) { switch ($entity_type_id) { case 'entity_test': switch ($operation) { case 'view': return ['view test entity']; case 'create': case 'update': case 'delete': return ['administer entity_test content']; } case 'node': switch ($operation) { case 'view': return ['access content']; case 'create': return ['create resttest content']; case 'update': return ['edit any resttest content']; case 'delete': return ['delete any resttest content']; } case 'comment': switch ($operation) { case 'view': return ['access comments']; case 'create': return ['post comments', 'skip comment approval']; case 'update': return ['edit own comments']; case 'delete': return ['administer comments']; } break; case 'user': switch ($operation) { case 'view': return ['access user profiles']; default: return ['administer users']; } default: if (isConfigEntity($entity_type_id)) { $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id); if ($admin_permission = $entity_type->getAdminPermission()) { return [$admin_permission]; } } } return []; } coder_sniffer/Drupal/Test/WhiteSpace/ScopeIndentUnitTest.inc.fixed +92 −0 Original line number Diff line number Diff line Loading @@ -45,3 +45,95 @@ function example_field_formatter_view($entity_type, $entity, $field, $instance, return $element; } /** * A test function. */ function test_form() { /* * Here is some long form comment which is discouraged but not forbidden, * I think? It goes over multiple lines in this pseudo doc comment style. * And even more text now. */ $form['submit_connection'] = [ '#prefix' => "<br style='clear:both'/>", '#name' => 'enter_connection_settings', '#type' => 'submit', '#value' => t('Enter connection settings'), '#weight' => 100, ]; } /** * Provides the necessary user permissions for entity operations. * * @param string $entity_type_id * The entity type. * @param string $operation * The operation, one of 'view', 'create', 'update' or 'delete'. * * @return array * The set of user permission strings. */ function entity_permissions($entity_type_id, $operation) { switch ($entity_type_id) { case 'entity_test': switch ($operation) { case 'view': return ['view test entity']; case 'create': case 'update': case 'delete': return ['administer entity_test content']; } case 'node': switch ($operation) { case 'view': return ['access content']; case 'create': return ['create resttest content']; case 'update': return ['edit any resttest content']; case 'delete': return ['delete any resttest content']; } case 'comment': switch ($operation) { case 'view': return ['access comments']; case 'create': return ['post comments', 'skip comment approval']; case 'update': return ['edit own comments']; case 'delete': return ['administer comments']; } break; case 'user': switch ($operation) { case 'view': return ['access user profiles']; default: return ['administer users']; } default: if (isConfigEntity($entity_type_id)) { $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id); if ($admin_permission = $entity_type->getAdminPermission()) { return [$admin_permission]; } } } return []; } phpcs.xml.dist +0 −3 Original line number Diff line number Diff line Loading @@ -152,9 +152,6 @@ </rule> <!-- Not compliant yet, should be fixed in the future. --> <rule ref="PSR2.Classes.PropertyDeclaration"> <exclude-pattern>coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php</exclude-pattern> </rule> <rule ref="PEAR.Commenting.FunctionComment.MissingParamComment"> <exclude-pattern>coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php</exclude-pattern> </rule> Loading Loading
coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php +5 −5 Original line number Diff line number Diff line Loading @@ -93,7 +93,7 @@ class ScopeIndentSniff implements Sniff * * @var int[] */ private $_ignoreIndentationTokens = []; private $ignoreIndentation = []; /** * Any scope openers that should not cause an indent. Loading Loading @@ -175,8 +175,8 @@ class ScopeIndentSniff implements Sniff echo "Start with token $stackPtr on line $line with indent $currentIndent".PHP_EOL; } if (empty($this->_ignoreIndentationTokens) === true) { $this->_ignoreIndentationTokens = [T_INLINE_HTML => true]; if (empty($this->ignoreIndentation) === true) { $this->ignoreIndentation = [T_INLINE_HTML => true]; foreach ($this->ignoreIndentationTokens as $token) { if (is_int($token) === false) { if (defined($token) === false) { Loading @@ -186,7 +186,7 @@ class ScopeIndentSniff implements Sniff $token = constant($token); } $this->_ignoreIndentationTokens[$token] = true; $this->ignoreIndentation[$token] = true; } }//end if Loading Loading @@ -823,7 +823,7 @@ class ScopeIndentSniff implements Sniff $adjusted = false; if ($checkToken !== null && isset($this->_ignoreIndentationTokens[$tokens[$checkToken]['code']]) === false && isset($this->ignoreIndentation[$tokens[$checkToken]['code']]) === false && (($tokenIndent !== $checkIndent && $exact === true) || ($tokenIndent < $checkIndent && $exact === false)) ) { Loading
coder_sniffer/Drupal/Test/WhiteSpace/ScopeIndentUnitTest.inc +88 −0 Original line number Diff line number Diff line Loading @@ -37,3 +37,91 @@ function example_field_formatter_view($entity_type, $entity, $field, $instance, return $element; } /** * A test function. */ function test_form() { /* * Here is some long form comment which is discouraged but not forbidden, * I think? It goes over multiple lines in this pseudo doc comment style. * And even more text now. */ $form['submit_connection'] = [ '#prefix' => "<br style='clear:both'/>", '#name' => 'enter_connection_settings', '#type' => 'submit', '#value' => t('Enter connection settings'), '#weight' => 100, ]; } /** * Provides the necessary user permissions for entity operations. * * @param string $entity_type_id * The entity type. * @param string $operation * The operation, one of 'view', 'create', 'update' or 'delete'. * * @return array * The set of user permission strings. */ function entity_permissions($entity_type_id, $operation) { switch ($entity_type_id) { case 'entity_test': switch ($operation) { case 'view': return ['view test entity']; case 'create': case 'update': case 'delete': return ['administer entity_test content']; } case 'node': switch ($operation) { case 'view': return ['access content']; case 'create': return ['create resttest content']; case 'update': return ['edit any resttest content']; case 'delete': return ['delete any resttest content']; } case 'comment': switch ($operation) { case 'view': return ['access comments']; case 'create': return ['post comments', 'skip comment approval']; case 'update': return ['edit own comments']; case 'delete': return ['administer comments']; } break; case 'user': switch ($operation) { case 'view': return ['access user profiles']; default: return ['administer users']; } default: if (isConfigEntity($entity_type_id)) { $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id); if ($admin_permission = $entity_type->getAdminPermission()) { return [$admin_permission]; } } } return []; }
coder_sniffer/Drupal/Test/WhiteSpace/ScopeIndentUnitTest.inc.fixed +92 −0 Original line number Diff line number Diff line Loading @@ -45,3 +45,95 @@ function example_field_formatter_view($entity_type, $entity, $field, $instance, return $element; } /** * A test function. */ function test_form() { /* * Here is some long form comment which is discouraged but not forbidden, * I think? It goes over multiple lines in this pseudo doc comment style. * And even more text now. */ $form['submit_connection'] = [ '#prefix' => "<br style='clear:both'/>", '#name' => 'enter_connection_settings', '#type' => 'submit', '#value' => t('Enter connection settings'), '#weight' => 100, ]; } /** * Provides the necessary user permissions for entity operations. * * @param string $entity_type_id * The entity type. * @param string $operation * The operation, one of 'view', 'create', 'update' or 'delete'. * * @return array * The set of user permission strings. */ function entity_permissions($entity_type_id, $operation) { switch ($entity_type_id) { case 'entity_test': switch ($operation) { case 'view': return ['view test entity']; case 'create': case 'update': case 'delete': return ['administer entity_test content']; } case 'node': switch ($operation) { case 'view': return ['access content']; case 'create': return ['create resttest content']; case 'update': return ['edit any resttest content']; case 'delete': return ['delete any resttest content']; } case 'comment': switch ($operation) { case 'view': return ['access comments']; case 'create': return ['post comments', 'skip comment approval']; case 'update': return ['edit own comments']; case 'delete': return ['administer comments']; } break; case 'user': switch ($operation) { case 'view': return ['access user profiles']; default: return ['administer users']; } default: if (isConfigEntity($entity_type_id)) { $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id); if ($admin_permission = $entity_type->getAdminPermission()) { return [$admin_permission]; } } } return []; }
phpcs.xml.dist +0 −3 Original line number Diff line number Diff line Loading @@ -152,9 +152,6 @@ </rule> <!-- Not compliant yet, should be fixed in the future. --> <rule ref="PSR2.Classes.PropertyDeclaration"> <exclude-pattern>coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php</exclude-pattern> </rule> <rule ref="PEAR.Commenting.FunctionComment.MissingParamComment"> <exclude-pattern>coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php</exclude-pattern> </rule> Loading