You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
## Allow in classes, child classes, classes implementing an interface
2
+
3
+
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
4
+
- a class of given name
5
+
- a class that inherits from a class of given name
6
+
- a class that implements given interface
7
+
8
+
This is useful for example when you want to allow properties or parameters of class `ClassName` in all classes that extend `ParentClass`:
9
+
10
+
```neon
11
+
parameters:
12
+
disallowedClasses:
13
+
-
14
+
class: 'ClassName'
15
+
allowInInstanceOf:
16
+
- 'ParentClass'
17
+
```
18
+
Another example could be if you'd like to disallow a `function()` in all classes that implement the `MyInterface` interface.
19
+
You can use the `allowExceptInInstanceOf` counterpart (or the `disallowInInstanceOf` alias) for that, like this:
20
+
21
+
```neon
22
+
parameters:
23
+
disallowedFunctionCalls:
24
+
-
25
+
function: 'function()'
26
+
disallowInInstanceOf:
27
+
- 'MyInterface'
28
+
```
29
+
30
+
### Allow in `use` imports
31
+
The `allowInInstanceOf` configuration above will also report an error on the line with the import, if present:
32
+
```php
33
+
use ClassName;
34
+
```
35
+
To omit the `use` finding, you can add the `allowInUse` line, like this:
0 commit comments