Showing 200 of 288 total issues
Avoid unused local variables such as '$database'. Open
$database = \Drupal::database();
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid unused local variables such as '$status'. Open
foreach ($changes['field_storage_definitions'] as $field_name => $status) {
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
The function stanford_basic_form_system_theme_settings_alter() has 233 lines of code. Current threshold is set to 100. Avoid really long methods. Open
function stanford_basic_form_system_theme_settings_alter(array &$form, FormStateInterface $form_state) {
$form['options_settings'] = [
'#type' => 'fieldset',
'#title' => t('Theme Specific Settings'),
- Exclude checks
Avoid assigning values to variables in if clauses and the like (line '151', column '9'). Open
protected static function redirectUser() {
$current_user = \Drupal::currentUser();
$cache = \Drupal::cache();
/** @var \Drupal\Core\Routing\CurrentRouteMatch $route_match */
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
The function _stanford_profile_fix_menu() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
function _stanford_profile_fix_menu(array $menu_items = [], string $parent = NULL): void {
$node_storage = \Drupal::entityTypeManager()
->getStorage('node');
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Class should be nested within its parent Class Open
.su-button.su-link,
- Read upRead up
- Exclude checks
Force Element Nesting
Rule force-element-nesting
will enforce the nesting of elements
Examples
When enabled, the following are disallowed:
div p {
content: '';
}
.parent {
&__child h1 {
content: '';
}
}
a[target="_blank"] span {
content: '';
}
When enabled, the following are allowed:
div {
p {
content: '';
}
}
.parent {
&__child {
h1 {
content: '';
}
}
}
a[target="_blank"] {
span {
content: '';
}
}
Files must end with a new line Open
}
- Read upRead up
- Exclude checks
Final Newline
Rule final-newline
will enforce whether or not files should end with a newline.
Options
-
include
:true
/false
(defaults totrue
)
Examples
When include: true
, the following are allowed. When include: false
, the following are disallowed:
.foo {
content: 'bar';
}
// Newline under this comment at end of file
When include: false
, the following are allowed. When include: true
, the following are disallowed:
.foo {
content: 'bar';
}
// No newline under this comment at end of file
Class should be nested within its parent Class Open
.su-lockup__cell1.empty-logo {
- Read upRead up
- Exclude checks
Force Element Nesting
Rule force-element-nesting
will enforce the nesting of elements
Examples
When enabled, the following are disallowed:
div p {
content: '';
}
.parent {
&__child h1 {
content: '';
}
}
a[target="_blank"] span {
content: '';
}
When enabled, the following are allowed:
div {
p {
content: '';
}
}
.parent {
&__child {
h1 {
content: '';
}
}
}
a[target="_blank"] {
span {
content: '';
}
}
Whitespace required before { Open
.su-multi-menu__link{
- Read upRead up
- Exclude checks
Space Before Brace
Rule space-before-brace
will enforce whether or not a space should be included before a brace ({
).
Options
-
include
:true
/false
(defaults totrue
)
Examples
When include: true
, the following are allowed. When include: false
, the following are disallowed:
.foo {
content: 'bar';
@include breakpoint {
content: 'baz';
}
}
@mixin foo {
content: 'bar';
}
When include: false
, the following are allowed. When include: true
, the following are disallowed:
.foo{
content: 'bar';
@include breakpoint{
content: 'baz';
}
}
@mixin foo{
content: 'bar';
}
Pseudo-elements must start with double colons Open
&:before {
- Read upRead up
- Exclude checks
Pseudo-element
Rule pseudo-element
will enforce that:
- Pseudo-elements must start with double colons.
- Pseudo-classes must start with single colon.
Examples
When enabled, the following are allowed:
.foo::before {
content: "bar";
}
.foo:hover {
content: "bar";
}
When enabled, the following are disallowed:
.foo:before {
content: "bar";
}
.foo::hover {
content: "bar";
}
Pseudo-elements must start with double colons Open
&:after {
- Read upRead up
- Exclude checks
Pseudo-element
Rule pseudo-element
will enforce that:
- Pseudo-elements must start with double colons.
- Pseudo-classes must start with single colon.
Examples
When enabled, the following are allowed:
.foo::before {
content: "bar";
}
.foo:hover {
content: "bar";
}
When enabled, the following are disallowed:
.foo:before {
content: "bar";
}
.foo::hover {
content: "bar";
}
Pseudo-elements must start with double colons Open
&:after {
- Read upRead up
- Exclude checks
Pseudo-element
Rule pseudo-element
will enforce that:
- Pseudo-elements must start with double colons.
- Pseudo-classes must start with single colon.
Examples
When enabled, the following are allowed:
.foo::before {
content: "bar";
}
.foo:hover {
content: "bar";
}
When enabled, the following are disallowed:
.foo:before {
content: "bar";
}
.foo::hover {
content: "bar";
}
No trailing whitespace allowed Open
color: $su-color-digital-blue;
- Read upRead up
- Exclude checks
No Trailing Whitespace
Rule no-trailing-whitespace
will enforce that trailing whitespace is not allowed.
Examples
When enabled, the following are disallowed (\s denotes spaces or tabs):
.foo {\s
margin: 1.5rem;
}
.foo {
margin: .5rem;\s
}
.foo {
margin: .4rem;
}\s
Expected indentation of 0 space but found 2. Open
//@include example--black-icons
- Read upRead up
- Exclude checks
Indentation
Rule indentation
will enforce an indentation size (tabs and spaces) and it will also ensure that tabs and spaces are not mixed.
The mixed spaces and tabs warnings check will take into account what you have set in your config file whether it should expect to see spaces or tabs. If it encounters a tab anywhere in a file when your rule config doesn't specify tabs it will flag a lint warning, Similarly for any whitespace using spaces when tabs are specified. Obviously spaces between properties and values etc are ignored.
Options
-
size
:number
or'tab'
(defaults to2
spaces)
Examples
When enabled (assuming size: 2
) the following are allowed:
.foo {
content: 'bar';
.baz {
content: 'qux';
// Waldo
&--waldo {
content: 'alpha';
}
}
}
When enabled (assuming size: 2
) the following are disallowed:
.foo {
content: 'bar';
.baz {
content: 'qux';
// Waldo
&--waldo {
content: 'alpha';
}
}
}
Pseudo-elements must start with double colons Open
&:after {
- Read upRead up
- Exclude checks
Pseudo-element
Rule pseudo-element
will enforce that:
- Pseudo-elements must start with double colons.
- Pseudo-classes must start with single colon.
Examples
When enabled, the following are allowed:
.foo::before {
content: "bar";
}
.foo:hover {
content: "bar";
}
When enabled, the following are disallowed:
.foo:before {
content: "bar";
}
.foo::hover {
content: "bar";
}
Expected indentation of 0 space but found 2. Open
// button colors here
- Read upRead up
- Exclude checks
Indentation
Rule indentation
will enforce an indentation size (tabs and spaces) and it will also ensure that tabs and spaces are not mixed.
The mixed spaces and tabs warnings check will take into account what you have set in your config file whether it should expect to see spaces or tabs. If it encounters a tab anywhere in a file when your rule config doesn't specify tabs it will flag a lint warning, Similarly for any whitespace using spaces when tabs are specified. Obviously spaces between properties and values etc are ignored.
Options
-
size
:number
or'tab'
(defaults to2
spaces)
Examples
When enabled (assuming size: 2
) the following are allowed:
.foo {
content: 'bar';
.baz {
content: 'qux';
// Waldo
&--waldo {
content: 'alpha';
}
}
}
When enabled (assuming size: 2
) the following are disallowed:
.foo {
content: 'bar';
.baz {
content: 'qux';
// Waldo
&--waldo {
content: 'alpha';
}
}
}
Pseudo-elements must start with double colons Open
&:before {
- Read upRead up
- Exclude checks
Pseudo-element
Rule pseudo-element
will enforce that:
- Pseudo-elements must start with double colons.
- Pseudo-classes must start with single colon.
Examples
When enabled, the following are allowed:
.foo::before {
content: "bar";
}
.foo:hover {
content: "bar";
}
When enabled, the following are disallowed:
.foo:before {
content: "bar";
}
.foo::hover {
content: "bar";
}
Qualifying elements are not allowed for class selectors Open
> a.su-link--external {
- Read upRead up
- Exclude checks
No Qualifying Elements
Rule no-qualifying-elements
will enforce that selectors are not allowed to have qualifying elements.
Options
-
allow-element-with-attribute
:true
/false
(defaults tofalse
) -
allow-element-with-class
:true
/false
(defaults tofalse
) -
allow-element-with-id
:true
/false
(defaults tofalse
)
Examples
By default, the following are disallowed:
div.foo {
content: 'foo';
}
ul#foo {
content: 'foo';
}
input[type='email'] {
content: 'foo';
}
allow-element-with-attribute
When allow-element-with-attribute: true
, the following are allowed. When allow-element-with-attribute: false
, the following are disallowed.
input[type='email'] {
content: 'foo';
}
a[href] {
content: 'foo';
}
allow-element-with-class
When allow-element-with-class: true
, the following are allowed. When allow-element-with-class: false
, the following are disallowed.
div.foo {
content: 'foo';
}
h1.bar {
content: 'foo';
}
allow-element-with-id
When allow-element-with-id: true
, the following are allowed. When allow-element-with-id: false
, the following are disallowed.
ul#foo {
content: 'foo';
}
p#bar {
content: 'foo';
}
Pseudo-elements must start with double colons Open
&:after {
- Read upRead up
- Exclude checks
Pseudo-element
Rule pseudo-element
will enforce that:
- Pseudo-elements must start with double colons.
- Pseudo-classes must start with single colon.
Examples
When enabled, the following are allowed:
.foo::before {
content: "bar";
}
.foo:hover {
content: "bar";
}
When enabled, the following are disallowed:
.foo:before {
content: "bar";
}
.foo::hover {
content: "bar";
}
Class should be nested within its parent Class Open
.stanford-people-grid .views-row .views-field-title a {
- Read upRead up
- Exclude checks
Force Element Nesting
Rule force-element-nesting
will enforce the nesting of elements
Examples
When enabled, the following are disallowed:
div p {
content: '';
}
.parent {
&__child h1 {
content: '';
}
}
a[target="_blank"] span {
content: '';
}
When enabled, the following are allowed:
div {
p {
content: '';
}
}
.parent {
&__child {
h1 {
content: '';
}
}
}
a[target="_blank"] {
span {
content: '';
}
}