Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linter: switchDefault, arrayAccess, complexity disabled by default #1105

Merged
merged 1 commit into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 75 additions & 75 deletions docs/checkers_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

| Total checks | Checks enabled by default | Disabled checks by default | Autofixable checks |
| ------------ | ------------------------- | -------------------------- | ------------------ |
| 95 | 86 | 9 | 12 |
| 95 | 83 | 12 | 12 |

## Table of contents
- Enabled by default
- [`accessLevel` checker](#accesslevel-checker)
- [`alwaysNull` checker](#alwaysnull-checker)
- [`argCount` checker](#argcount-checker)
- [`argsOrder` checker](#argsorder-checker)
- [`arrayAccess` checker](#arrayaccess-checker)
- [`arraySyntax` checker (autofixable)](#arraysyntax-checker)
- [`assignOp` checker (autofixable)](#assignop-checker)
- [`badTraitUse` checker](#badtraituse-checker)
Expand All @@ -23,7 +22,6 @@
- [`caseBreak` checker](#casebreak-checker)
- [`caseContinue` checker](#casecontinue-checker)
- [`catchOrder` checker](#catchorder-checker)
- [`complexity` checker](#complexity-checker)
- [`concatenationPrecedence` checker](#concatenationprecedence-checker)
- [`constCase` checker (autofixable)](#constcase-checker)
- [`countUse` checker (autofixable)](#countuse-checker)
Expand Down Expand Up @@ -78,7 +76,6 @@
- [`strangeCast` checker](#strangecast-checker)
- [`strictCmp` checker](#strictcmp-checker)
- [`stripTags` checker](#striptags-checker)
- [`switchDefault` checker](#switchdefault-checker)
- [`switchEmpty` checker](#switchempty-checker)
- [`switchSimplify` checker](#switchsimplify-checker)
- [`syntax` checker](#syntax-checker)
Expand All @@ -96,12 +93,15 @@
- [`voidResultUsed` checker](#voidresultused-checker)
- Disabled by default
- [`argsReverse` checker](#argsreverse-checker)
- [`arrayAccess` checker](#arrayaccess-checker)
- [`classMembersOrder` checker](#classmembersorder-checker)
- [`complexity` checker](#complexity-checker)
- [`deprecated` checker](#deprecated-checker)
- [`langDeprecated` checker](#langdeprecated-checker)
- [`missingPhpdoc` checker](#missingphpdoc-checker)
- [`propNullDefault` checker (autofixable)](#propnulldefault-checker)
- [`redundantCast` checker](#redundantcast-checker)
- [`switchDefault` checker](#switchdefault-checker)
- [`trailingComma` checker (autofixable)](#trailingcomma-checker)
- [`typeHint` checker](#typehint-checker)
## Enabled
Expand Down Expand Up @@ -180,26 +180,6 @@ strpos($s, '/');
<p><br></p>


### `arrayAccess` checker

#### Description

Report array access to non-array objects.

#### Non-compliant code:
```php
return $foo[0]; // $foo value may not implement ArrayAccess
```

#### Compliant code:
```php
if ($foo instanceof ArrayAccess) {
return $foo[0];
}
```
<p><br></p>


### `arraySyntax` checker

> Auto fix available
Expand Down Expand Up @@ -438,28 +418,6 @@ try {
<p><br></p>


### `complexity` checker

#### Description

Report funcs/methods that are too complex.

#### Non-compliant code:
```php
function checkRights() {
// Super big function.
}
```

#### Compliant code:
```php
function checkRights() {
return true; // Or 42 if you need int-typed result.
}
```
<p><br></p>


### `concatenationPrecedence` checker

#### Description
Expand Down Expand Up @@ -1510,35 +1468,6 @@ $s = strip_tags($s, '<br>')
<p><br></p>


### `switchDefault` checker

#### Description

Report the lack or wrong position of `default`.

#### Non-compliant code:
```php
switch ($a) {
case 1:
echo 1;
break;
}
```

#### Compliant code:
```php
switch ($a) {
case 1:
echo 1;
break;
default:
echo 2;
break;
}
```
<p><br></p>


### `switchEmpty` checker

#### Description
Expand Down Expand Up @@ -1892,6 +1821,26 @@ function main(): void {
<p><br></p>


### `arrayAccess` checker

#### Description

Report array access to non-array objects.

#### Non-compliant code:
```php
return $foo[0]; // $foo value may not implement ArrayAccess
```

#### Compliant code:
```php
if ($foo instanceof ArrayAccess) {
return $foo[0];
}
```
<p><br></p>


### `classMembersOrder` checker

#### Description
Expand Down Expand Up @@ -1919,6 +1868,28 @@ class A {
<p><br></p>


### `complexity` checker

#### Description

Report funcs/methods that are too complex.

#### Non-compliant code:
```php
function checkRights() {
// Super big function.
}
```

#### Compliant code:
```php
function checkRights() {
return true; // Or 42 if you need int-typed result.
}
```
<p><br></p>


### `deprecated` checker

#### Description
Expand Down Expand Up @@ -2035,6 +2006,35 @@ return 10;
<p><br></p>


### `switchDefault` checker

#### Description

Report the lack or wrong position of `default`.

#### Non-compliant code:
```php
switch ($a) {
case 1:
echo 1;
break;
}
```

#### Compliant code:
```php
switch ($a) {
case 1:
echo 1;
break;
default:
echo 2;
break;
}
```
<p><br></p>


### `trailingComma` checker

> Auto fix available
Expand Down
6 changes: 3 additions & 3 deletions src/linter/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ return -9223372036854775808;`,

{
Name: "arrayAccess",
Default: true,
Default: false,
Quickfix: false,
Comment: `Report array access to non-array objects.`,
Before: `return $foo[0]; // $foo value may not implement ArrayAccess`,
Expand Down Expand Up @@ -242,7 +242,7 @@ case 3:

{
Name: "complexity",
Default: true,
Default: false,
Quickfix: false,
Comment: `Report funcs/methods that are too complex.`,
Before: `function checkRights() {
Expand Down Expand Up @@ -842,7 +842,7 @@ strpos('/', $s);`,

{
Name: "switchDefault",
Default: true,
Default: false,
Quickfix: false,
Comment: "Report the lack or wrong position of `default`.",
Before: `switch ($a) {
Expand Down