-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
You can now allow some items in
instanceof
listed classes (#306)
Use `allowInInstanceOf`, named after the PHP's `instanceof` operator, if you want to allow a function or a method call, an attribute, a classname, or a namespace in - a class of given name - a class that inherits from a class of given name - a class that implements given interface In case of a namespace, you may also use `allowInUse`, because if you allow a namespace/class `A` in a class `B` using `allowInInstanceOf`, you will also get error on line with `use A;` even if you will not get any error when `A` is used in `B`. Close #302
- Loading branch information
Showing
21 changed files
with
455 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
## Allow in classes, child classes, classes implementing an interface | ||
|
||
Use `allowInInstanceOf`, named after the PHP's `instanceof` operator, if you want to allow a function or a method call, an attribute, a classname, or a namespace in | ||
- a class of given name | ||
- a class that inherits from a class of given name | ||
- a class that implements given interface | ||
|
||
This is useful for example when you want to allow properties or parameters of class `ClassName` in all classes that extend `ParentClass`: | ||
|
||
```neon | ||
parameters: | ||
disallowedClasses: | ||
- | ||
class: 'ClassName' | ||
allowInInstanceOf: | ||
- 'ParentClass' | ||
``` | ||
Another example could be if you'd like to disallow a `function()` in all classes that implement the `MyInterface` interface. | ||
You can use the `allowExceptInInstanceOf` counterpart (or the `disallowInInstanceOf` alias) for that, like this: | ||
|
||
```neon | ||
parameters: | ||
disallowedFunctionCalls: | ||
- | ||
function: 'function()' | ||
disallowInInstanceOf: | ||
- 'MyInterface' | ||
``` | ||
|
||
### Allow in `use` imports | ||
The `allowInInstanceOf` configuration above will also report an error on the line with the import, if present: | ||
```php | ||
use ClassName; | ||
``` | ||
To omit the `use` finding, you can add the `allowInUse` line, like this: | ||
|
||
```neon | ||
parameters: | ||
disallowedClasses: | ||
- | ||
class: 'ClassName' | ||
allowInInstanceOf: | ||
- 'ParentClass' | ||
allowInUse: true | ||
``` |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.