-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5400b58
commit 0ae28f7
Showing
3 changed files
with
151 additions
and
5 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
143 changes: 143 additions & 0 deletions
143
tests/PHPStan/Rules/Comparison/data/slevomat-cs-in-array.php
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,143 @@ | ||
<?php | ||
|
||
namespace SlevomatCsInArray; | ||
|
||
class Foo | ||
{ | ||
|
||
private const GROUP_PUBLIC_CONSTANTS = 'public constants'; | ||
private const GROUP_PROTECTED_CONSTANTS = 'protected constants'; | ||
private const GROUP_PRIVATE_CONSTANTS = 'private constants'; | ||
private const GROUP_PUBLIC_PROPERTIES = 'public properties'; | ||
private const GROUP_PUBLIC_STATIC_PROPERTIES = 'public static properties'; | ||
private const GROUP_PROTECTED_PROPERTIES = 'protected properties'; | ||
private const GROUP_PROTECTED_STATIC_PROPERTIES = 'protected static properties'; | ||
private const GROUP_PRIVATE_PROPERTIES = 'private properties'; | ||
private const GROUP_PRIVATE_STATIC_PROPERTIES = 'private static properties'; | ||
private const GROUP_CONSTRUCTOR = 'constructor'; | ||
private const GROUP_STATIC_CONSTRUCTORS = 'static constructors'; | ||
private const GROUP_DESTRUCTOR = 'destructor'; | ||
private const GROUP_MAGIC_METHODS = 'magic methods'; | ||
private const GROUP_PUBLIC_METHODS = 'public methods'; | ||
private const GROUP_PUBLIC_ABSTRACT_METHODS = 'public abstract methods'; | ||
private const GROUP_PUBLIC_FINAL_METHODS = 'public final methods'; | ||
private const GROUP_PUBLIC_STATIC_METHODS = 'public static methods'; | ||
private const GROUP_PUBLIC_STATIC_ABSTRACT_METHODS = 'public static abstract methods'; | ||
private const GROUP_PUBLIC_STATIC_FINAL_METHODS = 'public static final methods'; | ||
private const GROUP_PROTECTED_METHODS = 'protected methods'; | ||
private const GROUP_PROTECTED_ABSTRACT_METHODS = 'protected abstract methods'; | ||
private const GROUP_PROTECTED_FINAL_METHODS = 'protected final methods'; | ||
private const GROUP_PROTECTED_STATIC_METHODS = 'protected static methods'; | ||
private const GROUP_PROTECTED_STATIC_ABSTRACT_METHODS = 'protected static abstract methods'; | ||
private const GROUP_PROTECTED_STATIC_FINAL_METHODS = 'protected static final methods'; | ||
private const GROUP_PRIVATE_METHODS = 'private methods'; | ||
private const GROUP_PRIVATE_STATIC_METHODS = 'private static methods'; | ||
|
||
private const GROUP_SHORTCUT_CONSTANTS = 'constants'; | ||
private const GROUP_SHORTCUT_PROPERTIES = 'properties'; | ||
private const GROUP_SHORTCUT_STATIC_PROPERTIES = 'static properties'; | ||
private const GROUP_SHORTCUT_METHODS = 'methods'; | ||
private const GROUP_SHORTCUT_PUBLIC_METHODS = 'all public methods'; | ||
private const GROUP_SHORTCUT_PROTECTED_METHODS = 'all protected methods'; | ||
private const GROUP_SHORTCUT_PRIVATE_METHODS = 'all private methods'; | ||
private const GROUP_SHORTCUT_STATIC_METHODS = 'static methods'; | ||
private const GROUP_SHORTCUT_ABSTRACT_METHODS = 'abstract methods'; | ||
private const GROUP_SHORTCUT_FINAL_METHODS = 'final methods'; | ||
|
||
private const SHORTCUTS = [ | ||
self::GROUP_SHORTCUT_CONSTANTS => [ | ||
self::GROUP_PUBLIC_CONSTANTS, | ||
self::GROUP_PROTECTED_CONSTANTS, | ||
self::GROUP_PRIVATE_CONSTANTS, | ||
], | ||
self::GROUP_SHORTCUT_STATIC_PROPERTIES => [ | ||
self::GROUP_PUBLIC_STATIC_PROPERTIES, | ||
self::GROUP_PROTECTED_STATIC_PROPERTIES, | ||
self::GROUP_PRIVATE_STATIC_PROPERTIES, | ||
], | ||
self::GROUP_SHORTCUT_PROPERTIES => [ | ||
self::GROUP_SHORTCUT_STATIC_PROPERTIES, | ||
self::GROUP_PUBLIC_PROPERTIES, | ||
self::GROUP_PROTECTED_PROPERTIES, | ||
self::GROUP_PRIVATE_PROPERTIES, | ||
], | ||
self::GROUP_SHORTCUT_PUBLIC_METHODS => [ | ||
self::GROUP_PUBLIC_FINAL_METHODS, | ||
self::GROUP_PUBLIC_STATIC_FINAL_METHODS, | ||
self::GROUP_PUBLIC_ABSTRACT_METHODS, | ||
self::GROUP_PUBLIC_STATIC_ABSTRACT_METHODS, | ||
self::GROUP_PUBLIC_STATIC_METHODS, | ||
self::GROUP_PUBLIC_METHODS, | ||
], | ||
self::GROUP_SHORTCUT_PROTECTED_METHODS => [ | ||
self::GROUP_PROTECTED_FINAL_METHODS, | ||
self::GROUP_PROTECTED_STATIC_FINAL_METHODS, | ||
self::GROUP_PROTECTED_ABSTRACT_METHODS, | ||
self::GROUP_PROTECTED_STATIC_ABSTRACT_METHODS, | ||
self::GROUP_PROTECTED_STATIC_METHODS, | ||
self::GROUP_PROTECTED_METHODS, | ||
], | ||
self::GROUP_SHORTCUT_PRIVATE_METHODS => [ | ||
self::GROUP_PRIVATE_STATIC_METHODS, | ||
self::GROUP_PRIVATE_METHODS, | ||
], | ||
self::GROUP_SHORTCUT_FINAL_METHODS => [ | ||
self::GROUP_PUBLIC_FINAL_METHODS, | ||
self::GROUP_PROTECTED_FINAL_METHODS, | ||
self::GROUP_PUBLIC_STATIC_FINAL_METHODS, | ||
self::GROUP_PROTECTED_STATIC_FINAL_METHODS, | ||
], | ||
self::GROUP_SHORTCUT_ABSTRACT_METHODS => [ | ||
self::GROUP_PUBLIC_ABSTRACT_METHODS, | ||
self::GROUP_PROTECTED_ABSTRACT_METHODS, | ||
self::GROUP_PUBLIC_STATIC_ABSTRACT_METHODS, | ||
self::GROUP_PROTECTED_STATIC_ABSTRACT_METHODS, | ||
], | ||
self::GROUP_SHORTCUT_STATIC_METHODS => [ | ||
self::GROUP_STATIC_CONSTRUCTORS, | ||
self::GROUP_PUBLIC_STATIC_FINAL_METHODS, | ||
self::GROUP_PROTECTED_STATIC_FINAL_METHODS, | ||
self::GROUP_PUBLIC_STATIC_ABSTRACT_METHODS, | ||
self::GROUP_PROTECTED_STATIC_ABSTRACT_METHODS, | ||
self::GROUP_PUBLIC_STATIC_METHODS, | ||
self::GROUP_PROTECTED_STATIC_METHODS, | ||
self::GROUP_PRIVATE_STATIC_METHODS, | ||
], | ||
self::GROUP_SHORTCUT_METHODS => [ | ||
self::GROUP_SHORTCUT_FINAL_METHODS, | ||
self::GROUP_SHORTCUT_ABSTRACT_METHODS, | ||
self::GROUP_SHORTCUT_STATIC_METHODS, | ||
self::GROUP_CONSTRUCTOR, | ||
self::GROUP_DESTRUCTOR, | ||
self::GROUP_PUBLIC_METHODS, | ||
self::GROUP_PROTECTED_METHODS, | ||
self::GROUP_PRIVATE_METHODS, | ||
self::GROUP_MAGIC_METHODS, | ||
], | ||
]; | ||
|
||
/** | ||
* @param array<int, string> $supportedGroups | ||
* @return array<int, string> | ||
*/ | ||
public function unpackShortcut(string $shortcut, array $supportedGroups): array | ||
{ | ||
$groups = []; | ||
|
||
foreach (self::SHORTCUTS[$shortcut] as $groupOrShortcut) { | ||
if (in_array($groupOrShortcut, $supportedGroups, true)) { | ||
$groups[] = $groupOrShortcut; | ||
} elseif ( | ||
!array_key_exists($groupOrShortcut, self::SHORTCUTS) | ||
&& in_array($groupOrShortcut, self::SHORTCUTS[self::GROUP_SHORTCUT_FINAL_METHODS], true) | ||
) { | ||
// Nothing | ||
} else { | ||
$groups = array_merge($groups, $this->unpackShortcut($groupOrShortcut, $supportedGroups)); | ||
} | ||
} | ||
|
||
return $groups; | ||
} | ||
|
||
} |