Skip to content

Commit

Permalink
Merge pull request #91 from vmdef/phpcs3
Browse files Browse the repository at this point in the history
Bumps phpcs to 3.5.8
  • Loading branch information
stronk7 authored Oct 23, 2020
2 parents d9d5357 + 7a0959b commit 7d9cdbe
Show file tree
Hide file tree
Showing 17 changed files with 271 additions and 115 deletions.
63 changes: 43 additions & 20 deletions phpcs/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,30 +160,55 @@ public static function loadFile($path)
return self::$loadedClasses[$path];
}

$classes = get_declared_classes();
$interfaces = get_declared_interfaces();
$traits = get_declared_traits();
$classesBeforeLoad = [
'classes' => get_declared_classes(),
'interfaces' => get_declared_interfaces(),
'traits' => get_declared_traits(),
];

include $path;

$className = null;
$newClasses = array_reverse(array_diff(get_declared_classes(), $classes));
// Since PHP 7.4 get_declared_classes() does not guarantee any order. That
// implies that parent classes aren't the first any more, rendering the
// array_reverse() technique futile for the loop & break code that follows.
// So, additionally, let's try to reduce the list of candidates by removing all
// the classes known to be "parents". That way, at the end, only the "main"
// class just included with remain.
$classesAfterLoad = [
'classes' => get_declared_classes(),
'interfaces' => get_declared_interfaces(),
'traits' => get_declared_traits(),
];

$className = self::determineLoadedClass($classesBeforeLoad, $classesAfterLoad);

self::$loadedClasses[$path] = $className;
self::$loadedFiles[$className] = $path;
return self::$loadedClasses[$path];

}//end loadFile()


/**
* Determine which class was loaded based on the before and after lists of loaded classes.
*
* @param array $classesBeforeLoad The classes/interfaces/traits before the file was included.
* @param array $classesAfterLoad The classes/interfaces/traits after the file was included.
*
* @return string The fully qualified name of the class in the loaded file.
*/
public static function determineLoadedClass($classesBeforeLoad, $classesAfterLoad)
{
$className = null;

$newClasses = array_diff($classesAfterLoad['classes'], $classesBeforeLoad['classes']);

// Since PHP 7.4 get_declared_classes() does not guarantee any order, making
// it impossible to use order to determine which is the parent an which is the child.
// Let's reduce the list of candidates by removing all the classes known to be "parents".
// That way, at the end, only the "main" class just included will remain.
$newClasses = array_reduce(
$newClasses,
function ($remaining, $current) {
return array_diff($remaining, class_parents($current));
},
$newClasses
);
$newClasses = array_reduce($newClasses, function($remaining, $current) {
return array_diff($remaining, class_parents($current));
}, $newClasses);

foreach ($newClasses as $name) {
if (isset(self::$loadedFiles[$name]) === false) {
$className = $name;
Expand All @@ -192,7 +217,7 @@ function ($remaining, $current) {
}

if ($className === null) {
$newClasses = array_reverse(array_diff(get_declared_interfaces(), $interfaces));
$newClasses = array_reverse(array_diff($classesAfterLoad['interfaces'], $classesBeforeLoad['interfaces']));
foreach ($newClasses as $name) {
if (isset(self::$loadedFiles[$name]) === false) {
$className = $name;
Expand All @@ -202,7 +227,7 @@ function ($remaining, $current) {
}

if ($className === null) {
$newClasses = array_reverse(array_diff(get_declared_traits(), $traits));
$newClasses = array_reverse(array_diff($classesAfterLoad['traits'], $classesBeforeLoad['traits']));
foreach ($newClasses as $name) {
if (isset(self::$loadedFiles[$name]) === false) {
$className = $name;
Expand All @@ -211,11 +236,9 @@ function ($remaining, $current) {
}
}

self::$loadedClasses[$path] = $className;
self::$loadedFiles[$className] = $path;
return self::$loadedClasses[$path];
return $className;

}//end loadFile()
}//end determineLoadedClass()


/**
Expand Down
150 changes: 108 additions & 42 deletions phpcs/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,20 @@ http://pear.php.net/dtd/package-2.0.xsd">
<email>[email protected]</email>
<active>yes</active>
</lead>
<date>2020-08-10</date>
<time>14:49:00</time>
<date>2020-10-23</date>
<time>13:00:00</time>
<version>
<release>3.5.7</release>
<api>3.5.7</api>
<release>3.5.8</release>
<api>3.5.8</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license>
<notes>
- The PHP 8.0 T_NULLSAFE_OBJECT_OPERATOR token has been made available for older versions
-- Existing sniffs that check for T_OBJECT_OPERATOR have been modified to apply the same rules for the nullsafe object operator
-- Thanks to Juliette Reinders Folmer for the patch
- The new method of PHP 8.0 tokenizing for namespaced names has been revert to thr pre 8.0 method
-- This maintains backwards compatible for existing sniffs on PHP 8.0
-- This change will be removed in PHPCS 4.0 as the PHP 8.0 tokenizing method will be backported for pre 8.0 versions
-- Thanks to Juliette Reinders Folmer for the patch
- Added support for changes to the way PHP 8.0 tokenizes hash comments
-- The existing PHP 5-7 behaviour has been replicated for version 8, so no sniff changes are required
-- Thanks to Juliette Reinders Folmer for the patch
- Running the unit tests now includes warnings in the found and fixable error code counts
-- Thanks to Juliette Reinders Folmer for the patch
- PSR12.Functions.NullableTypeDeclaration now supports the PHP8 static return type
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed Squiz.Formatting.OperatorBracket false positive when exiting with a negative number
- Fixed Squiz.PHP.DisallowComparisonAssignment false positive for methods called on an object
- Fixed bug #2882 : Generic.Arrays.ArrayIndent can request close brace indent to be less than the statement indent level
- Fixed bug #2883 : Generic.WhiteSpace.ScopeIndent.Incorrect issue after NOWDOC
- Fixed bug #2975 : Undefined offset in PSR12.Functions.ReturnTypeDeclaration when checking function return type inside ternary
- Fixed bug #2988 : Undefined offset in Squiz.Strings.ConcatenationSpacing during live coding
-- Thanks to Thiemo Kreuz for the patch
- Fixed bug #2989 : Incorrect auto-fixing in Generic.ControlStructures.InlineControlStructure during live coding
-- Thanks to Thiemo Kreuz for the patch
- Fixed bug #3007 : Directory exclude pattern improperly excludes directories with names that start the same
-- Thanks to Steve Talbot for the patch
- Fixed bug #3053 : PSR2 incorrect fix when multiple use statements on same line do not have whitespace between them
- Fixed bug #3058 : Progress gets unaligned when 100% happens at the end of the available dots
- Fixed bug #3059 : Squiz.Arrays.ArrayDeclaration false positive when using type casting
-- Thanks to Sergei Morozov for the patch
- Fixed bug #3060 : Squiz.Arrays.ArrayDeclaration false positive for static functions
-- Thanks to Sergei Morozov for the patch
- Fixed bug #3065 : Should not fix Squiz.Arrays.ArrayDeclaration.SpaceBeforeComma if comment between element and comma
-- Thanks to Sergei Morozov for the patch
- Fixed bug #3066 : No support for namespace operator used in type declarations
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #3099 : Squiz.WhiteSpace.OperatorSpacing false positive when exiting with negative number
-- Thanks to Sergei Morozov for the patch
- Fixed bug #3124 : PSR-12 not reporting error for empty lines with only whitespace
- Reverted a change to the way include/exclude patterns are processed for STDIN content
-- This change is not backwards compatible and will be re-introduced in version 3.6.0
</notes>
<contents>
<dir name="/">
Expand Down Expand Up @@ -95,6 +59,17 @@ http://pear.php.net/dtd/package-2.0.xsd">
</dir>
<dir name="tests">
<dir name="Core">
<dir name="Autoloader">
<dir name="TestFiles">
<dir name="Sub">
<file baseinstalldir="" name="C.inc" role="test" />
</dir>
<file baseinstalldir="" name="A.inc" role="test" />
<file baseinstalldir="" name="B.inc" role="test" />
<file baseinstalldir="" name="C.inc" role="test" />
</dir>
<file baseinstalldir="" name="DetermineLoadedClassTest.php" role="test" />
</dir>
<dir name="File">
<file baseinstalldir="" name="FindEndOfStatementTest.inc" role="test" />
<file baseinstalldir="" name="FindEndOfStatementTest.php" role="test" />
Expand Down Expand Up @@ -1986,6 +1961,11 @@ http://pear.php.net/dtd/package-2.0.xsd">
<install as="CodeSniffer/Core/AllTests.php" name="tests/Core/AllTests.php" />
<install as="CodeSniffer/Core/IsCamelCapsTest.php" name="tests/Core/IsCamelCapsTest.php" />
<install as="CodeSniffer/Core/ErrorSuppressionTest.php" name="tests/Core/ErrorSuppressionTest.php" />
<install as="CodeSniffer/Core/Autoloader/DetermineLoadedClassTest.php" name="tests/Core/Autoloader/DetermineLoadedClassTest.php" />
<install as="CodeSniffer/Core/Autoloader/TestFiles/A.inc" name="tests/Core/Autoloader/TestFiles/A.inc" />
<install as="CodeSniffer/Core/Autoloader/TestFiles/B.inc" name="tests/Core/Autoloader/TestFiles/B.inc" />
<install as="CodeSniffer/Core/Autoloader/TestFiles/C.inc" name="tests/Core/Autoloader/TestFiles/C.inc" />
<install as="CodeSniffer/Core/Autoloader/TestFiles/Sub/C.inc" name="tests/Core/Autoloader/TestFiles/Sub/C.inc" />
<install as="CodeSniffer/Core/File/FindEndOfStatementTest.php" name="tests/Core/File/FindEndOfStatementTest.php" />
<install as="CodeSniffer/Core/File/FindEndOfStatementTest.inc" name="tests/Core/File/FindEndOfStatementTest.inc" />
<install as="CodeSniffer/Core/File/FindExtendedClassNameTest.php" name="tests/Core/File/FindExtendedClassNameTest.php" />
Expand Down Expand Up @@ -2051,6 +2031,11 @@ http://pear.php.net/dtd/package-2.0.xsd">
<install as="CodeSniffer/Core/AllTests.php" name="tests/Core/AllTests.php" />
<install as="CodeSniffer/Core/IsCamelCapsTest.php" name="tests/Core/IsCamelCapsTest.php" />
<install as="CodeSniffer/Core/ErrorSuppressionTest.php" name="tests/Core/ErrorSuppressionTest.php" />
<install as="CodeSniffer/Core/Autoloader/DetermineLoadedClassTest.php" name="tests/Core/Autoloader/DetermineLoadedClassTest.php" />
<install as="CodeSniffer/Core/Autoloader/TestFiles/A.inc" name="tests/Core/Autoloader/TestFiles/A.inc" />
<install as="CodeSniffer/Core/Autoloader/TestFiles/B.inc" name="tests/Core/Autoloader/TestFiles/B.inc" />
<install as="CodeSniffer/Core/Autoloader/TestFiles/C.inc" name="tests/Core/Autoloader/TestFiles/C.inc" />
<install as="CodeSniffer/Core/Autoloader/TestFiles/Sub/C.inc" name="tests/Core/Autoloader/TestFiles/Sub/C.inc" />
<install as="CodeSniffer/Core/File/FindEndOfStatementTest.php" name="tests/Core/File/FindEndOfStatementTest.php" />
<install as="CodeSniffer/Core/File/FindEndOfStatementTest.inc" name="tests/Core/File/FindEndOfStatementTest.inc" />
<install as="CodeSniffer/Core/File/FindExtendedClassNameTest.php" name="tests/Core/File/FindExtendedClassNameTest.php" />
Expand Down Expand Up @@ -2102,6 +2087,87 @@ http://pear.php.net/dtd/package-2.0.xsd">
</filelist>
</phprelease>
<changelog>
<release>
<version>
<release>3.5.8</release>
<api>3.5.8</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2020-10-23</date>
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD License</license>
<notes>
- Reverted a change to the way include/exclude patterns are processed for STDIN content
-- This change is not backwards compatible and will be re-introduced in version 3.6.0
</notes>
</release>
<release>
<version>
<release>3.5.7</release>
<api>3.5.7</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2020-10-23</date>
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD License</license>
<notes>
- The PHP 8.0 T_NULLSAFE_OBJECT_OPERATOR token has been made available for older versions
-- Existing sniffs that check for T_OBJECT_OPERATOR have been modified to apply the same rules for the nullsafe object operator
-- Thanks to Juliette Reinders Folmer for the patch
- The new method of PHP 8.0 tokenizing for namespaced names has been revert to thr pre 8.0 method
-- This maintains backwards compatible for existing sniffs on PHP 8.0
-- This change will be removed in PHPCS 4.0 as the PHP 8.0 tokenizing method will be backported for pre 8.0 versions
-- Thanks to Juliette Reinders Folmer for the patch
- Added support for changes to the way PHP 8.0 tokenizes hash comments
-- The existing PHP 5-7 behaviour has been replicated for version 8, so no sniff changes are required
-- Thanks to Juliette Reinders Folmer for the patch
- The autoloader has been changed to fix sniff class name detection issues that may occur when running on PHP 7.4+
-- Thanks to Eloy Lafuente for the patch
- Running the unit tests now includes warnings in the found and fixable error code counts
-- Thanks to Juliette Reinders Folmer for the patch
- PSR12.ControlStructures.BooleanOperatorPlacement.FoundMixed error message is now more accurate when using the allowOnly setting
-- Thanks to Vincent Langlet for the patch
- PSR12.Functions.NullableTypeDeclaration now supports the PHP8 static return type
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed Squiz.Formatting.OperatorBracket false positive when exiting with a negative number
- Fixed Squiz.PHP.DisallowComparisonAssignment false positive for methods called on an object
- Fixed bug #2882 : Generic.Arrays.ArrayIndent can request close brace indent to be less than the statement indent level
- Fixed bug #2883 : Generic.WhiteSpace.ScopeIndent.Incorrect issue after NOWDOC
- Fixed bug #2975 : Undefined offset in PSR12.Functions.ReturnTypeDeclaration when checking function return type inside ternary
- Fixed bug #2988 : Undefined offset in Squiz.Strings.ConcatenationSpacing during live coding
-- Thanks to Thiemo Kreuz for the patch
- Fixed bug #2989 : Incorrect auto-fixing in Generic.ControlStructures.InlineControlStructure during live coding
-- Thanks to Thiemo Kreuz for the patch
- Fixed bug #3007 : Directory exclude pattern improperly excludes directories with names that start the same
-- Thanks to Steve Talbot for the patch
- Fixed bug #3043 : Squiz.WhiteSpace.OperatorSpacing false positive for negation in arrow function
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #3049 : Incorrect error with arrow function and parameter passed as reference
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #3053 : PSR2 incorrect fix when multiple use statements on same line do not have whitespace between them
- Fixed bug #3058 : Progress gets unaligned when 100% happens at the end of the available dots
- Fixed bug #3059 : Squiz.Arrays.ArrayDeclaration false positive when using type casting
-- Thanks to Sergei Morozov for the patch
- Fixed bug #3060 : Squiz.Arrays.ArrayDeclaration false positive for static functions
-- Thanks to Sergei Morozov for the patch
- Fixed bug #3065 : Should not fix Squiz.Arrays.ArrayDeclaration.SpaceBeforeComma if comment between element and comma
-- Thanks to Sergei Morozov for the patch
- Fixed bug #3066 : No support for namespace operator used in type declarations
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #3075 : PSR12.ControlStructures.BooleanOperatorPlacement false positive when operator is the only content on line
- Fixed bug #3099 : Squiz.WhiteSpace.OperatorSpacing false positive when exiting with negative number
-- Thanks to Sergei Morozov for the patch
- Fixed bug #3102 : PSR12.Squiz.OperatorSpacing false positive for default values of arrow functions
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #3124 : PSR-12 not reporting error for empty lines with only whitespace
- Fixed bug #3135 : Ignore annotations are broken on PHP 8.0
-- Thanks to Juliette Reinders Folmer for the patch
</notes>
</release>
<release>
<version>
<release>3.5.6</release>
Expand Down
2 changes: 1 addition & 1 deletion phpcs/src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Config
*
* @var string
*/
const VERSION = '3.5.7';
const VERSION = '3.5.8';

/**
* Package stability; either stable, beta or alpha.
Expand Down
Loading

0 comments on commit 7d9cdbe

Please sign in to comment.