From b86aa5795b21a0040f83757e7b2c101954846c15 Mon Sep 17 00:00:00 2001 From: alex_prokopenko Date: Wed, 15 Nov 2017 15:28:05 +0200 Subject: [PATCH] Reconfigured code sniffer to use vendor libs for wpcs and phpcs, update PSR2 to make comment required --- .gitignore | 4 +- README.md | 1 + bin/phpcsx-init | 22 + composer.json | 9 +- .../Sniffs/Commenting/DocCommentSniff.php | 40 +- justcoded/JustcodedPSR2/ruleset.xml | 9 +- .../ValidVariableNameSniff.php | 36 +- .../Sniffs/XSS/EscapeOutputSniff.php | 6 +- phpcs/.gitattributes | 13 - phpcs/.gitignore | 6 - phpcs/CONTRIBUTING.md | 13 - phpcs/CodeSniffer.conf.dist | 9 - phpcs/CodeSniffer.php | 2578 ----------- phpcs/CodeSniffer/CLI.php | 1444 ------- phpcs/CodeSniffer/DocGenerators/Generator.php | 184 - phpcs/CodeSniffer/DocGenerators/HTML.php | 292 -- phpcs/CodeSniffer/DocGenerators/Markdown.php | 179 - phpcs/CodeSniffer/DocGenerators/Text.php | 265 -- phpcs/CodeSniffer/Exception.php | 31 - phpcs/CodeSniffer/File.php | 3809 ----------------- phpcs/CodeSniffer/Fixer.php | 741 ---- phpcs/CodeSniffer/Report.php | 83 - phpcs/CodeSniffer/Reporting.php | 425 -- phpcs/CodeSniffer/Reports/Cbf.php | 151 - phpcs/CodeSniffer/Reports/Checkstyle.php | 128 - phpcs/CodeSniffer/Reports/Csv.php | 111 - phpcs/CodeSniffer/Reports/Diff.php | 149 - phpcs/CodeSniffer/Reports/Emacs.php | 110 - phpcs/CodeSniffer/Reports/Full.php | 237 - phpcs/CodeSniffer/Reports/Gitblame.php | 105 - phpcs/CodeSniffer/Reports/Hgblame.php | 124 - phpcs/CodeSniffer/Reports/Info.php | 162 - phpcs/CodeSniffer/Reports/Json.php | 128 - phpcs/CodeSniffer/Reports/Junit.php | 149 - phpcs/CodeSniffer/Reports/Notifysend.php | 262 -- phpcs/CodeSniffer/Reports/Source.php | 334 -- phpcs/CodeSniffer/Reports/Summary.php | 189 - phpcs/CodeSniffer/Reports/Svnblame.php | 90 - phpcs/CodeSniffer/Reports/VersionControl.php | 342 -- phpcs/CodeSniffer/Reports/Xml.php | 132 - phpcs/CodeSniffer/Sniff.php | 94 - .../Standards/AbstractPatternSniff.php | 962 ----- .../Standards/AbstractScopeSniff.php | 199 - .../Standards/AbstractVariableSniff.php | 245 -- .../Classes/DuplicateClassNameStandard.xml | 27 - .../Classes/OpeningBraceSameLineStandard.xml | 28 - .../CodeAnalysis/EmptyStatementStandard.xml | 23 - .../ForLoopShouldBeWhileLoopStandard.xml | 23 - .../ForLoopWithTestFunctionCallStandard.xml | 24 - .../JumbledIncrementerStandard.xml | 25 - .../UnconditionalIfStatementStandard.xml | 39 - .../UnnecessaryFinalModifierStandard.xml | 29 - .../UnusedFunctionParameterStandard.xml | 25 - .../UselessOverridingMethodStandard.xml | 32 - .../Generic/Docs/Commenting/FixmeStandard.xml | 25 - .../Generic/Docs/Commenting/TodoStandard.xml | 25 - .../InlineControlStructureStandard.xml | 22 - .../Generic/Docs/Debug/CSSLintStandard.xml | 19 - .../Docs/Debug/ClosureLinterStandard.xml | 19 - .../Generic/Docs/Debug/JSHintStandard.xml | 19 - .../Docs/Files/ByteOrderMarkStandard.xml | 7 - .../Docs/Files/EndFileNewlineStandard.xml | 7 - .../Docs/Files/EndFileNoNewlineStandard.xml | 7 - .../Generic/Docs/Files/InlineHTMLStandard.xml | 24 - .../Docs/Files/LineEndingsStandard.xml | 7 - .../Generic/Docs/Files/LineLengthStandard.xml | 7 - .../Docs/Files/LowercasedFilenameStandard.xml | 7 - .../Docs/Files/OneClassPerFileStandard.xml | 29 - .../Files/OneInterfacePerFileStandard.xml | 29 - .../DisallowMultipleStatementsStandard.xml | 20 - .../MultipleStatementAlignmentStandard.xml | 56 - .../Formatting/NoSpaceAfterCastStandard.xml | 19 - .../Formatting/SpaceAfterCastStandard.xml | 19 - .../CallTimePassByReferenceStandard.xml | 31 - .../FunctionCallArgumentSpacingStandard.xml | 39 - .../OpeningFunctionBraceBsdAllmanStandard.xml | 24 - ...gFunctionBraceKernighanRitchieStandard.xml | 24 - .../Metrics/CyclomaticComplexityStandard.xml | 7 - .../Docs/Metrics/NestingLevelStandard.xml | 7 - .../CamelCapsFunctionNameStandard.xml | 23 - .../ConstructorNameStandard.xml | 29 - .../UpperCaseConstantNameStandard.xml | 29 - .../Docs/PHP/BacktickOperatorStandard.xml | 7 - .../CharacterBeforePHPOpeningTagStandard.xml | 22 - .../Docs/PHP/ClosingPHPTagStandard.xml | 22 - .../Docs/PHP/DeprecatedFunctionsStandard.xml | 19 - .../DisallowAlternativePHPTagsStandard.xml | 7 - .../Docs/PHP/DisallowShortOpenTagStandard.xml | 7 - .../Docs/PHP/ForbiddenFunctionsStandard.xml | 19 - .../Docs/PHP/LowerCaseConstantStandard.xml | 23 - .../Docs/PHP/LowerCaseKeywordStandard.xml | 19 - .../Docs/PHP/NoSilencedErrorsStandard.xml | 23 - .../Generic/Docs/PHP/SAPIUsageStandard.xml | 23 - .../Docs/PHP/UpperCaseConstantStandard.xml | 23 - .../UnnecessaryStringConcatStandard.xml | 19 - .../SubversionPropertiesStandard.xml | 7 - .../DisallowSpaceIndentStandard.xml | 7 - .../WhiteSpace/DisallowTabIndentStandard.xml | 7 - .../Docs/WhiteSpace/ScopeIndentStandard.xml | 23 - .../Arrays/DisallowLongArraySyntaxSniff.php | 79 - .../Arrays/DisallowShortArraySyntaxSniff.php | 72 - .../Classes/DuplicateClassNameSniff.php | 127 - .../Classes/OpeningBraceSameLineSniff.php | 141 - .../CodeAnalysis/EmptyStatementSniff.php | 106 - .../ForLoopShouldBeWhileLoopSniff.php | 102 - .../ForLoopWithTestFunctionCallSniff.php | 111 - .../CodeAnalysis/JumbledIncrementerSniff.php | 146 - .../UnconditionalIfStatementSniff.php | 104 - .../UnnecessaryFinalModifierSniff.php | 96 - .../UnusedFunctionParameterSniff.php | 187 - .../UselessOverridingMethodSniff.php | 172 - .../Generic/Sniffs/Commenting/FixmeSniff.php | 91 - .../Generic/Sniffs/Commenting/TodoSniff.php | 89 - .../InlineControlStructureSniff.php | 316 -- .../Generic/Sniffs/Debug/CSSLintSniff.php | 107 - .../Sniffs/Debug/ClosureLinterSniff.php | 128 - .../Generic/Sniffs/Debug/JSHintSniff.php | 99 - .../Sniffs/Files/ByteOrderMarkSniff.php | 94 - .../Sniffs/Files/EndFileNewlineSniff.php | 94 - .../Sniffs/Files/EndFileNoNewlineSniff.php | 91 - .../Generic/Sniffs/Files/InlineHTMLSniff.php | 70 - .../Generic/Sniffs/Files/LineEndingsSniff.php | 151 - .../Generic/Sniffs/Files/LineLengthSniff.php | 177 - .../Sniffs/Files/LowercasedFilenameSniff.php | 78 - .../Sniffs/Files/OneClassPerFileSniff.php | 62 - .../Sniffs/Files/OneInterfacePerFileSniff.php | 62 - .../Sniffs/Files/OneTraitPerFileSniff.php | 62 - .../DisallowMultipleStatementsSniff.php | 102 - .../MultipleStatementAlignmentSniff.php | 330 -- .../Formatting/NoSpaceAfterCastSniff.php | 72 - .../Sniffs/Formatting/SpaceAfterCastSniff.php | 83 - .../Sniffs/Formatting/SpaceAfterNotSniff.php | 90 - .../CallTimePassByReferenceSniff.php | 159 - .../FunctionCallArgumentSpacingSniff.php | 179 - .../OpeningFunctionBraceBsdAllmanSniff.php | 191 - ...ningFunctionBraceKernighanRitchieSniff.php | 180 - .../Metrics/CyclomaticComplexitySniff.php | 127 - .../Sniffs/Metrics/NestingLevelSniff.php | 112 - .../CamelCapsFunctionNameSniff.php | 221 - .../ConstructorNameSniff.php | 148 - .../UpperCaseConstantNameSniff.php | 187 - .../Sniffs/PHP/BacktickOperatorSniff.php | 63 - .../PHP/CharacterBeforePHPOpeningTagSniff.php | 74 - .../Generic/Sniffs/PHP/ClosingPHPTagSniff.php | 62 - .../Sniffs/PHP/DeprecatedFunctionsSniff.php | 95 - .../PHP/DisallowAlternativePHPTagsSniff.php | 269 -- .../Sniffs/PHP/DisallowShortOpenTagSniff.php | 97 - .../Sniffs/PHP/ForbiddenFunctionsSniff.php | 243 -- .../Sniffs/PHP/LowerCaseConstantSniff.php | 98 - .../Sniffs/PHP/LowerCaseKeywordSniff.php | 148 - .../Sniffs/PHP/NoSilencedErrorsSniff.php | 79 - .../Generic/Sniffs/PHP/SAPIUsageSniff.php | 79 - .../Generic/Sniffs/PHP/SyntaxSniff.php | 97 - .../Sniffs/PHP/UpperCaseConstantSniff.php | 88 - .../Strings/UnnecessaryStringConcatSniff.php | 138 - .../SubversionPropertiesSniff.php | 204 - .../WhiteSpace/DisallowSpaceIndentSniff.php | 141 - .../WhiteSpace/DisallowTabIndentSniff.php | 149 - .../Sniffs/WhiteSpace/ScopeIndentSniff.php | 1274 ------ .../CodeSniffer/Standards/Generic/ruleset.xml | 4 - .../Standards/IncorrectPatternException.php | 33 - .../Sniffs/CSS/BrowserSpecificStylesSniff.php | 100 - .../Channels/DisallowSelfActionsSniff.php | 135 - .../Sniffs/Channels/IncludeOwnSystemSniff.php | 109 - .../Sniffs/Channels/IncludeSystemSniff.php | 335 -- .../Sniffs/Channels/UnusedSystemSniff.php | 152 - .../Commenting/FunctionCommentSniff.php | 100 - .../MySource/Sniffs/Debug/DebugCodeSniff.php | 66 - .../Sniffs/Debug/FirebugConsoleSniff.php | 75 - .../Sniffs/Objects/AssignThisSniff.php | 92 - .../Objects/CreateWidgetTypeCallbackSniff.php | 227 - .../Sniffs/Objects/DisallowNewWidgetSniff.php | 70 - .../Sniffs/PHP/AjaxNullComparisonSniff.php | 109 - .../Sniffs/PHP/EvalObjectFactorySniff.php | 124 - .../Sniffs/PHP/GetRequestDataSniff.php | 117 - .../Sniffs/PHP/ReturnFunctionValueSniff.php | 74 - .../Sniffs/Strings/JoinStringsSniff.php | 86 - .../Standards/MySource/ruleset.xml | 18 - .../Docs/Classes/ClassDeclarationStandard.xml | 22 - .../Docs/Commenting/ClassCommentStandard.xml | 177 - .../Docs/Commenting/FileCommentStandard.xml | 286 -- .../Commenting/FunctionCommentStandard.xml | 230 - .../Docs/Commenting/InlineCommentStandard.xml | 19 - .../ControlSignatureStandard.xml | 36 - .../MultiLineConditionStandard.xml | 60 - .../PEAR/Docs/Files/IncludingFileStandard.xml | 24 - .../PEAR/Docs/Files/LineLengthStandard.xml | 7 - .../MultiLineAssignmentStandard.xml | 35 - .../FunctionCallSignatureStandard.xml | 19 - .../Functions/FunctionDeclarationStandard.xml | 41 - .../Functions/ValidDefaultValueStandard.xml | 25 - .../ValidClassNameStandard.xml | 23 - .../ValidFunctionNameStandard.xml | 23 - .../ValidVariableNameStandard.xml | 29 - .../ObjectOperatorIndentStandard.xml | 39 - .../WhiteSpace/ScopeClosingBraceStandard.xml | 23 - .../Docs/WhiteSpace/ScopeIndentStandard.xml | 29 - .../Sniffs/Classes/ClassDeclarationSniff.php | 164 - .../Sniffs/Commenting/ClassCommentSniff.php | 117 - .../Sniffs/Commenting/FileCommentSniff.php | 582 --- .../Commenting/FunctionCommentSniff.php | 438 -- .../Sniffs/Commenting/InlineCommentSniff.php | 83 - .../ControlSignatureSniff.php | 65 - .../MultiLineConditionSniff.php | 279 -- .../PEAR/Sniffs/Files/IncludingFileSniff.php | 150 - .../Formatting/MultiLineAssignmentSniff.php | 119 - .../Functions/FunctionCallSignatureSniff.php | 560 --- .../Functions/FunctionDeclarationSniff.php | 438 -- .../Functions/ValidDefaultValueSniff.php | 98 - .../NamingConventions/ValidClassNameSniff.php | 113 - .../ValidFunctionNameSniff.php | 298 -- .../ValidVariableNameSniff.php | 121 - .../WhiteSpace/ObjectOperatorIndentSniff.php | 193 - .../WhiteSpace/ScopeClosingBraceSniff.php | 193 - .../Sniffs/WhiteSpace/ScopeIndentSniff.php | 46 - phpcs/CodeSniffer/Standards/PEAR/ruleset.xml | 40 - phpcs/CodeSniffer/Standards/PHPCS/ruleset.xml | 55 - .../Docs/Classes/ClassDeclarationStandard.xml | 48 - .../PSR1/Docs/Files/SideEffectsStandard.xml | 27 - .../Sniffs/Classes/ClassDeclarationSniff.php | 102 - .../PSR1/Sniffs/Files/SideEffectsSniff.php | 238 - .../Methods/CamelCapsMethodNameSniff.php | 93 - phpcs/CodeSniffer/Standards/PSR1/ruleset.xml | 45 - .../Docs/Classes/ClassDeclarationStandard.xml | 23 - .../Classes/PropertyDeclarationStandard.xml | 62 - .../ControlStructureSpacingStandard.xml | 23 - .../ElseIfDeclarationStandard.xml | 27 - .../SwitchDeclarationStandard.xml | 104 - .../Docs/Files/EndFileNewlineStandard.xml | 7 - .../Methods/MethodDeclarationStandard.xml | 51 - .../NamespaceDeclarationStandard.xml | 22 - .../Namespaces/UseDeclarationStandard.xml | 57 - .../Sniffs/Classes/ClassDeclarationSniff.php | 455 -- .../Classes/PropertyDeclarationSniff.php | 117 - .../ControlStructureSpacingSniff.php | 152 - .../ElseIfDeclarationSniff.php | 85 - .../SwitchDeclarationSniff.php | 248 -- .../PSR2/Sniffs/Files/ClosingTagSniff.php | 100 - .../PSR2/Sniffs/Files/EndFileNewlineSniff.php | 117 - .../Methods/FunctionCallSignatureSniff.php | 89 - .../Methods/FunctionClosingBraceSniff.php | 104 - .../Sniffs/Methods/MethodDeclarationSniff.php | 155 - .../Namespaces/NamespaceDeclarationSniff.php | 105 - .../Sniffs/Namespaces/UseDeclarationSniff.php | 216 - phpcs/CodeSniffer/Standards/PSR2/ruleset.xml | 206 - .../Arrays/ArrayBracketSpacingStandard.xml | 19 - .../Docs/Arrays/ArrayDeclarationStandard.xml | 117 - .../LowercaseClassKeywordsStandard.xml | 23 - .../Classes/SelfMemberReferenceStandard.xml | 63 - .../DocCommentAlignmentStandard.xml | 39 - .../FunctionCommentThrowTagStandard.xml | 32 - .../ForEachLoopDeclarationStandard.xml | 39 - .../ForLoopDeclarationStandard.xml | 55 - .../LowercaseDeclarationStandard.xml | 23 - .../FunctionDuplicateArgumentStandard.xml | 23 - .../LowercaseFunctionKeywordsStandard.xml | 25 - .../Docs/Scope/StaticThisUsageStandard.xml | 31 - .../Docs/Strings/EchoedStringsStandard.xml | 19 - .../Docs/WhiteSpace/CastSpacingStandard.xml | 19 - .../FunctionOpeningBraceStandard.xml | 41 - .../LanguageConstructSpacingStandard.xml | 19 - .../ObjectOperatorSpacingStandard.xml | 19 - .../ScopeKeywordSpacingStandard.xml | 23 - .../WhiteSpace/SemicolonSpacingStandard.xml | 19 - .../Arrays/ArrayBracketSpacingSniff.php | 119 - .../Sniffs/Arrays/ArrayDeclarationSniff.php | 863 ---- .../ClassDefinitionClosingBraceSpaceSniff.php | 122 - .../CSS/ClassDefinitionNameSpacingSniff.php | 118 - .../ClassDefinitionOpeningBraceSpaceSniff.php | 144 - .../Squiz/Sniffs/CSS/ColonSpacingSniff.php | 118 - .../Sniffs/CSS/ColourDefinitionSniff.php | 101 - .../DisallowMultipleStyleDefinitionsSniff.php | 84 - .../CSS/DuplicateClassDefinitionSniff.php | 128 - .../CSS/DuplicateStyleDefinitionSniff.php | 96 - .../Sniffs/CSS/EmptyClassDefinitionSniff.php | 73 - .../Sniffs/CSS/EmptyStyleDefinitionSniff.php | 73 - .../Squiz/Sniffs/CSS/ForbiddenStylesSniff.php | 190 - .../Squiz/Sniffs/CSS/IndentationSniff.php | 154 - .../CSS/LowercaseStyleDefinitionSniff.php | 110 - .../Squiz/Sniffs/CSS/MissingColonSniff.php | 99 - .../Squiz/Sniffs/CSS/NamedColoursSniff.php | 107 - .../Squiz/Sniffs/CSS/OpacitySniff.php | 110 - .../Sniffs/CSS/SemicolonSpacingSniff.php | 84 - .../Squiz/Sniffs/CSS/ShorthandSizeSniff.php | 191 - .../Sniffs/Classes/ClassDeclarationSniff.php | 219 - .../Sniffs/Classes/ClassFileNameSniff.php | 84 - .../Sniffs/Classes/DuplicatePropertySniff.php | 95 - .../Classes/LowercaseClassKeywordsSniff.php | 87 - .../Classes/SelfMemberReferenceSniff.php | 198 - .../Sniffs/Classes/ValidClassNameSniff.php | 100 - .../Sniffs/Commenting/BlockCommentSniff.php | 357 -- .../Sniffs/Commenting/ClassCommentSniff.php | 97 - .../ClosingDeclarationCommentSniff.php | 149 - .../Commenting/DocCommentAlignmentSniff.php | 167 - .../Commenting/EmptyCatchCommentSniff.php | 70 - .../Sniffs/Commenting/FileCommentSniff.php | 222 - .../Commenting/FunctionCommentSniff.php | 674 --- .../FunctionCommentThrowTagSniff.php | 203 - .../Sniffs/Commenting/InlineCommentSniff.php | 326 -- .../LongConditionClosingCommentSniff.php | 217 - .../Commenting/PostStatementCommentSniff.php | 103 - .../Commenting/VariableCommentSniff.php | 170 - .../ControlSignatureSniff.php | 271 -- .../ElseIfDeclarationSniff.php | 67 - .../ForEachLoopDeclarationSniff.php | 252 -- .../ForLoopDeclarationSniff.php | 232 - .../InlineIfDeclarationSniff.php | 166 - .../LowercaseDeclarationSniff.php | 88 - .../SwitchDeclarationSniff.php | 319 -- .../Squiz/Sniffs/Debug/JSLintSniff.php | 97 - .../Sniffs/Debug/JavaScriptLintSniff.php | 98 - .../Squiz/Sniffs/Files/FileExtensionSniff.php | 83 - .../Formatting/OperatorBracketSniff.php | 365 -- ...unctionDeclarationArgumentSpacingSniff.php | 417 -- .../Functions/FunctionDeclarationSniff.php | 54 - .../FunctionDuplicateArgumentSniff.php | 79 - .../Sniffs/Functions/GlobalFunctionSniff.php | 76 - .../LowercaseFunctionKeywordsSniff.php | 79 - .../MultiLineFunctionDeclarationSniff.php | 220 - .../ValidFunctionNameSniff.php | 72 - .../ValidVariableNameSniff.php | 234 - .../DisallowObjectStringIndexSniff.php | 96 - .../Objects/ObjectInstantiationSniff.php | 81 - .../Sniffs/Objects/ObjectMemberCommaSniff.php | 76 - .../ComparisonOperatorUsageSniff.php | 244 -- .../IncrementDecrementUsageSniff.php | 239 -- .../Operators/ValidLogicalOperatorsSniff.php | 83 - .../Sniffs/PHP/CommentedOutCodeSniff.php | 237 - .../PHP/DisallowBooleanStatementSniff.php | 72 - .../PHP/DisallowComparisonAssignmentSniff.php | 125 - .../Sniffs/PHP/DisallowInlineIfSniff.php | 72 - .../PHP/DisallowMultipleAssignmentsSniff.php | 183 - .../Sniffs/PHP/DisallowObEndFlushSniff.php | 66 - .../PHP/DisallowSizeFunctionsInLoopsSniff.php | 127 - .../Sniffs/PHP/DiscouragedFunctionsSniff.php | 56 - .../Squiz/Sniffs/PHP/EmbeddedPhpSniff.php | 405 -- .../Standards/Squiz/Sniffs/PHP/EvalSniff.php | 63 - .../Sniffs/PHP/ForbiddenFunctionsSniff.php | 54 - .../Squiz/Sniffs/PHP/GlobalKeywordSniff.php | 68 - .../Squiz/Sniffs/PHP/HeredocSniff.php | 66 - .../Squiz/Sniffs/PHP/InnerFunctionsSniff.php | 83 - .../Sniffs/PHP/LowercasePHPFunctionsSniff.php | 140 - .../Sniffs/PHP/NonExecutableCodeSniff.php | 270 -- .../Sniffs/Scope/MemberVarScopeSniff.php | 101 - .../Squiz/Sniffs/Scope/MethodScopeSniff.php | 89 - .../Sniffs/Scope/StaticThisUsageSniff.php | 95 - .../Strings/ConcatenationSpacingSniff.php | 159 - .../Sniffs/Strings/DoubleQuoteUsageSniff.php | 153 - .../Sniffs/Strings/EchoedStringsSniff.php | 103 - .../Sniffs/WhiteSpace/CastSpacingSniff.php | 79 - .../ControlStructureSpacingSniff.php | 316 -- .../FunctionClosingBraceSpaceSniff.php | 182 - .../FunctionOpeningBraceSpaceSniff.php | 113 - .../WhiteSpace/FunctionSpacingSniff.php | 239 -- .../LanguageConstructSpacingSniff.php | 100 - .../LogicalOperatorSpacingSniff.php | 116 - .../WhiteSpace/MemberVarSpacingSniff.php | 167 - .../WhiteSpace/ObjectOperatorSpacingSniff.php | 154 - .../WhiteSpace/OperatorSpacingSniff.php | 324 -- .../WhiteSpace/PropertyLabelSpacingSniff.php | 93 - .../WhiteSpace/ScopeClosingBraceSniff.php | 114 - .../WhiteSpace/ScopeKeywordSpacingSniff.php | 92 - .../WhiteSpace/SemicolonSpacingSniff.php | 106 - .../WhiteSpace/SuperfluousWhitespaceSniff.php | 265 -- phpcs/CodeSniffer/Standards/Squiz/ruleset.xml | 76 - .../Zend/Docs/Debug/CodeAnalyzerStandard.xml | 25 - .../Zend/Docs/Files/ClosingTagStandard.xml | 22 - .../ValidVariableNameStandard.xml | 37 - .../Zend/Sniffs/Debug/CodeAnalyzerSniff.php | 107 - .../Zend/Sniffs/Files/ClosingTagSniff.php | 83 - .../ValidVariableNameSniff.php | 245 -- phpcs/CodeSniffer/Standards/Zend/ruleset.xml | 32 - phpcs/CodeSniffer/Tokenizers/CSS.php | 537 --- phpcs/CodeSniffer/Tokenizers/Comment.php | 287 -- phpcs/CodeSniffer/Tokenizers/JS.php | 1179 ----- phpcs/CodeSniffer/Tokenizers/PHP.php | 1707 -------- phpcs/CodeSniffer/Tokens.php | 777 ---- phpcs/README.md | 75 - phpcs/composer.json | 67 - phpcs/licence.txt | 24 - phpcs/php5-testingConfig.ini | 12 - phpcs/php7-testingConfig.ini | 8 - phpcs/phpcs.xml.dist | 14 - phpcs/phpunit.xml.dist | 8 - phpcs/scripts/build-phar.php | 128 - phpcs/scripts/phpcbf | 23 - phpcs/scripts/phpcbf.bat | 19 - phpcs/scripts/phpcs | 25 - phpcs/scripts/phpcs-svn-pre-commit | 229 - phpcs/scripts/phpcs.bat | 21 - phpcsx | 35 +- wpcs/.gitignore | 5 - wpcs/.travis.yml | 65 - wpcs/CHANGELOG.md | 380 -- wpcs/CONTRIBUTING.md | 141 - wpcs/LICENSE | 21 - wpcs/README.md | 255 -- wpcs/WordPress-Core/ruleset.xml | 331 -- wpcs/WordPress-Docs/ruleset.xml | 119 - wpcs/WordPress-Extra/ruleset.xml | 101 - wpcs/WordPress-VIP/ruleset.xml | 89 - ...stractArrayAssignmentRestrictionsSniff.php | 206 - .../AbstractClassRestrictionsSniff.php | 278 -- .../AbstractFunctionParameterSniff.php | 108 - .../AbstractFunctionRestrictionsSniff.php | 298 -- .../AbstractVariableRestrictionsSniff.php | 198 - wpcs/WordPress/Sniff.php | 1784 -------- .../ArrayAssignmentRestrictionsSniff.php | 59 - .../Sniffs/Arrays/ArrayDeclarationSniff.php | 611 --- .../Arrays/ArrayDeclarationSpacingSniff.php | 248 -- .../ArrayKeySpacingRestrictionsSniff.php | 89 - .../Sniffs/CSRF/NonceVerificationSniff.php | 180 - .../Sniffs/DB/RestrictedClassesSniff.php | 55 - .../Sniffs/DB/RestrictedFunctionsSniff.php | 62 - wpcs/WordPress/Sniffs/Files/FileNameSniff.php | 207 - .../Sniffs/Functions/DontExtractSniff.php | 48 - .../Functions/FunctionRestrictionsSniff.php | 42 - .../ValidFunctionNameSniff.php | 178 - .../NamingConventions/ValidHookNameSniff.php | 253 -- .../ValidVariableNameSniff.php | 329 -- .../Sniffs/PHP/DevelopmentFunctionsSniff.php | 62 - .../Sniffs/PHP/DiscouragedFunctionsSniff.php | 57 - .../PHP/DiscouragedPHPFunctionsSniff.php | 108 - .../Sniffs/PHP/POSIXFunctionsSniff.php | 70 - .../Sniffs/PHP/StrictComparisonsSniff.php | 53 - .../Sniffs/PHP/StrictInArraySniff.php | 104 - .../Sniffs/PHP/YodaConditionsSniff.php | 105 - .../Sniffs/VIP/AdminBarRemovalSniff.php | 423 -- .../Sniffs/VIP/CronIntervalSniff.php | 185 - .../Sniffs/VIP/DirectDatabaseQuerySniff.php | 253 -- .../VIP/FileSystemWritesDisallowSniff.php | 101 - .../WordPress/Sniffs/VIP/OrderByRandSniff.php | 55 - .../Sniffs/VIP/PluginMenuSlugSniff.php | 82 - .../Sniffs/VIP/PostsPerPageSniff.php | 79 - .../Sniffs/VIP/RestrictedFunctionsSniff.php | 247 -- .../Sniffs/VIP/RestrictedVariablesSniff.php | 63 - .../Sniffs/VIP/SessionFunctionsUsageSniff.php | 73 - .../Sniffs/VIP/SessionVariableUsageSniff.php | 56 - .../WordPress/Sniffs/VIP/SlowDBQuerySniff.php | 86 - .../Sniffs/VIP/SuperGlobalInputUsageSniff.php | 61 - .../Sniffs/VIP/TimezoneChangeSniff.php | 48 - .../VIP/ValidatedSanitizedInputSniff.php | 172 - .../Sniffs/Variables/GlobalVariablesSniff.php | 419 -- .../Variables/VariableRestrictionsSniff.php | 45 - .../Sniffs/WP/AlternativeFunctionsSniff.php | 85 - .../Sniffs/WP/DeprecatedFunctionsSniff.php | 1146 ----- .../Sniffs/WP/DiscouragedFunctionsSniff.php | 53 - .../Sniffs/WP/EnqueuedResourcesSniff.php | 58 - wpcs/WordPress/Sniffs/WP/I18nSniff.php | 612 --- wpcs/WordPress/Sniffs/WP/PreparedSQLSniff.php | 244 -- .../WhiteSpace/CastStructureSpacingSniff.php | 61 - .../ControlStructureSpacingSniff.php | 557 --- .../WhiteSpace/OperatorSpacingSniff.php | 203 - .../Sniffs/XSS/EscapeOutputSniff.php | 415 -- .../ArrayAssignmentRestrictionsUnitTest.inc | 20 - .../ArrayAssignmentRestrictionsUnitTest.php | 61 - .../ArrayDeclarationSpacingUnitTest.inc | 24 - .../ArrayDeclarationSpacingUnitTest.inc.fixed | 54 - .../ArrayDeclarationSpacingUnitTest.php | 45 - .../Tests/Arrays/ArrayDeclarationUnitTest.txt | 13 - .../ArrayKeySpacingRestrictionsUnitTest.inc | 31 - ...ayKeySpacingRestrictionsUnitTest.inc.fixed | 31 - .../ArrayKeySpacingRestrictionsUnitTest.php | 51 - .../Tests/CSRF/NonceVerificationUnitTest.inc | 162 - .../Tests/CSRF/NonceVerificationUnitTest.php | 55 - .../Tests/DB/RestrictedClassesUnitTest.1.inc | 66 - .../Tests/DB/RestrictedClassesUnitTest.2.inc | 47 - .../Tests/DB/RestrictedClassesUnitTest.3.inc | 92 - .../Tests/DB/RestrictedClassesUnitTest.php | 147 - .../Tests/DB/RestrictedFunctionsUnitTest.inc | 90 - .../Tests/DB/RestrictedFunctionsUnitTest.php | 85 - .../Tests/Files/FileNameUnitTest.inc | 1 - .../Tests/Files/FileNameUnitTest.php | 121 - .../Files/FileNameUnitTests/ClassMyClass.inc | 3 - .../ClassNonStrictClass.inc | 5 - .../NonStrictClassNames/non-strict-class.inc | 5 - .../unrelated-filename.inc | 5 - .../Files/FileNameUnitTests/SomeFile.inc | 1 - .../ThemeExceptions/FrontPage.inc | 3 - .../ThemeExceptions/application_flash.inc | 3 - .../ThemeExceptions/archive-post_type.inc | 3 - .../ThemeExceptions/author-nice_name.inc | 3 - .../embed-post_type-post_format.inc | 3 - .../ThemeExceptions/embed-post_type.inc | 3 - .../ThemeExceptions/front-page.inc | 3 - .../ThemeExceptions/front_page.inc | 3 - .../ThemeExceptions/single-post-type.inc | 3 - .../ThemeExceptions/single-post_type-slug.inc | 3 - .../ThemeExceptions/single-post_type.inc | 3 - .../taxonomy-my_taxonomy-term.inc | 3 - .../ThemeExceptions/taxonomy-my_taxonomy.inc | 3 - .../taxonomy-post_format-post-format-link.inc | 3 - .../ThemeExceptions/taxonomy-post_format.inc | 3 - .../ThemeExceptions/text.inc | 3 - .../ThemeExceptions/text_plain.inc | 3 - .../class-different-class.inc | 3 - .../FileNameUnitTests/class-my-class.inc | 3 - .../class.wp-dependencies.inc | 3 - .../FileNameUnitTests/class.wp-scripts.inc | 3 - .../FileNameUnitTests/class.wp-styles.inc | 3 - .../Files/FileNameUnitTests/my-class.inc | 3 - .../FileNameUnitTests/single-my_post_type.inc | 1 - .../Files/FileNameUnitTests/some-File.inc | 1 - .../Files/FileNameUnitTests/some_file.inc | 1 - ...taxonomy-post_format-post-format-audio.inc | 1 - .../wp-includes/author-template.inc | 11 - .../wp-includes/bookmark-template.inc | 7 - .../wp-includes/class-walker-page.inc | 10 - .../FileNameUnitTests/wp-includes/general.inc | 7 - .../Tests/Functions/DontExtractUnitTest.inc | 9 - .../Tests/Functions/DontExtractUnitTest.php | 40 - .../ValidFunctionNameUnitTest.inc | 104 - .../ValidFunctionNameUnitTest.php | 54 - .../ValidHookNameUnitTest.1.inc | 17 - .../ValidHookNameUnitTest.2.inc | 17 - .../ValidHookNameUnitTest.inc | 85 - .../ValidHookNameUnitTest.php | 112 - .../ValidVariableNameUnitTest.inc | 138 - .../ValidVariableNameUnitTest.php | 84 - .../PHP/DevelopmentFunctionsUnitTest.inc | 34 - .../PHP/DevelopmentFunctionsUnitTest.php | 55 - .../PHP/DiscouragedPHPFunctionsUnitTest.inc | 40 - .../PHP/DiscouragedPHPFunctionsUnitTest.php | 65 - .../Tests/PHP/POSIXFunctionsUnitTest.inc | 26 - .../Tests/PHP/POSIXFunctionsUnitTest.php | 46 - .../Tests/PHP/StrictComparisonsUnitTest.inc | 21 - .../Tests/PHP/StrictComparisonsUnitTest.php | 42 - .../Tests/PHP/StrictInArrayUnitTest.inc | 37 - .../Tests/PHP/StrictInArrayUnitTest.php | 50 - .../Tests/PHP/YodaConditionsUnitTest.inc | 92 - .../Tests/PHP/YodaConditionsUnitTest.php | 52 - .../Tests/VIP/AdminBarRemovalUnitTest.css | 55 - .../Tests/VIP/AdminBarRemovalUnitTest.inc | 108 - .../Tests/VIP/AdminBarRemovalUnitTest.php | 90 - .../Tests/VIP/CronIntervalUnitTest.inc | 82 - .../Tests/VIP/CronIntervalUnitTest.php | 50 - .../Tests/VIP/DirectDatabaseQueryUnitTest.inc | 244 -- .../Tests/VIP/DirectDatabaseQueryUnitTest.php | 56 - .../VIP/FileSystemWritesDisallowUnitTest.inc | 37 - .../VIP/FileSystemWritesDisallowUnitTest.php | 62 - .../Tests/VIP/OrderByRandUnitTest.inc | 13 - .../Tests/VIP/OrderByRandUnitTest.php | 44 - .../Tests/VIP/PluginMenuSlugUnitTest.inc | 14 - .../Tests/VIP/PluginMenuSlugUnitTest.php | 43 - .../Tests/VIP/PostsPerPageUnitTest.inc | 18 - .../Tests/VIP/PostsPerPageUnitTest.php | 45 - .../Tests/VIP/RestrictedFunctionsUnitTest.inc | 84 - .../Tests/VIP/RestrictedFunctionsUnitTest.php | 81 - .../Tests/VIP/RestrictedVariablesUnitTest.inc | 19 - .../Tests/VIP/RestrictedVariablesUnitTest.php | 47 - .../VIP/SessionFunctionsUsageUnitTest.inc | 28 - .../VIP/SessionFunctionsUsageUnitTest.php | 37 - .../VIP/SessionVariableUsageUnitTest.inc | 4 - .../VIP/SessionVariableUsageUnitTest.php | 41 - .../Tests/VIP/SlowDBQueryUnitTest.inc | 39 - .../Tests/VIP/SlowDBQueryUnitTest.php | 45 - .../VIP/SuperGlobalInputUsageUnitTest.inc | 20 - .../VIP/SuperGlobalInputUsageUnitTest.php | 41 - .../Tests/VIP/TimezoneChangeUnitTest.inc | 6 - .../Tests/VIP/TimezoneChangeUnitTest.php | 40 - .../VIP/ValidatedSanitizedInputUnitTest.inc | 151 - .../VIP/ValidatedSanitizedInputUnitTest.php | 63 - .../Variables/GlobalVariablesUnitTest.inc | 131 - .../Variables/GlobalVariablesUnitTest.php | 50 - .../VariableRestrictionsUnitTest.inc | 62 - .../VariableRestrictionsUnitTest.php | 100 - .../Tests/WP/AlternativeFunctionsUnitTest.inc | 23 - .../Tests/WP/AlternativeFunctionsUnitTest.php | 58 - .../Tests/WP/DeprecatedFunctionsUnitTest.inc | 260 -- .../Tests/WP/DeprecatedFunctionsUnitTest.php | 39 - .../Tests/WP/DiscouragedFunctionsUnitTest.inc | 5 - .../Tests/WP/DiscouragedFunctionsUnitTest.php | 42 - .../Tests/WP/EnqueuedResourcesUnitTest.inc | 11 - .../Tests/WP/EnqueuedResourcesUnitTest.php | 56 - wpcs/WordPress/Tests/WP/I18nUnitTest.1.inc | 104 - wpcs/WordPress/Tests/WP/I18nUnitTest.inc | 132 - .../WordPress/Tests/WP/I18nUnitTest.inc.fixed | 132 - wpcs/WordPress/Tests/WP/I18nUnitTest.php | 142 - .../Tests/WP/PreparedSQLUnitTest.inc | 33 - .../Tests/WP/PreparedSQLUnitTest.php | 52 - .../CastStructureSpacingUnitTest.inc | 22 - .../CastStructureSpacingUnitTest.inc.fixed | 22 - .../CastStructureSpacingUnitTest.php | 46 - .../ControlStructureSpacingUnitTest.inc | 213 - .../ControlStructureSpacingUnitTest.inc.fixed | 208 - .../ControlStructureSpacingUnitTest.php | 95 - .../WhiteSpace/OperatorSpacingUnitTest.inc | 55 - .../OperatorSpacingUnitTest.inc.fixed | 55 - .../WhiteSpace/OperatorSpacingUnitTest.php | 43 - .../Tests/XSS/EscapeOutputUnitTest.inc | 207 - .../Tests/XSS/EscapeOutputUnitTest.php | 80 - wpcs/WordPress/ruleset.xml | 17 - wpcs/bin/phpcs.xml | 12 - wpcs/bin/pre-commit | 14 - wpcs/composer.json | 24 - wpcs/myconfig.ini | 3 - wpcs/project.ruleset.xml.example | 34 - 597 files changed, 99 insertions(+), 77251 deletions(-) create mode 100644 bin/phpcsx-init rename {phpcs/CodeSniffer/Standards/Generic => justcoded/JustcodedPSR2}/Sniffs/Commenting/DocCommentSniff.php (91%) delete mode 100644 phpcs/.gitattributes delete mode 100644 phpcs/.gitignore delete mode 100644 phpcs/CONTRIBUTING.md delete mode 100644 phpcs/CodeSniffer.conf.dist delete mode 100644 phpcs/CodeSniffer.php delete mode 100644 phpcs/CodeSniffer/CLI.php delete mode 100644 phpcs/CodeSniffer/DocGenerators/Generator.php delete mode 100644 phpcs/CodeSniffer/DocGenerators/HTML.php delete mode 100644 phpcs/CodeSniffer/DocGenerators/Markdown.php delete mode 100644 phpcs/CodeSniffer/DocGenerators/Text.php delete mode 100644 phpcs/CodeSniffer/Exception.php delete mode 100644 phpcs/CodeSniffer/File.php delete mode 100644 phpcs/CodeSniffer/Fixer.php delete mode 100644 phpcs/CodeSniffer/Report.php delete mode 100644 phpcs/CodeSniffer/Reporting.php delete mode 100644 phpcs/CodeSniffer/Reports/Cbf.php delete mode 100644 phpcs/CodeSniffer/Reports/Checkstyle.php delete mode 100644 phpcs/CodeSniffer/Reports/Csv.php delete mode 100644 phpcs/CodeSniffer/Reports/Diff.php delete mode 100644 phpcs/CodeSniffer/Reports/Emacs.php delete mode 100644 phpcs/CodeSniffer/Reports/Full.php delete mode 100644 phpcs/CodeSniffer/Reports/Gitblame.php delete mode 100644 phpcs/CodeSniffer/Reports/Hgblame.php delete mode 100644 phpcs/CodeSniffer/Reports/Info.php delete mode 100644 phpcs/CodeSniffer/Reports/Json.php delete mode 100644 phpcs/CodeSniffer/Reports/Junit.php delete mode 100644 phpcs/CodeSniffer/Reports/Notifysend.php delete mode 100644 phpcs/CodeSniffer/Reports/Source.php delete mode 100644 phpcs/CodeSniffer/Reports/Summary.php delete mode 100644 phpcs/CodeSniffer/Reports/Svnblame.php delete mode 100644 phpcs/CodeSniffer/Reports/VersionControl.php delete mode 100644 phpcs/CodeSniffer/Reports/Xml.php delete mode 100644 phpcs/CodeSniffer/Sniff.php delete mode 100644 phpcs/CodeSniffer/Standards/AbstractPatternSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/AbstractScopeSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/AbstractVariableSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Classes/DuplicateClassNameStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Classes/OpeningBraceSameLineStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/EmptyStatementStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/ForLoopShouldBeWhileLoopStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/ForLoopWithTestFunctionCallStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/JumbledIncrementerStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/UnconditionalIfStatementStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/UnnecessaryFinalModifierStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/UnusedFunctionParameterStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/UselessOverridingMethodStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Commenting/FixmeStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Commenting/TodoStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/ControlStructures/InlineControlStructureStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Debug/CSSLintStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Debug/ClosureLinterStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Debug/JSHintStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Files/ByteOrderMarkStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Files/EndFileNewlineStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Files/EndFileNoNewlineStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Files/InlineHTMLStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Files/LineEndingsStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Files/LineLengthStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Files/LowercasedFilenameStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Files/OneClassPerFileStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Files/OneInterfacePerFileStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Formatting/DisallowMultipleStatementsStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Formatting/MultipleStatementAlignmentStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Formatting/NoSpaceAfterCastStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Formatting/SpaceAfterCastStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Functions/CallTimePassByReferenceStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Functions/FunctionCallArgumentSpacingStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Functions/OpeningFunctionBraceBsdAllmanStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Functions/OpeningFunctionBraceKernighanRitchieStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Metrics/CyclomaticComplexityStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Metrics/NestingLevelStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/NamingConventions/CamelCapsFunctionNameStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/NamingConventions/ConstructorNameStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/NamingConventions/UpperCaseConstantNameStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/PHP/BacktickOperatorStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/PHP/CharacterBeforePHPOpeningTagStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/PHP/ClosingPHPTagStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/PHP/DeprecatedFunctionsStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/PHP/DisallowAlternativePHPTagsStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/PHP/DisallowShortOpenTagStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/PHP/ForbiddenFunctionsStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/PHP/LowerCaseConstantStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/PHP/LowerCaseKeywordStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/PHP/NoSilencedErrorsStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/PHP/SAPIUsageStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/PHP/UpperCaseConstantStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/Strings/UnnecessaryStringConcatStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/VersionControl/SubversionPropertiesStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/WhiteSpace/DisallowSpaceIndentStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/WhiteSpace/DisallowTabIndentStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Docs/WhiteSpace/ScopeIndentStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Arrays/DisallowLongArraySyntaxSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Arrays/DisallowShortArraySyntaxSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Classes/DuplicateClassNameSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Classes/OpeningBraceSameLineSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/EmptyStatementSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/ForLoopShouldBeWhileLoopSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/ForLoopWithTestFunctionCallSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/JumbledIncrementerSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnnecessaryFinalModifierSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnusedFunctionParameterSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Commenting/FixmeSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Commenting/TodoSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Debug/CSSLintSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Debug/ClosureLinterSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Debug/JSHintSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/ByteOrderMarkSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/EndFileNewlineSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/EndFileNoNewlineSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/InlineHTMLSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/LineEndingsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/LineLengthSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/LowercasedFilenameSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/OneClassPerFileSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/OneInterfacePerFileSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/OneTraitPerFileSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/DisallowMultipleStatementsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/NoSpaceAfterCastSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/SpaceAfterCastSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/SpaceAfterNotSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Functions/CallTimePassByReferenceSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceKernighanRitchieSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Metrics/NestingLevelSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/CamelCapsFunctionNameSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/BacktickOperatorSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/CharacterBeforePHPOpeningTagSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/ClosingPHPTagSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/DeprecatedFunctionsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/DisallowAlternativePHPTagsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/ForbiddenFunctionsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/LowerCaseConstantSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/LowerCaseKeywordSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/NoSilencedErrorsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/SAPIUsageSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/SyntaxSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/UpperCaseConstantSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/Strings/UnnecessaryStringConcatSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/VersionControl/SubversionPropertiesSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Generic/ruleset.xml delete mode 100644 phpcs/CodeSniffer/Standards/IncorrectPatternException.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/Sniffs/CSS/BrowserSpecificStylesSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/Sniffs/Channels/DisallowSelfActionsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/Sniffs/Channels/IncludeOwnSystemSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/Sniffs/Channels/IncludeSystemSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/Sniffs/Channels/UnusedSystemSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/Sniffs/Commenting/FunctionCommentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/Sniffs/Debug/DebugCodeSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/Sniffs/Debug/FirebugConsoleSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/Sniffs/Objects/AssignThisSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/Sniffs/Objects/CreateWidgetTypeCallbackSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/Sniffs/Objects/DisallowNewWidgetSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/Sniffs/PHP/AjaxNullComparisonSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/Sniffs/PHP/EvalObjectFactorySniff.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/Sniffs/PHP/GetRequestDataSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/Sniffs/PHP/ReturnFunctionValueSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/Sniffs/Strings/JoinStringsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/MySource/ruleset.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/Classes/ClassDeclarationStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/Commenting/ClassCommentStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/Commenting/FileCommentStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/Commenting/FunctionCommentStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/Commenting/InlineCommentStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/ControlStructures/ControlSignatureStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/ControlStructures/MultiLineConditionStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/Files/IncludingFileStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/Files/LineLengthStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/Formatting/MultiLineAssignmentStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/Functions/FunctionCallSignatureStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/Functions/FunctionDeclarationStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/Functions/ValidDefaultValueStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/NamingConventions/ValidClassNameStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/NamingConventions/ValidFunctionNameStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/NamingConventions/ValidVariableNameStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/WhiteSpace/ObjectOperatorIndentStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/WhiteSpace/ScopeClosingBraceStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Docs/WhiteSpace/ScopeIndentStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/Classes/ClassDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/Commenting/ClassCommentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/Commenting/InlineCommentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/ControlSignatureSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/MultiLineConditionSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/Files/IncludingFileSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/Formatting/MultiLineAssignmentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/Functions/ValidDefaultValueSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidClassNameSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidVariableNameSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ScopeIndentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PEAR/ruleset.xml delete mode 100644 phpcs/CodeSniffer/Standards/PHPCS/ruleset.xml delete mode 100644 phpcs/CodeSniffer/Standards/PSR1/Docs/Classes/ClassDeclarationStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PSR1/Docs/Files/SideEffectsStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PSR1/Sniffs/Classes/ClassDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PSR1/Sniffs/Methods/CamelCapsMethodNameSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PSR1/ruleset.xml delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Docs/Classes/ClassDeclarationStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Docs/Classes/PropertyDeclarationStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Docs/ControlStructures/ControlStructureSpacingStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Docs/ControlStructures/ElseIfDeclarationStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Docs/ControlStructures/SwitchDeclarationStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Docs/Files/EndFileNewlineStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Docs/Methods/MethodDeclarationStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Docs/Namespaces/NamespaceDeclarationStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Docs/Namespaces/UseDeclarationStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Sniffs/Classes/PropertyDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/ControlStructureSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/ElseIfDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Sniffs/Files/ClosingTagSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Sniffs/Files/EndFileNewlineSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Sniffs/Methods/FunctionCallSignatureSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Sniffs/Methods/FunctionClosingBraceSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Sniffs/Methods/MethodDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Sniffs/Namespaces/NamespaceDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/Sniffs/Namespaces/UseDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/PSR2/ruleset.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/Arrays/ArrayBracketSpacingStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/Arrays/ArrayDeclarationStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/Classes/LowercaseClassKeywordsStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/Classes/SelfMemberReferenceStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/Commenting/DocCommentAlignmentStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/Commenting/FunctionCommentThrowTagStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/ControlStructures/ForEachLoopDeclarationStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/ControlStructures/ForLoopDeclarationStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/ControlStructures/LowercaseDeclarationStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/Functions/FunctionDuplicateArgumentStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/Functions/LowercaseFunctionKeywordsStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/Scope/StaticThisUsageStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/Strings/EchoedStringsStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/CastSpacingStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/FunctionOpeningBraceStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/LanguageConstructSpacingStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/ObjectOperatorSpacingStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/ScopeKeywordSpacingStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/SemicolonSpacingStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Arrays/ArrayBracketSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ClassDefinitionClosingBraceSpaceSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ClassDefinitionOpeningBraceSpaceSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ColonSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ColourDefinitionSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/DisallowMultipleStyleDefinitionsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/DuplicateClassDefinitionSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/DuplicateStyleDefinitionSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/EmptyClassDefinitionSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/EmptyStyleDefinitionSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ForbiddenStylesSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/IndentationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/LowercaseStyleDefinitionSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/MissingColonSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/NamedColoursSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/OpacitySniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/SemicolonSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ShorthandSizeSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/ClassDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/ClassFileNameSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/DuplicatePropertySniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/LowercaseClassKeywordsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/SelfMemberReferenceSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/BlockCommentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/ClassCommentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/ClosingDeclarationCommentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/EmptyCatchCommentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FunctionCommentThrowTagSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/InlineCommentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/LongConditionClosingCommentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/PostStatementCommentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ControlSignatureSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ElseIfDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ForEachLoopDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ForLoopDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/InlineIfDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/LowercaseDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Debug/JSLintSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Files/FileExtensionSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDuplicateArgumentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/GlobalFunctionSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/LowercaseFunctionKeywordsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidFunctionNameSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Objects/DisallowObjectStringIndexSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Objects/ObjectInstantiationSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Objects/ObjectMemberCommaSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Operators/ComparisonOperatorUsageSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Operators/IncrementDecrementUsageSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Operators/ValidLogicalOperatorsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/CommentedOutCodeSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowBooleanStatementSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowComparisonAssignmentSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowInlineIfSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowMultipleAssignmentsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowObEndFlushSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowSizeFunctionsInLoopsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DiscouragedFunctionsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/EmbeddedPhpSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/EvalSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/ForbiddenFunctionsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/GlobalKeywordSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/HeredocSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/InnerFunctionsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/LowercasePHPFunctionsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/NonExecutableCodeSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Scope/MemberVarScopeSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Scope/MethodScopeSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Scope/StaticThisUsageSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Strings/ConcatenationSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Strings/DoubleQuoteUsageSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/Strings/EchoedStringsSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/CastSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/FunctionClosingBraceSpaceSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/FunctionOpeningBraceSpaceSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/LanguageConstructSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/LogicalOperatorSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ObjectOperatorSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/PropertyLabelSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/SemicolonSpacingSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Squiz/ruleset.xml delete mode 100644 phpcs/CodeSniffer/Standards/Zend/Docs/Debug/CodeAnalyzerStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Zend/Docs/Files/ClosingTagStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Zend/Docs/NamingConventions/ValidVariableNameStandard.xml delete mode 100644 phpcs/CodeSniffer/Standards/Zend/Sniffs/Debug/CodeAnalyzerSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Zend/Sniffs/Files/ClosingTagSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Zend/Sniffs/NamingConventions/ValidVariableNameSniff.php delete mode 100644 phpcs/CodeSniffer/Standards/Zend/ruleset.xml delete mode 100644 phpcs/CodeSniffer/Tokenizers/CSS.php delete mode 100644 phpcs/CodeSniffer/Tokenizers/Comment.php delete mode 100644 phpcs/CodeSniffer/Tokenizers/JS.php delete mode 100644 phpcs/CodeSniffer/Tokenizers/PHP.php delete mode 100644 phpcs/CodeSniffer/Tokens.php delete mode 100644 phpcs/README.md delete mode 100644 phpcs/composer.json delete mode 100644 phpcs/licence.txt delete mode 100644 phpcs/php5-testingConfig.ini delete mode 100644 phpcs/php7-testingConfig.ini delete mode 100644 phpcs/phpcs.xml.dist delete mode 100644 phpcs/phpunit.xml.dist delete mode 100644 phpcs/scripts/build-phar.php delete mode 100755 phpcs/scripts/phpcbf delete mode 100644 phpcs/scripts/phpcbf.bat delete mode 100755 phpcs/scripts/phpcs delete mode 100755 phpcs/scripts/phpcs-svn-pre-commit delete mode 100755 phpcs/scripts/phpcs.bat delete mode 100644 wpcs/.gitignore delete mode 100644 wpcs/.travis.yml delete mode 100644 wpcs/CHANGELOG.md delete mode 100644 wpcs/CONTRIBUTING.md delete mode 100644 wpcs/LICENSE delete mode 100644 wpcs/README.md delete mode 100644 wpcs/WordPress-Core/ruleset.xml delete mode 100644 wpcs/WordPress-Docs/ruleset.xml delete mode 100644 wpcs/WordPress-Extra/ruleset.xml delete mode 100644 wpcs/WordPress-VIP/ruleset.xml delete mode 100644 wpcs/WordPress/AbstractArrayAssignmentRestrictionsSniff.php delete mode 100644 wpcs/WordPress/AbstractClassRestrictionsSniff.php delete mode 100644 wpcs/WordPress/AbstractFunctionParameterSniff.php delete mode 100644 wpcs/WordPress/AbstractFunctionRestrictionsSniff.php delete mode 100644 wpcs/WordPress/AbstractVariableRestrictionsSniff.php delete mode 100644 wpcs/WordPress/Sniff.php delete mode 100644 wpcs/WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php delete mode 100644 wpcs/WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php delete mode 100644 wpcs/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php delete mode 100644 wpcs/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php delete mode 100644 wpcs/WordPress/Sniffs/CSRF/NonceVerificationSniff.php delete mode 100644 wpcs/WordPress/Sniffs/DB/RestrictedClassesSniff.php delete mode 100644 wpcs/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php delete mode 100644 wpcs/WordPress/Sniffs/Files/FileNameSniff.php delete mode 100644 wpcs/WordPress/Sniffs/Functions/DontExtractSniff.php delete mode 100644 wpcs/WordPress/Sniffs/Functions/FunctionRestrictionsSniff.php delete mode 100644 wpcs/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php delete mode 100644 wpcs/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php delete mode 100644 wpcs/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php delete mode 100644 wpcs/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php delete mode 100644 wpcs/WordPress/Sniffs/PHP/DiscouragedFunctionsSniff.php delete mode 100644 wpcs/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php delete mode 100644 wpcs/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php delete mode 100644 wpcs/WordPress/Sniffs/PHP/StrictComparisonsSniff.php delete mode 100644 wpcs/WordPress/Sniffs/PHP/StrictInArraySniff.php delete mode 100644 wpcs/WordPress/Sniffs/PHP/YodaConditionsSniff.php delete mode 100644 wpcs/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php delete mode 100644 wpcs/WordPress/Sniffs/VIP/CronIntervalSniff.php delete mode 100644 wpcs/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php delete mode 100644 wpcs/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php delete mode 100644 wpcs/WordPress/Sniffs/VIP/OrderByRandSniff.php delete mode 100644 wpcs/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php delete mode 100644 wpcs/WordPress/Sniffs/VIP/PostsPerPageSniff.php delete mode 100644 wpcs/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php delete mode 100644 wpcs/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php delete mode 100644 wpcs/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php delete mode 100644 wpcs/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php delete mode 100644 wpcs/WordPress/Sniffs/VIP/SlowDBQuerySniff.php delete mode 100644 wpcs/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php delete mode 100644 wpcs/WordPress/Sniffs/VIP/TimezoneChangeSniff.php delete mode 100644 wpcs/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php delete mode 100644 wpcs/WordPress/Sniffs/Variables/GlobalVariablesSniff.php delete mode 100644 wpcs/WordPress/Sniffs/Variables/VariableRestrictionsSniff.php delete mode 100644 wpcs/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php delete mode 100644 wpcs/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php delete mode 100644 wpcs/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php delete mode 100644 wpcs/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php delete mode 100644 wpcs/WordPress/Sniffs/WP/I18nSniff.php delete mode 100644 wpcs/WordPress/Sniffs/WP/PreparedSQLSniff.php delete mode 100755 wpcs/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php delete mode 100644 wpcs/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php delete mode 100644 wpcs/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php delete mode 100644 wpcs/WordPress/Sniffs/XSS/EscapeOutputSniff.php delete mode 100644 wpcs/WordPress/Tests/Arrays/ArrayAssignmentRestrictionsUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/Arrays/ArrayAssignmentRestrictionsUnitTest.php delete mode 100644 wpcs/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.inc.fixed delete mode 100644 wpcs/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php delete mode 100644 wpcs/WordPress/Tests/Arrays/ArrayDeclarationUnitTest.txt delete mode 100644 wpcs/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.inc.fixed delete mode 100644 wpcs/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.php delete mode 100644 wpcs/WordPress/Tests/CSRF/NonceVerificationUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/CSRF/NonceVerificationUnitTest.php delete mode 100644 wpcs/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc delete mode 100644 wpcs/WordPress/Tests/DB/RestrictedClassesUnitTest.2.inc delete mode 100644 wpcs/WordPress/Tests/DB/RestrictedClassesUnitTest.3.inc delete mode 100644 wpcs/WordPress/Tests/DB/RestrictedClassesUnitTest.php delete mode 100644 wpcs/WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTest.php delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ClassMyClass.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/NonStrictClassNames/ClassNonStrictClass.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/NonStrictClassNames/non-strict-class.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/NonStrictClassNames/unrelated-filename.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/SomeFile.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/FrontPage.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/application_flash.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/archive-post_type.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/author-nice_name.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/embed-post_type-post_format.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/embed-post_type.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/front-page.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/front_page.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/single-post-type.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/single-post_type-slug.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/single-post_type.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/taxonomy-my_taxonomy-term.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/taxonomy-my_taxonomy.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/taxonomy-post_format-post-format-link.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/taxonomy-post_format.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/text.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/ThemeExceptions/text_plain.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/class-different-class.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/class-my-class.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/class.wp-dependencies.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/class.wp-scripts.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/class.wp-styles.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/my-class.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/single-my_post_type.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/some-File.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/some_file.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/taxonomy-post_format-post-format-audio.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/wp-includes/author-template.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/wp-includes/bookmark-template.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/wp-includes/class-walker-page.inc delete mode 100644 wpcs/WordPress/Tests/Files/FileNameUnitTests/wp-includes/general.inc delete mode 100644 wpcs/WordPress/Tests/Functions/DontExtractUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/Functions/DontExtractUnitTest.php delete mode 100644 wpcs/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php delete mode 100644 wpcs/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.1.inc delete mode 100644 wpcs/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.2.inc delete mode 100644 wpcs/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php delete mode 100644 wpcs/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php delete mode 100644 wpcs/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php delete mode 100644 wpcs/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php delete mode 100644 wpcs/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php delete mode 100644 wpcs/WordPress/Tests/PHP/StrictComparisonsUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/PHP/StrictComparisonsUnitTest.php delete mode 100644 wpcs/WordPress/Tests/PHP/StrictInArrayUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/PHP/StrictInArrayUnitTest.php delete mode 100644 wpcs/WordPress/Tests/PHP/YodaConditionsUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/PHP/YodaConditionsUnitTest.php delete mode 100644 wpcs/WordPress/Tests/VIP/AdminBarRemovalUnitTest.css delete mode 100644 wpcs/WordPress/Tests/VIP/AdminBarRemovalUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php delete mode 100644 wpcs/WordPress/Tests/VIP/CronIntervalUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/VIP/CronIntervalUnitTest.php delete mode 100644 wpcs/WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.php delete mode 100644 wpcs/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php delete mode 100644 wpcs/WordPress/Tests/VIP/OrderByRandUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/VIP/OrderByRandUnitTest.php delete mode 100644 wpcs/WordPress/Tests/VIP/PluginMenuSlugUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/VIP/PluginMenuSlugUnitTest.php delete mode 100644 wpcs/WordPress/Tests/VIP/PostsPerPageUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/VIP/PostsPerPageUnitTest.php delete mode 100644 wpcs/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php delete mode 100644 wpcs/WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/VIP/RestrictedVariablesUnitTest.php delete mode 100644 wpcs/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.php delete mode 100644 wpcs/WordPress/Tests/VIP/SessionVariableUsageUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/VIP/SessionVariableUsageUnitTest.php delete mode 100644 wpcs/WordPress/Tests/VIP/SlowDBQueryUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/VIP/SlowDBQueryUnitTest.php delete mode 100644 wpcs/WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.php delete mode 100644 wpcs/WordPress/Tests/VIP/TimezoneChangeUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/VIP/TimezoneChangeUnitTest.php delete mode 100644 wpcs/WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.php delete mode 100644 wpcs/WordPress/Tests/Variables/GlobalVariablesUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/Variables/GlobalVariablesUnitTest.php delete mode 100644 wpcs/WordPress/Tests/Variables/VariableRestrictionsUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/Variables/VariableRestrictionsUnitTest.php delete mode 100644 wpcs/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php delete mode 100644 wpcs/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php delete mode 100644 wpcs/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.php delete mode 100644 wpcs/WordPress/Tests/WP/EnqueuedResourcesUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php delete mode 100644 wpcs/WordPress/Tests/WP/I18nUnitTest.1.inc delete mode 100644 wpcs/WordPress/Tests/WP/I18nUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/WP/I18nUnitTest.inc.fixed delete mode 100644 wpcs/WordPress/Tests/WP/I18nUnitTest.php delete mode 100644 wpcs/WordPress/Tests/WP/PreparedSQLUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/WP/PreparedSQLUnitTest.php delete mode 100644 wpcs/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc.fixed delete mode 100644 wpcs/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php delete mode 100644 wpcs/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc.fixed delete mode 100644 wpcs/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php delete mode 100644 wpcs/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed delete mode 100644 wpcs/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php delete mode 100644 wpcs/WordPress/Tests/XSS/EscapeOutputUnitTest.inc delete mode 100644 wpcs/WordPress/Tests/XSS/EscapeOutputUnitTest.php delete mode 100644 wpcs/WordPress/ruleset.xml delete mode 100644 wpcs/bin/phpcs.xml delete mode 100755 wpcs/bin/pre-commit delete mode 100644 wpcs/composer.json delete mode 100644 wpcs/myconfig.ini delete mode 100644 wpcs/project.ruleset.xml.example diff --git a/.gitignore b/.gitignore index 3d72576..97c270a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .DS_Store -.idea \ No newline at end of file +.idea +/vendor +/composer.lock \ No newline at end of file diff --git a/README.md b/README.md index b6c5e73..48993f2 100644 --- a/README.md +++ b/README.md @@ -3,5 +3,6 @@ Installation instructions: 1. Clone repository on your drive +2. Run `composer install` 2. Run: `chmod +x phpcsx phpmd` 3. Configure your PhpStorm to use both scripts \ No newline at end of file diff --git a/bin/phpcsx-init b/bin/phpcsx-init new file mode 100644 index 0000000..d0227fa --- /dev/null +++ b/bin/phpcsx-init @@ -0,0 +1,22 @@ +#!/usr/bin/env php +runPHPCS(); +exit($exitCode); diff --git a/composer.json b/composer.json index a935cbc..488aa01 100644 --- a/composer.json +++ b/composer.json @@ -22,9 +22,14 @@ "php": ">=5.4.0", "ext-tokenizer": "*", "ext-xmlwriter": "*", - "ext-simplexml": "*" + "ext-simplexml": "*", + "wp-coding-standards/wpcs": "~0.14.0" + }, + "scripts": { + "post-install-cmd": "phpcsx-init", + "post-update-cmd": "phpcsx-init" }, "bin": [ - "phpcsx" + "bin/phpcsx-init" ] } \ No newline at end of file diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Commenting/DocCommentSniff.php b/justcoded/JustcodedPSR2/Sniffs/Commenting/DocCommentSniff.php similarity index 91% rename from phpcs/CodeSniffer/Standards/Generic/Sniffs/Commenting/DocCommentSniff.php rename to justcoded/JustcodedPSR2/Sniffs/Commenting/DocCommentSniff.php index 2b093af..6e5a7e7 100644 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Commenting/DocCommentSniff.php +++ b/justcoded/JustcodedPSR2/Sniffs/Commenting/DocCommentSniff.php @@ -2,28 +2,15 @@ /** * Ensures doc blocks follow basic formatting. * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer * @author Greg Sherwood - * @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600) + * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer */ -/** - * Ensures doc blocks follow basic formatting. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Commenting_DocCommentSniff implements PHP_CodeSniffer_Sniff +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; + +class JustcodedPSR2_Sniffs_Commenting_DocCommentSniff extends \PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff { /** @@ -50,15 +37,15 @@ public function register() /** - * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $commentStart = $stackPtr; @@ -119,8 +106,11 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) // Check for a comment description. if ($tokens[$short]['code'] !== T_DOC_COMMENT_STRING) { - $error = 'Missing short description in doc comment'; - $phpcsFile->addError($error, $stackPtr, 'MissingShort'); + // @inheritdoc hotfix + if (stripos($tokens[$short]['content'], '@inheritdoc') === false) { + $error = 'Missing short description in doc comment'; + $phpcsFile->addError($error, $stackPtr, 'MissingShort'); + } return; } diff --git a/justcoded/JustcodedPSR2/ruleset.xml b/justcoded/JustcodedPSR2/ruleset.xml index a887744..e305aaf 100644 --- a/justcoded/JustcodedPSR2/ruleset.xml +++ b/justcoded/JustcodedPSR2/ruleset.xml @@ -19,5 +19,12 @@ - + + + + + + + + diff --git a/justcoded/JustcodedWordpress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/justcoded/JustcodedWordpress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 575d1b8..a5128b7 100644 --- a/justcoded/JustcodedWordpress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/justcoded/JustcodedWordpress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -7,10 +7,6 @@ * @license https://opensource.org/licenses/MIT MIT */ -if ( ! class_exists( 'WordPress_Sniffs_NamingConventions_ValidVariableNameSniff', true ) ) { - throw new PHP_CodeSniffer_Exception( 'Class WordPress_Sniffs_NamingConventions_ValidVariableNameSniff not found' ); -} - /** * Checks the naming of variables and member variables. * @@ -23,19 +19,27 @@ * Last synced with base class July 2014 at commit ed257ca0e56ad86cd2a4d6fa38ce0b95141c824f. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php */ -class JustcodedWordpress_Sniffs_NamingConventions_ValidVariableNameSniff extends WordPress_Sniffs_NamingConventions_ValidVariableNameSniff +class JustcodedWordpress_Sniffs_NamingConventions_ValidVariableNameSniff extends \WordPress\Sniffs\NamingConventions\ValidVariableNameSniff { - /** - * Custom list of variables which can have mixed case. - * - * @since 0.10.0 - * - * @var string[] - */ - public $customPropertiesWhitelist = array( - 'SLUG', - 'TITLE', - ); + /** + * List of member variables that can have mixed case. + * + * @since 0.9.0 + * @since 0.11.0 Changed from public to protected. + * + * @var array + */ + protected $whitelisted_mixed_case_member_var_names = array( + 'ID' => true, + 'comment_ID' => true, + 'comment_post_ID' => true, + 'post_ID' => true, + 'comment_author_IP' => true, + 'cat_ID' => true, + + 'SLUG' => true, + 'TITLE' => true, + ); } diff --git a/justcoded/JustcodedWordpress/Sniffs/XSS/EscapeOutputSniff.php b/justcoded/JustcodedWordpress/Sniffs/XSS/EscapeOutputSniff.php index c0c7638..18b950c 100644 --- a/justcoded/JustcodedWordpress/Sniffs/XSS/EscapeOutputSniff.php +++ b/justcoded/JustcodedWordpress/Sniffs/XSS/EscapeOutputSniff.php @@ -3,16 +3,12 @@ * WordPress Coding Standard, Justcoded edition. */ -if ( ! class_exists( 'WordPress_Sniffs_XSS_EscapeOutputSniff', true ) ) { - throw new PHP_CodeSniffer_Exception( 'Class WordPress_Sniffs_XSS_EscapeOutputSniff not found' ); -} - /** * Verifies that all outputted strings are escaped. * * @link http://codex.wordpress.org/Data_Validation Data Validation on WordPress Codex */ -class JustcodedWordpress_Sniffs_XSS_EscapeOutputSniff extends WordPress_Sniffs_XSS_EscapeOutputSniff { +class JustcodedWordpress_Sniffs_XSS_EscapeOutputSniff extends \WordPress\Sniffs\XSS\EscapeOutputSniff { /** * Custom list of functions which escape values for output. diff --git a/phpcs/.gitattributes b/phpcs/.gitattributes deleted file mode 100644 index db3c554..0000000 --- a/phpcs/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ -/tests export-ignore -/CodeSniffer/Standards/Generic/Tests export-ignore -/CodeSniffer/Standards/MySource/Tests export-ignore -/CodeSniffer/Standards/PEAR/Tests export-ignore -/CodeSniffer/Standards/PSR1/Tests export-ignore -/CodeSniffer/Standards/PSR2/Tests export-ignore -/CodeSniffer/Standards/Squiz/Tests export-ignore -/CodeSniffer/Standards/Zend/Tests export-ignore -.travis.yml export-ignore -package.xml export-ignore -phpunit.xml.dist export-ignore -php5-testingConfig.ini export-ignore -php7-testingConfig.ini export-ignore diff --git a/phpcs/.gitignore b/phpcs/.gitignore deleted file mode 100644 index 9965895..0000000 --- a/phpcs/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/CodeSniffer.conf -/phpcs.xml -/phpunit.xml -.idea/* -/vendor/ -composer.lock diff --git a/phpcs/CONTRIBUTING.md b/phpcs/CONTRIBUTING.md deleted file mode 100644 index 22e3872..0000000 --- a/phpcs/CONTRIBUTING.md +++ /dev/null @@ -1,13 +0,0 @@ -Contributing -------------- - -Before you contribute code to PHP\_CodeSniffer, please make sure it conforms to the PHPCS coding standard and that the PHP\_CodeSniffer unit tests still pass. The easiest way to contribute is to work on a checkout of the repository, or your own fork, rather than an installed PEAR version. If you do this, you can run the following commands to check if everything is ready to submit: - - cd PHP_CodeSniffer - php scripts/phpcs - -Which should give you no output, indicating that there are no coding standard errors. And then: - - phpunit - -Which should give you no failures or errors. You can ignore any skipped tests as these are for external tools. \ No newline at end of file diff --git a/phpcs/CodeSniffer.conf.dist b/phpcs/CodeSniffer.conf.dist deleted file mode 100644 index 62dc395..0000000 --- a/phpcs/CodeSniffer.conf.dist +++ /dev/null @@ -1,9 +0,0 @@ - 'PSR2', - 'report_format' => 'summary', - 'show_warnings' => '0', - 'show_progress' => '1', - 'report_width' => '120', -) -?> diff --git a/phpcs/CodeSniffer.php b/phpcs/CodeSniffer.php deleted file mode 100644 index bcf27b9..0000000 --- a/phpcs/CodeSniffer.php +++ /dev/null @@ -1,2578 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -spl_autoload_register(array('PHP_CodeSniffer', 'autoload')); - -if (class_exists('PHP_CodeSniffer_Exception', true) === false) { - throw new Exception('Class PHP_CodeSniffer_Exception not found'); -} - -if (class_exists('PHP_CodeSniffer_File', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_File not found'); -} - -if (class_exists('PHP_CodeSniffer_Fixer', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Fixer not found'); -} - -if (class_exists('PHP_CodeSniffer_Tokens', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Tokens not found'); -} - -if (class_exists('PHP_CodeSniffer_CLI', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_CLI not found'); -} - -if (interface_exists('PHP_CodeSniffer_Sniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Interface PHP_CodeSniffer_Sniff not found'); -} - -/** - * PHP_CodeSniffer tokenizes PHP code and detects violations of a - * defined set of coding standards. - * - * Standards are specified by classes that implement the PHP_CodeSniffer_Sniff - * interface. A sniff registers what token types it wishes to listen for, then - * PHP_CodeSniffer encounters that token, the sniff is invoked and passed - * information about where the token was found in the stack, and the token stack - * itself. - * - * Sniff files and their containing class must be prefixed with Sniff, and - * have an extension of .php. - * - * Multiple PHP_CodeSniffer operations can be performed by re-calling the - * process function with different parameters. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer -{ - - /** - * The current version. - * - * @var string - */ - const VERSION = '2.8.1'; - - /** - * Package stability; either stable, beta or alpha. - * - * @var string - */ - const STABILITY = 'stable'; - - /** - * The file or directory that is currently being processed. - * - * @var string - */ - protected $file = ''; - - /** - * The directories that the processed rulesets are in. - * - * This is declared static because it is also used in the - * autoloader to look for sniffs outside the PHPCS install. - * This way, standards designed to be installed inside PHPCS can - * also be used from outside the PHPCS Standards directory. - * - * @var string - */ - protected static $rulesetDirs = array(); - - /** - * The CLI object controlling the run. - * - * @var PHP_CodeSniffer_CLI - */ - public $cli = null; - - /** - * The Reporting object controlling report generation. - * - * @var PHP_CodeSniffer_Reporting - */ - public $reporting = null; - - /** - * An array of sniff objects that are being used to check files. - * - * @var array(PHP_CodeSniffer_Sniff) - */ - protected $listeners = array(); - - /** - * An array of sniffs that are being used to check files. - * - * @var array(string) - */ - protected $sniffs = array(); - - /** - * A mapping of sniff codes to fully qualified class names. - * - * The key is the sniff code and the value - * is the fully qualified name of the sniff class. - * - * @var array - */ - public $sniffCodes = array(); - - /** - * The listeners array, indexed by token type. - * - * @var array - */ - private $_tokenListeners = array(); - - /** - * An array of rules from the ruleset.xml file. - * - * It may be empty, indicating that the ruleset does not override - * any of the default sniff settings. - * - * @var array - */ - protected $ruleset = array(); - - /** - * An array of patterns to use for skipping files. - * - * @var array - */ - protected $ignorePatterns = array(); - - /** - * An array of extensions for files we will check. - * - * @var array - */ - public $allowedFileExtensions = array(); - - /** - * An array of default extensions and associated tokenizers. - * - * If no extensions are set, these will be used as the defaults. - * If extensions are set, these will be used when the correct tokenizer - * can not be determined, such as when checking a passed filename instead - * of files in a directory. - * - * @var array - */ - public $defaultFileExtensions = array( - 'php' => 'PHP', - 'inc' => 'PHP', - 'js' => 'JS', - 'css' => 'CSS', - ); - - /** - * An array of variable types for param/var we will check. - * - * @var array(string) - */ - public static $allowedTypes = array( - 'array', - 'boolean', - 'float', - 'integer', - 'mixed', - 'object', - 'string', - 'resource', - 'callable', - ); - - - /** - * Constructs a PHP_CodeSniffer object. - * - * @param int $verbosity The verbosity level. - * 1: Print progress information. - * 2: Print tokenizer debug information. - * 3: Print sniff debug information. - * @param int $tabWidth The number of spaces each tab represents. - * If greater than zero, tabs will be replaced - * by spaces before testing each file. - * @param string $encoding The charset of the sniffed files. - * This is important for some reports that output - * with utf-8 encoding as you don't want it double - * encoding messages. - * @param bool $interactive If TRUE, will stop after each file with errors - * and wait for user input. - * - * @see process() - */ - public function __construct( - $verbosity=0, - $tabWidth=0, - $encoding='iso-8859-1', - $interactive=false - ) { - if ($verbosity !== null) { - $this->setVerbosity($verbosity); - } - - if ($tabWidth !== null) { - $this->setTabWidth($tabWidth); - } - - if ($encoding !== null) { - $this->setEncoding($encoding); - } - - if ($interactive !== null) { - $this->setInteractive($interactive); - } - - if (defined('PHPCS_DEFAULT_ERROR_SEV') === false) { - define('PHPCS_DEFAULT_ERROR_SEV', 5); - } - - if (defined('PHPCS_DEFAULT_WARN_SEV') === false) { - define('PHPCS_DEFAULT_WARN_SEV', 5); - } - - if (defined('PHP_CODESNIFFER_CBF') === false) { - define('PHP_CODESNIFFER_CBF', false); - } - - // Set default CLI object in case someone is running us - // without using the command line script. - $this->cli = new PHP_CodeSniffer_CLI(); - $this->cli->errorSeverity = PHPCS_DEFAULT_ERROR_SEV; - $this->cli->warningSeverity = PHPCS_DEFAULT_WARN_SEV; - $this->cli->dieOnUnknownArg = false; - - $this->reporting = new PHP_CodeSniffer_Reporting(); - - }//end __construct() - - - /** - * Autoload static method for loading classes and interfaces. - * - * @param string $className The name of the class or interface. - * - * @return void - */ - public static function autoload($className) - { - if (substr($className, 0, 4) === 'PHP_') { - $newClassName = substr($className, 4); - } else { - $newClassName = $className; - } - - $path = str_replace(array('_', '\\'), DIRECTORY_SEPARATOR, $newClassName).'.php'; - - if (is_file(dirname(__FILE__).DIRECTORY_SEPARATOR.$path) === true) { - // Check standard file locations based on class name. - include dirname(__FILE__).DIRECTORY_SEPARATOR.$path; - return; - } else { - // Check for included sniffs. - $installedPaths = PHP_CodeSniffer::getInstalledStandardPaths(); - foreach ($installedPaths as $installedPath) { - if (is_file($installedPath.DIRECTORY_SEPARATOR.$path) === true) { - include $installedPath.DIRECTORY_SEPARATOR.$path; - return; - } - } - - // Check standard file locations based on the loaded rulesets. - foreach (self::$rulesetDirs as $rulesetDir) { - if (is_file(dirname($rulesetDir).DIRECTORY_SEPARATOR.$path) === true) { - include_once dirname($rulesetDir).DIRECTORY_SEPARATOR.$path; - return; - } - } - }//end if - - // Everything else. - @include $path; - - }//end autoload() - - - /** - * Sets the verbosity level. - * - * @param int $verbosity The verbosity level. - * 1: Print progress information. - * 2: Print tokenizer debug information. - * 3: Print sniff debug information. - * - * @return void - */ - public function setVerbosity($verbosity) - { - if (defined('PHP_CODESNIFFER_VERBOSITY') === false) { - define('PHP_CODESNIFFER_VERBOSITY', $verbosity); - } - - }//end setVerbosity() - - - /** - * Sets the tab width. - * - * @param int $tabWidth The number of spaces each tab represents. - * If greater than zero, tabs will be replaced - * by spaces before testing each file. - * - * @return void - */ - public function setTabWidth($tabWidth) - { - if (defined('PHP_CODESNIFFER_TAB_WIDTH') === false) { - define('PHP_CODESNIFFER_TAB_WIDTH', $tabWidth); - } - - }//end setTabWidth() - - - /** - * Sets the encoding. - * - * @param string $encoding The charset of the sniffed files. - * This is important for some reports that output - * with utf-8 encoding as you don't want it double - * encoding messages. - * - * @return void - */ - public function setEncoding($encoding) - { - if (defined('PHP_CODESNIFFER_ENCODING') === false) { - define('PHP_CODESNIFFER_ENCODING', $encoding); - } - - }//end setEncoding() - - - /** - * Sets the interactive flag. - * - * @param bool $interactive If TRUE, will stop after each file with errors - * and wait for user input. - * - * @return void - */ - public function setInteractive($interactive) - { - if (defined('PHP_CODESNIFFER_INTERACTIVE') === false) { - define('PHP_CODESNIFFER_INTERACTIVE', $interactive); - } - - }//end setInteractive() - - - /** - * Sets an array of file extensions that we will allow checking of. - * - * If the extension is one of the defaults, a specific tokenizer - * will be used. Otherwise, the PHP tokenizer will be used for - * all extensions passed. - * - * @param array $extensions An array of file extensions. - * - * @return void - */ - public function setAllowedFileExtensions(array $extensions) - { - $newExtensions = array(); - foreach ($extensions as $ext) { - $slash = strpos($ext, '/'); - if ($slash !== false) { - // They specified the tokenizer too. - list($ext, $tokenizer) = explode('/', $ext); - $newExtensions[$ext] = strtoupper($tokenizer); - continue; - } - - if (isset($this->allowedFileExtensions[$ext]) === true) { - $newExtensions[$ext] = $this->allowedFileExtensions[$ext]; - } else if (isset($this->defaultFileExtensions[$ext]) === true) { - $newExtensions[$ext] = $this->defaultFileExtensions[$ext]; - } else { - $newExtensions[$ext] = 'PHP'; - } - } - - $this->allowedFileExtensions = $newExtensions; - - }//end setAllowedFileExtensions() - - - /** - * Sets an array of ignore patterns that we use to skip files and folders. - * - * Patterns are not case sensitive. - * - * @param array $patterns An array of ignore patterns. The pattern is the key - * and the value is either "absolute" or "relative", - * depending on how the pattern should be applied to a - * file path. - * - * @return void - */ - public function setIgnorePatterns(array $patterns) - { - $this->ignorePatterns = $patterns; - - }//end setIgnorePatterns() - - - /** - * Gets the array of ignore patterns. - * - * Optionally takes a listener to get ignore patterns specified - * for that sniff only. - * - * @param string $listener The listener to get patterns for. If NULL, all - * patterns are returned. - * - * @return array - */ - public function getIgnorePatterns($listener=null) - { - if ($listener === null) { - return $this->ignorePatterns; - } - - if (isset($this->ignorePatterns[$listener]) === true) { - return $this->ignorePatterns[$listener]; - } - - return array(); - - }//end getIgnorePatterns() - - - /** - * Sets the internal CLI object. - * - * @param object $cli The CLI object controlling the run. - * - * @return void - */ - public function setCli($cli) - { - $this->cli = $cli; - - }//end setCli() - - - /** - * Start a PHP_CodeSniffer run. - * - * @param string|array $files The files and directories to process. For - * directories, each sub directory will also - * be traversed for source files. - * @param string|array $standards The set of code sniffs we are testing - * against. - * @param array $restrictions The sniff codes to restrict the - * violations to. - * @param boolean $local If true, don't recurse into directories. - * - * @return void - */ - public function process($files, $standards, array $restrictions=array(), $local=false) - { - $files = (array) $files; - $this->initStandard($standards, $restrictions); - $this->processFiles($files, $local); - - }//end process() - - - /** - * Initialise the standard that the run will use. - * - * @param string|array $standards The set of code sniffs we are testing - * against. - * @param array $restrictions The sniff codes to restrict the testing to. - * @param array $exclusions The sniff codes to exclude from testing. - * - * @return void - */ - public function initStandard($standards, array $restrictions=array(), array $exclusions=array()) - { - $standards = (array) $standards; - - // Reset the members. - $this->listeners = array(); - $this->sniffs = array(); - $this->ruleset = array(); - $this->_tokenListeners = array(); - self::$rulesetDirs = array(); - - // Ensure this option is enabled or else line endings will not always - // be detected properly for files created on a Mac with the /r line ending. - ini_set('auto_detect_line_endings', true); - - if (defined('PHP_CODESNIFFER_IN_TESTS') === true && empty($restrictions) === false) { - // Should be one standard and one sniff being tested at a time. - $installed = $this->getInstalledStandardPath($standards[0]); - if ($installed !== null) { - $standard = $installed; - } else { - $standard = self::realpath($standards[0]); - if (is_dir($standard) === true - && is_file(self::realpath($standard.DIRECTORY_SEPARATOR.'ruleset.xml')) === true - ) { - $standard = self::realpath($standard.DIRECTORY_SEPARATOR.'ruleset.xml'); - } - } - - $sniffs = $this->_expandRulesetReference($restrictions[0], dirname($standard)); - } else { - $sniffs = array(); - foreach ($standards as $standard) { - $installed = $this->getInstalledStandardPath($standard); - if ($installed !== null) { - $standard = $installed; - } else { - $standard = self::realpath($standard); - if (is_dir($standard) === true - && is_file(self::realpath($standard.DIRECTORY_SEPARATOR.'ruleset.xml')) === true - ) { - $standard = self::realpath($standard.DIRECTORY_SEPARATOR.'ruleset.xml'); - } - } - - if (PHP_CODESNIFFER_VERBOSITY === 1) { - $ruleset = simplexml_load_string(file_get_contents($standard)); - if ($ruleset !== false) { - $standardName = (string) $ruleset['name']; - } - - echo "Registering sniffs in the $standardName standard... "; - if (count($standards) > 1 || PHP_CODESNIFFER_VERBOSITY > 2) { - echo PHP_EOL; - } - } - - $sniffs = array_merge($sniffs, $this->processRuleset($standard)); - }//end foreach - }//end if - - $sniffRestrictions = array(); - foreach ($restrictions as $sniffCode) { - $parts = explode('.', strtolower($sniffCode)); - $sniffRestrictions[] = $parts[0].'_sniffs_'.$parts[1].'_'.$parts[2].'sniff'; - } - - $sniffExclusions = array(); - foreach ($exclusions as $sniffCode) { - $parts = explode('.', strtolower($sniffCode)); - $sniffExclusions[] = $parts[0].'_sniffs_'.$parts[1].'_'.$parts[2].'sniff'; - } - - $this->registerSniffs($sniffs, $sniffRestrictions, $sniffExclusions); - $this->populateTokenListeners(); - - if (PHP_CODESNIFFER_VERBOSITY === 1) { - $numSniffs = count($this->sniffs); - echo "DONE ($numSniffs sniffs registered)".PHP_EOL; - } - - }//end initStandard() - - - /** - * Processes the files/directories that PHP_CodeSniffer was constructed with. - * - * @param string|array $files The files and directories to process. For - * directories, each sub directory will also - * be traversed for source files. - * @param boolean $local If true, don't recurse into directories. - * - * @return void - * @throws PHP_CodeSniffer_Exception If files are invalid. - */ - public function processFiles($files, $local=false) - { - $files = (array) $files; - $cliValues = $this->cli->getCommandLineValues(); - $showProgress = $cliValues['showProgress']; - $useColors = $cliValues['colors']; - - if (PHP_CODESNIFFER_VERBOSITY > 0) { - echo 'Creating file list... '; - } - - if (empty($this->allowedFileExtensions) === true) { - $this->allowedFileExtensions = $this->defaultFileExtensions; - } - - $todo = $this->getFilesToProcess($files, $local); - $numFiles = count($todo); - - if (PHP_CODESNIFFER_VERBOSITY > 0) { - echo "DONE ($numFiles files in queue)".PHP_EOL; - } - - $numProcessed = 0; - $dots = 0; - $maxLength = strlen($numFiles); - $lastDir = ''; - foreach ($todo as $file) { - $this->file = $file; - $currDir = dirname($file); - if ($lastDir !== $currDir) { - if (PHP_CODESNIFFER_VERBOSITY > 0 || PHP_CODESNIFFER_CBF === true) { - echo 'Changing into directory '.$currDir.PHP_EOL; - } - - $lastDir = $currDir; - } - - $phpcsFile = $this->processFile($file, null); - $numProcessed++; - - if (PHP_CODESNIFFER_VERBOSITY > 0 - || PHP_CODESNIFFER_INTERACTIVE === true - || $showProgress === false - ) { - continue; - } - - // Show progress information. - if ($phpcsFile === null) { - echo 'S'; - } else { - $errors = $phpcsFile->getErrorCount(); - $warnings = $phpcsFile->getWarningCount(); - if ($errors > 0) { - if ($useColors === true) { - echo "\033[31m"; - } - - echo 'E'; - } else if ($warnings > 0) { - if ($useColors === true) { - echo "\033[33m"; - } - - echo 'W'; - } else { - echo '.'; - } - - if ($useColors === true) { - echo "\033[0m"; - } - }//end if - - $dots++; - if ($dots === 60) { - $padding = ($maxLength - strlen($numProcessed)); - echo str_repeat(' ', $padding); - $percent = round(($numProcessed / $numFiles) * 100); - echo " $numProcessed / $numFiles ($percent%)".PHP_EOL; - $dots = 0; - } - }//end foreach - - if (PHP_CODESNIFFER_VERBOSITY === 0 - && PHP_CODESNIFFER_INTERACTIVE === false - && $showProgress === true - ) { - echo PHP_EOL.PHP_EOL; - } - - }//end processFiles() - - - /** - * Processes a single ruleset and returns a list of the sniffs it represents. - * - * Rules founds within the ruleset are processed immediately, but sniff classes - * are not registered by this method. - * - * @param string $rulesetPath The path to a ruleset XML file. - * @param int $depth How many nested processing steps we are in. This - * is only used for debug output. - * - * @return array - * @throws PHP_CodeSniffer_Exception If the ruleset path is invalid. - */ - public function processRuleset($rulesetPath, $depth=0) - { - $rulesetPath = self::realpath($rulesetPath); - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "Processing ruleset $rulesetPath".PHP_EOL; - } - - $ruleset = simplexml_load_string(file_get_contents($rulesetPath)); - if ($ruleset === false) { - throw new PHP_CodeSniffer_Exception("Ruleset $rulesetPath is not valid"); - } - - $ownSniffs = array(); - $includedSniffs = array(); - $excludedSniffs = array(); - $cliValues = $this->cli->getCommandLineValues(); - - $rulesetDir = dirname($rulesetPath); - self::$rulesetDirs[] = $rulesetDir; - - if (is_dir($rulesetDir.DIRECTORY_SEPARATOR.'Sniffs') === true) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\tAdding sniff files from \"/.../".basename($rulesetDir)."/Sniffs/\" directory".PHP_EOL; - } - - $ownSniffs = $this->_expandSniffDirectory($rulesetDir.DIRECTORY_SEPARATOR.'Sniffs', $depth); - } - - // Process custom sniff config settings. - foreach ($ruleset->{'config'} as $config) { - if ($this->_shouldProcessElement($config) === false) { - continue; - } - - $this->setConfigData((string) $config['name'], (string) $config['value'], true); - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t=> set config value ".(string) $config['name'].': '.(string) $config['value'].PHP_EOL; - } - } - - foreach ($ruleset->rule as $rule) { - if (isset($rule['ref']) === false - || $this->_shouldProcessElement($rule) === false - ) { - continue; - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\tProcessing rule \"".$rule['ref'].'"'.PHP_EOL; - } - - $includedSniffs = array_merge( - $includedSniffs, - $this->_expandRulesetReference($rule['ref'], $rulesetDir, $depth) - ); - - if (isset($rule->exclude) === true) { - foreach ($rule->exclude as $exclude) { - if ($this->_shouldProcessElement($exclude) === false) { - continue; - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\tExcluding rule \"".$exclude['name'].'"'.PHP_EOL; - } - - // Check if a single code is being excluded, which is a shortcut - // for setting the severity of the message to 0. - $parts = explode('.', $exclude['name']); - if (count($parts) === 4) { - $this->ruleset[(string) $exclude['name']]['severity'] = 0; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\t=> severity set to 0".PHP_EOL; - } - } else { - $excludedSniffs = array_merge( - $excludedSniffs, - $this->_expandRulesetReference($exclude['name'], $rulesetDir, ($depth + 1)) - ); - } - }//end foreach - }//end if - - $this->_processRule($rule, $depth); - }//end foreach - - // Process custom command line arguments. - $cliArgs = array(); - foreach ($ruleset->{'arg'} as $arg) { - if ($this->_shouldProcessElement($arg) === false) { - continue; - } - - if (isset($arg['name']) === true) { - $argString = '--'.(string) $arg['name']; - if (isset($arg['value']) === true) { - $argString .= '='.(string) $arg['value']; - } - } else { - $argString = '-'.(string) $arg['value']; - } - - $cliArgs[] = $argString; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t=> set command line value $argString".PHP_EOL; - } - }//end foreach - - // Set custom php ini values as CLI args. - foreach ($ruleset->{'ini'} as $arg) { - if ($this->_shouldProcessElement($arg) === false) { - continue; - } - - if (isset($arg['name']) === false) { - continue; - } - - $name = (string) $arg['name']; - $argString = $name; - if (isset($arg['value']) === true) { - $value = (string) $arg['value']; - $argString .= "=$value"; - } else { - $value = 'true'; - } - - $cliArgs[] = '-d'; - $cliArgs[] = $argString; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t=> set PHP ini value $name to $value".PHP_EOL; - } - }//end foreach - - if (empty($cliValues['files']) === true && $cliValues['stdin'] === null) { - // Process hard-coded file paths. - foreach ($ruleset->{'file'} as $file) { - $file = (string) $file; - $cliArgs[] = $file; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t=> added \"$file\" to the file list".PHP_EOL; - } - } - } - - if (empty($cliArgs) === false) { - // Change the directory so all relative paths are worked - // out based on the location of the ruleset instead of - // the location of the user. - $inPhar = self::isPharFile($rulesetDir); - if ($inPhar === false) { - $currentDir = getcwd(); - chdir($rulesetDir); - } - - $this->cli->setCommandLineValues($cliArgs); - - if ($inPhar === false) { - chdir($currentDir); - } - } - - // Process custom ignore pattern rules. - foreach ($ruleset->{'exclude-pattern'} as $pattern) { - if ($this->_shouldProcessElement($pattern) === false) { - continue; - } - - if (isset($pattern['type']) === false) { - $pattern['type'] = 'absolute'; - } - - $this->ignorePatterns[(string) $pattern] = (string) $pattern['type']; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t=> added global ".(string) $pattern['type'].' ignore pattern: '.(string) $pattern.PHP_EOL; - } - } - - $includedSniffs = array_unique(array_merge($ownSniffs, $includedSniffs)); - $excludedSniffs = array_unique($excludedSniffs); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $included = count($includedSniffs); - $excluded = count($excludedSniffs); - echo str_repeat("\t", $depth); - echo "=> Ruleset processing complete; included $included sniffs and excluded $excluded".PHP_EOL; - } - - // Merge our own sniff list with our externally included - // sniff list, but filter out any excluded sniffs. - $files = array(); - foreach ($includedSniffs as $sniff) { - if (in_array($sniff, $excludedSniffs) === true) { - continue; - } else { - $files[] = self::realpath($sniff); - } - } - - return $files; - - }//end processRuleset() - - - /** - * Expands a directory into a list of sniff files within. - * - * @param string $directory The path to a directory. - * @param int $depth How many nested processing steps we are in. This - * is only used for debug output. - * - * @return array - */ - private function _expandSniffDirectory($directory, $depth=0) - { - $sniffs = array(); - - if (defined('RecursiveDirectoryIterator::FOLLOW_SYMLINKS') === true) { - $rdi = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::FOLLOW_SYMLINKS); - } else { - $rdi = new RecursiveDirectoryIterator($directory); - } - - $di = new RecursiveIteratorIterator($rdi, 0, RecursiveIteratorIterator::CATCH_GET_CHILD); - - $dirLen = strlen($directory); - - foreach ($di as $file) { - $filename = $file->getFilename(); - - // Skip hidden files. - if (substr($filename, 0, 1) === '.') { - continue; - } - - // We are only interested in PHP and sniff files. - $fileParts = explode('.', $filename); - if (array_pop($fileParts) !== 'php') { - continue; - } - - $basename = basename($filename, '.php'); - if (substr($basename, -5) !== 'Sniff') { - continue; - } - - $path = $file->getPathname(); - - // Skip files in hidden directories within the Sniffs directory of this - // standard. We use the offset with strpos() to allow hidden directories - // before, valid example: - // /home/foo/.composer/vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/... - if (strpos($path, DIRECTORY_SEPARATOR.'.', $dirLen) !== false) { - continue; - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\t=> $path".PHP_EOL; - } - - $sniffs[] = $path; - }//end foreach - - return $sniffs; - - }//end _expandSniffDirectory() - - - /** - * Expands a ruleset reference into a list of sniff files. - * - * @param string $ref The reference from the ruleset XML file. - * @param string $rulesetDir The directory of the ruleset XML file, used to - * evaluate relative paths. - * @param int $depth How many nested processing steps we are in. This - * is only used for debug output. - * - * @return array - * @throws PHP_CodeSniffer_Exception If the reference is invalid. - */ - private function _expandRulesetReference($ref, $rulesetDir, $depth=0) - { - // Ignore internal sniffs codes as they are used to only - // hide and change internal messages. - if (substr($ref, 0, 9) === 'Internal.') { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\t* ignoring internal sniff code *".PHP_EOL; - } - - return array(); - } - - // As sniffs can't begin with a full stop, assume references in - // this format are relative paths and attempt to convert them - // to absolute paths. If this fails, let the reference run through - // the normal checks and have it fail as normal. - if (substr($ref, 0, 1) === '.') { - $realpath = self::realpath($rulesetDir.'/'.$ref); - if ($realpath !== false) { - $ref = $realpath; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\t=> $ref".PHP_EOL; - } - } - } - - // As sniffs can't begin with a tilde, assume references in - // this format at relative to the user's home directory. - if (substr($ref, 0, 2) === '~/') { - $realpath = self::realpath($ref); - if ($realpath !== false) { - $ref = $realpath; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\t=> $ref".PHP_EOL; - } - } - } - - if (is_file($ref) === true) { - if (substr($ref, -9) === 'Sniff.php') { - // A single external sniff. - self::$rulesetDirs[] = dirname(dirname(dirname($ref))); - return array($ref); - } - } else { - // See if this is a whole standard being referenced. - $path = $this->getInstalledStandardPath($ref); - if (self::isPharFile($path) === true && strpos($path, 'ruleset.xml') === false) { - // If the ruleset exists inside the phar file, use it. - if (file_exists($path.DIRECTORY_SEPARATOR.'ruleset.xml') === true) { - $path = $path.DIRECTORY_SEPARATOR.'ruleset.xml'; - } else { - $path = null; - } - } - - if ($path !== null) { - $ref = $path; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\t=> $ref".PHP_EOL; - } - } else if (is_dir($ref) === false) { - // Work out the sniff path. - $sepPos = strpos($ref, DIRECTORY_SEPARATOR); - if ($sepPos !== false) { - $stdName = substr($ref, 0, $sepPos); - $path = substr($ref, $sepPos); - } else { - $parts = explode('.', $ref); - $stdName = $parts[0]; - if (count($parts) === 1) { - // A whole standard? - $path = ''; - } else if (count($parts) === 2) { - // A directory of sniffs? - $path = DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR.$parts[1]; - } else { - // A single sniff? - $path = DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR.$parts[1].DIRECTORY_SEPARATOR.$parts[2].'Sniff.php'; - } - } - - $newRef = false; - $stdPath = $this->getInstalledStandardPath($stdName); - if ($stdPath !== null && $path !== '') { - if (self::isPharFile($stdPath) === true - && strpos($stdPath, 'ruleset.xml') === false - ) { - // Phar files can only return the directory, - // since ruleset can be omitted if building one standard. - $newRef = self::realpath($stdPath.$path); - } else { - $newRef = self::realpath(dirname($stdPath).$path); - } - } - - if ($newRef === false) { - // The sniff is not locally installed, so check if it is being - // referenced as a remote sniff outside the install. We do this - // by looking through all directories where we have found ruleset - // files before, looking for ones for this particular standard, - // and seeing if it is in there. - foreach (self::$rulesetDirs as $dir) { - if (strtolower(basename($dir)) !== strtolower($stdName)) { - continue; - } - - $newRef = self::realpath($dir.$path); - - if ($newRef !== false) { - $ref = $newRef; - } - } - } else { - $ref = $newRef; - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\t=> $ref".PHP_EOL; - } - }//end if - }//end if - - if (is_dir($ref) === true) { - if (is_file($ref.DIRECTORY_SEPARATOR.'ruleset.xml') === true) { - // We are referencing an external coding standard. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\t* rule is referencing a standard using directory name; processing *".PHP_EOL; - } - - return $this->processRuleset($ref.DIRECTORY_SEPARATOR.'ruleset.xml', ($depth + 2)); - } else { - // We are referencing a whole directory of sniffs. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\t* rule is referencing a directory of sniffs *".PHP_EOL; - echo str_repeat("\t", $depth); - echo "\t\tAdding sniff files from directory".PHP_EOL; - } - - return $this->_expandSniffDirectory($ref, ($depth + 1)); - } - } else { - if (is_file($ref) === false) { - $error = "Referenced sniff \"$ref\" does not exist"; - throw new PHP_CodeSniffer_Exception($error); - } - - if (substr($ref, -9) === 'Sniff.php') { - // A single sniff. - return array($ref); - } else { - // Assume an external ruleset.xml file. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\t* rule is referencing a standard using ruleset path; processing *".PHP_EOL; - } - - return $this->processRuleset($ref, ($depth + 2)); - } - }//end if - - }//end _expandRulesetReference() - - - /** - * Processes a rule from a ruleset XML file, overriding built-in defaults. - * - * @param SimpleXMLElement $rule The rule object from a ruleset XML file. - * @param int $depth How many nested processing steps we are in. - * This is only used for debug output. - * - * @return void - */ - private function _processRule($rule, $depth=0) - { - $code = (string) $rule['ref']; - - // Custom severity. - if (isset($rule->severity) === true - && $this->_shouldProcessElement($rule->severity) === true - ) { - if (isset($this->ruleset[$code]) === false) { - $this->ruleset[$code] = array(); - } - - $this->ruleset[$code]['severity'] = (int) $rule->severity; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\t=> severity set to ".(int) $rule->severity.PHP_EOL; - } - } - - // Custom message type. - if (isset($rule->type) === true - && $this->_shouldProcessElement($rule->type) === true - ) { - if (isset($this->ruleset[$code]) === false) { - $this->ruleset[$code] = array(); - } - - $this->ruleset[$code]['type'] = (string) $rule->type; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\t=> message type set to ".(string) $rule->type.PHP_EOL; - } - } - - // Custom message. - if (isset($rule->message) === true - && $this->_shouldProcessElement($rule->message) === true - ) { - if (isset($this->ruleset[$code]) === false) { - $this->ruleset[$code] = array(); - } - - $this->ruleset[$code]['message'] = (string) $rule->message; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\t=> message set to ".(string) $rule->message.PHP_EOL; - } - } - - // Custom properties. - if (isset($rule->properties) === true - && $this->_shouldProcessElement($rule->properties) === true - ) { - foreach ($rule->properties->property as $prop) { - if ($this->_shouldProcessElement($prop) === false) { - continue; - } - - if (isset($this->ruleset[$code]) === false) { - $this->ruleset[$code] = array( - 'properties' => array(), - ); - } else if (isset($this->ruleset[$code]['properties']) === false) { - $this->ruleset[$code]['properties'] = array(); - } - - $name = (string) $prop['name']; - if (isset($prop['type']) === true - && (string) $prop['type'] === 'array' - ) { - $value = (string) $prop['value']; - $values = array(); - foreach (explode(',', $value) as $val) { - $v = ''; - - list($k,$v) = explode('=>', $val.'=>'); - if ($v !== '') { - $values[$k] = $v; - } else { - $values[] = $k; - } - } - - $this->ruleset[$code]['properties'][$name] = $values; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\t=> array property \"$name\" set to \"$value\"".PHP_EOL; - } - } else { - $this->ruleset[$code]['properties'][$name] = (string) $prop['value']; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\t=> property \"$name\" set to \"".(string) $prop['value'].'"'.PHP_EOL; - } - }//end if - }//end foreach - }//end if - - // Ignore patterns. - foreach ($rule->{'exclude-pattern'} as $pattern) { - if ($this->_shouldProcessElement($pattern) === false) { - continue; - } - - if (isset($this->ignorePatterns[$code]) === false) { - $this->ignorePatterns[$code] = array(); - } - - if (isset($pattern['type']) === false) { - $pattern['type'] = 'absolute'; - } - - $this->ignorePatterns[$code][(string) $pattern] = (string) $pattern['type']; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "\t\t=> added sniff-specific ".(string) $pattern['type'].' ignore pattern: '.(string) $pattern.PHP_EOL; - } - } - - }//end _processRule() - - - /** - * Determine if an element should be processed or ignored. - * - * @param SimpleXMLElement $element An object from a ruleset XML file. - * @param int $depth How many nested processing steps we are in. - * This is only used for debug output. - * - * @return bool - */ - private function _shouldProcessElement($element, $depth=0) - { - if (isset($element['phpcbf-only']) === false - && isset($element['phpcs-only']) === false - ) { - // No exceptions are being made. - return true; - } - - if (PHP_CODESNIFFER_CBF === true - && isset($element['phpcbf-only']) === true - && (string) $element['phpcbf-only'] === 'true' - ) { - return true; - } - - if (PHP_CODESNIFFER_CBF === false - && isset($element['phpcs-only']) === true - && (string) $element['phpcs-only'] === 'true' - ) { - return true; - } - - return false; - - }//end _shouldProcessElement() - - - /** - * Loads and stores sniffs objects used for sniffing files. - * - * @param array $files Paths to the sniff files to register. - * @param array $restrictions The sniff class names to restrict the allowed - * listeners to. - * @param array $exclusions The sniff class names to exclude from the - * listeners list. - * - * @return void - * @throws PHP_CodeSniffer_Exception If a sniff file path is invalid. - */ - public function registerSniffs($files, $restrictions, $exclusions) - { - $listeners = array(); - - foreach ($files as $file) { - // Work out where the position of /StandardName/Sniffs/... is - // so we can determine what the class will be called. - $sniffPos = strrpos($file, DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR); - if ($sniffPos === false) { - continue; - } - - $slashPos = strrpos(substr($file, 0, $sniffPos), DIRECTORY_SEPARATOR); - if ($slashPos === false) { - continue; - } - - $className = substr($file, ($slashPos + 1)); - - if (substr_count($className, DIRECTORY_SEPARATOR) !== 3) { - throw new PHP_CodeSniffer_Exception("Sniff file $className is not valid; sniff files must be located in a .../StandardName/Sniffs/CategoryName/ directory"); - } - - $className = substr($className, 0, -4); - $className = str_replace(DIRECTORY_SEPARATOR, '_', $className); - - // If they have specified a list of sniffs to restrict to, check - // to see if this sniff is allowed. - if (empty($restrictions) === false - && in_array(strtolower($className), $restrictions) === false - ) { - continue; - } - - // If they have specified a list of sniffs to exclude, check - // to see if this sniff is allowed. - if (empty($exclusions) === false - && in_array(strtolower($className), $exclusions) === true - ) { - continue; - } - - include_once $file; - - // Support the use of PHP namespaces. If the class name we included - // contains namespace separators instead of underscores, use this as the - // class name from now on. - $classNameNS = str_replace('_', '\\', $className); - if (class_exists($classNameNS, false) === true) { - $className = $classNameNS; - } - - // Skip abstract classes. - $reflection = new ReflectionClass($className); - if ($reflection->isAbstract() === true) { - continue; - } - - $listeners[$className] = $className; - - if (PHP_CODESNIFFER_VERBOSITY > 2) { - echo "Registered $className".PHP_EOL; - } - }//end foreach - - $this->sniffs = $listeners; - - }//end registerSniffs() - - - /** - * Populates the array of PHP_CodeSniffer_Sniff's for this file. - * - * @return void - * @throws PHP_CodeSniffer_Exception If sniff registration fails. - */ - public function populateTokenListeners() - { - // Construct a list of listeners indexed by token being listened for. - $this->_tokenListeners = array(); - - foreach ($this->sniffs as $listenerClass) { - // Work out the internal code for this sniff. Detect usage of namespace - // separators instead of underscores to support PHP namespaces. - if (strstr($listenerClass, '\\') === false) { - $parts = explode('_', $listenerClass); - } else { - $parts = explode('\\', $listenerClass); - } - - $code = $parts[0].'.'.$parts[2].'.'.$parts[3]; - $code = substr($code, 0, -5); - - $this->listeners[$listenerClass] = new $listenerClass(); - $this->sniffCodes[$code] = $listenerClass; - - // Set custom properties. - if (isset($this->ruleset[$code]['properties']) === true) { - foreach ($this->ruleset[$code]['properties'] as $name => $value) { - $this->setSniffProperty($listenerClass, $name, $value); - } - } - - $tokenizers = array(); - $vars = get_class_vars($listenerClass); - if (isset($vars['supportedTokenizers']) === true) { - foreach ($vars['supportedTokenizers'] as $tokenizer) { - $tokenizers[$tokenizer] = $tokenizer; - } - } else { - $tokenizers = array('PHP' => 'PHP'); - } - - $tokens = $this->listeners[$listenerClass]->register(); - if (is_array($tokens) === false) { - $msg = "Sniff $listenerClass register() method must return an array"; - throw new PHP_CodeSniffer_Exception($msg); - } - - $parts = explode('_', str_replace('\\', '_', $listenerClass)); - $listenerSource = $parts[0].'.'.$parts[2].'.'.substr($parts[3], 0, -5); - $ignorePatterns = array(); - $patterns = $this->getIgnorePatterns($listenerSource); - foreach ($patterns as $pattern => $type) { - // While there is support for a type of each pattern - // (absolute or relative) we don't actually support it here. - $replacements = array( - '\\,' => ',', - '*' => '.*', - ); - - $ignorePatterns[] = strtr($pattern, $replacements); - } - - foreach ($tokens as $token) { - if (isset($this->_tokenListeners[$token]) === false) { - $this->_tokenListeners[$token] = array(); - } - - if (isset($this->_tokenListeners[$token][$listenerClass]) === false) { - $this->_tokenListeners[$token][$listenerClass] = array( - 'class' => $listenerClass, - 'source' => $listenerSource, - 'tokenizers' => $tokenizers, - 'ignore' => $ignorePatterns, - ); - } - } - }//end foreach - - }//end populateTokenListeners() - - - /** - * Set a single property for a sniff. - * - * @param string $listenerClass The class name of the sniff. - * @param string $name The name of the property to change. - * @param string $value The new value of the property. - * - * @return void - */ - public function setSniffProperty($listenerClass, $name, $value) - { - // Setting a property for a sniff we are not using. - if (isset($this->listeners[$listenerClass]) === false) { - return; - } - - $name = trim($name); - if (is_string($value) === true) { - $value = trim($value); - } - - // Special case for booleans. - if ($value === 'true') { - $value = true; - } else if ($value === 'false') { - $value = false; - } - - $this->listeners[$listenerClass]->$name = $value; - - }//end setSniffProperty() - - - /** - * Get a list of files that will be processed. - * - * If passed directories, this method will find all files within them. - * The method will also perform file extension and ignore pattern filtering. - * - * @param string $paths A list of file or directory paths to process. - * @param boolean $local If true, only process 1 level of files in directories - * - * @return array - * @throws Exception If there was an error opening a directory. - * @see shouldProcessFile() - */ - public function getFilesToProcess($paths, $local=false) - { - $files = array(); - - foreach ($paths as $path) { - if (is_dir($path) === true || self::isPharFile($path) === true) { - if (self::isPharFile($path) === true) { - $path = 'phar://'.$path; - } - - if ($local === true) { - $di = new DirectoryIterator($path); - } else { - $di = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($path), - 0, - RecursiveIteratorIterator::CATCH_GET_CHILD - ); - } - - foreach ($di as $file) { - // Check if the file exists after all symlinks are resolved. - $filePath = self::realpath($file->getPathname()); - if ($filePath === false) { - continue; - } - - if (is_dir($filePath) === true) { - continue; - } - - if ($this->shouldProcessFile($file->getPathname(), $path) === false) { - continue; - } - - $files[] = $file->getPathname(); - }//end foreach - } else { - if ($this->shouldIgnoreFile($path, dirname($path)) === true) { - continue; - } - - $files[] = $path; - }//end if - }//end foreach - - return $files; - - }//end getFilesToProcess() - - - /** - * Checks filtering rules to see if a file should be checked. - * - * Checks both file extension filters and path ignore filters. - * - * @param string $path The path to the file being checked. - * @param string $basedir The directory to use for relative path checks. - * - * @return bool - */ - public function shouldProcessFile($path, $basedir) - { - // Check that the file's extension is one we are checking. - // We are strict about checking the extension and we don't - // let files through with no extension or that start with a dot. - $fileName = basename($path); - $fileParts = explode('.', $fileName); - if ($fileParts[0] === $fileName || $fileParts[0] === '') { - return false; - } - - // Checking multi-part file extensions, so need to create a - // complete extension list and make sure one is allowed. - $extensions = array(); - array_shift($fileParts); - foreach ($fileParts as $part) { - $extensions[implode('.', $fileParts)] = 1; - array_shift($fileParts); - } - - $matches = array_intersect_key($extensions, $this->allowedFileExtensions); - if (empty($matches) === true) { - return false; - } - - // If the file's path matches one of our ignore patterns, skip it. - if ($this->shouldIgnoreFile($path, $basedir) === true) { - return false; - } - - return true; - - }//end shouldProcessFile() - - - /** - * Checks filtering rules to see if a file should be ignored. - * - * @param string $path The path to the file being checked. - * @param string $basedir The directory to use for relative path checks. - * - * @return bool - */ - public function shouldIgnoreFile($path, $basedir) - { - $relativePath = $path; - if (strpos($path, $basedir) === 0) { - // The +1 cuts off the directory separator as well. - $relativePath = substr($path, (strlen($basedir) + 1)); - } - - foreach ($this->ignorePatterns as $pattern => $type) { - if (is_array($type) === true) { - // A sniff specific ignore pattern. - continue; - } - - // Maintains backwards compatibility in case the ignore pattern does - // not have a relative/absolute value. - if (is_int($pattern) === true) { - $pattern = $type; - $type = 'absolute'; - } - - $replacements = array( - '\\,' => ',', - '*' => '.*', - ); - - // We assume a / directory separator, as do the exclude rules - // most developers write, so we need a special case for any system - // that is different. - if (DIRECTORY_SEPARATOR === '\\') { - $replacements['/'] = '\\\\'; - } - - $pattern = strtr($pattern, $replacements); - - if ($type === 'relative') { - $testPath = $relativePath; - } else { - $testPath = $path; - } - - $pattern = '`'.$pattern.'`i'; - if (preg_match($pattern, $testPath) === 1) { - return true; - } - }//end foreach - - return false; - - }//end shouldIgnoreFile() - - - /** - * Run the code sniffs over a single given file. - * - * Processes the file and runs the PHP_CodeSniffer sniffs to verify that it - * conforms with the standard. Returns the processed file object, or NULL - * if no file was processed due to error. - * - * @param string $file The file to process. - * @param string $contents The contents to parse. If NULL, the content - * is taken from the file system. - * - * @return PHP_CodeSniffer_File - * @throws PHP_CodeSniffer_Exception If the file could not be processed. - * @see _processFile() - */ - public function processFile($file, $contents=null) - { - if ($contents === null && file_exists($file) === false) { - throw new PHP_CodeSniffer_Exception("Source file $file does not exist"); - } - - $filePath = self::realpath($file); - if ($filePath === false) { - $filePath = $file; - } - - // Before we go and spend time tokenizing this file, just check - // to see if there is a tag up top to indicate that the whole - // file should be ignored. It must be on one of the first two lines. - $firstContent = $contents; - if ($contents === null && is_readable($filePath) === true) { - $handle = fopen($filePath, 'r'); - stream_set_blocking($handle, true); - if ($handle !== false) { - $firstContent = fgets($handle); - $firstContent .= fgets($handle); - fclose($handle); - - if (strpos($firstContent, '@codingStandardsIgnoreFile') !== false) { - // We are ignoring the whole file. - if (PHP_CODESNIFFER_VERBOSITY > 0) { - echo 'Ignoring '.basename($filePath).PHP_EOL; - } - - return null; - } - } - }//end if - - try { - $phpcsFile = $this->_processFile($file, $contents); - } catch (Exception $e) { - $trace = $e->getTrace(); - - $filename = $trace[0]['args'][0]; - if (is_object($filename) === true - && get_class($filename) === 'PHP_CodeSniffer_File' - ) { - $filename = $filename->getFilename(); - } else if (is_numeric($filename) === true) { - // See if we can find the PHP_CodeSniffer_File object. - foreach ($trace as $data) { - if (isset($data['args'][0]) === true - && ($data['args'][0] instanceof PHP_CodeSniffer_File) === true - ) { - $filename = $data['args'][0]->getFilename(); - } - } - } else if (is_string($filename) === false) { - $filename = (string) $filename; - } - - $errorMessage = '"'.$e->getMessage().'" at '.$e->getFile().':'.$e->getLine(); - $error = "An error occurred during processing; checking has been aborted. The error message was: $errorMessage"; - - $phpcsFile = new PHP_CodeSniffer_File( - $filename, - $this->_tokenListeners, - $this->ruleset, - $this - ); - - $phpcsFile->addError($error, null); - }//end try - - $cliValues = $this->cli->getCommandLineValues(); - - if (PHP_CODESNIFFER_INTERACTIVE === false) { - // Cache the report data for this file so we can unset it to save memory. - $this->reporting->cacheFileReport($phpcsFile, $cliValues); - $phpcsFile->cleanUp(); - return $phpcsFile; - } - - /* - Running interactively. - Print the error report for the current file and then wait for user input. - */ - - // Get current violations and then clear the list to make sure - // we only print violations for a single file each time. - $numErrors = null; - while ($numErrors !== 0) { - $numErrors = ($phpcsFile->getErrorCount() + $phpcsFile->getWarningCount()); - if ($numErrors === 0) { - continue; - } - - $reportClass = $this->reporting->factory('full'); - $reportData = $this->reporting->prepareFileReport($phpcsFile); - $reportClass->generateFileReport($reportData, $phpcsFile, $cliValues['showSources'], $cliValues['reportWidth']); - - echo ' to recheck, [s] to skip or [q] to quit : '; - $input = fgets(STDIN); - $input = trim($input); - - switch ($input) { - case 's': - break(2); - case 'q': - exit(0); - break; - default: - // Repopulate the sniffs because some of them save their state - // and only clear it when the file changes, but we are rechecking - // the same file. - $this->populateTokenListeners(); - $phpcsFile = $this->_processFile($file, $contents); - break; - } - }//end while - - return $phpcsFile; - - }//end processFile() - - - /** - * Process the sniffs for a single file. - * - * Does raw processing only. No interactive support or error checking. - * - * @param string $file The file to process. - * @param string $contents The contents to parse. If NULL, the content - * is taken from the file system. - * - * @return PHP_CodeSniffer_File - * @see processFile() - */ - private function _processFile($file, $contents) - { - $stdin = false; - $cliValues = $this->cli->getCommandLineValues(); - if (empty($cliValues['files']) === true) { - $stdin = true; - } - - if (PHP_CODESNIFFER_VERBOSITY > 0 || (PHP_CODESNIFFER_CBF === true && $stdin === false)) { - $startTime = microtime(true); - echo 'Processing '.basename($file).' '; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo PHP_EOL; - } - } - - $phpcsFile = new PHP_CodeSniffer_File( - $file, - $this->_tokenListeners, - $this->ruleset, - $this - ); - - $phpcsFile->start($contents); - - if (PHP_CODESNIFFER_VERBOSITY > 0 || (PHP_CODESNIFFER_CBF === true && $stdin === false)) { - $timeTaken = ((microtime(true) - $startTime) * 1000); - if ($timeTaken < 1000) { - $timeTaken = round($timeTaken); - echo "DONE in {$timeTaken}ms"; - } else { - $timeTaken = round(($timeTaken / 1000), 2); - echo "DONE in $timeTaken secs"; - } - - if (PHP_CODESNIFFER_CBF === true) { - $errors = $phpcsFile->getFixableCount(); - echo " ($errors fixable violations)".PHP_EOL; - } else { - $errors = $phpcsFile->getErrorCount(); - $warnings = $phpcsFile->getWarningCount(); - echo " ($errors errors, $warnings warnings)".PHP_EOL; - } - } - - return $phpcsFile; - - }//end _processFile() - - - /** - * Generates documentation for a coding standard. - * - * @param string $standard The standard to generate docs for - * @param array $sniffs A list of sniffs to limit the docs to. - * @param string $generator The name of the generator class to use. - * - * @return void - */ - public function generateDocs($standard, array $sniffs=array(), $generator='Text') - { - if (class_exists('PHP_CodeSniffer_DocGenerators_'.$generator, true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_DocGenerators_'.$generator.' not found'); - } - - $class = "PHP_CodeSniffer_DocGenerators_$generator"; - $generator = new $class($standard, $sniffs); - - $generator->generate(); - - }//end generateDocs() - - - /** - * Gets the array of PHP_CodeSniffer_Sniff's. - * - * @return PHP_CodeSniffer_Sniff[] - */ - public function getSniffs() - { - return $this->listeners; - - }//end getSniffs() - - - /** - * Gets the array of PHP_CodeSniffer_Sniff's indexed by token type. - * - * @return array - */ - public function getTokenSniffs() - { - return $this->_tokenListeners; - - }//end getTokenSniffs() - - - /** - * Returns true if the specified string is in the camel caps format. - * - * @param string $string The string the verify. - * @param boolean $classFormat If true, check to see if the string is in the - * class format. Class format strings must start - * with a capital letter and contain no - * underscores. - * @param boolean $public If true, the first character in the string - * must be an a-z character. If false, the - * character must be an underscore. This - * argument is only applicable if $classFormat - * is false. - * @param boolean $strict If true, the string must not have two capital - * letters next to each other. If false, a - * relaxed camel caps policy is used to allow - * for acronyms. - * - * @return boolean - */ - public static function isCamelCaps( - $string, - $classFormat=false, - $public=true, - $strict=true - ) { - // Check the first character first. - if ($classFormat === false) { - $legalFirstChar = ''; - if ($public === false) { - $legalFirstChar = '[_]'; - } - - if ($strict === false) { - // Can either start with a lowercase letter, or multiple uppercase - // in a row, representing an acronym. - $legalFirstChar .= '([A-Z]{2,}|[a-z])'; - } else { - $legalFirstChar .= '[a-z]'; - } - } else { - $legalFirstChar = '[A-Z]'; - } - - if (preg_match("/^$legalFirstChar/", $string) === 0) { - return false; - } - - // Check that the name only contains legal characters. - $legalChars = 'a-zA-Z0-9'; - if (preg_match("|[^$legalChars]|", substr($string, 1)) > 0) { - return false; - } - - if ($strict === true) { - // Check that there are not two capital letters next to each other. - $length = strlen($string); - $lastCharWasCaps = $classFormat; - - for ($i = 1; $i < $length; $i++) { - $ascii = ord($string{$i}); - if ($ascii >= 48 && $ascii <= 57) { - // The character is a number, so it cant be a capital. - $isCaps = false; - } else { - if (strtoupper($string{$i}) === $string{$i}) { - $isCaps = true; - } else { - $isCaps = false; - } - } - - if ($isCaps === true && $lastCharWasCaps === true) { - return false; - } - - $lastCharWasCaps = $isCaps; - } - }//end if - - return true; - - }//end isCamelCaps() - - - /** - * Returns true if the specified string is in the underscore caps format. - * - * @param string $string The string to verify. - * - * @return boolean - */ - public static function isUnderscoreName($string) - { - // If there are space in the name, it can't be valid. - if (strpos($string, ' ') !== false) { - return false; - } - - $validName = true; - $nameBits = explode('_', $string); - - if (preg_match('|^[A-Z]|', $string) === 0) { - // Name does not begin with a capital letter. - $validName = false; - } else { - foreach ($nameBits as $bit) { - if ($bit === '') { - continue; - } - - if ($bit{0} !== strtoupper($bit{0})) { - $validName = false; - break; - } - } - } - - return $validName; - - }//end isUnderscoreName() - - - /** - * Returns a valid variable type for param/var tag. - * - * If type is not one of the standard type, it must be a custom type. - * Returns the correct type name suggestion if type name is invalid. - * - * @param string $varType The variable type to process. - * - * @return string - */ - public static function suggestType($varType) - { - if ($varType === '') { - return ''; - } - - if (in_array($varType, self::$allowedTypes) === true) { - return $varType; - } else { - $lowerVarType = strtolower($varType); - switch ($lowerVarType) { - case 'bool': - case 'boolean': - return 'boolean'; - case 'double': - case 'real': - case 'float': - return 'float'; - case 'int': - case 'integer': - return 'integer'; - case 'array()': - case 'array': - return 'array'; - }//end switch - - if (strpos($lowerVarType, 'array(') !== false) { - // Valid array declaration: - // array, array(type), array(type1 => type2). - $matches = array(); - $pattern = '/^array\(\s*([^\s^=^>]*)(\s*=>\s*(.*))?\s*\)/i'; - if (preg_match($pattern, $varType, $matches) !== 0) { - $type1 = ''; - if (isset($matches[1]) === true) { - $type1 = $matches[1]; - } - - $type2 = ''; - if (isset($matches[3]) === true) { - $type2 = $matches[3]; - } - - $type1 = self::suggestType($type1); - $type2 = self::suggestType($type2); - if ($type2 !== '') { - $type2 = ' => '.$type2; - } - - return "array($type1$type2)"; - } else { - return 'array'; - }//end if - } else if (in_array($lowerVarType, self::$allowedTypes) === true) { - // A valid type, but not lower cased. - return $lowerVarType; - } else { - // Must be a custom type name. - return $varType; - }//end if - }//end if - - }//end suggestType() - - - /** - * Prepares token content for output to screen. - * - * Replaces invisible characters so they are visible. On non-Windows - * OSes it will also colour the invisible characters. - * - * @param string $content The content to prepare. - * - * @return string - */ - public static function prepareForOutput($content) - { - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - $content = str_replace("\r", '\r', $content); - $content = str_replace("\n", '\n', $content); - $content = str_replace("\t", '\t', $content); - } else { - $content = str_replace("\r", "\033[30;1m\\r\033[0m", $content); - $content = str_replace("\n", "\033[30;1m\\n\033[0m", $content); - $content = str_replace("\t", "\033[30;1m\\t\033[0m", $content); - $content = str_replace(' ', "\033[30;1m·\033[0m", $content); - } - - return $content; - - }//end prepareForOutput() - - - /** - * Get a list paths where standards are installed. - * - * @return array - */ - public static function getInstalledStandardPaths() - { - $installedPaths = array(dirname(__FILE__).DIRECTORY_SEPARATOR.'CodeSniffer'.DIRECTORY_SEPARATOR.'Standards'); - $configPaths = PHP_CodeSniffer::getConfigData('installed_paths'); - if ($configPaths !== null) { - $installedPaths = array_merge($installedPaths, explode(',', $configPaths)); - } - - $resolvedInstalledPaths = array(); - foreach ($installedPaths as $installedPath) { - if (substr($installedPath, 0, 1) === '.') { - $installedPath = dirname(__FILE__).DIRECTORY_SEPARATOR.$installedPath; - } - - $resolvedInstalledPaths[] = $installedPath; - } - - return $resolvedInstalledPaths; - - }//end getInstalledStandardPaths() - - - /** - * Get a list of all coding standards installed. - * - * Coding standards are directories located in the - * CodeSniffer/Standards directory. Valid coding standards - * include a Sniffs subdirectory. - * - * @param boolean $includeGeneric If true, the special "Generic" - * coding standard will be included - * if installed. - * @param string $standardsDir A specific directory to look for standards - * in. If not specified, PHP_CodeSniffer will - * look in its default locations. - * - * @return array - * @see isInstalledStandard() - */ - public static function getInstalledStandards( - $includeGeneric=false, - $standardsDir='' - ) { - $installedStandards = array(); - - if ($standardsDir === '') { - $installedPaths = self::getInstalledStandardPaths(); - } else { - $installedPaths = array($standardsDir); - } - - foreach ($installedPaths as $standardsDir) { - $di = new DirectoryIterator($standardsDir); - foreach ($di as $file) { - if ($file->isDir() === true && $file->isDot() === false) { - $filename = $file->getFilename(); - - // Ignore the special "Generic" standard. - if ($includeGeneric === false && $filename === 'Generic') { - continue; - } - - // Valid coding standard dirs include a ruleset. - $csFile = $file->getPathname().'/ruleset.xml'; - if (is_file($csFile) === true) { - $installedStandards[] = $filename; - } - } - } - }//end foreach - - return $installedStandards; - - }//end getInstalledStandards() - - - /** - * Determine if a standard is installed. - * - * Coding standards are directories located in the - * CodeSniffer/Standards directory. Valid coding standards - * include a ruleset.xml file. - * - * @param string $standard The name of the coding standard. - * - * @return boolean - * @see getInstalledStandards() - */ - public static function isInstalledStandard($standard) - { - $path = self::getInstalledStandardPath($standard); - if ($path !== null && strpos($path, 'ruleset.xml') !== false) { - return true; - } else { - // This could be a custom standard, installed outside our - // standards directory. - $standard = self::realPath($standard); - - // Might be an actual ruleset file itself. - // If it has an XML extension, let's at least try it. - if (is_file($standard) === true - && (substr(strtolower($standard), -4) === '.xml' - || substr(strtolower($standard), -9) === '.xml.dist') - ) { - return true; - } - - // If it is a directory with a ruleset.xml file in it, - // it is a standard. - $ruleset = rtrim($standard, ' /\\').DIRECTORY_SEPARATOR.'ruleset.xml'; - if (is_file($ruleset) === true) { - return true; - } - }//end if - - return false; - - }//end isInstalledStandard() - - - /** - * Return the path of an installed coding standard. - * - * Coding standards are directories located in the - * CodeSniffer/Standards directory. Valid coding standards - * include a ruleset.xml file. - * - * @param string $standard The name of the coding standard. - * - * @return string|null - */ - public static function getInstalledStandardPath($standard) - { - $installedPaths = self::getInstalledStandardPaths(); - foreach ($installedPaths as $installedPath) { - $standardPath = $installedPath.DIRECTORY_SEPARATOR.$standard; - $path = self::realpath($standardPath.DIRECTORY_SEPARATOR.'ruleset.xml'); - if (is_file($path) === true) { - return $path; - } else if (self::isPharFile($standardPath) === true) { - $path = self::realpath($standardPath); - if ($path !== false) { - return $path; - } - } - } - - return null; - - }//end getInstalledStandardPath() - - - /** - * Get a single config value. - * - * Config data is stored in the data dir, in a file called - * CodeSniffer.conf. It is a simple PHP array. - * - * @param string $key The name of the config value. - * - * @return string|null - * @see setConfigData() - * @see getAllConfigData() - */ - public static function getConfigData($key) - { - $phpCodeSnifferConfig = self::getAllConfigData(); - - if ($phpCodeSnifferConfig === null) { - return null; - } - - if (isset($phpCodeSnifferConfig[$key]) === false) { - return null; - } - - return $phpCodeSnifferConfig[$key]; - - }//end getConfigData() - - - /** - * Set a single config value. - * - * Config data is stored in the data dir, in a file called - * CodeSniffer.conf. It is a simple PHP array. - * - * @param string $key The name of the config value. - * @param string|null $value The value to set. If null, the config - * entry is deleted, reverting it to the - * default value. - * @param boolean $temp Set this config data temporarily for this - * script run. This will not write the config - * data to the config file. - * - * @return boolean - * @see getConfigData() - * @throws PHP_CodeSniffer_Exception If the config file can not be written. - */ - public static function setConfigData($key, $value, $temp=false) - { - if ($temp === false) { - $path = ''; - if (is_callable('Phar::running') === true) { - $path = Phar::running(false); - } - - if ($path !== '') { - $configFile = dirname($path).'/CodeSniffer.conf'; - } else { - $configFile = dirname(__FILE__).'/CodeSniffer.conf'; - if (is_file($configFile) === false - && strpos('@data_dir@', '@data_dir') === false - ) { - // If data_dir was replaced, this is a PEAR install and we can - // use the PEAR data dir to store the conf file. - $configFile = '@data_dir@/PHP_CodeSniffer/CodeSniffer.conf'; - } - } - - if (is_file($configFile) === true - && is_writable($configFile) === false - ) { - $error = 'Config file '.$configFile.' is not writable'; - throw new PHP_CodeSniffer_Exception($error); - } - }//end if - - $phpCodeSnifferConfig = self::getAllConfigData(); - - if ($value === null) { - if (isset($phpCodeSnifferConfig[$key]) === true) { - unset($phpCodeSnifferConfig[$key]); - } - } else { - $phpCodeSnifferConfig[$key] = $value; - } - - if ($temp === false) { - $output = '<'.'?php'."\n".' $phpCodeSnifferConfig = '; - $output .= var_export($phpCodeSnifferConfig, true); - $output .= "\n?".'>'; - - if (file_put_contents($configFile, $output) === false) { - return false; - } - } - - $GLOBALS['PHP_CODESNIFFER_CONFIG_DATA'] = $phpCodeSnifferConfig; - - return true; - - }//end setConfigData() - - - /** - * Get all config data in an array. - * - * @return array - * @see getConfigData() - */ - public static function getAllConfigData() - { - if (isset($GLOBALS['PHP_CODESNIFFER_CONFIG_DATA']) === true) { - return $GLOBALS['PHP_CODESNIFFER_CONFIG_DATA']; - } - - $path = ''; - if (is_callable('Phar::running') === true) { - $path = Phar::running(false); - } - - if ($path !== '') { - $configFile = dirname($path).'/CodeSniffer.conf'; - } else { - $configFile = dirname(__FILE__).'/CodeSniffer.conf'; - if (is_file($configFile) === false) { - $configFile = '@data_dir@/PHP_CodeSniffer/CodeSniffer.conf'; - } - } - - if (is_file($configFile) === false) { - $GLOBALS['PHP_CODESNIFFER_CONFIG_DATA'] = array(); - return array(); - } - - include $configFile; - $GLOBALS['PHP_CODESNIFFER_CONFIG_DATA'] = $phpCodeSnifferConfig; - return $GLOBALS['PHP_CODESNIFFER_CONFIG_DATA']; - - }//end getAllConfigData() - - - /** - * Return TRUE, if the path is a phar file. - * - * @param string $path The path to use. - * - * @return mixed - */ - public static function isPharFile($path) - { - if (strpos($path, 'phar://') === 0) { - return true; - } - - return false; - - }//end isPharFile() - - - /** - * CodeSniffer alternative for realpath. - * - * Allows for phar support. - * - * @param string $path The path to use. - * - * @return mixed - */ - public static function realpath($path) - { - // Support the path replacement of ~ with the user's home directory. - if (substr($path, 0, 2) === '~/') { - $homeDir = getenv('HOME'); - if ($homeDir !== false) { - $path = $homeDir.substr($path, 1); - } - } - - // No extra work needed if this is not a phar file. - if (self::isPharFile($path) === false) { - return realpath($path); - } - - // Before trying to break down the file path, - // check if it exists first because it will mostly not - // change after running the below code. - if (file_exists($path) === true) { - return $path; - } - - $phar = Phar::running(false); - $extra = str_replace('phar://'.$phar, '', $path); - $path = realpath($phar); - if ($path === false) { - return false; - } - - $path = 'phar://'.$path.$extra; - if (file_exists($path) === true) { - return $path; - } - - return false; - - }//end realpath() - - - /** - * CodeSniffer alternative for chdir(). - * - * Allows for phar support. - * - * @param string $path The path to use. - * - * @return void - */ - public static function chdir($path) - { - if (self::isPharFile($path) === true) { - $phar = Phar::running(false); - chdir(dirname($phar)); - } else { - chdir($path); - } - - }//end chdir() - - -}//end class diff --git a/phpcs/CodeSniffer/CLI.php b/phpcs/CodeSniffer/CLI.php deleted file mode 100644 index 29403cf..0000000 --- a/phpcs/CodeSniffer/CLI.php +++ /dev/null @@ -1,1444 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -error_reporting(E_ALL | E_STRICT); - -// Make sure version id constant is available. -if (defined('PHP_VERSION_ID') === false) { - $version = explode('.', PHP_VERSION); - define('PHP_VERSION_ID', (int) (($version[0] * 10000) + ($version[1] * 100) + $version[2])); - unset($version); -} - -// Make sure that we autoload all dependencies if running via Composer. -if (PHP_VERSION_ID >= 50302) { - if (file_exists($a = dirname(__FILE__).'/../../../autoload.php') === true) { - include_once $a; - } else if (file_exists($a = dirname(__FILE__).'/../vendor/autoload.php') === true) { - include_once $a; - } -} - -if (file_exists($a = dirname(__FILE__).'/../CodeSniffer.php') === true) { - // Running from a git clone. - include_once $a; -} else { - // PEAR installed. - include_once 'PHP/CodeSniffer.php'; -} - -/** - * A class to process command line phpcs scripts. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_CLI -{ - - /** - * An array of all values specified on the command line. - * - * @var array - */ - protected $values = array(); - - /** - * The minimum severity level errors must have to be displayed. - * - * @var bool - */ - public $errorSeverity = 0; - - /** - * The minimum severity level warnings must have to be displayed. - * - * @var bool - */ - public $warningSeverity = 0; - - /** - * Whether or not to kill the process when an unknown command line arg is found. - * - * If FALSE, arguments that are not command line options or file/directory paths - * will be ignored and execution will continue. - * - * @var bool - */ - public $dieOnUnknownArg = true; - - /** - * An array of the current command line arguments we are processing. - * - * @var array - */ - private $_cliArgs = array(); - - - /** - * Run the PHPCS script. - * - * @return array - */ - public function runphpcs() - { - if (defined('PHP_CODESNIFFER_CBF') === false) { - define('PHP_CODESNIFFER_CBF', false); - } - - if (is_file(dirname(__FILE__).'/../CodeSniffer/Reporting.php') === true) { - include_once dirname(__FILE__).'/../CodeSniffer/Reporting.php'; - } else { - include_once 'PHP/CodeSniffer/Reporting.php'; - } - - PHP_CodeSniffer_Reporting::startTiming(); - $this->checkRequirements(); - $numErrors = $this->process(); - if ($numErrors === 0) { - exit(0); - } else { - exit(1); - } - - }//end runphpcs() - - - /** - * Run the PHPCBF script. - * - * @return array - */ - public function runphpcbf() - { - if (defined('PHP_CODESNIFFER_CBF') === false) { - define('PHP_CODESNIFFER_CBF', true); - } - - if (is_file(dirname(__FILE__).'/../CodeSniffer/Reporting.php') === true) { - include_once dirname(__FILE__).'/../CodeSniffer/Reporting.php'; - } else { - include_once 'PHP/CodeSniffer/Reporting.php'; - } - - PHP_CodeSniffer_Reporting::startTiming(); - $this->checkRequirements(); - - $this->dieOnUnknownArg = false; - - // Override some of the command line settings that might break the fixes. - $cliValues = $this->getCommandLineValues(); - $cliValues['verbosity'] = 0; - $cliValues['showProgress'] = false; - $cliValues['generator'] = ''; - $cliValues['explain'] = false; - $cliValues['interactive'] = false; - $cliValues['showSources'] = false; - $cliValues['reportFile'] = null; - $cliValues['reports'] = array(); - - $suffix = ''; - if (isset($cliValues['suffix']) === true) { - $suffix = $cliValues['suffix']; - } - - $allowPatch = true; - if (isset($cliValues['no-patch']) === true || empty($cliValues['files']) === true) { - // They either asked for this, - // or they are using STDIN, which can't use diff. - $allowPatch = false; - } - - if ($suffix === '' && $allowPatch === true) { - // Using the diff/patch tools. - $diffFile = getcwd().'/phpcbf-fixed.diff'; - $cliValues['reports'] = array('diff' => $diffFile); - if (file_exists($diffFile) === true) { - unlink($diffFile); - } - } else { - // Replace the file without the patch command - // or writing to a file with a new suffix. - $cliValues['reports'] = array('cbf' => null); - $cliValues['phpcbf-suffix'] = $suffix; - } - - $numErrors = $this->process($cliValues); - - if ($suffix === '' && $allowPatch === true) { - if (file_exists($diffFile) === false) { - // Nothing to fix. - if ($numErrors === 0) { - // And no errors reported. - $exit = 0; - } else { - // Errors we can't fix. - $exit = 2; - } - } else { - if (filesize($diffFile) < 10) { - // Empty or bad diff file. - if ($numErrors === 0) { - // And no errors reported. - $exit = 0; - } else { - // Errors we can't fix. - $exit = 2; - } - } else { - $cmd = "patch -p0 -ui \"$diffFile\""; - $output = array(); - $retVal = null; - exec($cmd, $output, $retVal); - - if ($retVal === 0) { - // Everything went well. - $filesPatched = count($output); - echo "Patched $filesPatched file"; - if ($filesPatched > 1) { - echo 's'; - } - - echo PHP_EOL; - $exit = 1; - } else { - print_r($output); - echo "Returned: $retVal".PHP_EOL; - $exit = 3; - } - }//end if - - unlink($diffFile); - }//end if - } else { - // File are being patched manually, so we can't tell - // how many errors were fixed. - $exit = 1; - }//end if - - if ($exit === 0) { - echo 'No fixable errors were found'.PHP_EOL; - } else if ($exit === 2) { - echo 'PHPCBF could not fix all the errors found'.PHP_EOL; - } - - PHP_CodeSniffer_Reporting::printRunTime(); - exit($exit); - - }//end runphpcbf() - - - /** - * Exits if the minimum requirements of PHP_CodSniffer are not met. - * - * @return array - */ - public function checkRequirements() - { - // Check the PHP version. - if (PHP_VERSION_ID < 50102) { - echo 'ERROR: PHP_CodeSniffer requires PHP version 5.1.2 or greater.'.PHP_EOL; - exit(2); - } - - if (extension_loaded('tokenizer') === false) { - echo 'ERROR: PHP_CodeSniffer requires the tokenizer extension to be enabled.'.PHP_EOL; - exit(2); - } - - }//end checkRequirements() - - - /** - * Get a list of default values for all possible command line arguments. - * - * @return array - */ - public function getDefaults() - { - if (defined('PHP_CODESNIFFER_IN_TESTS') === true) { - return array(); - } - - // The default values for config settings. - $defaults['files'] = array(); - $defaults['standard'] = null; - $defaults['verbosity'] = 0; - $defaults['interactive'] = false; - $defaults['colors'] = false; - $defaults['explain'] = false; - $defaults['local'] = false; - $defaults['showSources'] = false; - $defaults['extensions'] = array(); - $defaults['sniffs'] = array(); - $defaults['exclude'] = array(); - $defaults['ignored'] = array(); - $defaults['reportFile'] = null; - $defaults['generator'] = ''; - $defaults['reports'] = array(); - $defaults['bootstrap'] = array(); - $defaults['errorSeverity'] = null; - $defaults['warningSeverity'] = null; - $defaults['stdin'] = null; - $defaults['stdinPath'] = ''; - - $reportFormat = PHP_CodeSniffer::getConfigData('report_format'); - if ($reportFormat !== null) { - $defaults['reports'][$reportFormat] = null; - } - - $tabWidth = PHP_CodeSniffer::getConfigData('tab_width'); - if ($tabWidth === null) { - $defaults['tabWidth'] = 0; - } else { - $defaults['tabWidth'] = (int) $tabWidth; - } - - $encoding = PHP_CodeSniffer::getConfigData('encoding'); - if ($encoding === null) { - $defaults['encoding'] = 'iso-8859-1'; - } else { - $defaults['encoding'] = strtolower($encoding); - } - - $severity = PHP_CodeSniffer::getConfigData('severity'); - if ($severity !== null) { - $defaults['errorSeverity'] = (int) $severity; - $defaults['warningSeverity'] = (int) $severity; - } - - $severity = PHP_CodeSniffer::getConfigData('error_severity'); - if ($severity !== null) { - $defaults['errorSeverity'] = (int) $severity; - } - - $severity = PHP_CodeSniffer::getConfigData('warning_severity'); - if ($severity !== null) { - $defaults['warningSeverity'] = (int) $severity; - } - - $showWarnings = PHP_CodeSniffer::getConfigData('show_warnings'); - if ($showWarnings !== null) { - $showWarnings = (bool) $showWarnings; - if ($showWarnings === false) { - $defaults['warningSeverity'] = 0; - } - } - - $reportWidth = PHP_CodeSniffer::getConfigData('report_width'); - if ($reportWidth !== null) { - $defaults['reportWidth'] = $this->_validateReportWidth($reportWidth); - } else { - // Use function defaults. - $defaults['reportWidth'] = null; - } - - $showProgress = PHP_CodeSniffer::getConfigData('show_progress'); - if ($showProgress === null) { - $defaults['showProgress'] = false; - } else { - $defaults['showProgress'] = (bool) $showProgress; - } - - $quiet = PHP_CodeSniffer::getConfigData('quiet'); - if ($quiet === null) { - $defaults['quiet'] = false; - } else { - $defaults['quiet'] = (bool) $quiet; - } - - $colors = PHP_CodeSniffer::getConfigData('colors'); - if ($colors === null) { - $defaults['colors'] = false; - } else { - $defaults['colors'] = (bool) $colors; - } - - if (PHP_CodeSniffer::isPharFile(dirname(dirname(__FILE__))) === true) { - // If this is a phar file, check for the standard in the config. - $standard = PHP_CodeSniffer::getConfigData('standard'); - if ($standard !== null) { - $defaults['standard'] = $standard; - } - } - - return $defaults; - - }//end getDefaults() - - - /** - * Gets the processed command line values. - * - * If the values have not yet been set, the values will be sourced - * from the command line arguments. - * - * @return array - */ - public function getCommandLineValues() - { - if (empty($this->values) === false) { - return $this->values; - } - - $args = $_SERVER['argv']; - array_shift($args); - - $this->setCommandLineValues($args); - - // Check for content on STDIN. - $handle = fopen('php://stdin', 'r'); - if (stream_set_blocking($handle, false) === true) { - $fileContents = ''; - while (($line = fgets($handle)) !== false) { - $fileContents .= $line; - usleep(10); - } - - stream_set_blocking($handle, true); - fclose($handle); - if (trim($fileContents) !== '') { - $this->values['stdin'] = $fileContents; - } - } - - return $this->values; - - }//end getCommandLineValues() - - - /** - * Set the command line values. - * - * @param array $args An array of command line arguments to process. - * - * @return void - */ - public function setCommandLineValues($args) - { - if (defined('PHP_CODESNIFFER_IN_TESTS') === true) { - $this->values = array( - 'stdin' => null, - 'quiet' => true, - ); - } else if (empty($this->values) === true) { - $this->values = $this->getDefaults(); - } - - $this->_cliArgs = $args; - $numArgs = count($args); - - for ($i = 0; $i < $numArgs; $i++) { - $arg = $this->_cliArgs[$i]; - if ($arg === '') { - continue; - } - - if ($arg{0} === '-') { - if ($arg === '-' || $arg === '--') { - // Empty argument, ignore it. - continue; - } - - if ($arg{1} === '-') { - $this->processLongArgument(substr($arg, 2), $i); - } else { - $switches = str_split($arg); - foreach ($switches as $switch) { - if ($switch === '-') { - continue; - } - - $this->processShortArgument($switch, $i); - } - } - } else { - $this->processUnknownArgument($arg, $i); - }//end if - }//end for - - }//end setCommandLineValues() - - - /** - * Processes a short (-e) command line argument. - * - * @param string $arg The command line argument. - * @param int $pos The position of the argument on the command line. - * - * @return void - */ - public function processShortArgument($arg, $pos) - { - switch ($arg) { - case 'h': - case '?': - $this->printUsage(); - exit(0); - case 'i' : - $this->printInstalledStandards(); - exit(0); - case 'v' : - if ($this->values['quiet'] === true) { - // Ignore when quiet mode is enabled. - break; - } - - if (isset($this->values['verbosity']) === false) { - $this->values['verbosity'] = 1; - } else { - $this->values['verbosity']++; - } - break; - case 'l' : - $this->values['local'] = true; - break; - case 's' : - $this->values['showSources'] = true; - break; - case 'a' : - $this->values['interactive'] = true; - break; - case 'e': - $this->values['explain'] = true; - break; - case 'p' : - if ($this->values['quiet'] === true) { - // Ignore when quiet mode is enabled. - break; - } - - $this->values['showProgress'] = true; - break; - case 'q' : - // Quiet mode disables a few other settings as well. - $this->values['quiet'] = true; - $this->values['showProgress'] = false; - $this->values['verbosity'] = 0; - break; - case 'd' : - $ini = explode('=', $this->_cliArgs[($pos + 1)]); - $this->_cliArgs[($pos + 1)] = ''; - if (isset($ini[1]) === true) { - ini_set($ini[0], $ini[1]); - } else { - ini_set($ini[0], true); - } - break; - case 'n' : - $this->values['warningSeverity'] = 0; - break; - case 'w' : - $this->values['warningSeverity'] = null; - break; - default: - if ($this->dieOnUnknownArg === false) { - $this->values[$arg] = $arg; - } else { - $this->processUnknownArgument('-'.$arg, $pos); - } - }//end switch - - }//end processShortArgument() - - - /** - * Processes a long (--example) command line argument. - * - * @param string $arg The command line argument. - * @param int $pos The position of the argument on the command line. - * - * @return void - */ - public function processLongArgument($arg, $pos) - { - switch ($arg) { - case 'help': - $this->printUsage(); - exit(0); - case 'version': - echo 'PHP_CodeSniffer version '.PHP_CodeSniffer::VERSION.' ('.PHP_CodeSniffer::STABILITY.') '; - echo 'by Squiz (http://www.squiz.net)'.PHP_EOL; - exit(0); - case 'colors': - $this->values['colors'] = true; - break; - case 'no-colors': - $this->values['colors'] = false; - break; - case 'config-set': - if (isset($this->_cliArgs[($pos + 1)]) === false - || isset($this->_cliArgs[($pos + 2)]) === false - ) { - echo 'ERROR: Setting a config option requires a name and value'.PHP_EOL.PHP_EOL; - $this->printUsage(); - exit(0); - } - - $key = $this->_cliArgs[($pos + 1)]; - $value = $this->_cliArgs[($pos + 2)]; - $current = PHP_CodeSniffer::getConfigData($key); - - try { - PHP_CodeSniffer::setConfigData($key, $value); - } catch (Exception $e) { - echo $e->getMessage().PHP_EOL; - exit(2); - } - - if ($current === null) { - echo "Config value \"$key\" added successfully".PHP_EOL; - } else { - echo "Config value \"$key\" updated successfully; old value was \"$current\"".PHP_EOL; - } - exit(0); - case 'config-delete': - if (isset($this->_cliArgs[($pos + 1)]) === false) { - echo 'ERROR: Deleting a config option requires the name of the option'.PHP_EOL.PHP_EOL; - $this->printUsage(); - exit(0); - } - - $key = $this->_cliArgs[($pos + 1)]; - $current = PHP_CodeSniffer::getConfigData($key); - if ($current === null) { - echo "Config value \"$key\" has not been set".PHP_EOL; - } else { - try { - PHP_CodeSniffer::setConfigData($key, null); - } catch (Exception $e) { - echo $e->getMessage().PHP_EOL; - exit(2); - } - - echo "Config value \"$key\" removed successfully; old value was \"$current\"".PHP_EOL; - } - exit(0); - case 'config-show': - $data = PHP_CodeSniffer::getAllConfigData(); - $this->printConfigData($data); - exit(0); - case 'runtime-set': - if (isset($this->_cliArgs[($pos + 1)]) === false - || isset($this->_cliArgs[($pos + 2)]) === false - ) { - echo 'ERROR: Setting a runtime config option requires a name and value'.PHP_EOL.PHP_EOL; - $this->printUsage(); - exit(0); - } - - $key = $this->_cliArgs[($pos + 1)]; - $value = $this->_cliArgs[($pos + 2)]; - $this->_cliArgs[($pos + 1)] = ''; - $this->_cliArgs[($pos + 2)] = ''; - PHP_CodeSniffer::setConfigData($key, $value, true); - break; - default: - if (substr($arg, 0, 7) === 'sniffs=') { - $sniffs = explode(',', substr($arg, 7)); - foreach ($sniffs as $sniff) { - if (substr_count($sniff, '.') !== 2) { - echo 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL; - $this->printUsage(); - exit(2); - } - } - - $this->values['sniffs'] = $sniffs; - } else if (substr($arg, 0, 8) === 'exclude=') { - $sniffs = explode(',', substr($arg, 8)); - foreach ($sniffs as $sniff) { - if (substr_count($sniff, '.') !== 2) { - echo 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL; - $this->printUsage(); - exit(2); - } - } - - $this->values['exclude'] = $sniffs; - } else if (substr($arg, 0, 10) === 'bootstrap=') { - $files = explode(',', substr($arg, 10)); - foreach ($files as $file) { - $path = PHP_CodeSniffer::realpath($file); - if ($path === false) { - echo 'ERROR: The specified bootstrap file "'.$file.'" does not exist'.PHP_EOL.PHP_EOL; - $this->printUsage(); - exit(2); - } - - $this->values['bootstrap'][] = $path; - } - } else if (substr($arg, 0, 10) === 'file-list=') { - $fileList = substr($arg, 10); - $path = PHP_CodeSniffer::realpath($fileList); - if ($path === false) { - echo 'ERROR: The specified file list "'.$file.'" does not exist'.PHP_EOL.PHP_EOL; - $this->printUsage(); - exit(2); - } - - $files = file($path); - foreach ($files as $inputFile) { - $inputFile = trim($inputFile); - - // Skip empty lines. - if ($inputFile === '') { - continue; - } - - $realFile = PHP_CodeSniffer::realpath($inputFile); - if ($realFile === false) { - echo 'ERROR: The specified file "'.$inputFile.'" does not exist'.PHP_EOL.PHP_EOL; - $this->printUsage(); - exit(2); - } - - $this->values['files'][] = $realFile; - } - } else if (substr($arg, 0, 11) === 'stdin-path=') { - $this->values['stdinPath'] = PHP_CodeSniffer::realpath(substr($arg, 11)); - - // It may not exist and return false instead, so just use whatever they gave us. - if ($this->values['stdinPath'] === false) { - $this->values['stdinPath'] = trim(substr($arg, 11)); - } - } else if (substr($arg, 0, 12) === 'report-file=') { - $this->values['reportFile'] = PHP_CodeSniffer::realpath(substr($arg, 12)); - - // It may not exist and return false instead. - if ($this->values['reportFile'] === false) { - $this->values['reportFile'] = substr($arg, 12); - - $dir = dirname($this->values['reportFile']); - if (is_dir($dir) === false) { - echo 'ERROR: The specified report file path "'.$this->values['reportFile'].'" points to a non-existent directory'.PHP_EOL.PHP_EOL; - $this->printUsage(); - exit(2); - } - - if ($dir === '.') { - // Passed report file is a file in the current directory. - $this->values['reportFile'] = getcwd().'/'.basename($this->values['reportFile']); - } else { - if ($dir{0} === '/') { - // An absolute path. - $dir = PHP_CodeSniffer::realpath($dir); - } else { - $dir = PHP_CodeSniffer::realpath(getcwd().'/'.$dir); - } - - if ($dir !== false) { - // Report file path is relative. - $this->values['reportFile'] = $dir.'/'.basename($this->values['reportFile']); - } - } - }//end if - - if (is_dir($this->values['reportFile']) === true) { - echo 'ERROR: The specified report file path "'.$this->values['reportFile'].'" is a directory'.PHP_EOL.PHP_EOL; - $this->printUsage(); - exit(2); - } - } else if (substr($arg, 0, 13) === 'report-width=') { - $this->values['reportWidth'] = $this->_validateReportWidth(substr($arg, 13)); - } else if (substr($arg, 0, 7) === 'report=' - || substr($arg, 0, 7) === 'report-' - ) { - if ($arg[6] === '-') { - // This is a report with file output. - $split = strpos($arg, '='); - if ($split === false) { - $report = substr($arg, 7); - $output = null; - } else { - $report = substr($arg, 7, ($split - 7)); - $output = substr($arg, ($split + 1)); - if ($output === false) { - $output = null; - } else { - $dir = dirname($output); - if ($dir === '.') { - // Passed report file is a filename in the current directory. - $output = getcwd().'/'.basename($output); - } else { - if ($dir{0} === '/') { - // An absolute path. - $dir = PHP_CodeSniffer::realpath($dir); - } else { - $dir = PHP_CodeSniffer::realpath(getcwd().'/'.$dir); - } - - if ($dir !== false) { - // Report file path is relative. - $output = $dir.'/'.basename($output); - } - } - }//end if - }//end if - } else { - // This is a single report. - $report = substr($arg, 7); - $output = null; - }//end if - - $this->values['reports'][$report] = $output; - } else if (substr($arg, 0, 9) === 'standard=') { - $standards = trim(substr($arg, 9)); - if ($standards !== '') { - $this->values['standard'] = explode(',', $standards); - } - } else if (substr($arg, 0, 11) === 'extensions=') { - if (isset($this->values['extensions']) === false) { - $this->values['extensions'] = array(); - } - - $this->values['extensions'] = array_merge($this->values['extensions'], explode(',', substr($arg, 11))); - } else if (substr($arg, 0, 9) === 'severity=') { - $this->values['errorSeverity'] = (int) substr($arg, 9); - $this->values['warningSeverity'] = $this->values['errorSeverity']; - } else if (substr($arg, 0, 15) === 'error-severity=') { - $this->values['errorSeverity'] = (int) substr($arg, 15); - } else if (substr($arg, 0, 17) === 'warning-severity=') { - $this->values['warningSeverity'] = (int) substr($arg, 17); - } else if (substr($arg, 0, 7) === 'ignore=') { - // Split the ignore string on commas, unless the comma is escaped - // using 1 or 3 slashes (\, or \\\,). - $ignored = preg_split( - '/(?<=(?values['ignored'][$pattern] = 'absolute'; - } - } else if (substr($arg, 0, 10) === 'generator=') { - $this->values['generator'] = substr($arg, 10); - } else if (substr($arg, 0, 9) === 'encoding=') { - $this->values['encoding'] = strtolower(substr($arg, 9)); - } else if (substr($arg, 0, 10) === 'tab-width=') { - $this->values['tabWidth'] = (int) substr($arg, 10); - } else { - if ($this->dieOnUnknownArg === false) { - $eqPos = strpos($arg, '='); - if ($eqPos === false) { - $this->values[$arg] = $arg; - } else { - $value = substr($arg, ($eqPos + 1)); - $arg = substr($arg, 0, $eqPos); - $this->values[$arg] = $value; - } - } else { - $this->processUnknownArgument('--'.$arg, $pos); - } - }//end if - - break; - }//end switch - - }//end processLongArgument() - - - /** - * Processes an unknown command line argument. - * - * Assumes all unknown arguments are files and folders to check. - * - * @param string $arg The command line argument. - * @param int $pos The position of the argument on the command line. - * - * @return void - */ - public function processUnknownArgument($arg, $pos) - { - // We don't know about any additional switches; just files. - if ($arg{0} === '-') { - if ($this->dieOnUnknownArg === false) { - return; - } - - echo 'ERROR: option "'.$arg.'" not known.'.PHP_EOL.PHP_EOL; - $this->printUsage(); - exit(2); - } - - $file = PHP_CodeSniffer::realpath($arg); - if (file_exists($file) === false) { - if ($this->dieOnUnknownArg === false) { - return; - } - - echo 'ERROR: The file "'.$arg.'" does not exist.'.PHP_EOL.PHP_EOL; - $this->printUsage(); - exit(2); - } else { - $this->values['files'][] = $file; - } - - }//end processUnknownArgument() - - - /** - * Runs PHP_CodeSniffer over files and directories. - * - * @param array $values An array of values determined from CLI args. - * - * @return int The number of error and warning messages shown. - * @see getCommandLineValues() - */ - public function process($values=array()) - { - if (empty($values) === true) { - $values = $this->getCommandLineValues(); - } else { - $values = array_merge($this->getDefaults(), $values); - $this->values = $values; - } - - if ($values['generator'] !== '') { - $phpcs = new PHP_CodeSniffer($values['verbosity']); - if ($values['standard'] === null) { - $values['standard'] = $this->validateStandard(null); - } - - foreach ($values['standard'] as $standard) { - $phpcs->generateDocs( - $standard, - $values['sniffs'], - $values['generator'] - ); - } - - exit(0); - } - - // If no standard is supplied, get the default. - $values['standard'] = $this->validateStandard($values['standard']); - foreach ($values['standard'] as $standard) { - if (PHP_CodeSniffer::isInstalledStandard($standard) === false) { - // They didn't select a valid coding standard, so help them - // out by letting them know which standards are installed. - echo 'ERROR: the "'.$standard.'" coding standard is not installed. '; - $this->printInstalledStandards(); - exit(2); - } - } - - if ($values['explain'] === true) { - foreach ($values['standard'] as $standard) { - $this->explainStandard($standard); - } - - exit(0); - } - - $phpcs = new PHP_CodeSniffer($values['verbosity'], null, null, null); - $phpcs->setCli($this); - $phpcs->initStandard($values['standard'], $values['sniffs'], $values['exclude']); - $values = $this->values; - - $phpcs->setTabWidth($values['tabWidth']); - $phpcs->setEncoding($values['encoding']); - $phpcs->setInteractive($values['interactive']); - - // Set file extensions if they were specified. Otherwise, - // let PHP_CodeSniffer decide on the defaults. - if (empty($values['extensions']) === false) { - $phpcs->setAllowedFileExtensions($values['extensions']); - } - - // Set ignore patterns if they were specified. - if (empty($values['ignored']) === false) { - $ignorePatterns = array_merge($phpcs->getIgnorePatterns(), $values['ignored']); - $phpcs->setIgnorePatterns($ignorePatterns); - } - - // Set some convenience member vars. - if ($values['errorSeverity'] === null) { - $this->errorSeverity = PHPCS_DEFAULT_ERROR_SEV; - } else { - $this->errorSeverity = $values['errorSeverity']; - } - - if ($values['warningSeverity'] === null) { - $this->warningSeverity = PHPCS_DEFAULT_WARN_SEV; - } else { - $this->warningSeverity = $values['warningSeverity']; - } - - if (empty($values['reports']) === true) { - $values['reports']['full'] = $values['reportFile']; - $this->values['reports'] = $values['reports']; - } - - // Include bootstrap files. - foreach ($values['bootstrap'] as $bootstrap) { - include $bootstrap; - } - - $phpcs->processFiles($values['files'], $values['local']); - - if (empty($values['files']) === true || $values['stdin'] !== null) { - $fileContents = $values['stdin']; - if ($fileContents === null) { - // Check if they are passing in the file contents. - $handle = fopen('php://stdin', 'r'); - stream_set_blocking($handle, true); - $fileContents = stream_get_contents($handle); - fclose($handle); - } - - if ($fileContents === '') { - // No files and no content passed in. - echo 'ERROR: You must supply at least one file or directory to process.'.PHP_EOL.PHP_EOL; - $this->printUsage(); - exit(2); - } else { - $this->values['stdin'] = $fileContents; - $phpcs->processFile('STDIN', $fileContents); - } - } - - // Interactive runs don't require a final report and it doesn't really - // matter what the retun value is because we know it isn't being read - // by a script. - if ($values['interactive'] === true) { - return 0; - } - - return $this->printErrorReport( - $phpcs, - $values['reports'], - $values['showSources'], - $values['reportFile'], - $values['reportWidth'] - ); - - }//end process() - - - /** - * Prints the error report for the run. - * - * Note that this function may actually print multiple reports - * as the user may have specified a number of output formats. - * - * @param PHP_CodeSniffer $phpcs The PHP_CodeSniffer object containing - * the errors. - * @param array $reports A list of reports to print. - * @param bool $showSources TRUE if report should show error sources - * (not used by all reports). - * @param string $reportFile A default file to log report output to. - * @param int $reportWidth How wide the screen reports should be. - * - * @return int The number of error and warning messages shown. - */ - public function printErrorReport( - PHP_CodeSniffer $phpcs, - $reports, - $showSources, - $reportFile, - $reportWidth - ) { - if (empty($reports) === true) { - $reports['full'] = $reportFile; - } - - $errors = 0; - $warnings = 0; - $toScreen = false; - - foreach ($reports as $report => $output) { - if ($output === null) { - $output = $reportFile; - } - - if ($reportFile === null) { - $toScreen = true; - } - - // We don't add errors here because the number of - // errors reported by each report type will always be the - // same, so we really just need 1 number. - $result = $phpcs->reporting->printReport( - $report, - $showSources, - $this->values, - $output, - $reportWidth - ); - - $errors = $result['errors']; - $warnings = $result['warnings']; - }//end foreach - - // Only print timer output if no reports were - // printed to the screen so we don't put additional output - // in something like an XML report. If we are printing to screen, - // the report types would have already worked out who should - // print the timer info. - if (PHP_CODESNIFFER_INTERACTIVE === false - && ($toScreen === false - || (($errors + $warnings) === 0 && $this->values['showProgress'] === true)) - ) { - PHP_CodeSniffer_Reporting::printRunTime(); - } - - // They should all return the same value, so it - // doesn't matter which return value we end up using. - $ignoreWarnings = PHP_CodeSniffer::getConfigData('ignore_warnings_on_exit'); - $ignoreErrors = PHP_CodeSniffer::getConfigData('ignore_errors_on_exit'); - - $return = ($errors + $warnings); - if ($ignoreErrors !== null) { - $ignoreErrors = (bool) $ignoreErrors; - if ($ignoreErrors === true) { - $return -= $errors; - } - } - - if ($ignoreWarnings !== null) { - $ignoreWarnings = (bool) $ignoreWarnings; - if ($ignoreWarnings === true) { - $return -= $warnings; - } - } - - return $return; - - }//end printErrorReport() - - - /** - * Convert the passed standards into valid standards. - * - * Checks things like default values and case. - * - * @param array $standards The standards to validate. - * - * @return array - */ - public function validateStandard($standards) - { - if ($standards === null) { - // They did not supply a standard to use. - // Look for a default ruleset in the current directory or higher. - $currentDir = getcwd(); - - do { - $default = $currentDir.DIRECTORY_SEPARATOR.'phpcs.xml'; - if (is_file($default) === true) { - return array($default); - } - - $default = $currentDir.DIRECTORY_SEPARATOR.'phpcs.xml.dist'; - if (is_file($default) === true) { - return array($default); - } - - $lastDir = $currentDir; - $currentDir = dirname($currentDir); - } while ($currentDir !== '.' && $currentDir !== $lastDir); - - // Try to get the default from the config system. - $standard = PHP_CodeSniffer::getConfigData('default_standard'); - if ($standard === null) { - // Product default standard. - $standard = 'PEAR'; - } - - return explode(',', $standard); - }//end if - - $cleaned = array(); - $standards = (array) $standards; - - // Check if the standard name is valid, or if the case is invalid. - $installedStandards = PHP_CodeSniffer::getInstalledStandards(); - foreach ($standards as $standard) { - foreach ($installedStandards as $validStandard) { - if (strtolower($standard) === strtolower($validStandard)) { - $standard = $validStandard; - break; - } - } - - $cleaned[] = $standard; - } - - return $cleaned; - - }//end validateStandard() - - - /** - * Prints a report showing the sniffs contained in a standard. - * - * @param string $standard The standard to validate. - * - * @return void - */ - public function explainStandard($standard) - { - $phpcs = new PHP_CodeSniffer(); - $phpcs->process(array(), $standard); - $sniffs = $phpcs->getSniffs(); - $sniffs = array_keys($sniffs); - sort($sniffs); - - ob_start(); - - $lastStandard = ''; - $lastCount = ''; - $sniffCount = count($sniffs); - $sniffs[] = '___'; - - echo PHP_EOL."The $standard standard contains $sniffCount sniffs".PHP_EOL; - - ob_start(); - - foreach ($sniffs as $sniff) { - $parts = explode('_', str_replace('\\', '_', $sniff)); - if ($lastStandard === '') { - $lastStandard = $parts[0]; - } - - if ($parts[0] !== $lastStandard) { - $sniffList = ob_get_contents(); - ob_end_clean(); - - echo PHP_EOL.$lastStandard.' ('.$lastCount.' sniffs)'.PHP_EOL; - echo str_repeat('-', (strlen($lastStandard.$lastCount) + 10)); - echo PHP_EOL; - echo $sniffList; - - $lastStandard = $parts[0]; - $lastCount = 0; - - ob_start(); - } - - echo ' '.$parts[0].'.'.$parts[2].'.'.substr($parts[3], 0, -5).PHP_EOL; - $lastCount++; - }//end foreach - - ob_end_clean(); - - }//end explainStandard() - - - /** - * Prints out the gathered config data. - * - * @param array $data The config data to print. - * - * @return void - */ - public function printConfigData($data) - { - $max = 0; - $keys = array_keys($data); - foreach ($keys as $key) { - $len = strlen($key); - if (strlen($key) > $max) { - $max = $len; - } - } - - if ($max === 0) { - return; - } - - $max += 2; - ksort($data); - foreach ($data as $name => $value) { - echo str_pad($name.': ', $max).$value.PHP_EOL; - } - - }//end printConfigData() - - - /** - * Prints out the usage information for this script. - * - * @return void - */ - public function printUsage() - { - if (PHP_CODESNIFFER_CBF === true) { - $this->printPHPCBFUsage(); - } else { - $this->printPHPCSUsage(); - } - - }//end printUsage() - - - /** - * Prints out the usage information for PHPCS. - * - * @return void - */ - public function printPHPCSUsage() - { - echo 'Usage: phpcs [-nwlsaepqvi] [-d key[=value]] [--colors] [--no-colors] [--stdin-path=]'.PHP_EOL; - echo ' [--report=] [--report-file=] [--report-=] ...'.PHP_EOL; - echo ' [--report-width=] [--generator=] [--tab-width=]'.PHP_EOL; - echo ' [--severity=] [--error-severity=] [--warning-severity=]'.PHP_EOL; - echo ' [--runtime-set key value] [--config-set key value] [--config-delete key] [--config-show]'.PHP_EOL; - echo ' [--standard=] [--sniffs=] [--exclude=] [--encoding=]'.PHP_EOL; - echo ' [--extensions=] [--ignore=] [--bootstrap=]'.PHP_EOL; - echo ' [--file-list=] ...'.PHP_EOL; - echo ' Set runtime value (see --config-set) '.PHP_EOL; - echo ' -n Do not print warnings (shortcut for --warning-severity=0)'.PHP_EOL; - echo ' -w Print both warnings and errors (this is the default)'.PHP_EOL; - echo ' -l Local directory only, no recursion'.PHP_EOL; - echo ' -s Show sniff codes in all reports'.PHP_EOL; - echo ' -a Run interactively'.PHP_EOL; - echo ' -e Explain a standard by showing the sniffs it includes'.PHP_EOL; - echo ' -p Show progress of the run'.PHP_EOL; - echo ' -q Quiet mode; disables progress and verbose output'.PHP_EOL; - echo ' -v[v][v] Print verbose output'.PHP_EOL; - echo ' -i Show a list of installed coding standards'.PHP_EOL; - echo ' -d Set the [key] php.ini value to [value] or [true] if value is omitted'.PHP_EOL; - echo ' --help Print this help message'.PHP_EOL; - echo ' --version Print version information'.PHP_EOL; - echo ' --colors Use colors in output'.PHP_EOL; - echo ' --no-colors Do not use colors in output (this is the default)'.PHP_EOL; - echo ' One or more files and/or directories to check'.PHP_EOL; - echo ' A file containing a list of files and/or directories to check (one per line)'.PHP_EOL; - echo ' If processing STDIN, the file path that STDIN will be processed as '.PHP_EOL; - echo ' A comma separated list of files to run before processing starts'.PHP_EOL; - echo ' The encoding of the files being checked (default is iso-8859-1)'.PHP_EOL; - echo ' A comma separated list of file extensions to check'.PHP_EOL; - echo ' (extension filtering only valid when checking a directory)'.PHP_EOL; - echo ' The type of the file can be specified using: ext/type'.PHP_EOL; - echo ' e.g., module/php,es/js'.PHP_EOL; - echo ' Uses either the "HTML", "Markdown" or "Text" generator'.PHP_EOL; - echo ' (forces documentation generation instead of checking)'.PHP_EOL; - echo ' A comma separated list of patterns to ignore files and directories'.PHP_EOL; - echo ' Print either the "full", "xml", "checkstyle", "csv"'.PHP_EOL; - echo ' "json", "emacs", "source", "summary", "diff", "junit"'.PHP_EOL; - echo ' "svnblame", "gitblame", "hgblame" or "notifysend" report'.PHP_EOL; - echo ' (the "full" report is printed by default)'.PHP_EOL; - echo ' Write the report to the specified file path'.PHP_EOL; - echo ' How many columns wide screen reports should be printed'.PHP_EOL; - echo ' or set to "auto" to use current screen width, where supported'.PHP_EOL; - echo ' A comma separated list of sniff codes to include or exclude during checking'.PHP_EOL; - echo ' (all sniffs must be part of the specified standard)'.PHP_EOL; - echo ' The minimum severity required to display an error or warning'.PHP_EOL; - echo ' The name or path of the coding standard to use'.PHP_EOL; - echo ' The number of spaces each tab represents'.PHP_EOL; - - }//end printPHPCSUsage() - - - /** - * Prints out the usage information for PHPCBF. - * - * @return void - */ - public function printPHPCBFUsage() - { - echo 'Usage: phpcbf [-nwli] [-d key[=value]] [--stdin-path=]'.PHP_EOL; - echo ' [--standard=] [--sniffs=] [--exclude=] [--suffix=]'.PHP_EOL; - echo ' [--severity=] [--error-severity=] [--warning-severity=]'.PHP_EOL; - echo ' [--tab-width=] [--encoding=]'.PHP_EOL; - echo ' [--extensions=] [--ignore=] [--bootstrap=]'.PHP_EOL; - echo ' [--file-list=] ...'.PHP_EOL; - echo ' -n Do not fix warnings (shortcut for --warning-severity=0)'.PHP_EOL; - echo ' -w Fix both warnings and errors (on by default)'.PHP_EOL; - echo ' -l Local directory only, no recursion'.PHP_EOL; - echo ' -i Show a list of installed coding standards'.PHP_EOL; - echo ' -d Set the [key] php.ini value to [value] or [true] if value is omitted'.PHP_EOL; - echo ' --help Print this help message'.PHP_EOL; - echo ' --version Print version information'.PHP_EOL; - echo ' --no-patch Do not make use of the "diff" or "patch" programs'.PHP_EOL; - echo ' One or more files and/or directories to fix'.PHP_EOL; - echo ' A file containing a list of files and/or directories to fix (one per line)'.PHP_EOL; - echo ' If processing STDIN, the file path that STDIN will be processed as '.PHP_EOL; - echo ' A comma separated list of files to run before processing starts'.PHP_EOL; - echo ' The encoding of the files being fixed (default is iso-8859-1)'.PHP_EOL; - echo ' A comma separated list of file extensions to fix'.PHP_EOL; - echo ' (extension filtering only valid when checking a directory)'.PHP_EOL; - echo ' The type of the file can be specified using: ext/type'.PHP_EOL; - echo ' e.g., module/php,es/js'.PHP_EOL; - echo ' A comma separated list of patterns to ignore files and directories'.PHP_EOL; - echo ' A comma separated list of sniff codes to include or exclude during fixing'.PHP_EOL; - echo ' (all sniffs must be part of the specified standard)'.PHP_EOL; - echo ' The minimum severity required to fix an error or warning'.PHP_EOL; - echo ' The name or path of the coding standard to use'.PHP_EOL; - echo ' Write modified files to a filename using this suffix'.PHP_EOL; - echo ' ("diff" and "patch" are not used in this mode)'.PHP_EOL; - echo ' The number of spaces each tab represents'.PHP_EOL; - - }//end printPHPCBFUsage() - - - /** - * Prints out a list of installed coding standards. - * - * @return void - */ - public function printInstalledStandards() - { - $installedStandards = PHP_CodeSniffer::getInstalledStandards(); - $numStandards = count($installedStandards); - - if ($numStandards === 0) { - echo 'No coding standards are installed.'.PHP_EOL; - } else { - $lastStandard = array_pop($installedStandards); - if ($numStandards === 1) { - echo "The only coding standard installed is $lastStandard".PHP_EOL; - } else { - $standardList = implode(', ', $installedStandards); - $standardList .= ' and '.$lastStandard; - echo 'The installed coding standards are '.$standardList.PHP_EOL; - } - } - - }//end printInstalledStandards() - - - /** - * Set report width based on terminal width. - * - * @param int $width The width of the report. If "auto" then will - * be replaced by the terminal width. - * - * @return int - */ - private function _validateReportWidth($width) - { - if ($width === 'auto' - && preg_match('|\d+ (\d+)|', shell_exec('stty size 2>&1'), $matches) === 1 - ) { - return (int) $matches[1]; - } - - return (int) $width; - - }//end _validateReportWidth() - - -}//end class diff --git a/phpcs/CodeSniffer/DocGenerators/Generator.php b/phpcs/CodeSniffer/DocGenerators/Generator.php deleted file mode 100644 index 3834ba3..0000000 --- a/phpcs/CodeSniffer/DocGenerators/Generator.php +++ /dev/null @@ -1,184 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * The base class for all PHP_CodeSniffer documentation generators. - * - * Documentation generators are used to print documentation about code sniffs - * in a standard. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -abstract class PHP_CodeSniffer_DocGenerators_Generator -{ - - /** - * The name of the coding standard we are generating docs for. - * - * @var string - */ - private $_standard = ''; - - /** - * An array of sniffs that we are limiting the generated docs to. - * - * If this array is empty, docs are generated for all sniffs in the - * supplied coding standard. - * - * @var string - */ - private $_sniffs = array(); - - - /** - * Constructs a PHP_CodeSniffer_DocGenerators_Generator object. - * - * @param string $standard The name of the coding standard to generate - * docs for. - * @param array $sniffs An array of sniffs that we are limiting the - * generated docs to. - * - * @see generate() - */ - public function __construct($standard, array $sniffs=array()) - { - $this->_standard = $standard; - $this->_sniffs = $sniffs; - - }//end __construct() - - - /** - * Retrieves the title of the sniff from the DOMNode supplied. - * - * @param DOMNode $doc The DOMNode object for the sniff. - * It represents the "documentation" tag in the XML - * standard file. - * - * @return string - */ - protected function getTitle(DOMNode $doc) - { - return $doc->getAttribute('title'); - - }//end getTitle() - - - /** - * Retrieves the name of the standard we are generating docs for. - * - * @return string - */ - protected function getStandard() - { - return $this->_standard; - - }//end getStandard() - - - /** - * Generates the documentation for a standard. - * - * It's probably wise for doc generators to override this method so they - * have control over how the docs are produced. Otherwise, the processSniff - * method should be overridden to output content for each sniff. - * - * @return void - * @see processSniff() - */ - public function generate() - { - $standardFiles = $this->getStandardFiles(); - - foreach ($standardFiles as $standard) { - $doc = new DOMDocument(); - $doc->load($standard); - $documentation = $doc->getElementsByTagName('documentation')->item(0); - $this->processSniff($documentation); - } - - }//end generate() - - - /** - * Returns a list of paths to XML standard files for all sniffs in a standard. - * - * Any sniffs that do not have an XML standard file are obviously not included - * in the returned array. If documentation is only being generated for some - * sniffs (ie. $this->_sniffs is not empty) then all others sniffs will - * be filtered from the results as well. - * - * @return string[] - */ - protected function getStandardFiles() - { - $phpcs = new PHP_CodeSniffer(); - $phpcs->process(array(), $this->_standard); - $sniffs = $phpcs->getSniffs(); - - $standardFiles = array(); - foreach ($sniffs as $className => $sniffClass) { - $object = new ReflectionObject($sniffClass); - $sniff = $object->getFilename(); - if (empty($this->_sniffs) === false) { - // We are limiting the docs to certain sniffs only, so filter - // out any unwanted sniffs. - $parts = explode('_', $className); - $sniffName = $parts[0].'.'.$parts[2].'.'.substr($parts[3], 0, -5); - if (in_array($sniffName, $this->_sniffs) === false) { - continue; - } - } - - $standardFile = str_replace( - DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR, - DIRECTORY_SEPARATOR.'Docs'.DIRECTORY_SEPARATOR, - $sniff - ); - $standardFile = str_replace('Sniff.php', 'Standard.xml', $standardFile); - - if (is_file($standardFile) === true) { - $standardFiles[] = $standardFile; - } - }//end foreach - - return $standardFiles; - - }//end getStandardFiles() - - - /** - * Process the documentation for a single sniff. - * - * Doc generators must implement this function to produce output. - * - * @param DOMNode $doc The DOMNode object for the sniff. - * It represents the "documentation" tag in the XML - * standard file. - * - * @return void - * @see generate() - */ - protected abstract function processSniff(DOMNode $doc); - - -}//end class diff --git a/phpcs/CodeSniffer/DocGenerators/HTML.php b/phpcs/CodeSniffer/DocGenerators/HTML.php deleted file mode 100644 index e8bef20..0000000 --- a/phpcs/CodeSniffer/DocGenerators/HTML.php +++ /dev/null @@ -1,292 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_DocGenerators_Generator', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_DocGenerators_Generator not found'); -} - -/** - * A doc generator that outputs documentation in one big HTML file. - * - * Output is in one large HTML file and is designed for you to style with - * your own stylesheet. It contains a table of contents at the top with anchors - * to each sniff. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_DocGenerators_HTML extends PHP_CodeSniffer_DocGenerators_Generator -{ - - - /** - * Generates the documentation for a standard. - * - * @return void - * @see processSniff() - */ - public function generate() - { - ob_start(); - $this->printHeader(); - - $standardFiles = $this->getStandardFiles(); - $this->printToc($standardFiles); - - foreach ($standardFiles as $standard) { - $doc = new DOMDocument(); - $doc->load($standard); - $documentation = $doc->getElementsByTagName('documentation')->item(0); - $this->processSniff($documentation); - } - - $this->printFooter(); - - $content = ob_get_contents(); - ob_end_clean(); - - echo $content; - - }//end generate() - - - /** - * Print the header of the HTML page. - * - * @return void - */ - protected function printHeader() - { - $standard = $this->getStandard(); - echo ''.PHP_EOL; - echo ' '.PHP_EOL; - echo " $standard Coding Standards".PHP_EOL; - echo ' '.PHP_EOL; - echo ' '.PHP_EOL; - echo ' '.PHP_EOL; - echo "

$standard Coding Standards

".PHP_EOL; - - }//end printHeader() - - - /** - * Print the table of contents for the standard. - * - * The TOC is just an unordered list of bookmarks to sniffs on the page. - * - * @param array $standardFiles An array of paths to the XML standard files. - * - * @return void - */ - protected function printToc($standardFiles) - { - echo '

Table of Contents

'.PHP_EOL; - echo '
    '.PHP_EOL; - - foreach ($standardFiles as $standard) { - $doc = new DOMDocument(); - $doc->load($standard); - $documentation = $doc->getElementsByTagName('documentation')->item(0); - $title = $this->getTitle($documentation); - echo '
  • $title
  • ".PHP_EOL; - } - - echo '
'.PHP_EOL; - - }//end printToc() - - - /** - * Print the footer of the HTML page. - * - * @return void - */ - protected function printFooter() - { - // Turn off errors so we don't get timezone warnings if people - // don't have their timezone set. - $errorLevel = error_reporting(0); - echo '
'; - echo 'Documentation generated on '.date('r'); - echo ' by PHP_CodeSniffer '.PHP_CodeSniffer::VERSION.''; - echo '
'.PHP_EOL; - error_reporting($errorLevel); - - echo ' '.PHP_EOL; - echo ''.PHP_EOL; - - }//end printFooter() - - - /** - * Process the documentation for a single sniff. - * - * @param DOMNode $doc The DOMNode object for the sniff. - * It represents the "documentation" tag in the XML - * standard file. - * - * @return void - */ - public function processSniff(DOMNode $doc) - { - $title = $this->getTitle($doc); - echo ' '.PHP_EOL; - echo "

$title

".PHP_EOL; - - foreach ($doc->childNodes as $node) { - if ($node->nodeName === 'standard') { - $this->printTextBlock($node); - } else if ($node->nodeName === 'code_comparison') { - $this->printCodeComparisonBlock($node); - } - } - - }//end processSniff() - - - /** - * Print a text block found in a standard. - * - * @param DOMNode $node The DOMNode object for the text block. - * - * @return void - */ - protected function printTextBlock($node) - { - $content = trim($node->nodeValue); - $content = htmlspecialchars($content); - - // Allow em tags only. - $content = str_replace('<em>', '', $content); - $content = str_replace('</em>', '', $content); - - echo "

$content

".PHP_EOL; - - }//end printTextBlock() - - - /** - * Print a code comparison block found in a standard. - * - * @param DOMNode $node The DOMNode object for the code comparison block. - * - * @return void - */ - protected function printCodeComparisonBlock($node) - { - $codeBlocks = $node->getElementsByTagName('code'); - - $firstTitle = $codeBlocks->item(0)->getAttribute('title'); - $first = trim($codeBlocks->item(0)->nodeValue); - $first = str_replace('', $first); - $first = str_replace(' ', ' ', $first); - $first = str_replace('', '', $first); - $first = str_replace('', '', $first); - - $secondTitle = $codeBlocks->item(1)->getAttribute('title'); - $second = trim($codeBlocks->item(1)->nodeValue); - $second = str_replace('', $second); - $second = str_replace(' ', ' ', $second); - $second = str_replace('', '', $second); - $second = str_replace('', '', $second); - - echo ' '.PHP_EOL; - echo ' '.PHP_EOL; - echo " ".PHP_EOL; - echo " ".PHP_EOL; - echo ' '.PHP_EOL; - echo ' '.PHP_EOL; - echo " ".PHP_EOL; - echo " ".PHP_EOL; - echo ' '.PHP_EOL; - echo '
$firstTitle$secondTitle
$first$second
'.PHP_EOL; - - }//end printCodeComparisonBlock() - - -}//end class diff --git a/phpcs/CodeSniffer/DocGenerators/Markdown.php b/phpcs/CodeSniffer/DocGenerators/Markdown.php deleted file mode 100644 index f6455b7..0000000 --- a/phpcs/CodeSniffer/DocGenerators/Markdown.php +++ /dev/null @@ -1,179 +0,0 @@ - - * @copyright 2014 Arroba IT - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_DocGenerators_Generator', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_DocGenerators_Generator not found'); -} - -/** - * A doc generator that outputs documentation in Markdown format. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Stefano Kowalke - * @copyright 2014 Arroba IT - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_DocGenerators_Markdown extends PHP_CodeSniffer_DocGenerators_Generator -{ - - - /** - * Generates the documentation for a standard. - * - * @return void - * @see processSniff() - */ - public function generate() - { - ob_start(); - $this->printHeader(); - - $standardFiles = $this->getStandardFiles(); - - foreach ($standardFiles as $standard) { - $doc = new DOMDocument(); - $doc->load($standard); - $documentation = $doc->getElementsByTagName('documentation')->item(0); - $this->processSniff($documentation); - } - - $this->printFooter(); - $content = ob_get_contents(); - ob_end_clean(); - - echo $content; - - }//end generate() - - - /** - * Print the markdown header. - * - * @return void - */ - protected function printHeader() - { - $standard = $this->getStandard(); - - echo "# $standard Coding Standard".PHP_EOL; - - }//end printHeader() - - - /** - * Print the markdown footer. - * - * @return void - */ - protected function printFooter() - { - // Turn off errors so we don't get timezone warnings if people - // don't have their timezone set. - error_reporting(0); - echo 'Documentation generated on '.date('r'); - echo ' by [PHP_CodeSniffer '.PHP_CodeSniffer::VERSION.'](https://github.com/squizlabs/PHP_CodeSniffer)'; - - }//end printFooter() - - - /** - * Process the documentation for a single sniff. - * - * @param DOMNode $doc The DOMNode object for the sniff. - * It represents the "documentation" tag in the XML - * standard file. - * - * @return void - */ - protected function processSniff(DOMNode $doc) - { - $title = $this->getTitle($doc); - echo "## $title".PHP_EOL; - - foreach ($doc->childNodes as $node) { - if ($node->nodeName === 'standard') { - $this->printTextBlock($node); - } else if ($node->nodeName === 'code_comparison') { - $this->printCodeComparisonBlock($node); - } - } - - }//end processSniff() - - - /** - * Print a text block found in a standard. - * - * @param DOMNode $node The DOMNode object for the text block. - * - * @return void - */ - protected function printTextBlock(DOMNode $node) - { - $content = trim($node->nodeValue); - $content = htmlspecialchars($content); - - $content = str_replace('<em>', '*', $content); - $content = str_replace('</em>', '*', $content); - - echo $content.PHP_EOL; - - }//end printTextBlock() - - - /** - * Print a code comparison block found in a standard. - * - * @param DOMNode $node The DOMNode object for the code comparison block. - * - * @return void - */ - protected function printCodeComparisonBlock(DOMNode $node) - { - $codeBlocks = $node->getElementsByTagName('code'); - - $firstTitle = $codeBlocks->item(0)->getAttribute('title'); - $first = trim($codeBlocks->item(0)->nodeValue); - $first = str_replace("\n", "\n ", $first); - $first = str_replace('', '', $first); - $first = str_replace('', '', $first); - - $secondTitle = $codeBlocks->item(1)->getAttribute('title'); - $second = trim($codeBlocks->item(1)->nodeValue); - $second = str_replace("\n", "\n ", $second); - $second = str_replace('', '', $second); - $second = str_replace('', '', $second); - - echo ' '.PHP_EOL; - echo ' '.PHP_EOL; - echo " ".PHP_EOL; - echo " ".PHP_EOL; - echo ' '.PHP_EOL; - echo ' '.PHP_EOL; - echo ''.PHP_EOL; - echo ''.PHP_EOL; - echo ' '.PHP_EOL; - echo '
$firstTitle$secondTitle
'.PHP_EOL.PHP_EOL; - echo " $first".PHP_EOL.PHP_EOL; - echo ''.PHP_EOL.PHP_EOL; - echo " $second".PHP_EOL.PHP_EOL; - echo '
'.PHP_EOL; - - }//end printCodeComparisonBlock() - - -}//end class diff --git a/phpcs/CodeSniffer/DocGenerators/Text.php b/phpcs/CodeSniffer/DocGenerators/Text.php deleted file mode 100644 index 5a761ed..0000000 --- a/phpcs/CodeSniffer/DocGenerators/Text.php +++ /dev/null @@ -1,265 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_DocGenerators_Generator', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_DocGenerators_Generator not found'); -} - -/** - * A doc generator that outputs text-based documentation. - * - * Output is designed to be displayed in a terminal and is wrapped to 100 characters. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_DocGenerators_Text extends PHP_CodeSniffer_DocGenerators_Generator -{ - - - /** - * Process the documentation for a single sniff. - * - * @param DOMNode $doc The DOMNode object for the sniff. - * It represents the "documentation" tag in the XML - * standard file. - * - * @return void - */ - public function processSniff(DOMNode $doc) - { - $this->printTitle($doc); - - foreach ($doc->childNodes as $node) { - if ($node->nodeName === 'standard') { - $this->printTextBlock($node); - } else if ($node->nodeName === 'code_comparison') { - $this->printCodeComparisonBlock($node); - } - } - - }//end processSniff() - - - /** - * Prints the title area for a single sniff. - * - * @param DOMNode $doc The DOMNode object for the sniff. - * It represents the "documentation" tag in the XML - * standard file. - * - * @return void - */ - protected function printTitle(DOMNode $doc) - { - $title = $this->getTitle($doc); - $standard = $this->getStandard(); - - echo PHP_EOL; - echo str_repeat('-', (strlen("$standard CODING STANDARD: $title") + 4)); - echo strtoupper(PHP_EOL."| $standard CODING STANDARD: $title |".PHP_EOL); - echo str_repeat('-', (strlen("$standard CODING STANDARD: $title") + 4)); - echo PHP_EOL.PHP_EOL; - - }//end printTitle() - - - /** - * Print a text block found in a standard. - * - * @param DOMNode $node The DOMNode object for the text block. - * - * @return void - */ - protected function printTextBlock($node) - { - $text = trim($node->nodeValue); - $text = str_replace('', '*', $text); - $text = str_replace('', '*', $text); - - $lines = array(); - $tempLine = ''; - $words = explode(' ', $text); - - foreach ($words as $word) { - if (strlen($tempLine.$word) >= 99) { - if (strlen($tempLine.$word) === 99) { - // Adding the extra space will push us to the edge - // so we are done. - $lines[] = $tempLine.$word; - $tempLine = ''; - } else if (strlen($tempLine.$word) === 100) { - // We are already at the edge, so we are done. - $lines[] = $tempLine.$word; - $tempLine = ''; - } else { - $lines[] = rtrim($tempLine); - $tempLine = $word.' '; - } - } else { - $tempLine .= $word.' '; - } - }//end foreach - - if ($tempLine !== '') { - $lines[] = rtrim($tempLine); - } - - echo implode(PHP_EOL, $lines).PHP_EOL.PHP_EOL; - - }//end printTextBlock() - - - /** - * Print a code comparison block found in a standard. - * - * @param DOMNode $node The DOMNode object for the code comparison block. - * - * @return void - */ - protected function printCodeComparisonBlock($node) - { - $codeBlocks = $node->getElementsByTagName('code'); - $first = trim($codeBlocks->item(0)->nodeValue); - $firstTitle = $codeBlocks->item(0)->getAttribute('title'); - - $firstTitleLines = array(); - $tempTitle = ''; - $words = explode(' ', $firstTitle); - - foreach ($words as $word) { - if (strlen($tempTitle.$word) >= 45) { - if (strlen($tempTitle.$word) === 45) { - // Adding the extra space will push us to the edge - // so we are done. - $firstTitleLines[] = $tempTitle.$word; - $tempTitle = ''; - } else if (strlen($tempTitle.$word) === 46) { - // We are already at the edge, so we are done. - $firstTitleLines[] = $tempTitle.$word; - $tempTitle = ''; - } else { - $firstTitleLines[] = $tempTitle; - $tempTitle = $word; - } - } else { - $tempTitle .= $word.' '; - } - }//end foreach - - if ($tempTitle !== '') { - $firstTitleLines[] = $tempTitle; - } - - $first = str_replace('', '', $first); - $first = str_replace('', '', $first); - $firstLines = explode("\n", $first); - - $second = trim($codeBlocks->item(1)->nodeValue); - $secondTitle = $codeBlocks->item(1)->getAttribute('title'); - - $secondTitleLines = array(); - $tempTitle = ''; - $words = explode(' ', $secondTitle); - - foreach ($words as $word) { - if (strlen($tempTitle.$word) >= 45) { - if (strlen($tempTitle.$word) === 45) { - // Adding the extra space will push us to the edge - // so we are done. - $secondTitleLines[] = $tempTitle.$word; - $tempTitle = ''; - } else if (strlen($tempTitle.$word) === 46) { - // We are already at the edge, so we are done. - $secondTitleLines[] = $tempTitle.$word; - $tempTitle = ''; - } else { - $secondTitleLines[] = $tempTitle; - $tempTitle = $word; - } - } else { - $tempTitle .= $word.' '; - } - }//end foreach - - if ($tempTitle !== '') { - $secondTitleLines[] = $tempTitle; - } - - $second = str_replace('', '', $second); - $second = str_replace('', '', $second); - $secondLines = explode("\n", $second); - - $maxCodeLines = max(count($firstLines), count($secondLines)); - $maxTitleLines = max(count($firstTitleLines), count($secondTitleLines)); - - echo str_repeat('-', 41); - echo ' CODE COMPARISON '; - echo str_repeat('-', 42).PHP_EOL; - - for ($i = 0; $i < $maxTitleLines; $i++) { - if (isset($firstTitleLines[$i]) === true) { - $firstLineText = $firstTitleLines[$i]; - } else { - $firstLineText = ''; - } - - if (isset($secondTitleLines[$i]) === true) { - $secondLineText = $secondTitleLines[$i]; - } else { - $secondLineText = ''; - } - - echo '| '; - echo $firstLineText.str_repeat(' ', (46 - strlen($firstLineText))); - echo ' | '; - echo $secondLineText.str_repeat(' ', (47 - strlen($secondLineText))); - echo ' |'.PHP_EOL; - }//end for - - echo str_repeat('-', 100).PHP_EOL; - - for ($i = 0; $i < $maxCodeLines; $i++) { - if (isset($firstLines[$i]) === true) { - $firstLineText = $firstLines[$i]; - } else { - $firstLineText = ''; - } - - if (isset($secondLines[$i]) === true) { - $secondLineText = $secondLines[$i]; - } else { - $secondLineText = ''; - } - - echo '| '; - echo $firstLineText.str_repeat(' ', (47 - strlen($firstLineText))); - echo '| '; - echo $secondLineText.str_repeat(' ', (48 - strlen($secondLineText))); - echo '|'.PHP_EOL; - }//end for - - echo str_repeat('-', 100).PHP_EOL.PHP_EOL; - - }//end printCodeComparisonBlock() - - -}//end class diff --git a/phpcs/CodeSniffer/Exception.php b/phpcs/CodeSniffer/Exception.php deleted file mode 100644 index 9b5fb7a..0000000 --- a/phpcs/CodeSniffer/Exception.php +++ /dev/null @@ -1,31 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * An exception thrown by PHP_CodeSniffer when it encounters an unrecoverable error. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Exception extends Exception -{ - -}//end class diff --git a/phpcs/CodeSniffer/File.php b/phpcs/CodeSniffer/File.php deleted file mode 100644 index 0a17fa3..0000000 --- a/phpcs/CodeSniffer/File.php +++ /dev/null @@ -1,3809 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * A PHP_CodeSniffer_File object represents a PHP source file and the tokens - * associated with it. - * - * It provides a means for traversing the token stack, along with - * other token related operations. If a PHP_CodeSniffer_Sniff finds and error or - * warning within a PHP_CodeSniffer_File, you can raise an error using the - * addError() or addWarning() methods. - * - * Token Information - * - * Each token within the stack contains information about itself: - * - * - * array( - * 'code' => 301, // the token type code (see token_get_all()) - * 'content' => 'if', // the token content - * 'type' => 'T_IF', // the token name - * 'line' => 56, // the line number when the token is located - * 'column' => 12, // the column in the line where this token - * // starts (starts from 1) - * 'level' => 2 // the depth a token is within the scopes open - * 'conditions' => array( // a list of scope condition token - * // positions => codes that - * 2 => 50, // opened the scopes that this token exists - * 9 => 353, // in (see conditional tokens section below) - * ), - * ); - * - * - * Conditional Tokens - * - * In addition to the standard token fields, conditions contain information to - * determine where their scope begins and ends: - * - * - * array( - * 'scope_condition' => 38, // the token position of the condition - * 'scope_opener' => 41, // the token position that started the scope - * 'scope_closer' => 70, // the token position that ended the scope - * ); - * - * - * The condition, the scope opener and the scope closer each contain this - * information. - * - * Parenthesis Tokens - * - * Each parenthesis token (T_OPEN_PARENTHESIS and T_CLOSE_PARENTHESIS) has a - * reference to their opening and closing parenthesis, one being itself, the - * other being its opposite. - * - * - * array( - * 'parenthesis_opener' => 34, - * 'parenthesis_closer' => 40, - * ); - * - * - * Some tokens can "own" a set of parenthesis. For example a T_FUNCTION token - * has parenthesis around its argument list. These tokens also have the - * parenthesis_opener and and parenthesis_closer indices. Not all parenthesis - * have owners, for example parenthesis used for arithmetic operations and - * function calls. The parenthesis tokens that have an owner have the following - * auxiliary array indices. - * - * - * array( - * 'parenthesis_opener' => 34, - * 'parenthesis_closer' => 40, - * 'parenthesis_owner' => 33, - * ); - * - * - * Each token within a set of parenthesis also has an array index - * 'nested_parenthesis' which is an array of the - * left parenthesis => right parenthesis token positions. - * - * - * 'nested_parenthesis' => array( - * 12 => 15 - * 11 => 14 - * ); - * - * - * Extended Tokens - * - * PHP_CodeSniffer extends and augments some of the tokens created by - * token_get_all(). A full list of these tokens can be seen in the - * Tokens.php file. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_File -{ - - /** - * The absolute path to the file associated with this object. - * - * @var string - */ - private $_file = ''; - - /** - * The EOL character this file uses. - * - * @var string - */ - public $eolChar = ''; - - /** - * The PHP_CodeSniffer object controlling this run. - * - * @var PHP_CodeSniffer - */ - public $phpcs = null; - - /** - * The Fixer object to control fixing errors. - * - * @var PHP_CodeSniffer_Fixer - */ - public $fixer = null; - - /** - * The tokenizer being used for this file. - * - * @var object - */ - public $tokenizer = null; - - /** - * The tokenizer being used for this file. - * - * @var string - */ - public $tokenizerType = 'PHP'; - - /** - * The number of tokens in this file. - * - * Stored here to save calling count() everywhere. - * - * @var int - */ - public $numTokens = 0; - - /** - * The tokens stack map. - * - * Note that the tokens in this array differ in format to the tokens - * produced by token_get_all(). Tokens are initially produced with - * token_get_all(), then augmented so that it's easier to process them. - * - * @var array() - * @see Tokens.php - */ - private $_tokens = array(); - - /** - * The errors raised from PHP_CodeSniffer_Sniffs. - * - * @var array() - * @see getErrors() - */ - private $_errors = array(); - - /** - * The warnings raised from PHP_CodeSniffer_Sniffs. - * - * @var array() - * @see getWarnings() - */ - private $_warnings = array(); - - /** - * The metrics recorded from PHP_CodeSniffer_Sniffs. - * - * @var array() - * @see getMetrics() - */ - private $_metrics = array(); - - /** - * Record the errors and warnings raised. - * - * @var bool - */ - private $_recordErrors = true; - - /** - * An array of lines that are being ignored. - * - * @var array() - */ - private static $_ignoredLines = array(); - - /** - * An array of sniffs that are being ignored. - * - * @var array() - */ - private $_ignoredListeners = array(); - - /** - * An array of message codes that are being ignored. - * - * @var array() - */ - private $_ignoredCodes = array(); - - /** - * The total number of errors raised. - * - * @var int - */ - private $_errorCount = 0; - - /** - * The total number of warnings raised. - * - * @var int - */ - private $_warningCount = 0; - - /** - * The total number of errors/warnings that can be fixed. - * - * @var int - */ - private $_fixableCount = 0; - - /** - * An array of sniffs listening to this file's processing. - * - * @var array(PHP_CodeSniffer_Sniff) - */ - private $_listeners = array(); - - /** - * The class name of the sniff currently processing the file. - * - * @var string - */ - private $_activeListener = ''; - - /** - * An array of sniffs being processed and how long they took. - * - * @var array() - */ - private $_listenerTimes = array(); - - /** - * An array of rules from the ruleset.xml file. - * - * This value gets set by PHP_CodeSniffer when the object is created. - * It may be empty, indicating that the ruleset does not override - * any of the default sniff settings. - * - * @var array - */ - protected $ruleset = array(); - - - /** - * Constructs a PHP_CodeSniffer_File. - * - * @param string $file The absolute path to the file to process. - * @param array(string) $listeners The initial listeners listening to processing of this file. - * to processing of this file. - * @param array $ruleset An array of rules from the ruleset.xml file. - * ruleset.xml file. - * @param PHP_CodeSniffer $phpcs The PHP_CodeSniffer object controlling this run. - * this run. - * - * @throws PHP_CodeSniffer_Exception If the register() method does - * not return an array. - */ - public function __construct( - $file, - array $listeners, - array $ruleset, - PHP_CodeSniffer $phpcs - ) { - $this->_file = trim($file); - $this->_listeners = $listeners; - $this->ruleset = $ruleset; - $this->phpcs = $phpcs; - $this->fixer = new PHP_CodeSniffer_Fixer(); - - if (PHP_CODESNIFFER_INTERACTIVE === false) { - $cliValues = $phpcs->cli->getCommandLineValues(); - if (isset($cliValues['showSources']) === true - && $cliValues['showSources'] !== true - ) { - $recordErrors = false; - foreach ($cliValues['reports'] as $report => $output) { - $reportClass = $phpcs->reporting->factory($report); - if (property_exists($reportClass, 'recordErrors') === false - || $reportClass->recordErrors === true - ) { - $recordErrors = true; - break; - } - } - - $this->_recordErrors = $recordErrors; - } - } - - }//end __construct() - - - /** - * Sets the name of the currently active sniff. - * - * @param string $activeListener The class name of the current sniff. - * - * @return void - */ - public function setActiveListener($activeListener) - { - $this->_activeListener = $activeListener; - - }//end setActiveListener() - - - /** - * Adds a listener to the token stack that listens to the specific tokens. - * - * When PHP_CodeSniffer encounters on the the tokens specified in $tokens, - * it invokes the process method of the sniff. - * - * @param PHP_CodeSniffer_Sniff $listener The listener to add to the - * listener stack. - * @param array(int) $tokens The token types the listener wishes to - * listen to. - * - * @return void - */ - public function addTokenListener(PHP_CodeSniffer_Sniff $listener, array $tokens) - { - $class = get_class($listener); - foreach ($tokens as $token) { - if (isset($this->_listeners[$token]) === false) { - $this->_listeners[$token] = array(); - } - - if (isset($this->_listeners[$token][$class]) === false) { - $this->_listeners[$token][$class] = $listener; - } - } - - }//end addTokenListener() - - - /** - * Removes a listener from listening from the specified tokens. - * - * @param PHP_CodeSniffer_Sniff $listener The listener to remove from the - * listener stack. - * @param array(int) $tokens The token types the listener wishes to - * stop listen to. - * - * @return void - */ - public function removeTokenListener( - PHP_CodeSniffer_Sniff $listener, - array $tokens - ) { - $class = get_class($listener); - foreach ($tokens as $token) { - if (isset($this->_listeners[$token]) === false) { - continue; - } - - unset($this->_listeners[$token][$class]); - } - - }//end removeTokenListener() - - - /** - * Rebuilds the list of listeners to ensure their state is cleared. - * - * @return void - */ - public function refreshTokenListeners() - { - $this->phpcs->populateTokenListeners(); - $this->_listeners = $this->phpcs->getTokenSniffs(); - - }//end refreshTokenListeners() - - - /** - * Returns the token stack for this file. - * - * @return array - */ - public function getTokens() - { - return $this->_tokens; - - }//end getTokens() - - - /** - * Starts the stack traversal and tells listeners when tokens are found. - * - * @param string $contents The contents to parse. If NULL, the content - * is taken from the file system. - * - * @return void - */ - public function start($contents=null) - { - $this->_errors = array(); - $this->_warnings = array(); - $this->_errorCount = 0; - $this->_warningCount = 0; - $this->_fixableCount = 0; - - // Reset the ignored lines because lines numbers may have changed - // if we are fixing this file. - self::$_ignoredLines = array(); - - try { - $this->eolChar = self::detectLineEndings($this->_file, $contents); - } catch (PHP_CodeSniffer_Exception $e) { - $this->addWarning($e->getMessage(), null, 'Internal.DetectLineEndings'); - return; - } - - // If this is standard input, see if a filename was passed in as well. - // This is done by including: phpcs_input_file: [file path] - // as the first line of content. - if ($this->_file === 'STDIN') { - $cliValues = $this->phpcs->cli->getCommandLineValues(); - if ($cliValues['stdinPath'] !== '') { - $this->_file = $cliValues['stdinPath']; - } else if ($contents !== null && substr($contents, 0, 17) === 'phpcs_input_file:') { - $eolPos = strpos($contents, $this->eolChar); - $filename = trim(substr($contents, 17, ($eolPos - 17))); - $contents = substr($contents, ($eolPos + strlen($this->eolChar))); - $this->_file = $filename; - } - } - - $this->_parse($contents); - $this->fixer->startFile($this); - - if (PHP_CODESNIFFER_VERBOSITY > 2) { - echo "\t*** START TOKEN PROCESSING ***".PHP_EOL; - } - - $foundCode = false; - $listeners = $this->phpcs->getSniffs(); - $listenerIgnoreTo = array(); - $inTests = defined('PHP_CODESNIFFER_IN_TESTS'); - - // Foreach of the listeners that have registered to listen for this - // token, get them to process it. - foreach ($this->_tokens as $stackPtr => $token) { - // Check for ignored lines. - if ($token['code'] === T_COMMENT - || $token['code'] === T_DOC_COMMENT_TAG - || ($inTests === true && $token['code'] === T_INLINE_HTML) - ) { - if (strpos($token['content'], '@codingStandards') !== false) { - if (strpos($token['content'], '@codingStandardsIgnoreFile') !== false) { - // Ignoring the whole file, just a little late. - $this->_errors = array(); - $this->_warnings = array(); - $this->_errorCount = 0; - $this->_warningCount = 0; - $this->_fixableCount = 0; - return; - } else if (strpos($token['content'], '@codingStandardsChangeSetting') !== false) { - $start = strpos($token['content'], '@codingStandardsChangeSetting'); - $comment = substr($token['content'], ($start + 30)); - $parts = explode(' ', $comment); - if (count($parts) >= 3 - && isset($this->phpcs->sniffCodes[$parts[0]]) === true - ) { - $listenerCode = array_shift($parts); - $propertyCode = array_shift($parts); - $propertyValue = rtrim(implode(' ', $parts), " */\r\n"); - $listenerClass = $this->phpcs->sniffCodes[$listenerCode]; - $this->phpcs->setSniffProperty($listenerClass, $propertyCode, $propertyValue); - } - }//end if - }//end if - }//end if - - if (PHP_CODESNIFFER_VERBOSITY > 2) { - $type = $token['type']; - $content = PHP_CodeSniffer::prepareForOutput($token['content']); - echo "\t\tProcess token $stackPtr: $type => $content".PHP_EOL; - } - - if ($token['code'] !== T_INLINE_HTML) { - $foundCode = true; - } - - if (isset($this->_listeners[$token['code']]) === false) { - continue; - } - - foreach ($this->_listeners[$token['code']] as $listenerData) { - if (isset($this->_ignoredListeners[$listenerData['class']]) === true - || (isset($listenerIgnoreTo[$listenerData['class']]) === true - && $listenerIgnoreTo[$listenerData['class']] > $stackPtr) - ) { - // This sniff is ignoring past this token, or the whole file. - continue; - } - - // Make sure this sniff supports the tokenizer - // we are currently using. - $class = $listenerData['class']; - - if (isset($listenerData['tokenizers'][$this->tokenizerType]) === false) { - continue; - } - - // If the file path matches one of our ignore patterns, skip it. - // While there is support for a type of each pattern - // (absolute or relative) we don't actually support it here. - foreach ($listenerData['ignore'] as $pattern) { - // We assume a / directory separator, as do the exclude rules - // most developers write, so we need a special case for any system - // that is different. - if (DIRECTORY_SEPARATOR === '\\') { - $pattern = str_replace('/', '\\\\', $pattern); - } - - $pattern = '`'.$pattern.'`i'; - if (preg_match($pattern, $this->_file) === 1) { - $this->_ignoredListeners[$class] = true; - continue(2); - } - } - - $this->_activeListener = $class; - - if (PHP_CODESNIFFER_VERBOSITY > 2) { - $startTime = microtime(true); - echo "\t\t\tProcessing ".$this->_activeListener.'... '; - } - - $ignoreTo = $listeners[$class]->process($this, $stackPtr); - if ($ignoreTo !== null) { - $listenerIgnoreTo[$this->_activeListener] = $ignoreTo; - } - - if (PHP_CODESNIFFER_VERBOSITY > 2) { - $timeTaken = (microtime(true) - $startTime); - if (isset($this->_listenerTimes[$this->_activeListener]) === false) { - $this->_listenerTimes[$this->_activeListener] = 0; - } - - $this->_listenerTimes[$this->_activeListener] += $timeTaken; - - $timeTaken = round(($timeTaken), 4); - echo "DONE in $timeTaken seconds".PHP_EOL; - } - - $this->_activeListener = ''; - }//end foreach - }//end foreach - - if ($this->_recordErrors === false) { - $this->_errors = array(); - $this->_warnings = array(); - } - - // If short open tags are off but the file being checked uses - // short open tags, the whole content will be inline HTML - // and nothing will be checked. So try and handle this case. - // We don't show this error for STDIN because we can't be sure the content - // actually came directly from the user. It could be something like - // refs from a Git pre-push hook. - if ($foundCode === false && $this->tokenizerType === 'PHP' && $this->_file !== 'STDIN') { - $shortTags = (bool) ini_get('short_open_tag'); - if ($shortTags === false) { - $error = 'No PHP code was found in this file and short open tags are not allowed by this install of PHP. This file may be using short open tags but PHP does not allow them.'; - $this->addWarning($error, null, 'Internal.NoCodeFound'); - } - } - - if (PHP_CODESNIFFER_VERBOSITY > 2) { - echo "\t*** END TOKEN PROCESSING ***".PHP_EOL; - echo "\t*** START SNIFF PROCESSING REPORT ***".PHP_EOL; - - asort($this->_listenerTimes, SORT_NUMERIC); - $this->_listenerTimes = array_reverse($this->_listenerTimes, true); - foreach ($this->_listenerTimes as $listener => $timeTaken) { - echo "\t$listener: ".round(($timeTaken), 4).' secs'.PHP_EOL; - } - - echo "\t*** END SNIFF PROCESSING REPORT ***".PHP_EOL; - } - - }//end start() - - - /** - * Remove vars stored in this file that are no longer required. - * - * @return void - */ - public function cleanUp() - { - $this->_tokens = null; - $this->_listeners = null; - - }//end cleanUp() - - - /** - * Tokenizes the file and prepares it for the test run. - * - * @param string $contents The contents to parse. If NULL, the content - * is taken from the file system. - * - * @return void - */ - private function _parse($contents=null) - { - if ($contents === null && empty($this->_tokens) === false) { - // File has already been parsed. - return; - } - - $stdin = false; - $cliValues = $this->phpcs->cli->getCommandLineValues(); - if (empty($cliValues['files']) === true) { - $stdin = true; - } - - // Determine the tokenizer from the file extension. - $fileParts = explode('.', $this->_file); - $extension = array_pop($fileParts); - if (isset($this->phpcs->allowedFileExtensions[$extension]) === true) { - $tokenizerClass = 'PHP_CodeSniffer_Tokenizers_'.$this->phpcs->allowedFileExtensions[$extension]; - $this->tokenizerType = $this->phpcs->allowedFileExtensions[$extension]; - } else if (isset($this->phpcs->defaultFileExtensions[$extension]) === true) { - $tokenizerClass = 'PHP_CodeSniffer_Tokenizers_'.$this->phpcs->defaultFileExtensions[$extension]; - $this->tokenizerType = $this->phpcs->defaultFileExtensions[$extension]; - } else { - // Revert to default. - $tokenizerClass = 'PHP_CodeSniffer_Tokenizers_'.$this->tokenizerType; - } - - $tokenizer = new $tokenizerClass(); - $this->tokenizer = $tokenizer; - - if ($contents === null) { - $contents = file_get_contents($this->_file); - } - - try { - $tabWidth = null; - $encoding = null; - if (defined('PHP_CODESNIFFER_IN_TESTS') === true) { - $cliValues = $this->phpcs->cli->getCommandLineValues(); - if (isset($cliValues['tabWidth']) === true) { - $tabWidth = $cliValues['tabWidth']; - } - - if (isset($cliValues['encoding']) === true) { - $encoding = $cliValues['encoding']; - } - } - - $this->_tokens = self::tokenizeString($contents, $tokenizer, $this->eolChar, $tabWidth, $encoding); - } catch (PHP_CodeSniffer_Exception $e) { - $this->addWarning($e->getMessage(), null, 'Internal.Tokenizer.Exception'); - if (PHP_CODESNIFFER_VERBOSITY > 0 || (PHP_CODESNIFFER_CBF === true && $stdin === false)) { - echo "[$this->tokenizerType => tokenizer error]... "; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo PHP_EOL; - } - } - - return; - }//end try - - $this->numTokens = count($this->_tokens); - - // Check for mixed line endings as these can cause tokenizer errors and we - // should let the user know that the results they get may be incorrect. - // This is done by removing all backslashes, removing the newline char we - // detected, then converting newlines chars into text. If any backslashes - // are left at the end, we have additional newline chars in use. - $contents = str_replace('\\', '', $contents); - $contents = str_replace($this->eolChar, '', $contents); - $contents = str_replace("\n", '\n', $contents); - $contents = str_replace("\r", '\r', $contents); - if (strpos($contents, '\\') !== false) { - $error = 'File has mixed line endings; this may cause incorrect results'; - $this->addWarning($error, 0, 'Internal.LineEndings.Mixed'); - } - - if (PHP_CODESNIFFER_VERBOSITY > 0 || (PHP_CODESNIFFER_CBF === true && $stdin === false)) { - if ($this->numTokens === 0) { - $numLines = 0; - } else { - $numLines = $this->_tokens[($this->numTokens - 1)]['line']; - } - - echo "[$this->tokenizerType => $this->numTokens tokens in $numLines lines]... "; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo PHP_EOL; - } - } - - }//end _parse() - - - /** - * Opens a file and detects the EOL character being used. - * - * @param string $file The full path to the file. - * @param string $contents The contents to parse. If NULL, the content - * is taken from the file system. - * - * @return string - * @throws PHP_CodeSniffer_Exception If $file could not be opened. - */ - public static function detectLineEndings($file, $contents=null) - { - if ($contents === null) { - // Determine the newline character being used in this file. - // Will be either \r, \r\n or \n. - if (is_readable($file) === false) { - $error = 'Error opening file; file no longer exists or you do not have access to read the file'; - throw new PHP_CodeSniffer_Exception($error); - } else { - $handle = fopen($file, 'r'); - if ($handle === false) { - $error = 'Error opening file; could not auto-detect line endings'; - throw new PHP_CodeSniffer_Exception($error); - } - } - - $firstLine = fgets($handle); - fclose($handle); - - $eolChar = substr($firstLine, -1); - if ($eolChar === "\n") { - $secondLastChar = substr($firstLine, -2, 1); - if ($secondLastChar === "\r") { - $eolChar = "\r\n"; - } - } else if ($eolChar !== "\r") { - // Must not be an EOL char at the end of the line. - // Probably a one-line file, so assume \n as it really - // doesn't matter considering there are no newlines. - $eolChar = "\n"; - } - } else { - if (preg_match("/\r\n?|\n/", $contents, $matches) !== 1) { - // Assuming there are no newlines. - $eolChar = "\n"; - } else { - $eolChar = $matches[0]; - } - }//end if - - return $eolChar; - - }//end detectLineEndings() - - - /** - * Records an error against a specific token in the file. - * - * @param string $error The error message. - * @param int $stackPtr The stack position where the error occurred. - * @param string $code A violation code unique to the sniff message. - * @param array $data Replacements for the error message. - * @param int $severity The severity level for this error. A value of 0 - * will be converted into the default severity level. - * @param boolean $fixable Can the error be fixed by the sniff? - * - * @return boolean - */ - public function addError( - $error, - $stackPtr, - $code='', - $data=array(), - $severity=0, - $fixable=false - ) { - if ($stackPtr === null) { - $line = 1; - $column = 1; - } else { - $line = $this->_tokens[$stackPtr]['line']; - $column = $this->_tokens[$stackPtr]['column']; - } - - return $this->_addError($error, $line, $column, $code, $data, $severity, $fixable); - - }//end addError() - - - /** - * Records a warning against a specific token in the file. - * - * @param string $warning The error message. - * @param int $stackPtr The stack position where the error occurred. - * @param string $code A violation code unique to the sniff message. - * @param array $data Replacements for the warning message. - * @param int $severity The severity level for this warning. A value of 0 - * will be converted into the default severity level. - * @param boolean $fixable Can the warning be fixed by the sniff? - * - * @return boolean - */ - public function addWarning( - $warning, - $stackPtr, - $code='', - $data=array(), - $severity=0, - $fixable=false - ) { - if ($stackPtr === null) { - $line = 1; - $column = 1; - } else { - $line = $this->_tokens[$stackPtr]['line']; - $column = $this->_tokens[$stackPtr]['column']; - } - - return $this->_addWarning($warning, $line, $column, $code, $data, $severity, $fixable); - - }//end addWarning() - - - /** - * Records an error against a specific line in the file. - * - * @param string $error The error message. - * @param int $line The line on which the error occurred. - * @param string $code A violation code unique to the sniff message. - * @param array $data Replacements for the error message. - * @param int $severity The severity level for this error. A value of 0 - * will be converted into the default severity level. - * - * @return boolean - */ - public function addErrorOnLine( - $error, - $line, - $code='', - $data=array(), - $severity=0 - ) { - return $this->_addError($error, $line, 1, $code, $data, $severity, false); - - }//end addErrorOnLine() - - - /** - * Records a warning against a specific token in the file. - * - * @param string $warning The error message. - * @param int $line The line on which the warning occurred. - * @param string $code A violation code unique to the sniff message. - * @param array $data Replacements for the warning message. - * @param int $severity The severity level for this warning. A value of 0 - * will be converted into the default severity level. - * - * @return boolean - */ - public function addWarningOnLine( - $warning, - $line, - $code='', - $data=array(), - $severity=0 - ) { - return $this->_addWarning($warning, $line, 1, $code, $data, $severity, false); - - }//end addWarningOnLine() - - - /** - * Records a fixable error against a specific token in the file. - * - * Returns true if the error was recorded and should be fixed. - * - * @param string $error The error message. - * @param int $stackPtr The stack position where the error occurred. - * @param string $code A violation code unique to the sniff message. - * @param array $data Replacements for the error message. - * @param int $severity The severity level for this error. A value of 0 - * will be converted into the default severity level. - * - * @return boolean - */ - public function addFixableError( - $error, - $stackPtr, - $code='', - $data=array(), - $severity=0 - ) { - $recorded = $this->addError($error, $stackPtr, $code, $data, $severity, true); - if ($recorded === true && $this->fixer->enabled === true) { - return true; - } - - return false; - - }//end addFixableError() - - - /** - * Records a fixable warning against a specific token in the file. - * - * Returns true if the warning was recorded and should be fixed. - * - * @param string $warning The error message. - * @param int $stackPtr The stack position where the error occurred. - * @param string $code A violation code unique to the sniff message. - * @param array $data Replacements for the warning message. - * @param int $severity The severity level for this warning. A value of 0 - * will be converted into the default severity level. - * - * @return boolean - */ - public function addFixableWarning( - $warning, - $stackPtr, - $code='', - $data=array(), - $severity=0 - ) { - $recorded = $this->addWarning($warning, $stackPtr, $code, $data, $severity, true); - if ($recorded === true && $this->fixer->enabled === true) { - return true; - } - - return false; - - }//end addFixableWarning() - - - /** - * Adds an error to the error stack. - * - * @param string $error The error message. - * @param int $line The line on which the error occurred. - * @param int $column The column at which the error occurred. - * @param string $code A violation code unique to the sniff message. - * @param array $data Replacements for the error message. - * @param int $severity The severity level for this error. A value of 0 - * will be converted into the default severity level. - * @param boolean $fixable Can the error be fixed by the sniff? - * - * @return boolean - */ - private function _addError($error, $line, $column, $code, $data, $severity, $fixable) - { - if (isset(self::$_ignoredLines[$line]) === true) { - return false; - } - - // Work out which sniff generated the error. - if (substr($code, 0, 9) === 'Internal.') { - // Any internal message. - $sniffCode = $code; - } else { - $parts = explode('_', str_replace('\\', '_', $this->_activeListener)); - if (isset($parts[3]) === true) { - $sniff = $parts[0].'.'.$parts[2].'.'.$parts[3]; - - // Remove "Sniff" from the end. - $sniff = substr($sniff, 0, -5); - } else { - $sniff = 'unknownSniff'; - } - - $sniffCode = $sniff; - if ($code !== '') { - $sniffCode .= '.'.$code; - } - }//end if - - // If we know this sniff code is being ignored for this file, return early. - if (isset($this->_ignoredCodes[$sniffCode]) === true) { - return false; - } - - // Make sure this message type has not been set to "warning". - if (isset($this->ruleset[$sniffCode]['type']) === true - && $this->ruleset[$sniffCode]['type'] === 'warning' - ) { - // Pass this off to the warning handler. - return $this->_addWarning($error, $line, $column, $code, $data, $severity, $fixable); - } else if ($this->phpcs->cli->errorSeverity === 0) { - // Don't bother doing any processing as errors are just going to - // be hidden in the reports anyway. - return false; - } - - // Make sure we are interested in this severity level. - if (isset($this->ruleset[$sniffCode]['severity']) === true) { - $severity = $this->ruleset[$sniffCode]['severity']; - } else if ($severity === 0) { - $severity = PHPCS_DEFAULT_ERROR_SEV; - } - - if ($this->phpcs->cli->errorSeverity > $severity) { - return false; - } - - // Make sure we are not ignoring this file. - $patterns = $this->phpcs->getIgnorePatterns($sniffCode); - foreach ($patterns as $pattern => $type) { - // While there is support for a type of each pattern - // (absolute or relative) we don't actually support it here. - $replacements = array( - '\\,' => ',', - '*' => '.*', - ); - - // We assume a / directory separator, as do the exclude rules - // most developers write, so we need a special case for any system - // that is different. - if (DIRECTORY_SEPARATOR === '\\') { - $replacements['/'] = '\\\\'; - } - - $pattern = '`'.strtr($pattern, $replacements).'`i'; - if (preg_match($pattern, $this->_file) === 1) { - $this->_ignoredCodes[$sniffCode] = true; - return false; - } - }//end foreach - - $this->_errorCount++; - if ($fixable === true) { - $this->_fixableCount++; - } - - if ($this->_recordErrors === false) { - if (isset($this->_errors[$line]) === false) { - $this->_errors[$line] = 0; - } - - $this->_errors[$line]++; - return true; - } - - // Work out the error message. - if (isset($this->ruleset[$sniffCode]['message']) === true) { - $error = $this->ruleset[$sniffCode]['message']; - } - - if (empty($data) === true) { - $message = $error; - } else { - $message = vsprintf($error, $data); - } - - if (isset($this->_errors[$line]) === false) { - $this->_errors[$line] = array(); - } - - if (isset($this->_errors[$line][$column]) === false) { - $this->_errors[$line][$column] = array(); - } - - $this->_errors[$line][$column][] = array( - 'message' => $message, - 'source' => $sniffCode, - 'severity' => $severity, - 'fixable' => $fixable, - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1 - && $this->fixer->enabled === true - && $fixable === true - ) { - @ob_end_clean(); - echo "\tE: [Line $line] $message ($sniffCode)".PHP_EOL; - ob_start(); - } - - return true; - - }//end _addError() - - - /** - * Adds an warning to the warning stack. - * - * @param string $warning The error message. - * @param int $line The line on which the warning occurred. - * @param int $column The column at which the warning occurred. - * @param string $code A violation code unique to the sniff message. - * @param array $data Replacements for the warning message. - * @param int $severity The severity level for this warning. A value of 0 - * will be converted into the default severity level. - * @param boolean $fixable Can the warning be fixed by the sniff? - * - * @return boolean - */ - private function _addWarning($warning, $line, $column, $code, $data, $severity, $fixable) - { - if (isset(self::$_ignoredLines[$line]) === true) { - return false; - } - - // Work out which sniff generated the warning. - if (substr($code, 0, 9) === 'Internal.') { - // Any internal message. - $sniffCode = $code; - } else { - $parts = explode('_', str_replace('\\', '_', $this->_activeListener)); - if (isset($parts[3]) === true) { - $sniff = $parts[0].'.'.$parts[2].'.'.$parts[3]; - - // Remove "Sniff" from the end. - $sniff = substr($sniff, 0, -5); - } else { - $sniff = 'unknownSniff'; - } - - $sniffCode = $sniff; - if ($code !== '') { - $sniffCode .= '.'.$code; - } - }//end if - - // If we know this sniff code is being ignored for this file, return early. - if (isset($this->_ignoredCodes[$sniffCode]) === true) { - return false; - } - - // Make sure this message type has not been set to "error". - if (isset($this->ruleset[$sniffCode]['type']) === true - && $this->ruleset[$sniffCode]['type'] === 'error' - ) { - // Pass this off to the error handler. - return $this->_addError($warning, $line, $column, $code, $data, $severity, $fixable); - } else if ($this->phpcs->cli->warningSeverity === 0) { - // Don't bother doing any processing as warnings are just going to - // be hidden in the reports anyway. - return false; - } - - // Make sure we are interested in this severity level. - if (isset($this->ruleset[$sniffCode]['severity']) === true) { - $severity = $this->ruleset[$sniffCode]['severity']; - } else if ($severity === 0) { - $severity = PHPCS_DEFAULT_WARN_SEV; - } - - if ($this->phpcs->cli->warningSeverity > $severity) { - return false; - } - - // Make sure we are not ignoring this file. - $patterns = $this->phpcs->getIgnorePatterns($sniffCode); - foreach ($patterns as $pattern => $type) { - // While there is support for a type of each pattern - // (absolute or relative) we don't actually support it here. - $replacements = array( - '\\,' => ',', - '*' => '.*', - ); - - // We assume a / directory separator, as do the exclude rules - // most developers write, so we need a special case for any system - // that is different. - if (DIRECTORY_SEPARATOR === '\\') { - $replacements['/'] = '\\\\'; - } - - $pattern = '`'.strtr($pattern, $replacements).'`i'; - if (preg_match($pattern, $this->_file) === 1) { - $this->_ignoredCodes[$sniffCode] = true; - return false; - } - }//end foreach - - $this->_warningCount++; - if ($fixable === true) { - $this->_fixableCount++; - } - - if ($this->_recordErrors === false) { - if (isset($this->_warnings[$line]) === false) { - $this->_warnings[$line] = 0; - } - - $this->_warnings[$line]++; - return true; - } - - // Work out the warning message. - if (isset($this->ruleset[$sniffCode]['message']) === true) { - $warning = $this->ruleset[$sniffCode]['message']; - } - - if (empty($data) === true) { - $message = $warning; - } else { - $message = vsprintf($warning, $data); - } - - if (isset($this->_warnings[$line]) === false) { - $this->_warnings[$line] = array(); - } - - if (isset($this->_warnings[$line][$column]) === false) { - $this->_warnings[$line][$column] = array(); - } - - $this->_warnings[$line][$column][] = array( - 'message' => $message, - 'source' => $sniffCode, - 'severity' => $severity, - 'fixable' => $fixable, - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1 - && $this->fixer->enabled === true - && $fixable === true - ) { - @ob_end_clean(); - echo "\tW: $message ($sniffCode)".PHP_EOL; - ob_start(); - } - - return true; - - }//end _addWarning() - - - /** - * Adds an warning to the warning stack. - * - * @param int $stackPtr The stack position where the metric was recorded. - * @param string $metric The name of the metric being recorded. - * @param string $value The value of the metric being recorded. - * - * @return boolean - */ - public function recordMetric($stackPtr, $metric, $value) - { - if (isset($this->_metrics[$metric]) === false) { - $this->_metrics[$metric] = array( - 'values' => array( - $value => array($stackPtr), - ), - ); - } else { - if (isset($this->_metrics[$metric]['values'][$value]) === false) { - $this->_metrics[$metric]['values'][$value] = array($stackPtr); - } else { - $this->_metrics[$metric]['values'][$value][] = $stackPtr; - } - } - - return true; - - }//end recordMetric() - - - /** - * Returns the number of errors raised. - * - * @return int - */ - public function getErrorCount() - { - return $this->_errorCount; - - }//end getErrorCount() - - - /** - * Returns the number of warnings raised. - * - * @return int - */ - public function getWarningCount() - { - return $this->_warningCount; - - }//end getWarningCount() - - - /** - * Returns the number of successes recorded. - * - * @return int - */ - public function getSuccessCount() - { - return $this->_successCount; - - }//end getSuccessCount() - - - /** - * Returns the number of fixable errors/warnings raised. - * - * @return int - */ - public function getFixableCount() - { - return $this->_fixableCount; - - }//end getFixableCount() - - - /** - * Returns the list of ignored lines. - * - * @return array - */ - public function getIgnoredLines() - { - return self::$_ignoredLines; - - }//end getIgnoredLines() - - - /** - * Returns the errors raised from processing this file. - * - * @return array - */ - public function getErrors() - { - return $this->_errors; - - }//end getErrors() - - - /** - * Returns the warnings raised from processing this file. - * - * @return array - */ - public function getWarnings() - { - return $this->_warnings; - - }//end getWarnings() - - - /** - * Returns the metrics found while processing this file. - * - * @return array - */ - public function getMetrics() - { - return $this->_metrics; - - }//end getMetrics() - - - /** - * Returns the absolute filename of this file. - * - * @return string - */ - public function getFilename() - { - return $this->_file; - - }//end getFilename() - - - /** - * Creates an array of tokens when given some PHP code. - * - * Starts by using token_get_all() but does a lot of extra processing - * to insert information about the context of the token. - * - * @param string $string The string to tokenize. - * @param object $tokenizer A tokenizer class to use to tokenize the string. - * @param string $eolChar The EOL character to use for splitting strings. - * @param int $tabWidth The number of spaces each tab respresents. - * @param string $encoding The charset of the sniffed file. - * - * @throws PHP_CodeSniffer_Exception If the file cannot be processed. - * @return array - */ - public static function tokenizeString($string, $tokenizer, $eolChar='\n', $tabWidth=null, $encoding=null) - { - // Minified files often have a very large number of characters per line - // and cause issues when tokenizing. - if (property_exists($tokenizer, 'skipMinified') === true - && $tokenizer->skipMinified === true - ) { - $numChars = strlen($string); - $numLines = (substr_count($string, $eolChar) + 1); - $average = ($numChars / $numLines); - if ($average > 100) { - throw new PHP_CodeSniffer_Exception('File appears to be minified and cannot be processed'); - } - } - - $tokens = $tokenizer->tokenizeString($string, $eolChar); - - if ($tabWidth === null) { - $tabWidth = PHP_CODESNIFFER_TAB_WIDTH; - } - - if ($encoding === null) { - $encoding = PHP_CODESNIFFER_ENCODING; - } - - self::_createPositionMap($tokens, $tokenizer, $eolChar, $encoding, $tabWidth); - self::_createTokenMap($tokens, $tokenizer, $eolChar); - self::_createParenthesisNestingMap($tokens, $tokenizer, $eolChar); - self::_createScopeMap($tokens, $tokenizer, $eolChar); - - self::_createLevelMap($tokens, $tokenizer, $eolChar); - - // Allow the tokenizer to do additional processing if required. - $tokenizer->processAdditional($tokens, $eolChar); - - return $tokens; - - }//end tokenizeString() - - - /** - * Sets token position information. - * - * Can also convert tabs into spaces. Each tab can represent between - * 1 and $width spaces, so this cannot be a straight string replace. - * - * @param array $tokens The array of tokens to process. - * @param object $tokenizer The tokenizer being used to process this file. - * @param string $eolChar The EOL character to use for splitting strings. - * @param string $encoding The charset of the sniffed file. - * @param int $tabWidth The number of spaces that each tab represents. - * Set to 0 to disable tab replacement. - * - * @return void - */ - private static function _createPositionMap(&$tokens, $tokenizer, $eolChar, $encoding, $tabWidth) - { - $currColumn = 1; - $lineNumber = 1; - $eolLen = (strlen($eolChar) * -1); - $tokenizerType = get_class($tokenizer); - $ignoring = false; - $inTests = defined('PHP_CODESNIFFER_IN_TESTS'); - - $checkEncoding = false; - if ($encoding !== 'iso-8859-1' && function_exists('iconv_strlen') === true) { - $checkEncoding = true; - } - - $tokensWithTabs = array( - T_WHITESPACE => true, - T_COMMENT => true, - T_DOC_COMMENT => true, - T_DOC_COMMENT_WHITESPACE => true, - T_DOC_COMMENT_STRING => true, - T_CONSTANT_ENCAPSED_STRING => true, - T_DOUBLE_QUOTED_STRING => true, - T_HEREDOC => true, - T_NOWDOC => true, - T_INLINE_HTML => true, - ); - - $numTokens = count($tokens); - for ($i = 0; $i < $numTokens; $i++) { - $tokens[$i]['line'] = $lineNumber; - $tokens[$i]['column'] = $currColumn; - - if ($tokenizerType === 'PHP_CodeSniffer_Tokenizers_PHP' - && isset(PHP_CodeSniffer_Tokens::$knownLengths[$tokens[$i]['code']]) === true - ) { - // There are no tabs in the tokens we know the length of. - $length = PHP_CodeSniffer_Tokens::$knownLengths[$tokens[$i]['code']]; - $currColumn += $length; - } else if ($tabWidth === 0 - || isset($tokensWithTabs[$tokens[$i]['code']]) === false - || strpos($tokens[$i]['content'], "\t") === false - ) { - // There are no tabs in this content, or we aren't replacing them. - if ($checkEncoding === true) { - // Not using the default encoding, so take a bit more care. - $length = @iconv_strlen($tokens[$i]['content'], $encoding); - if ($length === false) { - // String contained invalid characters, so revert to default. - $length = strlen($tokens[$i]['content']); - } - } else { - $length = strlen($tokens[$i]['content']); - } - - $currColumn += $length; - } else { - if (str_replace("\t", '', $tokens[$i]['content']) === '') { - // String only contains tabs, so we can shortcut the process. - $numTabs = strlen($tokens[$i]['content']); - - $newContent = ''; - $firstTabSize = ($tabWidth - ($currColumn % $tabWidth) + 1); - $length = ($firstTabSize + ($tabWidth * ($numTabs - 1))); - $currColumn += $length; - $newContent = str_repeat(' ', $length); - } else { - // We need to determine the length of each tab. - $tabs = explode("\t", $tokens[$i]['content']); - - $numTabs = (count($tabs) - 1); - $tabNum = 0; - $newContent = ''; - $length = 0; - - foreach ($tabs as $content) { - if ($content !== '') { - $newContent .= $content; - if ($checkEncoding === true) { - // Not using the default encoding, so take a bit more care. - $contentLength = @iconv_strlen($content, $encoding); - if ($contentLength === false) { - // String contained invalid characters, so revert to default. - $contentLength = strlen($content); - } - } else { - $contentLength = strlen($content); - } - - $currColumn += $contentLength; - $length += $contentLength; - } - - // The last piece of content does not have a tab after it. - if ($tabNum === $numTabs) { - break; - } - - // Process the tab that comes after the content. - $lastCurrColumn = $currColumn; - $tabNum++; - - // Move the pointer to the next tab stop. - if (($currColumn % $tabWidth) === 0) { - // This is the first tab, and we are already at a - // tab stop, so this tab counts as a single space. - $currColumn++; - } else { - $currColumn++; - while (($currColumn % $tabWidth) !== 0) { - $currColumn++; - } - - $currColumn++; - } - - $length += ($currColumn - $lastCurrColumn); - $newContent .= str_repeat(' ', ($currColumn - $lastCurrColumn)); - }//end foreach - }//end if - - $tokens[$i]['orig_content'] = $tokens[$i]['content']; - $tokens[$i]['content'] = $newContent; - }//end if - - $tokens[$i]['length'] = $length; - - if (isset(PHP_CodeSniffer_Tokens::$knownLengths[$tokens[$i]['code']]) === false - && strpos($tokens[$i]['content'], $eolChar) !== false - ) { - $lineNumber++; - $currColumn = 1; - - // Newline chars are not counted in the token length. - $tokens[$i]['length'] += $eolLen; - } - - if ($tokens[$i]['code'] === T_COMMENT - || $tokens[$i]['code'] === T_DOC_COMMENT_TAG - || ($inTests === true && $tokens[$i]['code'] === T_INLINE_HTML) - ) { - if (strpos($tokens[$i]['content'], '@codingStandards') !== false) { - if ($ignoring === false - && strpos($tokens[$i]['content'], '@codingStandardsIgnoreStart') !== false - ) { - $ignoring = true; - } else if ($ignoring === true - && strpos($tokens[$i]['content'], '@codingStandardsIgnoreEnd') !== false - ) { - $ignoring = false; - // Ignore this comment too. - self::$_ignoredLines[$tokens[$i]['line']] = true; - } else if ($ignoring === false - && strpos($tokens[$i]['content'], '@codingStandardsIgnoreLine') !== false - ) { - self::$_ignoredLines[($tokens[$i]['line'] + 1)] = true; - // Ignore this comment too. - self::$_ignoredLines[$tokens[$i]['line']] = true; - } - } - }//end if - - if ($ignoring === true) { - self::$_ignoredLines[$tokens[$i]['line']] = true; - } - }//end for - - }//end _createPositionMap() - - - /** - * Creates a map of brackets positions. - * - * @param array $tokens The array of tokens to process. - * @param object $tokenizer The tokenizer being used to process this file. - * @param string $eolChar The EOL character to use for splitting strings. - * - * @return void - */ - private static function _createTokenMap(&$tokens, $tokenizer, $eolChar) - { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** START TOKEN MAP ***".PHP_EOL; - } - - $squareOpeners = array(); - $curlyOpeners = array(); - $numTokens = count($tokens); - - $openers = array(); - $openOwner = null; - - for ($i = 0; $i < $numTokens; $i++) { - /* - Parenthesis mapping. - */ - - if (isset(PHP_CodeSniffer_Tokens::$parenthesisOpeners[$tokens[$i]['code']]) === true) { - $tokens[$i]['parenthesis_opener'] = null; - $tokens[$i]['parenthesis_closer'] = null; - $tokens[$i]['parenthesis_owner'] = $i; - $openOwner = $i; - } else if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS) { - $openers[] = $i; - $tokens[$i]['parenthesis_opener'] = $i; - if ($openOwner !== null) { - $tokens[$openOwner]['parenthesis_opener'] = $i; - $tokens[$i]['parenthesis_owner'] = $openOwner; - $openOwner = null; - } - } else if ($tokens[$i]['code'] === T_CLOSE_PARENTHESIS) { - // Did we set an owner for this set of parenthesis? - $numOpeners = count($openers); - if ($numOpeners !== 0) { - $opener = array_pop($openers); - if (isset($tokens[$opener]['parenthesis_owner']) === true) { - $owner = $tokens[$opener]['parenthesis_owner']; - - $tokens[$owner]['parenthesis_closer'] = $i; - $tokens[$i]['parenthesis_owner'] = $owner; - } - - $tokens[$i]['parenthesis_opener'] = $opener; - $tokens[$i]['parenthesis_closer'] = $i; - $tokens[$opener]['parenthesis_closer'] = $i; - } - }//end if - - /* - Bracket mapping. - */ - - switch ($tokens[$i]['code']) { - case T_OPEN_SQUARE_BRACKET: - $squareOpeners[] = $i; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", count($squareOpeners)); - echo str_repeat("\t", count($curlyOpeners)); - echo "=> Found square bracket opener at $i".PHP_EOL; - } - break; - case T_OPEN_CURLY_BRACKET: - if (isset($tokens[$i]['scope_closer']) === false) { - $curlyOpeners[] = $i; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", count($squareOpeners)); - echo str_repeat("\t", count($curlyOpeners)); - echo "=> Found curly bracket opener at $i".PHP_EOL; - } - } - break; - case T_CLOSE_SQUARE_BRACKET: - if (empty($squareOpeners) === false) { - $opener = array_pop($squareOpeners); - $tokens[$i]['bracket_opener'] = $opener; - $tokens[$i]['bracket_closer'] = $i; - $tokens[$opener]['bracket_opener'] = $opener; - $tokens[$opener]['bracket_closer'] = $i; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", count($squareOpeners)); - echo str_repeat("\t", count($curlyOpeners)); - echo "\t=> Found square bracket closer at $i for $opener".PHP_EOL; - } - } - break; - case T_CLOSE_CURLY_BRACKET: - if (empty($curlyOpeners) === false - && isset($tokens[$i]['scope_opener']) === false - ) { - $opener = array_pop($curlyOpeners); - $tokens[$i]['bracket_opener'] = $opener; - $tokens[$i]['bracket_closer'] = $i; - $tokens[$opener]['bracket_opener'] = $opener; - $tokens[$opener]['bracket_closer'] = $i; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", count($squareOpeners)); - echo str_repeat("\t", count($curlyOpeners)); - echo "\t=> Found curly bracket closer at $i for $opener".PHP_EOL; - } - } - break; - default: - continue; - }//end switch - }//end for - - // Cleanup for any openers that we didn't find closers for. - // This typically means there was a syntax error breaking things. - foreach ($openers as $opener) { - unset($tokens[$opener]['parenthesis_opener']); - unset($tokens[$opener]['parenthesis_owner']); - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** END TOKEN MAP ***".PHP_EOL; - } - - }//end _createTokenMap() - - - /** - * Creates a map for the parenthesis tokens that surround other tokens. - * - * @param array $tokens The array of tokens to process. - * @param object $tokenizer The tokenizer being used to process this file. - * @param string $eolChar The EOL character to use for splitting strings. - * - * @return void - */ - private static function _createParenthesisNestingMap( - &$tokens, - $tokenizer, - $eolChar - ) { - $numTokens = count($tokens); - $map = array(); - for ($i = 0; $i < $numTokens; $i++) { - if (isset($tokens[$i]['parenthesis_opener']) === true - && $i === $tokens[$i]['parenthesis_opener'] - ) { - if (empty($map) === false) { - $tokens[$i]['nested_parenthesis'] = $map; - } - - if (isset($tokens[$i]['parenthesis_closer']) === true) { - $map[$tokens[$i]['parenthesis_opener']] - = $tokens[$i]['parenthesis_closer']; - } - } else if (isset($tokens[$i]['parenthesis_closer']) === true - && $i === $tokens[$i]['parenthesis_closer'] - ) { - array_pop($map); - if (empty($map) === false) { - $tokens[$i]['nested_parenthesis'] = $map; - } - } else { - if (empty($map) === false) { - $tokens[$i]['nested_parenthesis'] = $map; - } - }//end if - }//end for - - }//end _createParenthesisNestingMap() - - - /** - * Creates a scope map of tokens that open scopes. - * - * @param array $tokens The array of tokens to process. - * @param object $tokenizer The tokenizer being used to process this file. - * @param string $eolChar The EOL character to use for splitting strings. - * - * @return void - * @see _recurseScopeMap() - */ - private static function _createScopeMap(&$tokens, $tokenizer, $eolChar) - { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** START SCOPE MAP ***".PHP_EOL; - } - - $numTokens = count($tokens); - for ($i = 0; $i < $numTokens; $i++) { - // Check to see if the current token starts a new scope. - if (isset($tokenizer->scopeOpeners[$tokens[$i]['code']]) === true) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$i]['type']; - $content = PHP_CodeSniffer::prepareForOutput($tokens[$i]['content']); - echo "\tStart scope map at $i:$type => $content".PHP_EOL; - } - - if (isset($tokens[$i]['scope_condition']) === true) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t* already processed, skipping *".PHP_EOL; - } - - continue; - } - - $i = self::_recurseScopeMap( - $tokens, - $numTokens, - $tokenizer, - $eolChar, - $i - ); - }//end if - }//end for - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** END SCOPE MAP ***".PHP_EOL; - } - - }//end _createScopeMap() - - - /** - * Recurses though the scope openers to build a scope map. - * - * @param array $tokens The array of tokens to process. - * @param int $numTokens The size of the tokens array. - * @param object $tokenizer The tokenizer being used to process this file. - * @param string $eolChar The EOL character to use for splitting strings. - * @param int $stackPtr The position in the stack of the token that - * opened the scope (eg. an IF token or FOR token). - * @param int $depth How many scope levels down we are. - * @param int $ignore How many curly braces we are ignoring. - * - * @return int The position in the stack that closed the scope. - */ - private static function _recurseScopeMap( - &$tokens, - $numTokens, - $tokenizer, - $eolChar, - $stackPtr, - $depth=1, - &$ignore=0 - ) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "=> Begin scope map recursion at token $stackPtr with depth $depth".PHP_EOL; - } - - $opener = null; - $currType = $tokens[$stackPtr]['code']; - $startLine = $tokens[$stackPtr]['line']; - - // We will need this to restore the value if we end up - // returning a token ID that causes our calling function to go back - // over already ignored braces. - $originalIgnore = $ignore; - - // If the start token for this scope opener is the same as - // the scope token, we have already found our opener. - if (isset($tokenizer->scopeOpeners[$currType]['start'][$currType]) === true) { - $opener = $stackPtr; - } - - for ($i = ($stackPtr + 1); $i < $numTokens; $i++) { - $tokenType = $tokens[$i]['code']; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$i]['type']; - $line = $tokens[$i]['line']; - $content = PHP_CodeSniffer::prepareForOutput($tokens[$i]['content']); - - echo str_repeat("\t", $depth); - echo "Process token $i on line $line ["; - if ($opener !== null) { - echo "opener:$opener;"; - } - - if ($ignore > 0) { - echo "ignore=$ignore;"; - } - - echo "]: $type => $content".PHP_EOL; - }//end if - - // Very special case for IF statements in PHP that can be defined without - // scope tokens. E.g., if (1) 1; 1 ? (1 ? 1 : 1) : 1; - // If an IF statement below this one has an opener but no - // keyword, the opener will be incorrectly assigned to this IF statement. - // The same case also applies to USE statements, which don't have to have - // openers, so a following USE statement can cause an incorrect brace match. - if (($currType === T_IF || $currType === T_ELSE || $currType === T_USE) - && $opener === null - && $tokens[$i]['code'] === T_SEMICOLON - ) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$stackPtr]['type']; - echo str_repeat("\t", $depth); - echo "=> Found semicolon before scope opener for $stackPtr:$type, bailing".PHP_EOL; - } - - return $i; - } - - if ($opener === null - && $ignore === 0 - && $tokenType === T_CLOSE_CURLY_BRACKET - && isset($tokenizer->scopeOpeners[$currType]['end'][$tokenType]) === true - ) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$stackPtr]['type']; - echo str_repeat("\t", $depth); - echo "=> Found curly brace closer before scope opener for $stackPtr:$type, bailing".PHP_EOL; - } - - return ($i - 1); - } - - if ($opener !== null - && (isset($tokens[$i]['scope_opener']) === false - || $tokenizer->scopeOpeners[$tokens[$stackPtr]['code']]['shared'] === true) - && isset($tokenizer->scopeOpeners[$currType]['end'][$tokenType]) === true - ) { - if ($ignore > 0 && $tokenType === T_CLOSE_CURLY_BRACKET) { - // The last opening bracket must have been for a string - // offset or alike, so let's ignore it. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo '* finished ignoring curly brace *'.PHP_EOL; - } - - $ignore--; - continue; - } else if ($tokens[$opener]['code'] === T_OPEN_CURLY_BRACKET - && $tokenType !== T_CLOSE_CURLY_BRACKET - ) { - // The opener is a curly bracket so the closer must be a curly bracket as well. - // We ignore this closer to handle cases such as T_ELSE or T_ELSEIF being considered - // a closer of T_IF when it should not. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$stackPtr]['type']; - echo str_repeat("\t", $depth); - echo "=> Ignoring non-curly scope closer for $stackPtr:$type".PHP_EOL; - } - } else { - $scopeCloser = $i; - $todo = array( - $stackPtr, - $opener, - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$stackPtr]['type']; - $closerType = $tokens[$scopeCloser]['type']; - echo str_repeat("\t", $depth); - echo "=> Found scope closer ($scopeCloser:$closerType) for $stackPtr:$type".PHP_EOL; - } - - $validCloser = true; - if (($tokens[$stackPtr]['code'] === T_IF || $tokens[$stackPtr]['code'] === T_ELSEIF) - && ($tokenType === T_ELSE || $tokenType === T_ELSEIF) - ) { - // To be a closer, this token must have an opener. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "* closer needs to be tested *".PHP_EOL; - } - - $i = self::_recurseScopeMap( - $tokens, - $numTokens, - $tokenizer, - $eolChar, - $i, - ($depth + 1), - $ignore - ); - - if (isset($tokens[$scopeCloser]['scope_opener']) === false) { - $validCloser = false; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "* closer is not valid (no opener found) *".PHP_EOL; - } - } else if ($tokens[$tokens[$scopeCloser]['scope_opener']]['code'] !== $tokens[$opener]['code']) { - $validCloser = false; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - $type = $tokens[$tokens[$scopeCloser]['scope_opener']]['type']; - $openerType = $tokens[$opener]['type']; - echo "* closer is not valid (mismatched opener type; $type != $openerType) *".PHP_EOL; - } - } else if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo "* closer was valid *".PHP_EOL; - } - } else { - // The closer was not processed, so we need to - // complete that token as well. - $todo[] = $scopeCloser; - }//end if - - if ($validCloser === true) { - foreach ($todo as $token) { - $tokens[$token]['scope_condition'] = $stackPtr; - $tokens[$token]['scope_opener'] = $opener; - $tokens[$token]['scope_closer'] = $scopeCloser; - } - - if ($tokenizer->scopeOpeners[$tokens[$stackPtr]['code']]['shared'] === true) { - // As we are going back to where we started originally, restore - // the ignore value back to its original value. - $ignore = $originalIgnore; - return $opener; - } else if ($scopeCloser === $i - && isset($tokenizer->scopeOpeners[$tokenType]) === true - ) { - // Unset scope_condition here or else the token will appear to have - // already been processed, and it will be skipped. Normally we want that, - // but in this case, the token is both a closer and an opener, so - // it needs to act like an opener. This is also why we return the - // token before this one; so the closer has a chance to be processed - // a second time, but as an opener. - unset($tokens[$scopeCloser]['scope_condition']); - return ($i - 1); - } else { - return $i; - } - } else { - continue; - }//end if - }//end if - }//end if - - // Is this an opening condition ? - if (isset($tokenizer->scopeOpeners[$tokenType]) === true) { - if ($opener === null) { - if ($tokenType === T_USE) { - // PHP use keywords are special because they can be - // used as blocks but also inline in function definitions. - // So if we find them nested inside another opener, just skip them. - continue; - } - - if ($tokenType === T_FUNCTION - && $tokens[$stackPtr]['code'] !== T_FUNCTION - ) { - // Probably a closure, so process it manually. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$stackPtr]['type']; - echo str_repeat("\t", $depth); - echo "=> Found function before scope opener for $stackPtr:$type, processing manually".PHP_EOL; - } - - if (isset($tokens[$i]['scope_closer']) === true) { - // We've already processed this closure. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo '* already processed, skipping *'.PHP_EOL; - } - - $i = $tokens[$i]['scope_closer']; - continue; - } - - $i = self::_recurseScopeMap( - $tokens, - $numTokens, - $tokenizer, - $eolChar, - $i, - ($depth + 1), - $ignore - ); - - continue; - }//end if - - // Found another opening condition but still haven't - // found our opener, so we are never going to find one. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$stackPtr]['type']; - echo str_repeat("\t", $depth); - echo "=> Found new opening condition before scope opener for $stackPtr:$type, "; - } - - if (($tokens[$stackPtr]['code'] === T_IF - || $tokens[$stackPtr]['code'] === T_ELSEIF - || $tokens[$stackPtr]['code'] === T_ELSE) - && ($tokens[$i]['code'] === T_ELSE - || $tokens[$i]['code'] === T_ELSEIF) - ) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "continuing".PHP_EOL; - } - - return ($i - 1); - } else { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "backtracking".PHP_EOL; - } - - return $stackPtr; - } - }//end if - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo '* token is an opening condition *'.PHP_EOL; - } - - $isShared = ($tokenizer->scopeOpeners[$tokenType]['shared'] === true); - - if (isset($tokens[$i]['scope_condition']) === true) { - // We've been here before. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo '* already processed, skipping *'.PHP_EOL; - } - - if ($isShared === false - && isset($tokens[$i]['scope_closer']) === true - ) { - $i = $tokens[$i]['scope_closer']; - } - - continue; - } else if ($currType === $tokenType - && $isShared === false - && $opener === null - ) { - // We haven't yet found our opener, but we have found another - // scope opener which is the same type as us, and we don't - // share openers, so we will never find one. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo '* it was another token\'s opener, bailing *'.PHP_EOL; - } - - return $stackPtr; - } else { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo '* searching for opener *'.PHP_EOL; - } - - if (isset($tokenizer->scopeOpeners[$tokenType]['end'][T_CLOSE_CURLY_BRACKET]) === true) { - $oldIgnore = $ignore; - $ignore = 0; - } - - // PHP has a max nesting level for functions. Stop before we hit that limit - // because too many loops means we've run into trouble anyway. - if ($depth > 50) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo '* reached maximum nesting level; aborting *'.PHP_EOL; - } - - throw new PHP_CodeSniffer_Exception('Maximum nesting level reached; file could not be processed'); - } - - $oldDepth = $depth; - if ($isShared === true - && isset($tokenizer->scopeOpeners[$tokenType]['with'][$currType]) === true - ) { - // Don't allow the depth to increment because this is - // possibly not a true nesting if we are sharing our closer. - // This can happen, for example, when a SWITCH has a large - // number of CASE statements with the same shared BREAK. - $depth--; - } - - $i = self::_recurseScopeMap( - $tokens, - $numTokens, - $tokenizer, - $eolChar, - $i, - ($depth + 1), - $ignore - ); - - $depth = $oldDepth; - - if (isset($tokenizer->scopeOpeners[$tokenType]['end'][T_CLOSE_CURLY_BRACKET]) === true) { - $ignore = $oldIgnore; - } - }//end if - }//end if - - if (isset($tokenizer->scopeOpeners[$currType]['start'][$tokenType]) === true - && $opener === null - ) { - if ($tokenType === T_OPEN_CURLY_BRACKET) { - if (isset($tokens[$stackPtr]['parenthesis_closer']) === true - && $i < $tokens[$stackPtr]['parenthesis_closer'] - ) { - // We found a curly brace inside the condition of the - // current scope opener, so it must be a string offset. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo '* ignoring curly brace *'.PHP_EOL; - } - - $ignore++; - } else { - // Make sure this is actually an opener and not a - // string offset (e.g., $var{0}). - for ($x = ($i - 1); $x > 0; $x--) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x]['code']]) === true) { - continue; - } else { - // If the first non-whitespace/comment token is a - // variable or object operator then this is an opener - // for a string offset and not a scope. - if ($tokens[$x]['code'] === T_VARIABLE - || $tokens[$x]['code'] === T_OBJECT_OPERATOR - ) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo '* ignoring curly brace *'.PHP_EOL; - } - - $ignore++; - }//end if - - break; - }//end if - }//end for - }//end if - }//end if - - if ($ignore === 0 || $tokenType !== T_OPEN_CURLY_BRACKET) { - // We found the opening scope token for $currType. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$stackPtr]['type']; - echo str_repeat("\t", $depth); - echo "=> Found scope opener for $stackPtr:$type".PHP_EOL; - } - - $opener = $i; - } - } else if ($tokenType === T_OPEN_PARENTHESIS) { - if (isset($tokens[$i]['parenthesis_owner']) === true) { - $owner = $tokens[$i]['parenthesis_owner']; - if (isset(PHP_CodeSniffer_Tokens::$scopeOpeners[$tokens[$owner]['code']]) === true - && isset($tokens[$i]['parenthesis_closer']) === true - ) { - // If we get into here, then we opened a parenthesis for - // a scope (eg. an if or else if) so we need to update the - // start of the line so that when we check to see - // if the closing parenthesis is more than 3 lines away from - // the statement, we check from the closing parenthesis. - $startLine = $tokens[$tokens[$i]['parenthesis_closer']]['line']; - } - } - } else if ($tokenType === T_OPEN_CURLY_BRACKET && $opener !== null) { - // We opened something that we don't have a scope opener for. - // Examples of this are curly brackets for string offsets etc. - // We want to ignore this so that we don't have an invalid scope - // map. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo '* ignoring curly brace *'.PHP_EOL; - } - - $ignore++; - } else if ($tokenType === T_CLOSE_CURLY_BRACKET && $ignore > 0) { - // We found the end token for the opener we were ignoring. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo '* finished ignoring curly brace *'.PHP_EOL; - } - - $ignore--; - } else if ($opener === null - && isset($tokenizer->scopeOpeners[$currType]) === true - ) { - // If we still haven't found the opener after 3 lines, - // we're not going to find it, unless we know it requires - // an opener (in which case we better keep looking) or the last - // token was empty (in which case we'll just confirm there is - // more code in this file and not just a big comment). - if ($tokens[$i]['line'] >= ($startLine + 3) - && isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[($i - 1)]['code']]) === false - ) { - if ($tokenizer->scopeOpeners[$currType]['strict'] === true) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$stackPtr]['type']; - $lines = ($tokens[$i]['line'] - $startLine); - echo str_repeat("\t", $depth); - echo "=> Still looking for $stackPtr:$type scope opener after $lines lines".PHP_EOL; - } - } else { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$stackPtr]['type']; - echo str_repeat("\t", $depth); - echo "=> Couldn't find scope opener for $stackPtr:$type, bailing".PHP_EOL; - } - - return $stackPtr; - } - } - } else if ($opener !== null - && $tokenType !== T_BREAK - && isset($tokenizer->endScopeTokens[$tokenType]) === true - ) { - if (isset($tokens[$i]['scope_condition']) === false) { - if ($ignore > 0) { - // We found the end token for the opener we were ignoring. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", $depth); - echo '* finished ignoring curly brace *'.PHP_EOL; - } - - $ignore--; - } else { - // We found a token that closes the scope but it doesn't - // have a condition, so it belongs to another token and - // our token doesn't have a closer, so pretend this is - // the closer. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$stackPtr]['type']; - echo str_repeat("\t", $depth); - echo "=> Found (unexpected) scope closer for $stackPtr:$type".PHP_EOL; - } - - foreach (array($stackPtr, $opener) as $token) { - $tokens[$token]['scope_condition'] = $stackPtr; - $tokens[$token]['scope_opener'] = $opener; - $tokens[$token]['scope_closer'] = $i; - } - - return ($i - 1); - }//end if - }//end if - }//end if - }//end for - - return $stackPtr; - - }//end _recurseScopeMap() - - - /** - * Constructs the level map. - * - * The level map adds a 'level' index to each token which indicates the - * depth that a token within a set of scope blocks. It also adds a - * 'condition' index which is an array of the scope conditions that opened - * each of the scopes - position 0 being the first scope opener. - * - * @param array $tokens The array of tokens to process. - * @param object $tokenizer The tokenizer being used to process this file. - * @param string $eolChar The EOL character to use for splitting strings. - * - * @return void - */ - private static function _createLevelMap(&$tokens, $tokenizer, $eolChar) - { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** START LEVEL MAP ***".PHP_EOL; - } - - $numTokens = count($tokens); - $level = 0; - $conditions = array(); - $lastOpener = null; - $openers = array(); - - for ($i = 0; $i < $numTokens; $i++) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$i]['type']; - $line = $tokens[$i]['line']; - $len = $tokens[$i]['length']; - $col = $tokens[$i]['column']; - - $content = PHP_CodeSniffer::prepareForOutput($tokens[$i]['content']); - - echo str_repeat("\t", ($level + 1)); - echo "Process token $i on line $line [col:$col;len:$len;lvl:$level;"; - if (empty($conditions) !== true) { - $condString = 'conds;'; - foreach ($conditions as $condition) { - $condString .= token_name($condition).','; - } - - echo rtrim($condString, ',').';'; - } - - echo "]: $type => $content".PHP_EOL; - }//end if - - $tokens[$i]['level'] = $level; - $tokens[$i]['conditions'] = $conditions; - - if (isset($tokens[$i]['scope_condition']) === true) { - // Check to see if this token opened the scope. - if ($tokens[$i]['scope_opener'] === $i) { - $stackPtr = $tokens[$i]['scope_condition']; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$stackPtr]['type']; - echo str_repeat("\t", ($level + 1)); - echo "=> Found scope opener for $stackPtr:$type".PHP_EOL; - } - - $stackPtr = $tokens[$i]['scope_condition']; - - // If we find a scope opener that has a shared closer, - // then we need to go back over the condition map that we - // just created and fix ourselves as we just added some - // conditions where there was none. This happens for T_CASE - // statements that are using the same break statement. - if ($lastOpener !== null && $tokens[$lastOpener]['scope_closer'] === $tokens[$i]['scope_closer']) { - // This opener shares its closer with the previous opener, - // but we still need to check if the two openers share their - // closer with each other directly (like CASE and DEFAULT) - // or if they are just sharing because one doesn't have a - // closer (like CASE with no BREAK using a SWITCHes closer). - $thisType = $tokens[$tokens[$i]['scope_condition']]['code']; - $opener = $tokens[$lastOpener]['scope_condition']; - - $isShared = isset($tokenizer->scopeOpeners[$thisType]['with'][$tokens[$opener]['code']]); - - reset($tokenizer->scopeOpeners[$thisType]['end']); - reset($tokenizer->scopeOpeners[$tokens[$opener]['code']]['end']); - $sameEnd = (current($tokenizer->scopeOpeners[$thisType]['end']) === current($tokenizer->scopeOpeners[$tokens[$opener]['code']]['end'])); - - if ($isShared === true && $sameEnd === true) { - $badToken = $opener; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$badToken]['type']; - echo str_repeat("\t", ($level + 1)); - echo "* shared closer, cleaning up $badToken:$type *".PHP_EOL; - } - - for ($x = $tokens[$i]['scope_condition']; $x <= $i; $x++) { - $oldConditions = $tokens[$x]['conditions']; - $oldLevel = $tokens[$x]['level']; - $tokens[$x]['level']--; - unset($tokens[$x]['conditions'][$badToken]); - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$x]['type']; - $oldConds = ''; - foreach ($oldConditions as $condition) { - $oldConds .= token_name($condition).','; - } - - $oldConds = rtrim($oldConds, ','); - - $newConds = ''; - foreach ($tokens[$x]['conditions'] as $condition) { - $newConds .= token_name($condition).','; - } - - $newConds = rtrim($newConds, ','); - - $newLevel = $tokens[$x]['level']; - echo str_repeat("\t", ($level + 1)); - echo "* cleaned $x:$type *".PHP_EOL; - echo str_repeat("\t", ($level + 2)); - echo "=> level changed from $oldLevel to $newLevel".PHP_EOL; - echo str_repeat("\t", ($level + 2)); - echo "=> conditions changed from $oldConds to $newConds".PHP_EOL; - }//end if - }//end for - - unset($conditions[$badToken]); - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$badToken]['type']; - echo str_repeat("\t", ($level + 1)); - echo "* token $badToken:$type removed from conditions array *".PHP_EOL; - } - - unset($openers[$lastOpener]); - - $level--; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", ($level + 2)); - echo '* level decreased *'.PHP_EOL; - } - }//end if - }//end if - - $level++; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", ($level + 1)); - echo '* level increased *'.PHP_EOL; - } - - $conditions[$stackPtr] = $tokens[$stackPtr]['code']; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$stackPtr]['type']; - echo str_repeat("\t", ($level + 1)); - echo "* token $stackPtr:$type added to conditions array *".PHP_EOL; - } - - $lastOpener = $tokens[$i]['scope_opener']; - if ($lastOpener !== null) { - $openers[$lastOpener] = $lastOpener; - } - } else if ($lastOpener !== null && $tokens[$lastOpener]['scope_closer'] === $i) { - foreach (array_reverse($openers) as $opener) { - if ($tokens[$opener]['scope_closer'] === $i) { - $oldOpener = array_pop($openers); - if (empty($openers) === false) { - $lastOpener = array_pop($openers); - $openers[$lastOpener] = $lastOpener; - } else { - $lastOpener = null; - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$oldOpener]['type']; - echo str_repeat("\t", ($level + 1)); - echo "=> Found scope closer for $oldOpener:$type".PHP_EOL; - } - - $oldCondition = array_pop($conditions); - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", ($level + 1)); - echo '* token '.token_name($oldCondition).' removed from conditions array *'.PHP_EOL; - } - - // Make sure this closer actually belongs to us. - // Either the condition also has to think this is the - // closer, or it has to allow sharing with us. - $condition = $tokens[$tokens[$i]['scope_condition']]['code']; - if ($condition !== $oldCondition) { - if (isset($tokenizer->scopeOpeners[$oldCondition]['with'][$condition]) === false) { - $badToken = $tokens[$oldOpener]['scope_condition']; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = token_name($oldCondition); - echo str_repeat("\t", ($level + 1)); - echo "* scope closer was bad, cleaning up $badToken:$type *".PHP_EOL; - } - - for ($x = ($oldOpener + 1); $x <= $i; $x++) { - $oldConditions = $tokens[$x]['conditions']; - $oldLevel = $tokens[$x]['level']; - $tokens[$x]['level']--; - unset($tokens[$x]['conditions'][$badToken]); - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$x]['type']; - $oldConds = ''; - foreach ($oldConditions as $condition) { - $oldConds .= token_name($condition).','; - } - - $oldConds = rtrim($oldConds, ','); - - $newConds = ''; - foreach ($tokens[$x]['conditions'] as $condition) { - $newConds .= token_name($condition).','; - } - - $newConds = rtrim($newConds, ','); - - $newLevel = $tokens[$x]['level']; - echo str_repeat("\t", ($level + 1)); - echo "* cleaned $x:$type *".PHP_EOL; - echo str_repeat("\t", ($level + 2)); - echo "=> level changed from $oldLevel to $newLevel".PHP_EOL; - echo str_repeat("\t", ($level + 2)); - echo "=> conditions changed from $oldConds to $newConds".PHP_EOL; - }//end if - }//end for - }//end if - }//end if - - $level--; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", ($level + 2)); - echo '* level decreased *'.PHP_EOL; - } - - $tokens[$i]['level'] = $level; - $tokens[$i]['conditions'] = $conditions; - }//end if - }//end foreach - }//end if - }//end if - }//end for - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** END LEVEL MAP ***".PHP_EOL; - } - - }//end _createLevelMap() - - - /** - * Returns the declaration names for classes, interfaces, and functions. - * - * @param int $stackPtr The position of the declaration token which - * declared the class, interface or function. - * - * @return string|null The name of the class, interface or function. - * or NULL if the function or class is anonymous. - * @throws PHP_CodeSniffer_Exception If the specified token is not of type - * T_FUNCTION, T_CLASS, T_ANON_CLASS, - * or T_INTERFACE. - */ - public function getDeclarationName($stackPtr) - { - $tokenCode = $this->_tokens[$stackPtr]['code']; - - if ($tokenCode === T_ANON_CLASS) { - return null; - } - - if ($tokenCode === T_FUNCTION - && $this->isAnonymousFunction($stackPtr) === true - ) { - return null; - } - - if ($tokenCode !== T_FUNCTION - && $tokenCode !== T_CLASS - && $tokenCode !== T_INTERFACE - && $tokenCode !== T_TRAIT - ) { - throw new PHP_CodeSniffer_Exception('Token type "'.$this->_tokens[$stackPtr]['type'].'" is not T_FUNCTION, T_CLASS, T_INTERFACE or T_TRAIT'); - } - - $content = null; - for ($i = $stackPtr; $i < $this->numTokens; $i++) { - if ($this->_tokens[$i]['code'] === T_STRING) { - $content = $this->_tokens[$i]['content']; - break; - } - } - - return $content; - - }//end getDeclarationName() - - - /** - * Check if the token at the specified position is a anonymous function. - * - * @param int $stackPtr The position of the declaration token which - * declared the class, interface or function. - * - * @return boolean - * @throws PHP_CodeSniffer_Exception If the specified token is not of type - * T_FUNCTION - */ - public function isAnonymousFunction($stackPtr) - { - $tokenCode = $this->_tokens[$stackPtr]['code']; - if ($tokenCode !== T_FUNCTION) { - throw new PHP_CodeSniffer_Exception('Token type is not T_FUNCTION'); - } - - if (isset($this->_tokens[$stackPtr]['parenthesis_opener']) === false) { - // Something is not right with this function. - return false; - } - - $name = false; - for ($i = ($stackPtr + 1); $i < $this->numTokens; $i++) { - if ($this->_tokens[$i]['code'] === T_STRING) { - $name = $i; - break; - } - } - - if ($name === false) { - // No name found. - return true; - } - - $open = $this->_tokens[$stackPtr]['parenthesis_opener']; - if ($name > $open) { - return true; - } - - return false; - - }//end isAnonymousFunction() - - - /** - * Returns the method parameters for the specified function token. - * - * Each parameter is in the following format: - * - * - * 0 => array( - * 'token' => int, // The position of the var in the token stack. - * 'name' => '$var', // The variable name. - * 'content' => string, // The full content of the variable definition. - * 'pass_by_reference' => boolean, // Is the variable passed by reference? - * 'type_hint' => string, // The type hint for the variable. - * 'nullable_type' => boolean, // Is the variable using a nullable type? - * ) - * - * - * Parameters with default values have an additional array index of - * 'default' with the value of the default as a string. - * - * @param int $stackPtr The position in the stack of the function token - * to acquire the parameters for. - * - * @return array - * @throws PHP_CodeSniffer_Exception If the specified $stackPtr is not of - * type T_FUNCTION or T_CLOSURE. - */ - public function getMethodParameters($stackPtr) - { - if ($this->_tokens[$stackPtr]['code'] !== T_FUNCTION - && $this->_tokens[$stackPtr]['code'] !== T_CLOSURE - ) { - throw new PHP_CodeSniffer_Exception('$stackPtr must be of type T_FUNCTION or T_CLOSURE'); - } - - $opener = $this->_tokens[$stackPtr]['parenthesis_opener']; - $closer = $this->_tokens[$stackPtr]['parenthesis_closer']; - - $vars = array(); - $currVar = null; - $paramStart = ($opener + 1); - $defaultStart = null; - $paramCount = 0; - $passByReference = false; - $variableLength = false; - $typeHint = ''; - $nullableType = false; - - for ($i = $paramStart; $i <= $closer; $i++) { - // Check to see if this token has a parenthesis or bracket opener. If it does - // it's likely to be an array which might have arguments in it. This - // could cause problems in our parsing below, so lets just skip to the - // end of it. - if (isset($this->_tokens[$i]['parenthesis_opener']) === true) { - // Don't do this if it's the close parenthesis for the method. - if ($i !== $this->_tokens[$i]['parenthesis_closer']) { - $i = ($this->_tokens[$i]['parenthesis_closer'] + 1); - } - } - - if (isset($this->_tokens[$i]['bracket_opener']) === true) { - // Don't do this if it's the close parenthesis for the method. - if ($i !== $this->_tokens[$i]['bracket_closer']) { - $i = ($this->_tokens[$i]['bracket_closer'] + 1); - } - } - - switch ($this->_tokens[$i]['code']) { - case T_BITWISE_AND: - $passByReference = true; - break; - case T_VARIABLE: - $currVar = $i; - break; - case T_ELLIPSIS: - $variableLength = true; - break; - case T_ARRAY_HINT: - case T_CALLABLE: - $typeHint .= $this->_tokens[$i]['content']; - break; - case T_SELF: - case T_PARENT: - case T_STATIC: - // Self is valid, the others invalid, but were probably intended as type hints. - if (isset($defaultStart) === false) { - $typeHint .= $this->_tokens[$i]['content']; - } - break; - case T_STRING: - // This is a string, so it may be a type hint, but it could - // also be a constant used as a default value. - $prevComma = false; - for ($t = $i; $t >= $opener; $t--) { - if ($this->_tokens[$t]['code'] === T_COMMA) { - $prevComma = $t; - break; - } - } - - if ($prevComma !== false) { - $nextEquals = false; - for ($t = $prevComma; $t < $i; $t++) { - if ($this->_tokens[$t]['code'] === T_EQUAL) { - $nextEquals = $t; - break; - } - } - - if ($nextEquals !== false) { - break; - } - } - - if ($defaultStart === null) { - $typeHint .= $this->_tokens[$i]['content']; - } - break; - case T_NS_SEPARATOR: - // Part of a type hint or default value. - if ($defaultStart === null) { - $typeHint .= $this->_tokens[$i]['content']; - } - break; - case T_NULLABLE: - if ($defaultStart === null) { - $nullableType = true; - $typeHint .= $this->_tokens[$i]['content']; - } - break; - case T_CLOSE_PARENTHESIS: - case T_COMMA: - // If it's null, then there must be no parameters for this - // method. - if ($currVar === null) { - continue; - } - - $vars[$paramCount] = array(); - $vars[$paramCount]['token'] = $currVar; - $vars[$paramCount]['name'] = $this->_tokens[$currVar]['content']; - $vars[$paramCount]['content'] = trim($this->getTokensAsString($paramStart, ($i - $paramStart))); - - if ($defaultStart !== null) { - $vars[$paramCount]['default'] = trim($this->getTokensAsString($defaultStart, ($i - $defaultStart))); - } - - $vars[$paramCount]['pass_by_reference'] = $passByReference; - $vars[$paramCount]['variable_length'] = $variableLength; - $vars[$paramCount]['type_hint'] = $typeHint; - $vars[$paramCount]['nullable_type'] = $nullableType; - - // Reset the vars, as we are about to process the next parameter. - $defaultStart = null; - $paramStart = ($i + 1); - $passByReference = false; - $variableLength = false; - $typeHint = ''; - $nullableType = false; - - $paramCount++; - break; - case T_EQUAL: - $defaultStart = ($i + 1); - break; - }//end switch - }//end for - - return $vars; - - }//end getMethodParameters() - - - /** - * Returns the visibility and implementation properties of a method. - * - * The format of the array is: - * - * array( - * 'scope' => 'public', // public private or protected - * 'scope_specified' => true, // true is scope keyword was found. - * 'is_abstract' => false, // true if the abstract keyword was found. - * 'is_final' => false, // true if the final keyword was found. - * 'is_static' => false, // true if the static keyword was found. - * 'is_closure' => false, // true if no name is found. - * ); - * - * - * @param int $stackPtr The position in the stack of the T_FUNCTION token to - * acquire the properties for. - * - * @return array - * @throws PHP_CodeSniffer_Exception If the specified position is not a - * T_FUNCTION token. - */ - public function getMethodProperties($stackPtr) - { - if ($this->_tokens[$stackPtr]['code'] !== T_FUNCTION) { - throw new PHP_CodeSniffer_Exception('$stackPtr must be of type T_FUNCTION'); - } - - $valid = array( - T_PUBLIC => T_PUBLIC, - T_PRIVATE => T_PRIVATE, - T_PROTECTED => T_PROTECTED, - T_STATIC => T_STATIC, - T_FINAL => T_FINAL, - T_ABSTRACT => T_ABSTRACT, - T_WHITESPACE => T_WHITESPACE, - T_COMMENT => T_COMMENT, - T_DOC_COMMENT => T_DOC_COMMENT, - ); - - $scope = 'public'; - $scopeSpecified = false; - $isAbstract = false; - $isFinal = false; - $isStatic = false; - $isClosure = $this->isAnonymousFunction($stackPtr); - - for ($i = ($stackPtr - 1); $i > 0; $i--) { - if (isset($valid[$this->_tokens[$i]['code']]) === false) { - break; - } - - switch ($this->_tokens[$i]['code']) { - case T_PUBLIC: - $scope = 'public'; - $scopeSpecified = true; - break; - case T_PRIVATE: - $scope = 'private'; - $scopeSpecified = true; - break; - case T_PROTECTED: - $scope = 'protected'; - $scopeSpecified = true; - break; - case T_ABSTRACT: - $isAbstract = true; - break; - case T_FINAL: - $isFinal = true; - break; - case T_STATIC: - $isStatic = true; - break; - }//end switch - }//end for - - return array( - 'scope' => $scope, - 'scope_specified' => $scopeSpecified, - 'is_abstract' => $isAbstract, - 'is_final' => $isFinal, - 'is_static' => $isStatic, - 'is_closure' => $isClosure, - ); - - }//end getMethodProperties() - - - /** - * Returns the visibility and implementation properties of the class member - * variable found at the specified position in the stack. - * - * The format of the array is: - * - * - * array( - * 'scope' => 'public', // public private or protected - * 'is_static' => false, // true if the static keyword was found. - * ); - * - * - * @param int $stackPtr The position in the stack of the T_VARIABLE token to - * acquire the properties for. - * - * @return array - * @throws PHP_CodeSniffer_Exception If the specified position is not a - * T_VARIABLE token, or if the position is not - * a class member variable. - */ - public function getMemberProperties($stackPtr) - { - if ($this->_tokens[$stackPtr]['code'] !== T_VARIABLE) { - throw new PHP_CodeSniffer_Exception('$stackPtr must be of type T_VARIABLE'); - } - - $conditions = array_keys($this->_tokens[$stackPtr]['conditions']); - $ptr = array_pop($conditions); - if (isset($this->_tokens[$ptr]) === false - || ($this->_tokens[$ptr]['code'] !== T_CLASS - && $this->_tokens[$ptr]['code'] !== T_ANON_CLASS - && $this->_tokens[$ptr]['code'] !== T_TRAIT) - ) { - if (isset($this->_tokens[$ptr]) === true - && $this->_tokens[$ptr]['code'] === T_INTERFACE - ) { - // T_VARIABLEs in interfaces can actually be method arguments - // but they wont be seen as being inside the method because there - // are no scope openers and closers for abstract methods. If it is in - // parentheses, we can be pretty sure it is a method argument. - if (isset($this->_tokens[$stackPtr]['nested_parenthesis']) === false - || empty($this->_tokens[$stackPtr]['nested_parenthesis']) === true - ) { - $error = 'Possible parse error: interfaces may not include member vars'; - $this->addWarning($error, $stackPtr, 'Internal.ParseError.InterfaceHasMemberVar'); - return array(); - } - } else { - throw new PHP_CodeSniffer_Exception('$stackPtr is not a class member var'); - } - } - - $valid = array( - T_PUBLIC => T_PUBLIC, - T_PRIVATE => T_PRIVATE, - T_PROTECTED => T_PROTECTED, - T_STATIC => T_STATIC, - T_WHITESPACE => T_WHITESPACE, - T_COMMENT => T_COMMENT, - T_DOC_COMMENT => T_DOC_COMMENT, - T_VARIABLE => T_VARIABLE, - T_COMMA => T_COMMA, - ); - - $scope = 'public'; - $scopeSpecified = false; - $isStatic = false; - - for ($i = ($stackPtr - 1); $i > 0; $i--) { - if (isset($valid[$this->_tokens[$i]['code']]) === false) { - break; - } - - switch ($this->_tokens[$i]['code']) { - case T_PUBLIC: - $scope = 'public'; - $scopeSpecified = true; - break; - case T_PRIVATE: - $scope = 'private'; - $scopeSpecified = true; - break; - case T_PROTECTED: - $scope = 'protected'; - $scopeSpecified = true; - break; - case T_STATIC: - $isStatic = true; - break; - } - }//end for - - return array( - 'scope' => $scope, - 'scope_specified' => $scopeSpecified, - 'is_static' => $isStatic, - ); - - }//end getMemberProperties() - - - /** - * Returns the visibility and implementation properties of a class. - * - * The format of the array is: - * - * array( - * 'is_abstract' => false, // true if the abstract keyword was found. - * 'is_final' => false, // true if the final keyword was found. - * ); - * - * - * @param int $stackPtr The position in the stack of the T_CLASS token to - * acquire the properties for. - * - * @return array - * @throws PHP_CodeSniffer_Exception If the specified position is not a - * T_CLASS token. - */ - public function getClassProperties($stackPtr) - { - if ($this->_tokens[$stackPtr]['code'] !== T_CLASS) { - throw new PHP_CodeSniffer_Exception('$stackPtr must be of type T_CLASS'); - } - - $valid = array( - T_FINAL => T_FINAL, - T_ABSTRACT => T_ABSTRACT, - T_WHITESPACE => T_WHITESPACE, - T_COMMENT => T_COMMENT, - T_DOC_COMMENT => T_DOC_COMMENT, - ); - - $isAbstract = false; - $isFinal = false; - - for ($i = ($stackPtr - 1); $i > 0; $i--) { - if (isset($valid[$this->_tokens[$i]['code']]) === false) { - break; - } - - switch ($this->_tokens[$i]['code']) { - case T_ABSTRACT: - $isAbstract = true; - break; - - case T_FINAL: - $isFinal = true; - break; - } - }//end for - - return array( - 'is_abstract' => $isAbstract, - 'is_final' => $isFinal, - ); - - }//end getClassProperties() - - - /** - * Determine if the passed token is a reference operator. - * - * Returns true if the specified token position represents a reference. - * Returns false if the token represents a bitwise operator. - * - * @param int $stackPtr The position of the T_BITWISE_AND token. - * - * @return boolean - */ - public function isReference($stackPtr) - { - if ($this->_tokens[$stackPtr]['code'] !== T_BITWISE_AND) { - return false; - } - - $tokenBefore = $this->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, - ($stackPtr - 1), - null, - true - ); - - if ($this->_tokens[$tokenBefore]['code'] === T_FUNCTION) { - // Function returns a reference. - return true; - } - - if ($this->_tokens[$tokenBefore]['code'] === T_DOUBLE_ARROW) { - // Inside a foreach loop, this is a reference. - return true; - } - - if ($this->_tokens[$tokenBefore]['code'] === T_AS) { - // Inside a foreach loop, this is a reference. - return true; - } - - if ($this->_tokens[$tokenBefore]['code'] === T_OPEN_SHORT_ARRAY) { - // Inside an array declaration, this is a reference. - return true; - } - - if (isset(PHP_CodeSniffer_Tokens::$assignmentTokens[$this->_tokens[$tokenBefore]['code']]) === true) { - // This is directly after an assignment. It's a reference. Even if - // it is part of an operation, the other tests will handle it. - return true; - } - - if (isset($this->_tokens[$stackPtr]['nested_parenthesis']) === true) { - $brackets = $this->_tokens[$stackPtr]['nested_parenthesis']; - $lastBracket = array_pop($brackets); - if (isset($this->_tokens[$lastBracket]['parenthesis_owner']) === true) { - $owner = $this->_tokens[$this->_tokens[$lastBracket]['parenthesis_owner']]; - if ($owner['code'] === T_FUNCTION - || $owner['code'] === T_CLOSURE - || $owner['code'] === T_ARRAY - ) { - // Inside a function or array declaration, this is a reference. - return true; - } - } else { - $prev = false; - for ($t = ($this->_tokens[$lastBracket]['parenthesis_opener'] - 1); $t >= 0; $t--) { - if ($this->_tokens[$t]['code'] !== T_WHITESPACE) { - $prev = $t; - break; - } - } - - if ($prev !== false && $this->_tokens[$prev]['code'] === T_USE) { - return true; - } - }//end if - }//end if - - $tokenAfter = $this->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, - ($stackPtr + 1), - null, - true - ); - - if ($this->_tokens[$tokenAfter]['code'] === T_VARIABLE - && ($this->_tokens[$tokenBefore]['code'] === T_OPEN_PARENTHESIS - || $this->_tokens[$tokenBefore]['code'] === T_COMMA) - ) { - return true; - } - - return false; - - }//end isReference() - - - /** - * Returns the content of the tokens from the specified start position in - * the token stack for the specified length. - * - * @param int $start The position to start from in the token stack. - * @param int $length The length of tokens to traverse from the start pos. - * - * @return string The token contents. - */ - public function getTokensAsString($start, $length) - { - $str = ''; - $end = ($start + $length); - if ($end > $this->numTokens) { - $end = $this->numTokens; - } - - for ($i = $start; $i < $end; $i++) { - $str .= $this->_tokens[$i]['content']; - } - - return $str; - - }//end getTokensAsString() - - - /** - * Returns the position of the previous specified token(s). - * - * If a value is specified, the previous token of the specified type(s) - * containing the specified value will be returned. - * - * Returns false if no token can be found. - * - * @param int|array $types The type(s) of tokens to search for. - * @param int $start The position to start searching from in the - * token stack. - * @param int $end The end position to fail if no token is found. - * if not specified or null, end will default to - * the start of the token stack. - * @param bool $exclude If true, find the previous token that are NOT of - * the types specified in $types. - * @param string $value The value that the token(s) must be equal to. - * If value is omitted, tokens with any value will - * be returned. - * @param bool $local If true, tokens outside the current statement - * will not be checked. IE. checking will stop - * at the previous semi-colon found. - * - * @return int|bool - * @see findNext() - */ - public function findPrevious( - $types, - $start, - $end=null, - $exclude=false, - $value=null, - $local=false - ) { - $types = (array) $types; - - if ($end === null) { - $end = 0; - } - - for ($i = $start; $i >= $end; $i--) { - $found = (bool) $exclude; - foreach ($types as $type) { - if ($this->_tokens[$i]['code'] === $type) { - $found = !$exclude; - break; - } - } - - if ($found === true) { - if ($value === null) { - return $i; - } else if ($this->_tokens[$i]['content'] === $value) { - return $i; - } - } - - if ($local === true) { - if (isset($this->_tokens[$i]['scope_opener']) === true - && $i === $this->_tokens[$i]['scope_closer'] - ) { - $i = $this->_tokens[$i]['scope_opener']; - } else if (isset($this->_tokens[$i]['bracket_opener']) === true - && $i === $this->_tokens[$i]['bracket_closer'] - ) { - $i = $this->_tokens[$i]['bracket_opener']; - } else if (isset($this->_tokens[$i]['parenthesis_opener']) === true - && $i === $this->_tokens[$i]['parenthesis_closer'] - ) { - $i = $this->_tokens[$i]['parenthesis_opener']; - } else if ($this->_tokens[$i]['code'] === T_SEMICOLON) { - break; - } - } - }//end for - - return false; - - }//end findPrevious() - - - /** - * Returns the position of the next specified token(s). - * - * If a value is specified, the next token of the specified type(s) - * containing the specified value will be returned. - * - * Returns false if no token can be found. - * - * @param int|array $types The type(s) of tokens to search for. - * @param int $start The position to start searching from in the - * token stack. - * @param int $end The end position to fail if no token is found. - * if not specified or null, end will default to - * the end of the token stack. - * @param bool $exclude If true, find the next token that is NOT of - * a type specified in $types. - * @param string $value The value that the token(s) must be equal to. - * If value is omitted, tokens with any value will - * be returned. - * @param bool $local If true, tokens outside the current statement - * will not be checked. i.e., checking will stop - * at the next semi-colon found. - * - * @return int|bool - * @see findPrevious() - */ - public function findNext( - $types, - $start, - $end=null, - $exclude=false, - $value=null, - $local=false - ) { - $types = (array) $types; - - if ($end === null || $end > $this->numTokens) { - $end = $this->numTokens; - } - - for ($i = $start; $i < $end; $i++) { - $found = (bool) $exclude; - foreach ($types as $type) { - if ($this->_tokens[$i]['code'] === $type) { - $found = !$exclude; - break; - } - } - - if ($found === true) { - if ($value === null) { - return $i; - } else if ($this->_tokens[$i]['content'] === $value) { - return $i; - } - } - - if ($local === true && $this->_tokens[$i]['code'] === T_SEMICOLON) { - break; - } - }//end for - - return false; - - }//end findNext() - - - /** - * Returns the position of the first non-whitespace token in a statement. - * - * @param int $start The position to start searching from in the token stack. - * @param int|array $ignore Token types that should not be considered stop points. - * - * @return int - */ - public function findStartOfStatement($start, $ignore=null) - { - $endTokens = PHP_CodeSniffer_Tokens::$blockOpeners; - - $endTokens[T_COLON] = true; - $endTokens[T_COMMA] = true; - $endTokens[T_DOUBLE_ARROW] = true; - $endTokens[T_SEMICOLON] = true; - $endTokens[T_OPEN_TAG] = true; - $endTokens[T_CLOSE_TAG] = true; - $endTokens[T_OPEN_SHORT_ARRAY] = true; - - if ($ignore !== null) { - $ignore = (array) $ignore; - foreach ($ignore as $code) { - if (isset($endTokens[$code]) === true) { - unset($endTokens[$code]); - } - } - } - - $lastNotEmpty = $start; - - for ($i = $start; $i >= 0; $i--) { - if (isset($endTokens[$this->_tokens[$i]['code']]) === true) { - // Found the end of the previous statement. - return $lastNotEmpty; - } - - if (isset($this->_tokens[$i]['scope_opener']) === true - && $i === $this->_tokens[$i]['scope_closer'] - ) { - // Found the end of the previous scope block. - return $lastNotEmpty; - } - - // Skip nested statements. - if (isset($this->_tokens[$i]['bracket_opener']) === true - && $i === $this->_tokens[$i]['bracket_closer'] - ) { - $i = $this->_tokens[$i]['bracket_opener']; - } else if (isset($this->_tokens[$i]['parenthesis_opener']) === true - && $i === $this->_tokens[$i]['parenthesis_closer'] - ) { - $i = $this->_tokens[$i]['parenthesis_opener']; - } - - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$this->_tokens[$i]['code']]) === false) { - $lastNotEmpty = $i; - } - }//end for - - return 0; - - }//end findStartOfStatement() - - - /** - * Returns the position of the last non-whitespace token in a statement. - * - * @param int $start The position to start searching from in the token stack. - * @param int|array $ignore Token types that should not be considered stop points. - * - * @return int - */ - public function findEndOfStatement($start, $ignore=null) - { - $endTokens = array( - T_COLON => true, - T_COMMA => true, - T_DOUBLE_ARROW => true, - T_SEMICOLON => true, - T_CLOSE_PARENTHESIS => true, - T_CLOSE_SQUARE_BRACKET => true, - T_CLOSE_CURLY_BRACKET => true, - T_CLOSE_SHORT_ARRAY => true, - T_OPEN_TAG => true, - T_CLOSE_TAG => true, - ); - - if ($ignore !== null) { - $ignore = (array) $ignore; - foreach ($ignore as $code) { - if (isset($endTokens[$code]) === true) { - unset($endTokens[$code]); - } - } - } - - $lastNotEmpty = $start; - - for ($i = $start; $i < $this->numTokens; $i++) { - if ($i !== $start && isset($endTokens[$this->_tokens[$i]['code']]) === true) { - // Found the end of the statement. - if ($this->_tokens[$i]['code'] === T_CLOSE_PARENTHESIS - || $this->_tokens[$i]['code'] === T_CLOSE_SQUARE_BRACKET - || $this->_tokens[$i]['code'] === T_CLOSE_CURLY_BRACKET - || $this->_tokens[$i]['code'] === T_CLOSE_SHORT_ARRAY - || $this->_tokens[$i]['code'] === T_OPEN_TAG - || $this->_tokens[$i]['code'] === T_CLOSE_TAG - ) { - return $lastNotEmpty; - } - - return $i; - } - - // Skip nested statements. - if (isset($this->_tokens[$i]['scope_closer']) === true - && ($i === $this->_tokens[$i]['scope_opener'] - || $i === $this->_tokens[$i]['scope_condition']) - ) { - $i = $this->_tokens[$i]['scope_closer']; - } else if (isset($this->_tokens[$i]['bracket_closer']) === true - && $i === $this->_tokens[$i]['bracket_opener'] - ) { - $i = $this->_tokens[$i]['bracket_closer']; - } else if (isset($this->_tokens[$i]['parenthesis_closer']) === true - && $i === $this->_tokens[$i]['parenthesis_opener'] - ) { - $i = $this->_tokens[$i]['parenthesis_closer']; - } - - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$this->_tokens[$i]['code']]) === false) { - $lastNotEmpty = $i; - } - }//end for - - return ($this->numTokens - 1); - - }//end findEndOfStatement() - - - /** - * Returns the position of the first token on a line, matching given type. - * - * Returns false if no token can be found. - * - * @param int|array $types The type(s) of tokens to search for. - * @param int $start The position to start searching from in the - * token stack. The first token matching on - * this line before this token will be returned. - * @param bool $exclude If true, find the token that is NOT of - * the types specified in $types. - * @param string $value The value that the token must be equal to. - * If value is omitted, tokens with any value will - * be returned. - * - * @return int | bool - */ - public function findFirstOnLine($types, $start, $exclude=false, $value=null) - { - if (is_array($types) === false) { - $types = array($types); - } - - $foundToken = false; - - for ($i = $start; $i >= 0; $i--) { - if ($this->_tokens[$i]['line'] < $this->_tokens[$start]['line']) { - break; - } - - $found = $exclude; - foreach ($types as $type) { - if ($exclude === false) { - if ($this->_tokens[$i]['code'] === $type) { - $found = true; - break; - } - } else { - if ($this->_tokens[$i]['code'] === $type) { - $found = false; - break; - } - } - } - - if ($found === true) { - if ($value === null) { - $foundToken = $i; - } else if ($this->_tokens[$i]['content'] === $value) { - $foundToken = $i; - } - } - }//end for - - return $foundToken; - - }//end findFirstOnLine() - - - /** - * Determine if the passed token has a condition of one of the passed types. - * - * @param int $stackPtr The position of the token we are checking. - * @param int|array $types The type(s) of tokens to search for. - * - * @return boolean - */ - public function hasCondition($stackPtr, $types) - { - // Check for the existence of the token. - if (isset($this->_tokens[$stackPtr]) === false) { - return false; - } - - // Make sure the token has conditions. - if (isset($this->_tokens[$stackPtr]['conditions']) === false) { - return false; - } - - $types = (array) $types; - $conditions = $this->_tokens[$stackPtr]['conditions']; - - foreach ($types as $type) { - if (in_array($type, $conditions) === true) { - // We found a token with the required type. - return true; - } - } - - return false; - - }//end hasCondition() - - - /** - * Return the position of the condition for the passed token. - * - * Returns FALSE if the token does not have the condition. - * - * @param int $stackPtr The position of the token we are checking. - * @param int $type The type of token to search for. - * - * @return int - */ - public function getCondition($stackPtr, $type) - { - // Check for the existence of the token. - if (isset($this->_tokens[$stackPtr]) === false) { - return false; - } - - // Make sure the token has conditions. - if (isset($this->_tokens[$stackPtr]['conditions']) === false) { - return false; - } - - $conditions = $this->_tokens[$stackPtr]['conditions']; - foreach ($conditions as $token => $condition) { - if ($condition === $type) { - return $token; - } - } - - return false; - - }//end getCondition() - - - /** - * Returns the name of the class that the specified class extends. - * - * Returns FALSE on error or if there is no extended class name. - * - * @param int $stackPtr The stack position of the class. - * - * @return string - */ - public function findExtendedClassName($stackPtr) - { - // Check for the existence of the token. - if (isset($this->_tokens[$stackPtr]) === false) { - return false; - } - - if ($this->_tokens[$stackPtr]['code'] !== T_CLASS - && $this->_tokens[$stackPtr]['code'] !== T_ANON_CLASS - ) { - return false; - } - - if (isset($this->_tokens[$stackPtr]['scope_closer']) === false) { - return false; - } - - $classCloserIndex = $this->_tokens[$stackPtr]['scope_closer']; - $extendsIndex = $this->findNext(T_EXTENDS, $stackPtr, $classCloserIndex); - if (false === $extendsIndex) { - return false; - } - - $find = array( - T_NS_SEPARATOR, - T_STRING, - T_WHITESPACE, - ); - - $end = $this->findNext($find, ($extendsIndex + 1), $classCloserIndex, true); - $name = $this->getTokensAsString(($extendsIndex + 1), ($end - $extendsIndex - 1)); - $name = trim($name); - - if ($name === '') { - return false; - } - - return $name; - - }//end findExtendedClassName() - - - /** - * Returns the name(s) of the interface(s) that the specified class implements. - * - * Returns FALSE on error or if there are no implemented interface names. - * - * @param int $stackPtr The stack position of the class. - * - * @return array|false - */ - public function findImplementedInterfaceNames($stackPtr) - { - // Check for the existence of the token. - if (isset($this->_tokens[$stackPtr]) === false) { - return false; - } - - if ($this->_tokens[$stackPtr]['code'] !== T_CLASS - && $this->_tokens[$stackPtr]['code'] !== T_ANON_CLASS - ) { - return false; - } - - if (isset($this->_tokens[$stackPtr]['scope_closer']) === false) { - return false; - } - - $classOpenerIndex = $this->_tokens[$stackPtr]['scope_opener']; - $implementsIndex = $this->findNext(T_IMPLEMENTS, $stackPtr, $classOpenerIndex); - if ($implementsIndex === false) { - return false; - } - - $find = array( - T_NS_SEPARATOR, - T_STRING, - T_WHITESPACE, - T_COMMA, - ); - - $end = $this->findNext($find, ($implementsIndex + 1), ($classOpenerIndex + 1), true); - $name = $this->getTokensAsString(($implementsIndex + 1), ($end - $implementsIndex - 1)); - $name = trim($name); - - if ($name === '') { - return false; - } else { - $names = explode(',', $name); - $names = array_map('trim', $names); - return $names; - } - - }//end findImplementedInterfaceNames() - - -}//end class diff --git a/phpcs/CodeSniffer/Fixer.php b/phpcs/CodeSniffer/Fixer.php deleted file mode 100644 index 3481878..0000000 --- a/phpcs/CodeSniffer/Fixer.php +++ /dev/null @@ -1,741 +0,0 @@ - - * @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * A helper class for fixing errors. - * - * Provides helper functions that act upon a token array and modify the file - * content. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Fixer -{ - - /** - * Is the fixer enabled and fixing a file? - * - * Sniffs should check this value to ensure they are not - * doing extra processing to prepare for a fix when fixing is - * not required. - * - * @var boolean - */ - public $enabled = false; - - /** - * The number of times we have looped over a file. - * - * @var int - */ - public $loops = 0; - - /** - * The file being fixed. - * - * @var PHP_CodeSniffer_File - */ - private $_currentFile = null; - - /** - * The list of tokens that make up the file contents. - * - * This is a simplified list which just contains the token content and nothing - * else. This is the array that is updated as fixes are made, not the file's - * token array. Imploding this array will give you the file content back. - * - * @var array(int => string) - */ - private $_tokens = array(); - - /** - * A list of tokens that have already been fixed. - * - * We don't allow the same token to be fixed more than once each time - * through a file as this can easily cause conflicts between sniffs. - * - * @var array(int) - */ - private $_fixedTokens = array(); - - /** - * The last value of each fixed token. - * - * If a token is being "fixed" back to its last value, the fix is - * probably conflicting with another. - * - * @var array(int => string) - */ - private $_oldTokenValues = array(); - - /** - * A list of tokens that have been fixed during a changeset. - * - * All changes in changeset must be able to be applied, or else - * the entire changeset is rejected. - * - * @var array() - */ - private $_changeset = array(); - - /** - * Is there an open changeset. - * - * @var boolean - */ - private $_inChangeset = false; - - /** - * Is the current fixing loop in conflict? - * - * @var boolean - */ - private $_inConflict = false; - - /** - * The number of fixes that have been performed. - * - * @var int - */ - private $_numFixes = 0; - - - /** - * Starts fixing a new file. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being fixed. - * - * @return void - */ - public function startFile($phpcsFile) - { - $this->_currentFile = $phpcsFile; - $this->_numFixes = 0; - $this->_fixedTokens = array(); - - $tokens = $phpcsFile->getTokens(); - $this->_tokens = array(); - foreach ($tokens as $index => $token) { - if (isset($token['orig_content']) === true) { - $this->_tokens[$index] = $token['orig_content']; - } else { - $this->_tokens[$index] = $token['content']; - } - } - - }//end startFile() - - - /** - * Attempt to fix the file by processing it until no fixes are made. - * - * @return boolean - */ - public function fixFile() - { - $fixable = $this->_currentFile->getFixableCount(); - if ($fixable === 0) { - // Nothing to fix. - return false; - } - - $stdin = false; - $cliValues = $this->_currentFile->phpcs->cli->getCommandLineValues(); - if (empty($cliValues['files']) === true) { - $stdin = true; - } - - $this->enabled = true; - - $this->loops = 0; - while ($this->loops < 50) { - ob_start(); - - // Only needed once file content has changed. - $contents = $this->getContents(); - - if (PHP_CODESNIFFER_VERBOSITY > 2) { - @ob_end_clean(); - echo '---START FILE CONTENT---'.PHP_EOL; - $lines = explode($this->_currentFile->eolChar, $contents); - $max = strlen(count($lines)); - foreach ($lines as $lineNum => $line) { - $lineNum++; - echo str_pad($lineNum, $max, ' ', STR_PAD_LEFT).'|'.$line.PHP_EOL; - } - - echo '--- END FILE CONTENT ---'.PHP_EOL; - ob_start(); - } - - $this->_inConflict = false; - $this->_currentFile->refreshTokenListeners(); - $this->_currentFile->start($contents); - ob_end_clean(); - - $this->loops++; - - if (PHP_CODESNIFFER_CBF === true && $stdin === false) { - echo "\r".str_repeat(' ', 80)."\r"; - echo "\t=> Fixing file: $this->_numFixes/$fixable violations remaining [made $this->loops pass"; - if ($this->loops > 1) { - echo 'es'; - } - - echo ']... '; - } - - if ($this->_numFixes === 0 && $this->_inConflict === false) { - // Nothing left to do. - break; - } else if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t* fixed $this->_numFixes violations, starting loop ".($this->loops + 1).' *'.PHP_EOL; - } - }//end while - - $this->enabled = false; - - if ($this->_numFixes > 0) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - @ob_end_clean(); - echo "\t*** Reached maximum number of loops with $this->_numFixes violations left unfixed ***".PHP_EOL; - ob_start(); - } - - return false; - } - - return true; - - }//end fixFile() - - - /** - * Generates a text diff of the original file and the new content. - * - * @param string $filePath Optional file path to diff the file against. - * If not specified, the original version of the - * file will be used. - * @param boolean $colors Print colored output or not. - * - * @return string - */ - public function generateDiff($filePath=null, $colors=true) - { - if ($filePath === null) { - $filePath = $this->_currentFile->getFilename(); - } - - $cwd = getcwd().DIRECTORY_SEPARATOR; - if (strpos($filePath, $cwd) === 0) { - $filename = substr($filePath, strlen($cwd)); - } else { - $filename = $filePath; - } - - $contents = $this->getContents(); - - if (function_exists('sys_get_temp_dir') === true) { - // This is needed for HHVM support, but only available from 5.2.1. - $tempName = tempnam(sys_get_temp_dir(), 'phpcs-fixer'); - $fixedFile = fopen($tempName, 'w'); - } else { - $fixedFile = tmpfile(); - $data = stream_get_meta_data($fixedFile); - $tempName = $data['uri']; - } - - fwrite($fixedFile, $contents); - - // We must use something like shell_exec() because whitespace at the end - // of lines is critical to diff files. - $filename = escapeshellarg($filename); - $cmd = "diff -u -L$filename -LPHP_CodeSniffer $filename \"$tempName\""; - - $diff = shell_exec($cmd); - - fclose($fixedFile); - if (is_file($tempName) === true) { - unlink($tempName); - } - - if ($colors === false) { - return $diff; - } - - $diffLines = explode(PHP_EOL, $diff); - if (count($diffLines) === 1) { - // Seems to be required for cygwin. - $diffLines = explode("\n", $diff); - } - - $diff = array(); - foreach ($diffLines as $line) { - if (isset($line[0]) === true) { - switch ($line[0]) { - case '-': - $diff[] = "\033[31m$line\033[0m"; - break; - case '+': - $diff[] = "\033[32m$line\033[0m"; - break; - default: - $diff[] = $line; - } - } - } - - $diff = implode(PHP_EOL, $diff); - - return $diff; - - }//end generateDiff() - - - /** - * Get a count of fixes that have been performed on the file. - * - * This value is reset every time a new file is started, or an existing - * file is restarted. - * - * @return int - */ - public function getFixCount() - { - return $this->_numFixes; - - }//end getFixCount() - - - /** - * Get the current content of the file, as a string. - * - * @return string - */ - public function getContents() - { - $contents = implode($this->_tokens); - return $contents; - - }//end getContents() - - - /** - * Get the current fixed content of a token. - * - * This function takes changesets into account so should be used - * instead of directly accessing the token array. - * - * @param int $stackPtr The position of the token in the token stack. - * - * @return string - */ - public function getTokenContent($stackPtr) - { - if ($this->_inChangeset === true - && isset($this->_changeset[$stackPtr]) === true - ) { - return $this->_changeset[$stackPtr]; - } else { - return $this->_tokens[$stackPtr]; - } - - }//end getTokenContent() - - - /** - * Start recording actions for a changeset. - * - * @return void - */ - public function beginChangeset() - { - if ($this->_inConflict === true) { - return false; - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $bt = debug_backtrace(); - $sniff = $bt[1]['class']; - $line = $bt[0]['line']; - - @ob_end_clean(); - echo "\t=> Changeset started by $sniff (line $line)".PHP_EOL; - ob_start(); - } - - $this->_changeset = array(); - $this->_inChangeset = true; - - }//end beginChangeset() - - - /** - * Stop recording actions for a changeset, and apply logged changes. - * - * @return boolean - */ - public function endChangeset() - { - if ($this->_inConflict === true) { - return false; - } - - $this->_inChangeset = false; - - $success = true; - $applied = array(); - foreach ($this->_changeset as $stackPtr => $content) { - $success = $this->replaceToken($stackPtr, $content); - if ($success === false) { - break; - } else { - $applied[] = $stackPtr; - } - } - - if ($success === false) { - // Rolling back all changes. - foreach ($applied as $stackPtr) { - $this->revertToken($stackPtr); - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - @ob_end_clean(); - echo "\t=> Changeset failed to apply".PHP_EOL; - ob_start(); - } - } else if (PHP_CODESNIFFER_VERBOSITY > 1) { - $fixes = count($this->_changeset); - @ob_end_clean(); - echo "\t=> Changeset ended: $fixes changes applied".PHP_EOL; - ob_start(); - } - - $this->_changeset = array(); - - }//end endChangeset() - - - /** - * Stop recording actions for a changeset, and discard logged changes. - * - * @return void - */ - public function rollbackChangeset() - { - $this->_inChangeset = false; - $this->_inConflict = false; - - if (empty($this->_changeset) === false) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $bt = debug_backtrace(); - if ($bt[1]['class'] === 'PHP_CodeSniffer_Fixer') { - $sniff = $bt[2]['class']; - $line = $bt[1]['line']; - } else { - $sniff = $bt[1]['class']; - $line = $bt[0]['line']; - } - - $numChanges = count($this->_changeset); - - @ob_end_clean(); - echo "\t\tR: $sniff (line $line) rolled back the changeset ($numChanges changes)".PHP_EOL; - echo "\t=> Changeset rolled back".PHP_EOL; - ob_start(); - } - - $this->_changeset = array(); - }//end if - - }//end rollbackChangeset() - - - /** - * Replace the entire contents of a token. - * - * @param int $stackPtr The position of the token in the token stack. - * @param string $content The new content of the token. - * - * @return bool If the change was accepted. - */ - public function replaceToken($stackPtr, $content) - { - if ($this->_inConflict === true) { - return false; - } - - if ($this->_inChangeset === false - && isset($this->_fixedTokens[$stackPtr]) === true - ) { - $indent = "\t"; - if (empty($this->_changeset) === false) { - $indent .= "\t"; - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - @ob_end_clean(); - echo "$indent* token $stackPtr has already been modified, skipping *".PHP_EOL; - ob_start(); - } - - return false; - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $bt = debug_backtrace(); - if ($bt[1]['class'] === 'PHP_CodeSniffer_Fixer') { - $sniff = $bt[2]['class']; - $line = $bt[1]['line']; - } else { - $sniff = $bt[1]['class']; - $line = $bt[0]['line']; - } - - $tokens = $this->_currentFile->getTokens(); - $type = $tokens[$stackPtr]['type']; - $oldContent = PHP_CodeSniffer::prepareForOutput($this->_tokens[$stackPtr]); - $newContent = PHP_CodeSniffer::prepareForOutput($content); - if (trim($this->_tokens[$stackPtr]) === '' && isset($this->_tokens[($stackPtr + 1)]) === true) { - // Add some context for whitespace only changes. - $append = PHP_CodeSniffer::prepareForOutput($this->_tokens[($stackPtr + 1)]); - $oldContent .= $append; - $newContent .= $append; - } - }//end if - - if ($this->_inChangeset === true) { - $this->_changeset[$stackPtr] = $content; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - @ob_end_clean(); - echo "\t\tQ: $sniff (line $line) replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\"".PHP_EOL; - ob_start(); - } - - return true; - } - - if (isset($this->_oldTokenValues[$stackPtr]) === false) { - $this->_oldTokenValues[$stackPtr] = array( - 'curr' => $content, - 'prev' => $this->_tokens[$stackPtr], - 'loop' => $this->loops, - ); - } else { - if ($this->_oldTokenValues[$stackPtr]['prev'] === $content - && $this->_oldTokenValues[$stackPtr]['loop'] === ($this->loops - 1) - ) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $indent = "\t"; - if (empty($this->_changeset) === false) { - $indent .= "\t"; - } - - $loop = $this->_oldTokenValues[$stackPtr]['loop']; - - @ob_end_clean(); - echo "$indent**** $sniff (line $line) has possible conflict with another sniff on loop $loop; caused by the following change ****".PHP_EOL; - echo "$indent**** replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\" ****".PHP_EOL; - } - - if ($this->_oldTokenValues[$stackPtr]['loop'] >= ($this->loops - 1)) { - $this->_inConflict = true; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "$indent**** ignoring all changes until next loop ****".PHP_EOL; - } - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - ob_start(); - } - - return false; - }//end if - - $this->_oldTokenValues[$stackPtr]['prev'] = $this->_oldTokenValues[$stackPtr]['curr']; - $this->_oldTokenValues[$stackPtr]['curr'] = $content; - $this->_oldTokenValues[$stackPtr]['loop'] = $this->loops; - }//end if - - $this->_fixedTokens[$stackPtr] = $this->_tokens[$stackPtr]; - $this->_tokens[$stackPtr] = $content; - $this->_numFixes++; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $indent = "\t"; - if (empty($this->_changeset) === false) { - $indent .= "\tA: "; - } - - @ob_end_clean(); - echo "$indent$sniff (line $line) replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\"".PHP_EOL; - ob_start(); - } - - return true; - - }//end replaceToken() - - - /** - * Reverts the previous fix made to a token. - * - * @param int $stackPtr The position of the token in the token stack. - * - * @return bool If a change was reverted. - */ - public function revertToken($stackPtr) - { - if (isset($this->_fixedTokens[$stackPtr]) === false) { - return false; - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $bt = debug_backtrace(); - if ($bt[1]['class'] === 'PHP_CodeSniffer_Fixer') { - $sniff = $bt[2]['class']; - $line = $bt[1]['line']; - } else { - $sniff = $bt[1]['class']; - $line = $bt[0]['line']; - } - - $tokens = $this->_currentFile->getTokens(); - $type = $tokens[$stackPtr]['type']; - $oldContent = PHP_CodeSniffer::prepareForOutput($this->_tokens[$stackPtr]); - $newContent = PHP_CodeSniffer::prepareForOutput($this->_fixedTokens[$stackPtr]); - if (trim($this->_tokens[$stackPtr]) === '' && isset($tokens[($stackPtr + 1)]) === true) { - // Add some context for whitespace only changes. - $append = PHP_CodeSniffer::prepareForOutput($this->_tokens[($stackPtr + 1)]); - $oldContent .= $append; - $newContent .= $append; - } - }//end if - - $this->_tokens[$stackPtr] = $this->_fixedTokens[$stackPtr]; - unset($this->_fixedTokens[$stackPtr]); - $this->_numFixes--; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $indent = "\t"; - if (empty($this->_changeset) === false) { - $indent .= "\tR: "; - } - - @ob_end_clean(); - echo "$indent$sniff (line $line) reverted token $stackPtr ($type) \"$oldContent\" => \"$newContent\"".PHP_EOL; - ob_start(); - } - - return true; - - }//end revertToken() - - - /** - * Replace the content of a token with a part of its current content. - * - * @param int $stackPtr The position of the token in the token stack. - * @param int $start The first character to keep. - * @param int $length The number of chacters to keep. If NULL, the content of - * the token from $start to the end of the content is kept. - * - * @return bool If the change was accepted. - */ - public function substrToken($stackPtr, $start, $length=null) - { - $current = $this->getTokenContent($stackPtr); - - if ($length === null) { - $newContent = substr($current, $start); - } else { - $newContent = substr($current, $start, $length); - } - - return $this->replaceToken($stackPtr, $newContent); - - }//end substrToken() - - - /** - * Adds a newline to end of a token's content. - * - * @param int $stackPtr The position of the token in the token stack. - * - * @return bool If the change was accepted. - */ - public function addNewline($stackPtr) - { - $current = $this->getTokenContent($stackPtr); - return $this->replaceToken($stackPtr, $current.$this->_currentFile->eolChar); - - }//end addNewline() - - - /** - * Adds a newline to the start of a token's content. - * - * @param int $stackPtr The position of the token in the token stack. - * - * @return bool If the change was accepted. - */ - public function addNewlineBefore($stackPtr) - { - $current = $this->getTokenContent($stackPtr); - return $this->replaceToken($stackPtr, $this->_currentFile->eolChar.$current); - - }//end addNewlineBefore() - - - /** - * Adds content to the end of a token's current content. - * - * @param int $stackPtr The position of the token in the token stack. - * @param string $content The content to add. - * - * @return bool If the change was accepted. - */ - public function addContent($stackPtr, $content) - { - $current = $this->getTokenContent($stackPtr); - return $this->replaceToken($stackPtr, $current.$content); - - }//end addContent() - - - /** - * Adds content to the start of a token's current content. - * - * @param int $stackPtr The position of the token in the token stack. - * @param string $content The content to add. - * - * @return bool If the change was accepted. - */ - public function addContentBefore($stackPtr, $content) - { - $current = $this->getTokenContent($stackPtr); - return $this->replaceToken($stackPtr, $content.$current); - - }//end addContentBefore() - - -}//end class diff --git a/phpcs/CodeSniffer/Report.php b/phpcs/CodeSniffer/Report.php deleted file mode 100644 index 0f158c5..0000000 --- a/phpcs/CodeSniffer/Report.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Represents a PHP_CodeSniffer report. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Gabriele Santini - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -interface PHP_CodeSniffer_Report -{ - - - /** - * Generate a partial report for a single processed file. - * - * Function should return TRUE if it printed or stored data about the file - * and FALSE if it ignored the file. Returning TRUE indicates that the file and - * its data should be counted in the grand totals. - * - * @param array $report Prepared report data. - * @param PHP_CodeSniffer_File $phpcsFile The file being reported on. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * - * @return boolean - */ - public function generateFileReport( - $report, - PHP_CodeSniffer_File $phpcsFile, - $showSources=false, - $width=80 - ); - - - /** - * Generate the actual report. - * - * @param string $cachedData Any partial report data that was returned from - * generateFileReport during the run. - * @param int $totalFiles Total number of files processed during the run. - * @param int $totalErrors Total number of errors found during the run. - * @param int $totalWarnings Total number of warnings found during the run. - * @param int $totalFixable Total number of problems that can be fixed. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * @param boolean $toScreen Is the report being printed to screen? - * - * @return void - */ - public function generate( - $cachedData, - $totalFiles, - $totalErrors, - $totalWarnings, - $totalFixable, - $showSources=false, - $width=80, - $toScreen=true - ); - - -}//end interface diff --git a/phpcs/CodeSniffer/Reporting.php b/phpcs/CodeSniffer/Reporting.php deleted file mode 100644 index 5cf26d8..0000000 --- a/phpcs/CodeSniffer/Reporting.php +++ /dev/null @@ -1,425 +0,0 @@ - - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * A class to manage reporting. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Gabriele Santini - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reporting -{ - - /** - * Total number of files that contain errors or warnings. - * - * @var int - */ - public $totalFiles = 0; - - /** - * Total number of errors found during the run. - * - * @var int - */ - public $totalErrors = 0; - - /** - * Total number of warnings found during the run. - * - * @var int - */ - public $totalWarnings = 0; - - /** - * Total number of errors/warnings that can be fixed. - * - * @var int - */ - public $totalFixable = 0; - - /** - * When the PHPCS run started. - * - * @var float - */ - public static $startTime = 0; - - /** - * A list of reports that have written partial report output. - * - * @var array - */ - private $_cachedReports = array(); - - /** - * A cache of report objects. - * - * @var array - */ - private $_reports = array(); - - /** - * A cache of opened tmp files. - * - * @var array - */ - private $_tmpFiles = array(); - - - /** - * Produce the appropriate report object based on $type parameter. - * - * @param string $type The type of the report. - * - * @return PHP_CodeSniffer_Report - * @throws PHP_CodeSniffer_Exception If report is not available. - */ - public function factory($type) - { - $type = ucfirst($type); - if (isset($this->_reports[$type]) === true) { - return $this->_reports[$type]; - } - - if (strpos($type, '.') !== false) { - // This is a path to a custom report class. - $filename = realpath($type); - if ($filename === false) { - echo 'ERROR: Custom report "'.$type.'" not found'.PHP_EOL; - exit(2); - } - - $reportClassName = 'PHP_CodeSniffer_Reports_'.basename($filename); - $reportClassName = substr($reportClassName, 0, strpos($reportClassName, '.')); - include_once $filename; - } else { - $filename = $type.'.php'; - $reportClassName = 'PHP_CodeSniffer_Reports_'.$type; - if (class_exists($reportClassName, true) === false) { - echo 'ERROR: Report type "'.$type.'" not found'.PHP_EOL; - exit(2); - } - }//end if - - $reportClass = new $reportClassName(); - if (false === ($reportClass instanceof PHP_CodeSniffer_Report)) { - throw new PHP_CodeSniffer_Exception('Class "'.$reportClassName.'" must implement the "PHP_CodeSniffer_Report" interface.'); - } - - $this->_reports[$type] = $reportClass; - return $this->_reports[$type]; - - }//end factory() - - - /** - * Actually generates the report. - * - * @param PHP_CodeSniffer_File $phpcsFile The file that has been processed. - * @param array $cliValues An array of command line arguments. - * - * @return void - */ - public function cacheFileReport(PHP_CodeSniffer_File $phpcsFile, array $cliValues) - { - if (isset($cliValues['reports']) === false) { - // This happens during unit testing, or any time someone just wants - // the error data and not the printed report. - return; - } - - $reportData = $this->prepareFileReport($phpcsFile); - $errorsShown = false; - - foreach ($cliValues['reports'] as $report => $output) { - $reportClass = $this->factory($report); - $report = get_class($reportClass); - - ob_start(); - $result = $reportClass->generateFileReport($reportData, $phpcsFile, $cliValues['showSources'], $cliValues['reportWidth']); - if ($result === true) { - $errorsShown = true; - } - - $generatedReport = ob_get_contents(); - ob_end_clean(); - - if ($output === null && $cliValues['reportFile'] !== null) { - $output = $cliValues['reportFile']; - } - - if ($output === null) { - // Using a temp file. - if (isset($this->_tmpFiles[$report]) === false) { - if (function_exists('sys_get_temp_dir') === true) { - // This is needed for HHVM support, but only available from 5.2.1. - $this->_tmpFiles[$report] = fopen(tempnam(sys_get_temp_dir(), 'phpcs'), 'w'); - } else { - $this->_tmpFiles[$report] = tmpfile(); - } - } - - fwrite($this->_tmpFiles[$report], $generatedReport); - } else { - $flags = FILE_APPEND; - if (isset($this->_cachedReports[$report]) === false) { - $this->_cachedReports[$report] = true; - $flags = null; - } - - file_put_contents($output, $generatedReport, $flags); - }//end if - }//end foreach - - if ($errorsShown === true) { - $this->totalFiles++; - $this->totalErrors += $reportData['errors']; - $this->totalWarnings += $reportData['warnings']; - $this->totalFixable += $reportData['fixable']; - } - - }//end cacheFileReport() - - - /** - * Generates and prints a final report. - * - * Returns an array with the number of errors and the number of - * warnings, in the form ['errors' => int, 'warnings' => int]. - * - * @param string $report Report type. - * @param boolean $showSources Show sources? - * @param array $cliValues An array of command line arguments. - * @param string $reportFile Report file to generate. - * @param integer $reportWidth Report max width. - * - * @return int[] - */ - public function printReport( - $report, - $showSources, - array $cliValues, - $reportFile='', - $reportWidth=80 - ) { - $reportClass = $this->factory($report); - $report = get_class($reportClass); - - if ($reportFile !== null) { - $filename = $reportFile; - $toScreen = false; - - if (file_exists($filename) === true - && isset($this->_cachedReports[$report]) === true - ) { - $reportCache = file_get_contents($filename); - } else { - $reportCache = ''; - } - } else { - if (isset($this->_tmpFiles[$report]) === true) { - $data = stream_get_meta_data($this->_tmpFiles[$report]); - $filename = $data['uri']; - $reportCache = file_get_contents($filename); - fclose($this->_tmpFiles[$report]); - } else { - $reportCache = ''; - $filename = null; - } - - $toScreen = true; - }//end if - - ob_start(); - $reportClass->generate( - $reportCache, - $this->totalFiles, - $this->totalErrors, - $this->totalWarnings, - $this->totalFixable, - $showSources, - $reportWidth, - $toScreen - ); - $generatedReport = ob_get_contents(); - ob_end_clean(); - - if ($cliValues['colors'] !== true || $reportFile !== null) { - $generatedReport = preg_replace('`\033\[[0-9]+m`', '', $generatedReport); - } - - if ($reportFile !== null) { - if (PHP_CODESNIFFER_VERBOSITY > 0) { - echo $generatedReport; - } - - file_put_contents($reportFile, $generatedReport.PHP_EOL); - } else { - echo $generatedReport; - if ($filename !== null && file_exists($filename) === true) { - unlink($filename); - } - } - - return array( - 'errors' => $this->totalErrors, - 'warnings' => $this->totalWarnings, - ); - - }//end printReport() - - - /** - * Pre-process and package violations for all files. - * - * Used by error reports to get a packaged list of all errors in each file. - * - * @param PHP_CodeSniffer_File $phpcsFile The file that has been processed. - * - * @return array - */ - public function prepareFileReport(PHP_CodeSniffer_File $phpcsFile) - { - $report = array( - 'filename' => $phpcsFile->getFilename(), - 'errors' => $phpcsFile->getErrorCount(), - 'warnings' => $phpcsFile->getWarningCount(), - 'fixable' => $phpcsFile->getFixableCount(), - 'messages' => array(), - ); - - if ($report['errors'] === 0 && $report['warnings'] === 0) { - // Prefect score! - return $report; - } - - $errors = array(); - - // Merge errors and warnings. - foreach ($phpcsFile->getErrors() as $line => $lineErrors) { - if (is_array($lineErrors) === false) { - continue; - } - - foreach ($lineErrors as $column => $colErrors) { - $newErrors = array(); - foreach ($colErrors as $data) { - $newErrors[] = array( - 'message' => $data['message'], - 'source' => $data['source'], - 'severity' => $data['severity'], - 'fixable' => $data['fixable'], - 'type' => 'ERROR', - ); - }//end foreach - - $errors[$line][$column] = $newErrors; - }//end foreach - - ksort($errors[$line]); - }//end foreach - - foreach ($phpcsFile->getWarnings() as $line => $lineWarnings) { - if (is_array($lineWarnings) === false) { - continue; - } - - foreach ($lineWarnings as $column => $colWarnings) { - $newWarnings = array(); - foreach ($colWarnings as $data) { - $newWarnings[] = array( - 'message' => $data['message'], - 'source' => $data['source'], - 'severity' => $data['severity'], - 'fixable' => $data['fixable'], - 'type' => 'WARNING', - ); - }//end foreach - - if (isset($errors[$line]) === false) { - $errors[$line] = array(); - } - - if (isset($errors[$line][$column]) === true) { - $errors[$line][$column] = array_merge( - $newWarnings, - $errors[$line][$column] - ); - } else { - $errors[$line][$column] = $newWarnings; - } - }//end foreach - - ksort($errors[$line]); - }//end foreach - - ksort($errors); - $report['messages'] = $errors; - return $report; - - }//end prepareFileReport() - - - /** - * Start recording time for the run. - * - * @return void - */ - public static function startTiming() - { - - self::$startTime = microtime(true); - - }//end startTiming() - - - /** - * Print information about the run. - * - * @return void - */ - public static function printRunTime() - { - $time = ((microtime(true) - self::$startTime) * 1000); - - if ($time > 60000) { - $mins = floor($time / 60000); - $secs = round((($time % 60000) / 1000), 2); - $time = $mins.' mins'; - if ($secs !== 0) { - $time .= ", $secs secs"; - } - } else if ($time > 1000) { - $time = round(($time / 1000), 2).' secs'; - } else { - $time = round($time).'ms'; - } - - $mem = round((memory_get_peak_usage(true) / (1024 * 1024)), 2).'Mb'; - echo "Time: $time; Memory: $mem".PHP_EOL.PHP_EOL; - - }//end printRunTime() - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/Cbf.php b/phpcs/CodeSniffer/Reports/Cbf.php deleted file mode 100644 index 69f98b9..0000000 --- a/phpcs/CodeSniffer/Reports/Cbf.php +++ /dev/null @@ -1,151 +0,0 @@ - - * @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * CBF report for PHP_CodeSniffer. - * - * This report implements the various auto-fixing features of the - * PHPCBF script and is not intended (or allowed) to be selected as a - * report from the command line. - * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reports_Cbf implements PHP_CodeSniffer_Report -{ - - - /** - * Generate a partial report for a single processed file. - * - * Function should return TRUE if it printed or stored data about the file - * and FALSE if it ignored the file. Returning TRUE indicates that the file and - * its data should be counted in the grand totals. - * - * @param array $report Prepared report data. - * @param PHP_CodeSniffer_File $phpcsFile The file being reported on. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * - * @return boolean - */ - public function generateFileReport( - $report, - PHP_CodeSniffer_File $phpcsFile, - $showSources=false, - $width=80 - ) { - $cliValues = $phpcsFile->phpcs->cli->getCommandLineValues(); - $errors = $phpcsFile->getFixableCount(); - if ($errors !== 0) { - if (empty($cliValues['files']) === false) { - ob_end_clean(); - $errors = $phpcsFile->getFixableCount(); - $startTime = microtime(true); - echo "\t=> Fixing file: $errors/$errors violations remaining"; - } - - $fixed = $phpcsFile->fixer->fixFile(); - } - - if (empty($cliValues['files']) === true) { - // Replacing STDIN, so output current file to STDOUT - // even if nothing was fixed. Exit here because we - // can't process any more than 1 file in this setup. - echo $phpcsFile->fixer->getContents(); - ob_end_flush(); - exit(1); - } - - if ($errors === 0) { - return false; - } - - if ($fixed === false) { - echo 'ERROR'; - } else { - echo 'DONE'; - } - - $timeTaken = ((microtime(true) - $startTime) * 1000); - if ($timeTaken < 1000) { - $timeTaken = round($timeTaken); - echo " in {$timeTaken}ms".PHP_EOL; - } else { - $timeTaken = round(($timeTaken / 1000), 2); - echo " in $timeTaken secs".PHP_EOL; - } - - if ($fixed === true) { - $newFilename = $report['filename'].$cliValues['phpcbf-suffix']; - $newContent = $phpcsFile->fixer->getContents(); - file_put_contents($newFilename, $newContent); - - if ($newFilename === $report['filename']) { - echo "\t=> File was overwritten".PHP_EOL; - } else { - echo "\t=> Fixed file written to ".basename($newFilename).PHP_EOL; - } - } - - ob_start(); - - return $fixed; - - }//end generateFileReport() - - - /** - * Prints all errors and warnings for each file processed. - * - * @param string $cachedData Any partial report data that was returned from - * generateFileReport during the run. - * @param int $totalFiles Total number of files processed during the run. - * @param int $totalErrors Total number of errors found during the run. - * @param int $totalWarnings Total number of warnings found during the run. - * @param int $totalFixable Total number of problems that can be fixed. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * @param boolean $toScreen Is the report being printed to screen? - * - * @return void - */ - public function generate( - $cachedData, - $totalFiles, - $totalErrors, - $totalWarnings, - $totalFixable, - $showSources=false, - $width=80, - $toScreen=true - ) { - echo $cachedData; - echo "Fixed $totalFiles files".PHP_EOL; - - }//end generate() - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/Checkstyle.php b/phpcs/CodeSniffer/Reports/Checkstyle.php deleted file mode 100644 index 5ba89b9..0000000 --- a/phpcs/CodeSniffer/Reports/Checkstyle.php +++ /dev/null @@ -1,128 +0,0 @@ - - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Checkstyle report for PHP_CodeSniffer. - * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer - * @author Gabriele Santini - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reports_Checkstyle implements PHP_CodeSniffer_Report -{ - - - /** - * Generate a partial report for a single processed file. - * - * Function should return TRUE if it printed or stored data about the file - * and FALSE if it ignored the file. Returning TRUE indicates that the file and - * its data should be counted in the grand totals. - * - * @param array $report Prepared report data. - * @param PHP_CodeSniffer_File $phpcsFile The file being reported on. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * - * @return boolean - */ - public function generateFileReport( - $report, - PHP_CodeSniffer_File $phpcsFile, - $showSources=false, - $width=80 - ) { - $out = new XMLWriter; - $out->openMemory(); - $out->setIndent(true); - - if ($report['errors'] === 0 && $report['warnings'] === 0) { - // Nothing to print. - return false; - } - - $out->startElement('file'); - $out->writeAttribute('name', $report['filename']); - - foreach ($report['messages'] as $line => $lineErrors) { - foreach ($lineErrors as $column => $colErrors) { - foreach ($colErrors as $error) { - $error['type'] = strtolower($error['type']); - if (PHP_CODESNIFFER_ENCODING !== 'utf-8') { - $error['message'] = iconv(PHP_CODESNIFFER_ENCODING, 'utf-8', $error['message']); - } - - $out->startElement('error'); - $out->writeAttribute('line', $line); - $out->writeAttribute('column', $column); - $out->writeAttribute('severity', $error['type']); - $out->writeAttribute('message', $error['message']); - $out->writeAttribute('source', $error['source']); - $out->endElement(); - } - } - }//end foreach - - $out->endElement(); - echo $out->flush(); - - return true; - - }//end generateFileReport() - - - /** - * Prints all violations for processed files, in a Checkstyle format. - * - * @param string $cachedData Any partial report data that was returned from - * generateFileReport during the run. - * @param int $totalFiles Total number of files processed during the run. - * @param int $totalErrors Total number of errors found during the run. - * @param int $totalWarnings Total number of warnings found during the run. - * @param int $totalFixable Total number of problems that can be fixed. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * @param boolean $toScreen Is the report being printed to screen? - * - * @return void - */ - public function generate( - $cachedData, - $totalFiles, - $totalErrors, - $totalWarnings, - $totalFixable, - $showSources=false, - $width=80, - $toScreen=true - ) { - echo ''.PHP_EOL; - echo ''.PHP_EOL; - echo $cachedData; - echo ''.PHP_EOL; - - }//end generate() - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/Csv.php b/phpcs/CodeSniffer/Reports/Csv.php deleted file mode 100644 index b884c61..0000000 --- a/phpcs/CodeSniffer/Reports/Csv.php +++ /dev/null @@ -1,111 +0,0 @@ - - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Csv report for PHP_CodeSniffer. - * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer - * @author Gabriele Santini - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reports_Csv implements PHP_CodeSniffer_Report -{ - - - /** - * Generate a partial report for a single processed file. - * - * Function should return TRUE if it printed or stored data about the file - * and FALSE if it ignored the file. Returning TRUE indicates that the file and - * its data should be counted in the grand totals. - * - * @param array $report Prepared report data. - * @param PHP_CodeSniffer_File $phpcsFile The file being reported on. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * - * @return boolean - */ - public function generateFileReport( - $report, - PHP_CodeSniffer_File $phpcsFile, - $showSources=false, - $width=80 - ) { - if ($report['errors'] === 0 && $report['warnings'] === 0) { - // Nothing to print. - return false; - } - - foreach ($report['messages'] as $line => $lineErrors) { - foreach ($lineErrors as $column => $colErrors) { - foreach ($colErrors as $error) { - $filename = str_replace('"', '\"', $report['filename']); - $message = str_replace('"', '\"', $error['message']); - $type = strtolower($error['type']); - $source = $error['source']; - $severity = $error['severity']; - $fixable = (int) $error['fixable']; - echo "\"$filename\",$line,$column,$type,\"$message\",$source,$severity,$fixable".PHP_EOL; - } - } - } - - return true; - - }//end generateFileReport() - - - /** - * Generates a csv report. - * - * @param string $cachedData Any partial report data that was returned from - * generateFileReport during the run. - * @param int $totalFiles Total number of files processed during the run. - * @param int $totalErrors Total number of errors found during the run. - * @param int $totalWarnings Total number of warnings found during the run. - * @param int $totalFixable Total number of problems that can be fixed. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * @param boolean $toScreen Is the report being printed to screen? - * - * @return void - */ - public function generate( - $cachedData, - $totalFiles, - $totalErrors, - $totalWarnings, - $totalFixable, - $showSources=false, - $width=80, - $toScreen=true - ) { - echo 'File,Line,Column,Type,Message,Source,Severity,Fixable'.PHP_EOL; - echo $cachedData; - - }//end generate() - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/Diff.php b/phpcs/CodeSniffer/Reports/Diff.php deleted file mode 100644 index 4fa5a0b..0000000 --- a/phpcs/CodeSniffer/Reports/Diff.php +++ /dev/null @@ -1,149 +0,0 @@ - - * @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Diff report for PHP_CodeSniffer. - * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reports_Diff implements PHP_CodeSniffer_Report -{ - - - /** - * Generate a partial report for a single processed file. - * - * Function should return TRUE if it printed or stored data about the file - * and FALSE if it ignored the file. Returning TRUE indicates that the file and - * its data should be counted in the grand totals. - * - * @param array $report Prepared report data. - * @param PHP_CodeSniffer_File $phpcsFile The file being reported on. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * - * @return boolean - */ - public function generateFileReport( - $report, - PHP_CodeSniffer_File $phpcsFile, - $showSources=false, - $width=80 - ) { - $errors = $phpcsFile->getFixableCount(); - if ($errors === 0) { - return false; - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - ob_end_clean(); - echo "\t*** START FILE FIXING ***".PHP_EOL; - } - - if (PHP_CODESNIFFER_CBF === true) { - ob_end_clean(); - $startTime = microtime(true); - echo "\t=> Fixing file: $errors/$errors violations remaining"; - } - - $fixed = $phpcsFile->fixer->fixFile(); - - if (PHP_CODESNIFFER_CBF === true) { - if ($fixed === false) { - echo "\033[31mERROR\033[0m"; - } else { - echo "\033[32mDONE\033[0m"; - } - - $timeTaken = ((microtime(true) - $startTime) * 1000); - if ($timeTaken < 1000) { - $timeTaken = round($timeTaken); - echo " in {$timeTaken}ms".PHP_EOL; - } else { - $timeTaken = round(($timeTaken / 1000), 2); - echo " in $timeTaken secs".PHP_EOL; - } - - ob_start(); - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** END FILE FIXING ***".PHP_EOL; - ob_start(); - } - - if ($fixed === false) { - return false; - } - - if (PHP_CODESNIFFER_CBF === true) { - // Diff without colours. - $diff = $phpcsFile->fixer->generateDiff(null, false); - } else { - $diff = $phpcsFile->fixer->generateDiff(); - } - - if ($diff === '') { - // Nothing to print. - return false; - } - - echo $diff.PHP_EOL; - return true; - - }//end generateFileReport() - - - /** - * Prints all errors and warnings for each file processed. - * - * @param string $cachedData Any partial report data that was returned from - * generateFileReport during the run. - * @param int $totalFiles Total number of files processed during the run. - * @param int $totalErrors Total number of errors found during the run. - * @param int $totalWarnings Total number of warnings found during the run. - * @param int $totalFixable Total number of problems that can be fixed. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * @param boolean $toScreen Is the report being printed to screen? - * - * @return void - */ - public function generate( - $cachedData, - $totalFiles, - $totalErrors, - $totalWarnings, - $totalFixable, - $showSources=false, - $width=80, - $toScreen=true - ) { - echo $cachedData; - if ($toScreen === true) { - echo PHP_EOL; - } - - }//end generate() - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/Emacs.php b/phpcs/CodeSniffer/Reports/Emacs.php deleted file mode 100644 index 1b5475f..0000000 --- a/phpcs/CodeSniffer/Reports/Emacs.php +++ /dev/null @@ -1,110 +0,0 @@ - - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Emacs report for PHP_CodeSniffer. - * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer - * @author Gabriele Santini - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reports_Emacs implements PHP_CodeSniffer_Report -{ - - - /** - * Generate a partial report for a single processed file. - * - * Function should return TRUE if it printed or stored data about the file - * and FALSE if it ignored the file. Returning TRUE indicates that the file and - * its data should be counted in the grand totals. - * - * @param array $report Prepared report data. - * @param PHP_CodeSniffer_File $phpcsFile The file being reported on. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * - * @return boolean - */ - public function generateFileReport( - $report, - PHP_CodeSniffer_File $phpcsFile, - $showSources=false, - $width=80 - ) { - if ($report['errors'] === 0 && $report['warnings'] === 0) { - // Nothing to print. - return false; - } - - foreach ($report['messages'] as $line => $lineErrors) { - foreach ($lineErrors as $column => $colErrors) { - foreach ($colErrors as $error) { - $message = $error['message']; - if ($showSources === true) { - $message .= ' ('.$error['source'].')'; - } - - $type = strtolower($error['type']); - echo $report['filename'].':'.$line.':'.$column.': '.$type.' - '.$message.PHP_EOL; - } - } - } - - return true; - - }//end generateFileReport() - - - /** - * Generates an emacs report. - * - * @param string $cachedData Any partial report data that was returned from - * generateFileReport during the run. - * @param int $totalFiles Total number of files processed during the run. - * @param int $totalErrors Total number of errors found during the run. - * @param int $totalWarnings Total number of warnings found during the run. - * @param int $totalFixable Total number of problems that can be fixed. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * @param boolean $toScreen Is the report being printed to screen? - * - * @return void - */ - public function generate( - $cachedData, - $totalFiles, - $totalErrors, - $totalWarnings, - $totalFixable, - $showSources=false, - $width=80, - $toScreen=true - ) { - echo $cachedData; - - }//end generate() - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/Full.php b/phpcs/CodeSniffer/Reports/Full.php deleted file mode 100644 index 1ce8cd1..0000000 --- a/phpcs/CodeSniffer/Reports/Full.php +++ /dev/null @@ -1,237 +0,0 @@ - - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Full report for PHP_CodeSniffer. - * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer - * @author Gabriele Santini - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reports_Full implements PHP_CodeSniffer_Report -{ - - - /** - * Generate a partial report for a single processed file. - * - * Function should return TRUE if it printed or stored data about the file - * and FALSE if it ignored the file. Returning TRUE indicates that the file and - * its data should be counted in the grand totals. - * - * @param array $report Prepared report data. - * @param PHP_CodeSniffer_File $phpcsFile The file being reported on. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * - * @return boolean - */ - public function generateFileReport( - $report, - PHP_CodeSniffer_File $phpcsFile, - $showSources=false, - $width=80 - ) { - if ($report['errors'] === 0 && $report['warnings'] === 0) { - // Nothing to print. - return false; - } - - // The length of the word ERROR or WARNING; used for padding. - if ($report['warnings'] > 0) { - $typeLength = 7; - } else { - $typeLength = 5; - } - - // Work out the max line number length for formatting. - $maxLineNumLength = max(array_map('strlen', array_keys($report['messages']))); - - // The padding that all lines will require that are - // printing an error message overflow. - $paddingLine2 = str_repeat(' ', ($maxLineNumLength + 1)); - $paddingLine2 .= ' | '; - $paddingLine2 .= str_repeat(' ', $typeLength); - $paddingLine2 .= ' | '; - if ($report['fixable'] > 0) { - $paddingLine2 .= ' '; - } - - $paddingLength = strlen($paddingLine2); - - // Make sure the report width isn't too big. - $maxErrorLength = 0; - foreach ($report['messages'] as $line => $lineErrors) { - foreach ($lineErrors as $column => $colErrors) { - foreach ($colErrors as $error) { - $length = strlen($error['message']); - if ($showSources === true) { - $length += (strlen($error['source']) + 3); - } - - $maxErrorLength = max($maxErrorLength, ($length + 1)); - } - } - } - - $file = $report['filename']; - $fileLength = strlen($file); - $maxWidth = max(($fileLength + 6), ($maxErrorLength + $paddingLength)); - $width = min($width, $maxWidth); - if ($width < 70) { - $width = 70; - } - - echo PHP_EOL."\033[1mFILE: "; - if ($fileLength <= ($width - 6)) { - echo $file; - } else { - echo '...'.substr($file, ($fileLength - ($width - 6))); - } - - echo "\033[0m".PHP_EOL; - echo str_repeat('-', $width).PHP_EOL; - - echo "\033[1m".'FOUND '.$report['errors'].' ERROR'; - if ($report['errors'] !== 1) { - echo 'S'; - } - - if ($report['warnings'] > 0) { - echo ' AND '.$report['warnings'].' WARNING'; - if ($report['warnings'] !== 1) { - echo 'S'; - } - } - - echo ' AFFECTING '.count($report['messages']).' LINE'; - if (count($report['messages']) !== 1) { - echo 'S'; - } - - echo "\033[0m".PHP_EOL; - echo str_repeat('-', $width).PHP_EOL; - - // The maximum amount of space an error message can use. - $maxErrorSpace = ($width - $paddingLength - 1); - if ($showSources === true) { - // Account for the chars used to print colors. - $maxErrorSpace += 8; - } - - foreach ($report['messages'] as $line => $lineErrors) { - foreach ($lineErrors as $column => $colErrors) { - foreach ($colErrors as $error) { - $message = $error['message']; - $message = str_replace("\n", "\n".$paddingLine2, $message); - if ($showSources === true) { - $message = "\033[1m".$message."\033[0m".' ('.$error['source'].')'; - } - - // The padding that goes on the front of the line. - $padding = ($maxLineNumLength - strlen($line)); - $errorMsg = wordwrap( - $message, - $maxErrorSpace, - PHP_EOL.$paddingLine2 - ); - - echo ' '.str_repeat(' ', $padding).$line.' | '; - if ($error['type'] === 'ERROR') { - echo "\033[31mERROR\033[0m"; - if ($report['warnings'] > 0) { - echo ' '; - } - } else { - echo "\033[33mWARNING\033[0m"; - } - - echo ' | '; - if ($report['fixable'] > 0) { - echo '['; - if ($error['fixable'] === true) { - echo 'x'; - } else { - echo ' '; - } - - echo '] '; - } - - echo $errorMsg.PHP_EOL; - }//end foreach - }//end foreach - }//end foreach - - echo str_repeat('-', $width).PHP_EOL; - if ($report['fixable'] > 0) { - echo "\033[1m".'PHPCBF CAN FIX THE '.$report['fixable'].' MARKED SNIFF VIOLATIONS AUTOMATICALLY'."\033[0m".PHP_EOL; - echo str_repeat('-', $width).PHP_EOL; - } - - echo PHP_EOL; - return true; - - }//end generateFileReport() - - - /** - * Prints all errors and warnings for each file processed. - * - * @param string $cachedData Any partial report data that was returned from - * generateFileReport during the run. - * @param int $totalFiles Total number of files processed during the run. - * @param int $totalErrors Total number of errors found during the run. - * @param int $totalWarnings Total number of warnings found during the run. - * @param int $totalFixable Total number of problems that can be fixed. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * @param boolean $toScreen Is the report being printed to screen? - * - * @return void - */ - public function generate( - $cachedData, - $totalFiles, - $totalErrors, - $totalWarnings, - $totalFixable, - $showSources=false, - $width=80, - $toScreen=true - ) { - if ($cachedData === '') { - return; - } - - echo $cachedData; - - if ($toScreen === true && PHP_CODESNIFFER_INTERACTIVE === false) { - PHP_CodeSniffer_Reporting::printRunTime(); - } - - }//end generate() - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/Gitblame.php b/phpcs/CodeSniffer/Reports/Gitblame.php deleted file mode 100644 index 099c858..0000000 --- a/phpcs/CodeSniffer/Reports/Gitblame.php +++ /dev/null @@ -1,105 +0,0 @@ - - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Gitblame report for PHP_CodeSniffer. - * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer - * @author Ben Selby - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: 1.2.2 - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reports_Gitblame extends PHP_CodeSniffer_Reports_VersionControl -{ - - /** - * The name of the report we want in the output - * - * @var string - */ - protected $reportName = 'GIT'; - - - /** - * Extract the author from a blame line. - * - * @param string $line Line to parse. - * - * @return mixed string or false if impossible to recover. - */ - protected function getAuthor($line) - { - $blameParts = array(); - $line = preg_replace('|\s+|', ' ', $line); - preg_match( - '|\(.+[0-9]{4}-[0-9]{2}-[0-9]{2}\s+[0-9]+\)|', - $line, - $blameParts - ); - - if (isset($blameParts[0]) === false) { - return false; - } - - $parts = explode(' ', $blameParts[0]); - - if (count($parts) < 2) { - return false; - } - - $parts = array_slice($parts, 0, (count($parts) - 2)); - $author = preg_replace('|\(|', '', implode($parts, ' ')); - return $author; - - }//end getAuthor() - - - /** - * Gets the blame output. - * - * @param string $filename File to blame. - * - * @return array - */ - protected function getBlameContent($filename) - { - $cwd = getcwd(); - - chdir(dirname($filename)); - $command = 'git blame --date=short "'.$filename.'" 2>&1'; - $handle = popen($command, 'r'); - if ($handle === false) { - echo 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL; - exit(2); - } - - $rawContent = stream_get_contents($handle); - fclose($handle); - - $blames = explode("\n", $rawContent); - chdir($cwd); - - return $blames; - - }//end getBlameContent() - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/Hgblame.php b/phpcs/CodeSniffer/Reports/Hgblame.php deleted file mode 100644 index 5c167f2..0000000 --- a/phpcs/CodeSniffer/Reports/Hgblame.php +++ /dev/null @@ -1,124 +0,0 @@ - - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Mercurial report for PHP_CodeSniffer. - * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer - * @author Ben Selby - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reports_Hgblame extends PHP_CodeSniffer_Reports_VersionControl -{ - - /** - * The name of the report we want in the output - * - * @var string - */ - protected $reportName = 'MERCURIAL'; - - - /** - * Extract the author from a blame line. - * - * @param string $line Line to parse. - * - * @return mixed string or false if impossible to recover. - */ - protected function getAuthor($line) - { - $blameParts = array(); - $line = preg_replace('|\s+|', ' ', $line); - - preg_match( - '|(.+[0-9]{2}:[0-9]{2}:[0-9]{2}\s[0-9]{4}\s.[0-9]{4}:)|', - $line, - $blameParts - ); - - if (isset($blameParts[0]) === false) { - return false; - } - - $parts = explode(' ', $blameParts[0]); - - if (count($parts) < 6) { - return false; - } - - $parts = array_slice($parts, 0, (count($parts) - 6)); - - return trim(preg_replace('|<.+>|', '', implode($parts, ' '))); - - }//end getAuthor() - - - /** - * Gets the blame output. - * - * @param string $filename File to blame. - * - * @return array - */ - protected function getBlameContent($filename) - { - $cwd = getcwd(); - - $fileParts = explode(DIRECTORY_SEPARATOR, $filename); - $found = false; - $location = ''; - while (empty($fileParts) === false) { - array_pop($fileParts); - $location = implode($fileParts, DIRECTORY_SEPARATOR); - if (is_dir($location.DIRECTORY_SEPARATOR.'.hg') === true) { - $found = true; - break; - } - } - - if ($found === true) { - chdir($location); - } else { - echo 'ERROR: Could not locate .hg directory '.PHP_EOL.PHP_EOL; - exit(2); - } - - $command = 'hg blame -u -d -v "'.$filename.'" 2>&1'; - $handle = popen($command, 'r'); - if ($handle === false) { - echo 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL; - exit(2); - } - - $rawContent = stream_get_contents($handle); - fclose($handle); - - $blames = explode("\n", $rawContent); - chdir($cwd); - - return $blames; - - }//end getBlameContent() - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/Info.php b/phpcs/CodeSniffer/Reports/Info.php deleted file mode 100644 index a599d9c..0000000 --- a/phpcs/CodeSniffer/Reports/Info.php +++ /dev/null @@ -1,162 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Info report for PHP_CodeSniffer. - * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reports_Info implements PHP_CodeSniffer_Report -{ - - /** - * TRUE if this report needs error messages instead of just totals. - * - * @var boolean - */ - public $recordErrors = false; - - /** - * A cache of metrics collected during the run. - * - * @var array - */ - private $_metricCache = array(); - - - /** - * Generate a partial report for a single processed file. - * - * Function should return TRUE if it printed or stored data about the file - * and FALSE if it ignored the file. Returning TRUE indicates that the file and - * its data should be counted in the grand totals. - * - * @param array $report Prepared report data. - * @param PHP_CodeSniffer_File $phpcsFile The file being reported on. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * - * @return boolean - */ - public function generateFileReport( - $report, - PHP_CodeSniffer_File $phpcsFile, - $showSources=false, - $width=80 - ) { - $metrics = $phpcsFile->getMetrics(); - foreach ($metrics as $metric => $data) { - if (isset($this->_metricCache[$metric]) === false) { - $this->_metricCache[$metric] = array(); - } - - foreach ($data['values'] as $value => $locations) { - $locations = array_unique($locations); - $count = count($locations); - - if (isset($this->_metricCache[$metric][$value]) === false) { - $this->_metricCache[$metric][$value] = $count; - } else { - $this->_metricCache[$metric][$value] += $count; - } - } - }//end foreach - - return true; - - }//end generateFileReport() - - - /** - * Prints the source of all errors and warnings. - * - * @param string $cachedData Any partial report data that was returned from - * generateFileReport during the run. - * @param int $totalFiles Total number of files processed during the run. - * @param int $totalErrors Total number of errors found during the run. - * @param int $totalWarnings Total number of warnings found during the run. - * @param int $totalFixable Total number of problems that can be fixed. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * @param boolean $toScreen Is the report being printed to screen? - * - * @return void - */ - public function generate( - $cachedData, - $totalFiles, - $totalErrors, - $totalWarnings, - $totalFixable, - $showSources=false, - $width=80, - $toScreen=true - ) { - if (empty($this->_metricCache) === true) { - // Nothing to show. - return; - } - - ksort($this->_metricCache); - - echo PHP_EOL."\033[1m".'PHP CODE SNIFFER INFORMATION REPORT'."\033[0m".PHP_EOL; - echo str_repeat('-', 70).PHP_EOL; - - foreach ($this->_metricCache as $metric => $values) { - $winner = ''; - $winnerCount = 0; - $totalCount = 0; - foreach ($values as $value => $count) { - $totalCount += $count; - if ($count > $winnerCount) { - $winner = $value; - $winnerCount = $count; - } - } - - $winPercent = round(($winnerCount / $totalCount * 100), 2); - echo "$metric: \033[4m$winner\033[0m [$winnerCount/$totalCount, $winPercent%]".PHP_EOL; - - asort($values); - $values = array_reverse($values, true); - foreach ($values as $value => $count) { - if ($value === $winner) { - continue; - } - - $percent = round(($count / $totalCount * 100), 2); - echo "\t$value => $count ($percent%)".PHP_EOL; - } - - echo PHP_EOL; - }//end foreach - - echo str_repeat('-', 70).PHP_EOL; - - if ($toScreen === true && PHP_CODESNIFFER_INTERACTIVE === false) { - PHP_CodeSniffer_Reporting::printRunTime(); - } - - }//end generate() - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/Json.php b/phpcs/CodeSniffer/Reports/Json.php deleted file mode 100644 index 5bbf4dd..0000000 --- a/phpcs/CodeSniffer/Reports/Json.php +++ /dev/null @@ -1,128 +0,0 @@ - - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Json report for PHP_CodeSniffer. - * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer - * @author Jeffrey Fisher - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reports_Json implements PHP_CodeSniffer_Report -{ - - - /** - * Generate a partial report for a single processed file. - * - * Function should return TRUE if it printed or stored data about the file - * and FALSE if it ignored the file. Returning TRUE indicates that the file and - * its data should be counted in the grand totals. - * - * @param array $report Prepared report data. - * @param PHP_CodeSniffer_File $phpcsFile The file being reported on. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * - * @return boolean - */ - public function generateFileReport( - $report, - PHP_CodeSniffer_File $phpcsFile, - $showSources=false, - $width=80 - ) { - $filename = str_replace('\\', '\\\\', $report['filename']); - $filename = str_replace('"', '\"', $filename); - $filename = str_replace('/', '\/', $filename); - echo '"'.$filename.'":{'; - echo '"errors":'.$report['errors'].',"warnings":'.$report['warnings'].',"messages":['; - - $messages = ''; - foreach ($report['messages'] as $line => $lineErrors) { - foreach ($lineErrors as $column => $colErrors) { - foreach ($colErrors as $error) { - $error['message'] = str_replace('\\', '\\\\', $error['message']); - $error['message'] = str_replace('"', '\"', $error['message']); - $error['message'] = str_replace('/', '\/', $error['message']); - $error['message'] = str_replace("\n", '\n', $error['message']); - $error['message'] = str_replace("\r", '\r', $error['message']); - $error['message'] = str_replace("\t", '\t', $error['message']); - - $fixable = 'false'; - if ($error['fixable'] === true) { - $fixable = 'true'; - } - - $messages .= '{"message":"'.$error['message'].'",'; - $messages .= '"source":"'.$error['source'].'",'; - $messages .= '"severity":'.$error['severity'].','; - $messages .= '"type":"'.$error['type'].'",'; - $messages .= '"line":'.$line.','; - $messages .= '"column":'.$column.','; - $messages .= '"fixable":'.$fixable; - $messages .= '},'; - }//end foreach - }//end foreach - }//end foreach - - echo rtrim($messages, ','); - echo ']},'; - - return true; - - }//end generateFileReport() - - - /** - * Generates a JSON report. - * - * @param string $cachedData Any partial report data that was returned from - * generateFileReport during the run. - * @param int $totalFiles Total number of files processed during the run. - * @param int $totalErrors Total number of errors found during the run. - * @param int $totalWarnings Total number of warnings found during the run. - * @param int $totalFixable Total number of problems that can be fixed. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * @param boolean $toScreen Is the report being printed to screen? - * - * @return void - */ - public function generate( - $cachedData, - $totalFiles, - $totalErrors, - $totalWarnings, - $totalFixable, - $showSources=false, - $width=80, - $toScreen=true - ) { - echo '{"totals":{"errors":'.$totalErrors.',"warnings":'.$totalWarnings.',"fixable":'.$totalFixable.'},"files":{'; - echo rtrim($cachedData, ','); - echo "}}"; - - }//end generate() - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/Junit.php b/phpcs/CodeSniffer/Reports/Junit.php deleted file mode 100644 index 76334f6..0000000 --- a/phpcs/CodeSniffer/Reports/Junit.php +++ /dev/null @@ -1,149 +0,0 @@ - - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * JUnit report for PHP_CodeSniffer. - * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer - * @author Oleg Lobach - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reports_Junit implements PHP_CodeSniffer_Report -{ - - /** - * A count of tests that have been performed. - * - * @var int - */ - private $_tests = 0; - - - /** - * Generate a partial report for a single processed file. - * - * Function should return TRUE if it printed or stored data about the file - * and FALSE if it ignored the file. Returning TRUE indicates that the file and - * its data should be counted in the grand totals. - * - * @param array $report Prepared report data. - * @param PHP_CodeSniffer_File $phpcsFile The file being reported on. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * - * @return boolean - */ - public function generateFileReport( - $report, - PHP_CodeSniffer_File $phpcsFile, - $showSources=false, - $width=80 - ) { - if (count($report['messages']) === 0) { - $this->_tests++; - } else { - $this->_tests += ($report['errors'] + $report['warnings']); - } - - $out = new XMLWriter; - $out->openMemory(); - $out->setIndent(true); - - $out->startElement('testsuite'); - $out->writeAttribute('name', $report['filename']); - - if (count($report['messages']) === 0) { - $out->writeAttribute('tests', 1); - $out->writeAttribute('failures', 0); - - $out->startElement('testcase'); - $out->writeAttribute('name', $report['filename']); - $out->endElement(); - } else { - $failures = ($report['errors'] + $report['warnings']); - $out->writeAttribute('tests', $failures); - $out->writeAttribute('failures', $failures); - - foreach ($report['messages'] as $line => $lineErrors) { - foreach ($lineErrors as $column => $colErrors) { - foreach ($colErrors as $error) { - $out->startElement('testcase'); - $out->writeAttribute('name', $error['source'].' at '.$report['filename']." ($line:$column)"); - - $error['type'] = strtolower($error['type']); - if (PHP_CODESNIFFER_ENCODING !== 'utf-8') { - $error['message'] = iconv(PHP_CODESNIFFER_ENCODING, 'utf-8', $error['message']); - } - - $out->startElement('failure'); - $out->writeAttribute('type', $error['type']); - $out->writeAttribute('message', $error['message']); - $out->endElement(); - - $out->endElement(); - } - } - } - }//end if - - $out->endElement(); - echo $out->flush(); - return true; - - }//end generateFileReport() - - - /** - * Prints all violations for processed files, in a proprietary XML format. - * - * @param string $cachedData Any partial report data that was returned from - * generateFileReport during the run. - * @param int $totalFiles Total number of files processed during the run. - * @param int $totalErrors Total number of errors found during the run. - * @param int $totalWarnings Total number of warnings found during the run. - * @param int $totalFixable Total number of problems that can be fixed. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * @param boolean $toScreen Is the report being printed to screen? - * - * @return void - */ - public function generate( - $cachedData, - $totalFiles, - $totalErrors, - $totalWarnings, - $totalFixable, - $showSources=false, - $width=80, - $toScreen=true - ) { - $failures = ($totalErrors + $totalWarnings); - echo ''.PHP_EOL; - echo ''.PHP_EOL; - echo $cachedData; - echo ''.PHP_EOL; - - }//end generate() - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/Notifysend.php b/phpcs/CodeSniffer/Reports/Notifysend.php deleted file mode 100644 index fc3fcce..0000000 --- a/phpcs/CodeSniffer/Reports/Notifysend.php +++ /dev/null @@ -1,262 +0,0 @@ - - * @author Greg Sherwood - * @copyright 2012-2014 Christian Weiske - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Notify-send report for PHP_CodeSniffer. - * - * Supported configuration parameters: - * - notifysend_path - Full path to notify-send cli command - * - notifysend_timeout - Timeout in milliseconds - * - notifysend_showok - Show "ok, all fine" messages (0/1) - * - * @category PHP - * @package PHP_CodeSniffer - * @author Christian Weiske - * @author Greg Sherwood - * @copyright 2012-2014 Christian Weiske - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reports_Notifysend implements PHP_CodeSniffer_Report -{ - - /** - * Notification timeout in milliseconds. - * - * @var integer - */ - protected $timeout = 3000; - - /** - * Path to notify-send command. - * - * @var string - */ - protected $path = 'notify-send'; - - /** - * Show "ok, all fine" messages. - * - * @var boolean - */ - protected $showOk = true; - - /** - * Version of installed notify-send executable. - * - * @var string - */ - protected $version = null; - - /** - * A record of the last file checked. - * - * This is used in case we only checked one file and need to print - * the name/path of the file. We wont have access to the checked file list - * after the run has been completed. - * - * @var string - */ - private $_lastCheckedFile = ''; - - - /** - * Load configuration data. - */ - public function __construct() - { - $path = PHP_CodeSniffer::getConfigData('notifysend_path'); - if ($path !== null) { - $this->path = escapeshellcmd($path); - } - - $timeout = PHP_CodeSniffer::getConfigData('notifysend_timeout'); - if ($timeout !== null) { - $this->timeout = (int) $timeout; - } - - $showOk = PHP_CodeSniffer::getConfigData('notifysend_showok'); - if ($showOk !== null) { - $this->showOk = (boolean) $showOk; - } - - $this->version = str_replace( - 'notify-send ', - '', - exec($this->path.' --version') - ); - - }//end __construct() - - - /** - * Generate a partial report for a single processed file. - * - * Function should return TRUE if it printed or stored data about the file - * and FALSE if it ignored the file. Returning TRUE indicates that the file and - * its data should be counted in the grand totals. - * - * @param array $report Prepared report data. - * @param PHP_CodeSniffer_File $phpcsFile The file being reported on. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * - * @return boolean - */ - public function generateFileReport( - $report, - PHP_CodeSniffer_File $phpcsFile, - $showSources=false, - $width=80 - ) { - // We don't need to print anything, but we want this file counted - // in the total number of checked files even if it has no errors. - $this->_lastCheckedFile = $report['filename']; - return true; - - }//end generateFileReport() - - - /** - * Generates a summary of errors and warnings for each file processed. - * - * @param string $cachedData Any partial report data that was returned from - * generateFileReport during the run. - * @param int $totalFiles Total number of files processed during the run. - * @param int $totalErrors Total number of errors found during the run. - * @param int $totalWarnings Total number of warnings found during the run. - * @param int $totalFixable Total number of problems that can be fixed. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * @param boolean $toScreen Is the report being printed to screen? - * - * @return void - */ - public function generate( - $cachedData, - $totalFiles, - $totalErrors, - $totalWarnings, - $totalFixable, - $showSources=false, - $width=80, - $toScreen=true - ) { - $msg = $this->generateMessage($totalFiles, $totalErrors, $totalWarnings); - if ($msg === null) { - if ($this->showOk === true) { - $this->notifyAllFine(); - } - } else { - $this->notifyErrors($msg); - } - - }//end generate() - - - /** - * Generate the error message to show to the user. - * - * @param int $totalFiles Total number of files processed during the run. - * @param int $totalErrors Total number of errors found during the run. - * @param int $totalWarnings Total number of warnings found during the run. - * - * @return string Error message or NULL if no error/warning found. - */ - protected function generateMessage($totalFiles, $totalErrors, $totalWarnings) - { - if ($totalErrors === 0 && $totalWarnings === 0) { - // Nothing to print. - return null; - } - - $msg = ''; - if ($totalFiles > 1) { - $msg .= 'Checked '.$totalFiles.' files'.PHP_EOL; - } else { - $msg .= $this->_lastCheckedFile.PHP_EOL; - } - - if ($totalWarnings > 0) { - $msg .= $totalWarnings.' warnings'.PHP_EOL; - } - - if ($totalErrors > 0) { - $msg .= $totalErrors.' errors'.PHP_EOL; - } - - return $msg; - - }//end generateMessage() - - - /** - * Tell the user that all is fine and no error/warning has been found. - * - * @return void - */ - protected function notifyAllFine() - { - $cmd = $this->getBasicCommand(); - $cmd .= ' -i info'; - $cmd .= ' "PHP CodeSniffer: Ok"'; - $cmd .= ' "All fine"'; - exec($cmd); - - }//end notifyAllFine() - - - /** - * Tell the user that errors/warnings have been found. - * - * @param string $msg Message to display. - * - * @return void - */ - protected function notifyErrors($msg) - { - $cmd = $this->getBasicCommand(); - $cmd .= ' -i error'; - $cmd .= ' "PHP CodeSniffer: Error"'; - $cmd .= ' '.escapeshellarg(trim($msg)); - exec($cmd); - - }//end notifyErrors() - - - /** - * Generate and return the basic notify-send command string to execute. - * - * @return string Shell command with common parameters. - */ - protected function getBasicCommand() - { - $cmd = $this->path; - $cmd .= ' --category dev.validate'; - $cmd .= ' -h int:transient:1'; - $cmd .= ' -t '.(int) $this->timeout; - if (version_compare($this->version, '0.7.3', '>=') === true) { - $cmd .= ' -a phpcs'; - } - - return $cmd; - - }//end getBasicCommand() - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/Source.php b/phpcs/CodeSniffer/Reports/Source.php deleted file mode 100644 index 93d02df..0000000 --- a/phpcs/CodeSniffer/Reports/Source.php +++ /dev/null @@ -1,334 +0,0 @@ - - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Source report for PHP_CodeSniffer. - * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer - * @author Gabriele Santini - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reports_Source implements PHP_CodeSniffer_Report -{ - - /** - * A cache of source stats collected during the run. - * - * @var array - */ - private $_sourceCache = array(); - - - /** - * Generate a partial report for a single processed file. - * - * Function should return TRUE if it printed or stored data about the file - * and FALSE if it ignored the file. Returning TRUE indicates that the file and - * its data should be counted in the grand totals. - * - * @param array $report Prepared report data. - * @param PHP_CodeSniffer_File $phpcsFile The file being reported on. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * - * @return boolean - */ - public function generateFileReport( - $report, - PHP_CodeSniffer_File $phpcsFile, - $showSources=false, - $width=80 - ) { - if ($report['errors'] === 0 && $report['warnings'] === 0) { - // Nothing to print. - return false; - } - - foreach ($report['messages'] as $line => $lineErrors) { - foreach ($lineErrors as $column => $colErrors) { - foreach ($colErrors as $error) { - $source = $error['source']; - if (isset($this->_sourceCache[$source]) === false) { - if ($showSources === true) { - $parts = null; - $sniff = $source; - } else { - $parts = explode('.', $source); - if ($parts[0] === 'Internal') { - $parts[2] = $parts[1]; - $parts[1] = ''; - } - - $parts[1] = $this->makeFriendlyName($parts[1]); - - $sniff = $this->makeFriendlyName($parts[2]); - if (isset($parts[3]) === true) { - $name = $this->makeFriendlyName($parts[3]); - $name[0] = strtolower($name[0]); - $sniff .= ' '.$name; - unset($parts[3]); - } - - $parts[2] = $sniff; - }//end if - - $this->_sourceCache[$source] = array( - 'count' => 1, - 'fixable' => $error['fixable'], - 'parts' => $parts, - 'strlen' => strlen($sniff), - ); - } else { - $this->_sourceCache[$source]['count']++; - }//end if - }//end foreach - }//end foreach - }//end foreach - - return true; - - }//end generateFileReport() - - - /** - * Prints the source of all errors and warnings. - * - * @param string $cachedData Any partial report data that was returned from - * generateFileReport during the run. - * @param int $totalFiles Total number of files processed during the run. - * @param int $totalErrors Total number of errors found during the run. - * @param int $totalWarnings Total number of warnings found during the run. - * @param int $totalFixable Total number of problems that can be fixed. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * @param boolean $toScreen Is the report being printed to screen? - * - * @return void - */ - public function generate( - $cachedData, - $totalFiles, - $totalErrors, - $totalWarnings, - $totalFixable, - $showSources=false, - $width=80, - $toScreen=true - ) { - if (empty($this->_sourceCache) === true) { - // Nothing to show. - return; - } - - // Make sure the report width isn't too big. - $maxLength = 0; - foreach ($this->_sourceCache as $source => $data) { - $maxLength = max($maxLength, $data['strlen']); - } - - if ($showSources === true) { - $width = min($width, ($maxLength + 11)); - } else { - $width = min($width, ($maxLength + 41)); - } - - $width = max($width, 70); - - asort($this->_sourceCache); - $this->_sourceCache = array_reverse($this->_sourceCache); - - echo PHP_EOL."\033[1mPHP CODE SNIFFER VIOLATION SOURCE SUMMARY\033[0m".PHP_EOL; - echo str_repeat('-', $width).PHP_EOL."\033[1m"; - if ($showSources === true) { - if ($totalFixable > 0) { - echo ' SOURCE'.str_repeat(' ', ($width - 15)).'COUNT'.PHP_EOL; - } else { - echo 'SOURCE'.str_repeat(' ', ($width - 11)).'COUNT'.PHP_EOL; - } - } else { - if ($totalFixable > 0) { - echo ' STANDARD CATEGORY SNIFF'.str_repeat(' ', ($width - 44)).'COUNT'.PHP_EOL; - } else { - echo 'STANDARD CATEGORY SNIFF'.str_repeat(' ', ($width - 40)).'COUNT'.PHP_EOL; - } - } - - echo "\033[0m".str_repeat('-', $width).PHP_EOL; - - $fixableSources = 0; - - if ($showSources === true) { - $maxSniffWidth = ($width - 7); - } else { - $maxSniffWidth = ($width - 37); - } - - if ($totalFixable > 0) { - $maxSniffWidth -= 4; - } - - foreach ($this->_sourceCache as $source => $sourceData) { - if ($totalFixable > 0) { - echo '['; - if ($sourceData['fixable'] === true) { - echo 'x'; - $fixableSources++; - } else { - echo ' '; - } - - echo '] '; - } - - if ($showSources === true) { - if ($sourceData['strlen'] > $maxSniffWidth) { - $source = substr($source, 0, $maxSniffWidth); - } - - echo $source; - if ($totalFixable > 0) { - echo str_repeat(' ', ($width - 9 - strlen($source))); - } else { - echo str_repeat(' ', ($width - 5 - strlen($source))); - } - } else { - $parts = $sourceData['parts']; - - if (strlen($parts[0]) > 8) { - $parts[0] = substr($parts[0], 0, ((strlen($parts[0]) - 8) * -1)); - } - - echo $parts[0].str_repeat(' ', (10 - strlen($parts[0]))); - - $category = $parts[1]; - if (strlen($category) > 18) { - $category = substr($category, 0, ((strlen($category) - 18) * -1)); - } - - echo $category.str_repeat(' ', (20 - strlen($category))); - - $sniff = $parts[2]; - if (strlen($sniff) > $maxSniffWidth) { - $sniff = substr($sniff, 0, $maxSniffWidth); - } - - if ($totalFixable > 0) { - echo $sniff.str_repeat(' ', ($width - 39 - strlen($sniff))); - } else { - echo $sniff.str_repeat(' ', ($width - 35 - strlen($sniff))); - } - }//end if - - echo $sourceData['count'].PHP_EOL; - }//end foreach - - echo str_repeat('-', $width).PHP_EOL; - echo "\033[1m".'A TOTAL OF '.($totalErrors + $totalWarnings).' SNIFF VIOLATION'; - if (($totalErrors + $totalWarnings) > 1) { - echo 'S'; - } - - echo ' WERE FOUND IN '.count($this->_sourceCache).' SOURCE'; - if (count($this->_sourceCache) !== 1) { - echo 'S'; - } - - echo "\033[0m"; - - if ($totalFixable > 0) { - echo PHP_EOL.str_repeat('-', $width).PHP_EOL; - echo "\033[1mPHPCBF CAN FIX THE $fixableSources MARKED SOURCES AUTOMATICALLY ($totalFixable VIOLATIONS IN TOTAL)\033[0m"; - } - - echo PHP_EOL.str_repeat('-', $width).PHP_EOL.PHP_EOL; - - if ($toScreen === true && PHP_CODESNIFFER_INTERACTIVE === false) { - PHP_CodeSniffer_Reporting::printRunTime(); - } - - }//end generate() - - - /** - * Converts a camel caps name into a readable string. - * - * @param string $name The camel caps name to convert. - * - * @return string - */ - public function makeFriendlyName($name) - { - if (trim($name) === '') { - return ''; - } - - $friendlyName = ''; - $length = strlen($name); - - $lastWasUpper = false; - $lastWasNumeric = false; - for ($i = 0; $i < $length; $i++) { - if (is_numeric($name[$i]) === true) { - if ($lastWasNumeric === false) { - $friendlyName .= ' '; - } - - $lastWasUpper = false; - $lastWasNumeric = true; - } else { - $lastWasNumeric = false; - - $char = strtolower($name[$i]); - if ($char === $name[$i]) { - // Lowercase. - $lastWasUpper = false; - } else { - // Uppercase. - if ($lastWasUpper === false) { - $friendlyName .= ' '; - if ($i < ($length - 1)) { - $next = $name[($i + 1)]; - if (strtolower($next) === $next) { - // Next char is lowercase so it is a word boundary. - $name[$i] = strtolower($name[$i]); - } - } - } - - $lastWasUpper = true; - } - }//end if - - $friendlyName .= $name[$i]; - }//end for - - $friendlyName = trim($friendlyName); - $friendlyName[0] = strtoupper($friendlyName[0]); - - return $friendlyName; - - }//end makeFriendlyName() - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/Summary.php b/phpcs/CodeSniffer/Reports/Summary.php deleted file mode 100644 index 5781485..0000000 --- a/phpcs/CodeSniffer/Reports/Summary.php +++ /dev/null @@ -1,189 +0,0 @@ - - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Summary report for PHP_CodeSniffer. - * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer - * @author Gabriele Santini - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reports_Summary implements PHP_CodeSniffer_Report -{ - - /** - * TRUE if this report needs error messages instead of just totals. - * - * @var boolean - */ - public $recordErrors = false; - - /** - * An array of process files and their error data. - * - * @var boolean - */ - private $_reportFiles = array(); - - - /** - * Generate a partial report for a single processed file. - * - * Function should return TRUE if it printed or stored data about the file - * and FALSE if it ignored the file. Returning TRUE indicates that the file and - * its data should be counted in the grand totals. - * - * @param array $report Prepared report data. - * @param PHP_CodeSniffer_File $phpcsFile The file being reported on. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * - * @return boolean - */ - public function generateFileReport( - $report, - PHP_CodeSniffer_File $phpcsFile, - $showSources=false, - $width=80 - ) { - if (PHP_CODESNIFFER_VERBOSITY === 0 - && $report['errors'] === 0 - && $report['warnings'] === 0 - ) { - // Nothing to print. - return false; - } - - $this->_reportFiles[$report['filename']] = array( - 'errors' => $report['errors'], - 'warnings' => $report['warnings'], - 'strlen' => strlen($report['filename']), - ); - - return true; - - }//end generateFileReport() - - - /** - * Generates a summary of errors and warnings for each file processed. - * - * @param string $cachedData Any partial report data that was returned from - * generateFileReport during the run. - * @param int $totalFiles Total number of files processed during the run. - * @param int $totalErrors Total number of errors found during the run. - * @param int $totalWarnings Total number of warnings found during the run. - * @param int $totalFixable Total number of problems that can be fixed. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * @param boolean $toScreen Is the report being printed to screen? - * - * @return void - */ - public function generate( - $cachedData, - $totalFiles, - $totalErrors, - $totalWarnings, - $totalFixable, - $showSources=false, - $width=80, - $toScreen=true - ) { - - if (empty($this->_reportFiles) === true) { - return; - } - - // Make sure the report width isn't too big. - $maxLength = 0; - foreach ($this->_reportFiles as $file => $data) { - $maxLength = max($maxLength, $data['strlen']); - } - - $width = min($width, ($maxLength + 21)); - $width = max($width, 70); - - echo PHP_EOL."\033[1m".'PHP CODE SNIFFER REPORT SUMMARY'."\033[0m".PHP_EOL; - echo str_repeat('-', $width).PHP_EOL; - echo "\033[1m".'FILE'.str_repeat(' ', ($width - 20)).'ERRORS WARNINGS'."\033[0m".PHP_EOL; - echo str_repeat('-', $width).PHP_EOL; - - foreach ($this->_reportFiles as $file => $data) { - $padding = ($width - 18 - $data['strlen']); - if ($padding < 0) { - $file = '...'.substr($file, (($padding * -1) + 3)); - $padding = 0; - } - - echo $file.str_repeat(' ', $padding).' '; - if ($data['errors'] !== 0) { - echo "\033[31m".$data['errors']."\033[0m"; - echo str_repeat(' ', (8 - strlen((string) $data['errors']))); - } else { - echo '0 '; - } - - if ($data['warnings'] !== 0) { - echo "\033[33m".$data['warnings']."\033[0m"; - } else { - echo '0'; - } - - echo PHP_EOL; - }//end foreach - - echo str_repeat('-', $width).PHP_EOL; - echo "\033[1mA TOTAL OF $totalErrors ERROR"; - if ($totalErrors !== 1) { - echo 'S'; - } - - echo ' AND '.$totalWarnings.' WARNING'; - if ($totalWarnings !== 1) { - echo 'S'; - } - - echo ' WERE FOUND IN '.$totalFiles.' FILE'; - if ($totalFiles !== 1) { - echo 'S'; - } - - echo "\033[0m"; - - if ($totalFixable > 0) { - echo PHP_EOL.str_repeat('-', $width).PHP_EOL; - echo "\033[1mPHPCBF CAN FIX $totalFixable OF THESE SNIFF VIOLATIONS AUTOMATICALLY\033[0m"; - } - - echo PHP_EOL.str_repeat('-', $width).PHP_EOL.PHP_EOL; - - if ($toScreen === true && PHP_CODESNIFFER_INTERACTIVE === false) { - PHP_CodeSniffer_Reporting::printRunTime(); - } - - }//end generate() - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/Svnblame.php b/phpcs/CodeSniffer/Reports/Svnblame.php deleted file mode 100644 index 88e3b71..0000000 --- a/phpcs/CodeSniffer/Reports/Svnblame.php +++ /dev/null @@ -1,90 +0,0 @@ - - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Svnblame report for PHP_CodeSniffer. - * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer - * @author Gabriele Santini - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reports_Svnblame extends PHP_CodeSniffer_Reports_VersionControl -{ - - /** - * The name of the report we want in the output - * - * @var string - */ - protected $reportName = 'SVN'; - - - /** - * Extract the author from a blame line. - * - * @param string $line Line to parse. - * - * @return mixed string or false if impossible to recover. - */ - protected function getAuthor($line) - { - $blameParts = array(); - preg_match('|\s*([^\s]+)\s+([^\s]+)|', $line, $blameParts); - - if (isset($blameParts[2]) === false) { - return false; - } - - return $blameParts[2]; - - }//end getAuthor() - - - /** - * Gets the blame output. - * - * @param string $filename File to blame. - * - * @return array - */ - protected function getBlameContent($filename) - { - $command = 'svn blame "'.$filename.'" 2>&1'; - $handle = popen($command, 'r'); - if ($handle === false) { - echo 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL; - exit(2); - } - - $rawContent = stream_get_contents($handle); - fclose($handle); - - $blames = explode("\n", $rawContent); - - return $blames; - - }//end getBlameContent() - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/VersionControl.php b/phpcs/CodeSniffer/Reports/VersionControl.php deleted file mode 100644 index 80c51b2..0000000 --- a/phpcs/CodeSniffer/Reports/VersionControl.php +++ /dev/null @@ -1,342 +0,0 @@ - - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Version control report base class for PHP_CodeSniffer. - * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer - * @author Ben Selby - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: 1.2.2 - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -abstract class PHP_CodeSniffer_Reports_VersionControl implements PHP_CodeSniffer_Report -{ - - /** - * The name of the report we want in the output. - * - * @var string - */ - protected $reportName = 'VERSION CONTROL'; - - /** - * A cache of author stats collected during the run. - * - * @var array - */ - private $_authorCache = array(); - - /** - * A cache of blame stats collected during the run. - * - * @var array - */ - private $_praiseCache = array(); - - /** - * A cache of source stats collected during the run. - * - * @var array - */ - private $_sourceCache = array(); - - - /** - * Generate a partial report for a single processed file. - * - * Function should return TRUE if it printed or stored data about the file - * and FALSE if it ignored the file. Returning TRUE indicates that the file and - * its data should be counted in the grand totals. - * - * @param array $report Prepared report data. - * @param PHP_CodeSniffer_File $phpcsFile The file being reported on. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * - * @return boolean - */ - public function generateFileReport( - $report, - PHP_CodeSniffer_File $phpcsFile, - $showSources=false, - $width=80 - ) { - $blames = $this->getBlameContent($report['filename']); - - foreach ($report['messages'] as $line => $lineErrors) { - $author = 'Unknown'; - if (isset($blames[($line - 1)]) === true) { - $blameAuthor = $this->getAuthor($blames[($line - 1)]); - if ($blameAuthor !== false) { - $author = $blameAuthor; - } - } - - if (isset($this->_authorCache[$author]) === false) { - $this->_authorCache[$author] = 0; - $this->_praiseCache[$author] = array( - 'good' => 0, - 'bad' => 0, - ); - } - - $this->_praiseCache[$author]['bad']++; - - foreach ($lineErrors as $column => $colErrors) { - foreach ($colErrors as $error) { - $this->_authorCache[$author]++; - - if ($showSources === true) { - $source = $error['source']; - if (isset($this->_sourceCache[$author][$source]) === false) { - $this->_sourceCache[$author][$source] = array( - 'count' => 1, - 'fixable' => $error['fixable'], - ); - } else { - $this->_sourceCache[$author][$source]['count']++; - } - } - } - } - - unset($blames[($line - 1)]); - }//end foreach - - // No go through and give the authors some credit for - // all the lines that do not have errors. - foreach ($blames as $line) { - $author = $this->getAuthor($line); - if ($author === false) { - $author = 'Unknown'; - } - - if (isset($this->_authorCache[$author]) === false) { - // This author doesn't have any errors. - if (PHP_CODESNIFFER_VERBOSITY === 0) { - continue; - } - - $this->_authorCache[$author] = 0; - $this->_praiseCache[$author] = array( - 'good' => 0, - 'bad' => 0, - ); - } - - $this->_praiseCache[$author]['good']++; - }//end foreach - - return true; - - }//end generateFileReport() - - - /** - * Prints the author of all errors and warnings, as given by "version control blame". - * - * @param string $cachedData Any partial report data that was returned from - * generateFileReport during the run. - * @param int $totalFiles Total number of files processed during the run. - * @param int $totalErrors Total number of errors found during the run. - * @param int $totalWarnings Total number of warnings found during the run. - * @param int $totalFixable Total number of problems that can be fixed. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * @param boolean $toScreen Is the report being printed to screen? - * - * @return void - */ - public function generate( - $cachedData, - $totalFiles, - $totalErrors, - $totalWarnings, - $totalFixable, - $showSources=false, - $width=80, - $toScreen=true - ) { - $errorsShown = ($totalErrors + $totalWarnings); - if ($errorsShown === 0) { - // Nothing to show. - return; - } - - // Make sure the report width isn't too big. - $maxLength = 0; - foreach ($this->_authorCache as $author => $count) { - $maxLength = max($maxLength, strlen($author)); - if ($showSources === true && isset($this->_sourceCache[$author]) === true) { - foreach ($this->_sourceCache[$author] as $source => $sourceData) { - if ($source === 'count') { - continue; - } - - $maxLength = max($maxLength, (strlen($source) + 9)); - } - } - } - - $width = min($width, ($maxLength + 30)); - $width = max($width, 70); - arsort($this->_authorCache); - - echo PHP_EOL."\033[1m".'PHP CODE SNIFFER '.$this->reportName.' BLAME SUMMARY'."\033[0m".PHP_EOL; - echo str_repeat('-', $width).PHP_EOL."\033[1m"; - if ($showSources === true) { - echo 'AUTHOR SOURCE'.str_repeat(' ', ($width - 43)).'(Author %) (Overall %) COUNT'.PHP_EOL; - echo str_repeat('-', $width).PHP_EOL; - } else { - echo 'AUTHOR'.str_repeat(' ', ($width - 34)).'(Author %) (Overall %) COUNT'.PHP_EOL; - echo str_repeat('-', $width).PHP_EOL; - } - - echo "\033[0m"; - - if ($showSources === true) { - $maxSniffWidth = ($width - 15); - - if ($totalFixable > 0) { - $maxSniffWidth -= 4; - } - } - - $fixableSources = 0; - - foreach ($this->_authorCache as $author => $count) { - if ($this->_praiseCache[$author]['good'] === 0) { - $percent = 0; - } else { - $total = ($this->_praiseCache[$author]['bad'] + $this->_praiseCache[$author]['good']); - $percent = round(($this->_praiseCache[$author]['bad'] / $total * 100), 2); - } - - $overallPercent = '('.round((($count / $errorsShown) * 100), 2).')'; - $authorPercent = '('.$percent.')'; - $line = str_repeat(' ', (6 - strlen($count))).$count; - $line = str_repeat(' ', (12 - strlen($overallPercent))).$overallPercent.$line; - $line = str_repeat(' ', (11 - strlen($authorPercent))).$authorPercent.$line; - $line = $author.str_repeat(' ', ($width - strlen($author) - strlen($line))).$line; - - if ($showSources === true) { - $line = "\033[1m$line\033[0m"; - } - - echo $line.PHP_EOL; - - if ($showSources === true && isset($this->_sourceCache[$author]) === true) { - $errors = $this->_sourceCache[$author]; - asort($errors); - $errors = array_reverse($errors); - - foreach ($errors as $source => $sourceData) { - if ($source === 'count') { - continue; - } - - $count = $sourceData['count']; - - $srcLength = strlen($source); - if ($srcLength > $maxSniffWidth) { - $source = substr($source, 0, $maxSniffWidth); - } - - $line = str_repeat(' ', (5 - strlen($count))).$count; - - echo ' '; - if ($totalFixable > 0) { - echo '['; - if ($sourceData['fixable'] === true) { - echo 'x'; - $fixableSources++; - } else { - echo ' '; - } - - echo '] '; - } - - echo $source; - if ($totalFixable > 0) { - echo str_repeat(' ', ($width - 18 - strlen($source))); - } else { - echo str_repeat(' ', ($width - 14 - strlen($source))); - } - - echo $line.PHP_EOL; - }//end foreach - }//end if - }//end foreach - - echo str_repeat('-', $width).PHP_EOL; - echo "\033[1m".'A TOTAL OF '.$errorsShown.' SNIFF VIOLATION'; - if ($errorsShown !== 1) { - echo 'S'; - } - - echo ' WERE COMMITTED BY '.count($this->_authorCache).' AUTHOR'; - if (count($this->_authorCache) !== 1) { - echo 'S'; - } - - echo "\033[0m"; - - if ($totalFixable > 0) { - if ($showSources === true) { - echo PHP_EOL.str_repeat('-', $width).PHP_EOL; - echo "\033[1mPHPCBF CAN FIX THE $fixableSources MARKED SOURCES AUTOMATICALLY ($totalFixable VIOLATIONS IN TOTAL)\033[0m"; - } else { - echo PHP_EOL.str_repeat('-', $width).PHP_EOL; - echo "\033[1mPHPCBF CAN FIX $totalFixable OF THESE SNIFF VIOLATIONS AUTOMATICALLY\033[0m"; - } - } - - echo PHP_EOL.str_repeat('-', $width).PHP_EOL.PHP_EOL; - - if ($toScreen === true && PHP_CODESNIFFER_INTERACTIVE === false) { - PHP_CodeSniffer_Reporting::printRunTime(); - } - - }//end generate() - - - /** - * Extract the author from a blame line. - * - * @param string $line Line to parse. - * - * @return mixed string or false if impossible to recover. - */ - abstract protected function getAuthor($line); - - - /** - * Gets the blame output. - * - * @param string $filename File to blame. - * - * @return array - */ - abstract protected function getBlameContent($filename); - - -}//end class diff --git a/phpcs/CodeSniffer/Reports/Xml.php b/phpcs/CodeSniffer/Reports/Xml.php deleted file mode 100644 index 769ec95..0000000 --- a/phpcs/CodeSniffer/Reports/Xml.php +++ /dev/null @@ -1,132 +0,0 @@ - - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Xml report for PHP_CodeSniffer. - * - * PHP version 5 - * - * @category PHP - * @package PHP_CodeSniffer - * @author Gabriele Santini - * @author Greg Sherwood - * @copyright 2009-2014 SQLI - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Reports_Xml implements PHP_CodeSniffer_Report -{ - - - /** - * Generate a partial report for a single processed file. - * - * Function should return TRUE if it printed or stored data about the file - * and FALSE if it ignored the file. Returning TRUE indicates that the file and - * its data should be counted in the grand totals. - * - * @param array $report Prepared report data. - * @param PHP_CodeSniffer_File $phpcsFile The file being reported on. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * - * @return boolean - */ - public function generateFileReport( - $report, - PHP_CodeSniffer_File $phpcsFile, - $showSources=false, - $width=80 - ) { - $out = new XMLWriter; - $out->openMemory(); - $out->setIndent(true); - - if ($report['errors'] === 0 && $report['warnings'] === 0) { - // Nothing to print. - return false; - } - - $out->startElement('file'); - $out->writeAttribute('name', $report['filename']); - $out->writeAttribute('errors', $report['errors']); - $out->writeAttribute('warnings', $report['warnings']); - $out->writeAttribute('fixable', $report['fixable']); - - foreach ($report['messages'] as $line => $lineErrors) { - foreach ($lineErrors as $column => $colErrors) { - foreach ($colErrors as $error) { - $error['type'] = strtolower($error['type']); - if (PHP_CODESNIFFER_ENCODING !== 'utf-8') { - $error['message'] = iconv(PHP_CODESNIFFER_ENCODING, 'utf-8', $error['message']); - } - - $out->startElement($error['type']); - $out->writeAttribute('line', $line); - $out->writeAttribute('column', $column); - $out->writeAttribute('source', $error['source']); - $out->writeAttribute('severity', $error['severity']); - $out->writeAttribute('fixable', (int) $error['fixable']); - $out->text($error['message']); - $out->endElement(); - } - } - }//end foreach - - $out->endElement(); - echo $out->flush(); - - return true; - - }//end generateFileReport() - - - /** - * Prints all violations for processed files, in a proprietary XML format. - * - * @param string $cachedData Any partial report data that was returned from - * generateFileReport during the run. - * @param int $totalFiles Total number of files processed during the run. - * @param int $totalErrors Total number of errors found during the run. - * @param int $totalWarnings Total number of warnings found during the run. - * @param int $totalFixable Total number of problems that can be fixed. - * @param boolean $showSources Show sources? - * @param int $width Maximum allowed line width. - * @param boolean $toScreen Is the report being printed to screen? - * - * @return void - */ - public function generate( - $cachedData, - $totalFiles, - $totalErrors, - $totalWarnings, - $totalFixable, - $showSources=false, - $width=80, - $toScreen=true - ) { - echo ''.PHP_EOL; - echo ''.PHP_EOL; - echo $cachedData; - echo ''.PHP_EOL; - - }//end generate() - - -}//end class diff --git a/phpcs/CodeSniffer/Sniff.php b/phpcs/CodeSniffer/Sniff.php deleted file mode 100644 index 3624a16..0000000 --- a/phpcs/CodeSniffer/Sniff.php +++ /dev/null @@ -1,94 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Represents a PHP_CodeSniffer sniff for sniffing coding standards. - * - * A sniff registers what token types it wishes to listen for, then, when - * PHP_CodeSniffer encounters that token, the sniff is invoked and passed - * information about where the token was found in the stack, and the - * PHP_CodeSniffer file in which the token was found. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -interface PHP_CodeSniffer_Sniff -{ - - - /** - * Registers the tokens that this sniff wants to listen for. - * - * An example return value for a sniff that wants to listen for whitespace - * and any comments would be: - * - * - * return array( - * T_WHITESPACE, - * T_DOC_COMMENT, - * T_COMMENT, - * ); - * - * - * @return int[] - * @see Tokens.php - */ - public function register(); - - - /** - * Called when one of the token types that this sniff is listening for - * is found. - * - * The stackPtr variable indicates where in the stack the token was found. - * A sniff can acquire information this token, along with all the other - * tokens within the stack by first acquiring the token stack: - * - * - * $tokens = $phpcsFile->getTokens(); - * echo 'Encountered a '.$tokens[$stackPtr]['type'].' token'; - * echo 'token information: '; - * print_r($tokens[$stackPtr]); - * - * - * If the sniff discovers an anomaly in the code, they can raise an error - * by calling addError() on the PHP_CodeSniffer_File object, specifying an error - * message and the position of the offending token: - * - * - * $phpcsFile->addError('Encountered an error', $stackPtr); - * - * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the - * token was found. - * @param int $stackPtr The position in the PHP_CodeSniffer - * file's token stack where the token - * was found. - * - * @return void|int Optionally returns a stack pointer. The sniff will not be - * called again on the current file until the returned stack - * pointer is reached. Return (count($tokens) + 1) to skip - * the rest of the file. - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr); - - -}//end interface diff --git a/phpcs/CodeSniffer/Standards/AbstractPatternSniff.php b/phpcs/CodeSniffer/Standards/AbstractPatternSniff.php deleted file mode 100644 index 69b39f7..0000000 --- a/phpcs/CodeSniffer/Standards/AbstractPatternSniff.php +++ /dev/null @@ -1,962 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_IncorrectPatternException', true) === false) { - $error = 'Class PHP_CodeSniffer_Standards_IncorrectPatternException not found'; - throw new PHP_CodeSniffer_Exception($error); -} - -/** - * Processes pattern strings and checks that the code conforms to the pattern. - * - * This test essentially checks that code is correctly formatted with whitespace. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -abstract class PHP_CodeSniffer_Standards_AbstractPatternSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * If true, comments will be ignored if they are found in the code. - * - * @var boolean - */ - public $ignoreComments = false; - - /** - * The current file being checked. - * - * @var string - */ - protected $currFile = ''; - - /** - * The parsed patterns array. - * - * @var array - */ - private $_parsedPatterns = array(); - - /** - * Tokens that this sniff wishes to process outside of the patterns. - * - * @var array(int) - * @see registerSupplementary() - * @see processSupplementary() - */ - private $_supplementaryTokens = array(); - - /** - * Positions in the stack where errors have occurred. - * - * @var array() - */ - private $_errorPos = array(); - - - /** - * Constructs a PHP_CodeSniffer_Standards_AbstractPatternSniff. - * - * @param boolean $ignoreComments If true, comments will be ignored. - */ - public function __construct($ignoreComments=null) - { - // This is here for backwards compatibility. - if ($ignoreComments !== null) { - $this->ignoreComments = $ignoreComments; - } - - $this->_supplementaryTokens = $this->registerSupplementary(); - - }//end __construct() - - - /** - * Registers the tokens to listen to. - * - * Classes extending AbstractPatternTest should implement the - * getPatterns() method to register the patterns they wish to test. - * - * @return int[] - * @see process() - */ - public final function register() - { - $listenTypes = array(); - $patterns = $this->getPatterns(); - - foreach ($patterns as $pattern) { - $parsedPattern = $this->_parse($pattern); - - // Find a token position in the pattern that we can use - // for a listener token. - $pos = $this->_getListenerTokenPos($parsedPattern); - $tokenType = $parsedPattern[$pos]['token']; - $listenTypes[] = $tokenType; - - $patternArray = array( - 'listen_pos' => $pos, - 'pattern' => $parsedPattern, - 'pattern_code' => $pattern, - ); - - if (isset($this->_parsedPatterns[$tokenType]) === false) { - $this->_parsedPatterns[$tokenType] = array(); - } - - $this->_parsedPatterns[$tokenType][] = $patternArray; - }//end foreach - - return array_unique(array_merge($listenTypes, $this->_supplementaryTokens)); - - }//end register() - - - /** - * Returns the token types that the specified pattern is checking for. - * - * Returned array is in the format: - * - * array( - * T_WHITESPACE => 0, // 0 is the position where the T_WHITESPACE token - * // should occur in the pattern. - * ); - * - * - * @param array $pattern The parsed pattern to find the acquire the token - * types from. - * - * @return array - */ - private function _getPatternTokenTypes($pattern) - { - $tokenTypes = array(); - foreach ($pattern as $pos => $patternInfo) { - if ($patternInfo['type'] === 'token') { - if (isset($tokenTypes[$patternInfo['token']]) === false) { - $tokenTypes[$patternInfo['token']] = $pos; - } - } - } - - return $tokenTypes; - - }//end _getPatternTokenTypes() - - - /** - * Returns the position in the pattern that this test should register as - * a listener for the pattern. - * - * @param array $pattern The pattern to acquire the listener for. - * - * @return int The position in the pattern that this test should register - * as the listener. - * @throws PHP_CodeSniffer_Exception If we could not determine a token - * to listen for. - */ - private function _getListenerTokenPos($pattern) - { - $tokenTypes = $this->_getPatternTokenTypes($pattern); - $tokenCodes = array_keys($tokenTypes); - $token = PHP_CodeSniffer_Tokens::getHighestWeightedToken($tokenCodes); - - // If we could not get a token. - if ($token === false) { - $error = 'Could not determine a token to listen for'; - throw new PHP_CodeSniffer_Exception($error); - } - - return $tokenTypes[$token]; - - }//end _getListenerTokenPos() - - - /** - * Processes the test. - * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the - * token occurred. - * @param int $stackPtr The position in the tokens stack - * where the listening token type was - * found. - * - * @return void - * @see register() - */ - public final function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $file = $phpcsFile->getFilename(); - if ($this->currFile !== $file) { - // We have changed files, so clean up. - $this->_errorPos = array(); - $this->currFile = $file; - } - - $tokens = $phpcsFile->getTokens(); - - if (in_array($tokens[$stackPtr]['code'], $this->_supplementaryTokens) === true) { - $this->processSupplementary($phpcsFile, $stackPtr); - } - - $type = $tokens[$stackPtr]['code']; - - // If the type is not set, then it must have been a token registered - // with registerSupplementary(). - if (isset($this->_parsedPatterns[$type]) === false) { - return; - } - - $allErrors = array(); - - // Loop over each pattern that is listening to the current token type - // that we are processing. - foreach ($this->_parsedPatterns[$type] as $patternInfo) { - // If processPattern returns false, then the pattern that we are - // checking the code with must not be designed to check that code. - $errors = $this->processPattern($patternInfo, $phpcsFile, $stackPtr); - if ($errors === false) { - // The pattern didn't match. - continue; - } else if (empty($errors) === true) { - // The pattern matched, but there were no errors. - break; - } - - foreach ($errors as $stackPtr => $error) { - if (isset($this->_errorPos[$stackPtr]) === false) { - $this->_errorPos[$stackPtr] = true; - $allErrors[$stackPtr] = $error; - } - } - } - - foreach ($allErrors as $stackPtr => $error) { - $phpcsFile->addError($error, $stackPtr); - } - - }//end process() - - - /** - * Processes the pattern and verifies the code at $stackPtr. - * - * @param array $patternInfo Information about the pattern used - * for checking, which includes are - * parsed token representation of the - * pattern. - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the - * token occurred. - * @param int $stackPtr The position in the tokens stack where - * the listening token type was found. - * - * @return array - */ - protected function processPattern( - $patternInfo, - PHP_CodeSniffer_File $phpcsFile, - $stackPtr - ) { - $tokens = $phpcsFile->getTokens(); - $pattern = $patternInfo['pattern']; - $patternCode = $patternInfo['pattern_code']; - $errors = array(); - $found = ''; - - $ignoreTokens = array(T_WHITESPACE); - if ($this->ignoreComments === true) { - $ignoreTokens - = array_merge($ignoreTokens, PHP_CodeSniffer_Tokens::$commentTokens); - } - - $origStackPtr = $stackPtr; - $hasError = false; - - if ($patternInfo['listen_pos'] > 0) { - $stackPtr--; - - for ($i = ($patternInfo['listen_pos'] - 1); $i >= 0; $i--) { - if ($pattern[$i]['type'] === 'token') { - if ($pattern[$i]['token'] === T_WHITESPACE) { - if ($tokens[$stackPtr]['code'] === T_WHITESPACE) { - $found = $tokens[$stackPtr]['content'].$found; - } - - // Only check the size of the whitespace if this is not - // the first token. We don't care about the size of - // leading whitespace, just that there is some. - if ($i !== 0) { - if ($tokens[$stackPtr]['content'] !== $pattern[$i]['value']) { - $hasError = true; - } - } - } else { - // Check to see if this important token is the same as the - // previous important token in the pattern. If it is not, - // then the pattern cannot be for this piece of code. - $prev = $phpcsFile->findPrevious( - $ignoreTokens, - $stackPtr, - null, - true - ); - - if ($prev === false - || $tokens[$prev]['code'] !== $pattern[$i]['token'] - ) { - return false; - } - - // If we skipped past some whitespace tokens, then add them - // to the found string. - $tokenContent = $phpcsFile->getTokensAsString( - ($prev + 1), - ($stackPtr - $prev - 1) - ); - - $found = $tokens[$prev]['content'].$tokenContent.$found; - - if (isset($pattern[($i - 1)]) === true - && $pattern[($i - 1)]['type'] === 'skip' - ) { - $stackPtr = $prev; - } else { - $stackPtr = ($prev - 1); - } - }//end if - } else if ($pattern[$i]['type'] === 'skip') { - // Skip to next piece of relevant code. - if ($pattern[$i]['to'] === 'parenthesis_closer') { - $to = 'parenthesis_opener'; - } else { - $to = 'scope_opener'; - } - - // Find the previous opener. - $next = $phpcsFile->findPrevious( - $ignoreTokens, - $stackPtr, - null, - true - ); - - if ($next === false || isset($tokens[$next][$to]) === false) { - // If there was not opener, then we must be - // using the wrong pattern. - return false; - } - - if ($to === 'parenthesis_opener') { - $found = '{'.$found; - } else { - $found = '('.$found; - } - - $found = '...'.$found; - - // Skip to the opening token. - $stackPtr = ($tokens[$next][$to] - 1); - } else if ($pattern[$i]['type'] === 'string') { - $found = 'abc'; - } else if ($pattern[$i]['type'] === 'newline') { - if ($this->ignoreComments === true - && isset(PHP_CodeSniffer_Tokens::$commentTokens[$tokens[$stackPtr]['code']]) === true - ) { - $startComment = $phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$commentTokens, - ($stackPtr - 1), - null, - true - ); - - if ($tokens[$startComment]['line'] !== $tokens[($startComment + 1)]['line']) { - $startComment++; - } - - $tokenContent = $phpcsFile->getTokensAsString( - $startComment, - ($stackPtr - $startComment + 1) - ); - - $found = $tokenContent.$found; - $stackPtr = ($startComment - 1); - } - - if ($tokens[$stackPtr]['code'] === T_WHITESPACE) { - if ($tokens[$stackPtr]['content'] !== $phpcsFile->eolChar) { - $found = $tokens[$stackPtr]['content'].$found; - - // This may just be an indent that comes after a newline - // so check the token before to make sure. If it is a newline, we - // can ignore the error here. - if (($tokens[($stackPtr - 1)]['content'] !== $phpcsFile->eolChar) - && ($this->ignoreComments === true - && isset(PHP_CodeSniffer_Tokens::$commentTokens[$tokens[($stackPtr - 1)]['code']]) === false) - ) { - $hasError = true; - } else { - $stackPtr--; - } - } else { - $found = 'EOL'.$found; - } - } else { - $found = $tokens[$stackPtr]['content'].$found; - $hasError = true; - }//end if - - if ($hasError === false && $pattern[($i - 1)]['type'] !== 'newline') { - // Make sure they only have 1 newline. - $prev = $phpcsFile->findPrevious($ignoreTokens, ($stackPtr - 1), null, true); - if ($prev !== false && $tokens[$prev]['line'] !== $tokens[$stackPtr]['line']) { - $hasError = true; - } - } - }//end if - }//end for - }//end if - - $stackPtr = $origStackPtr; - $lastAddedStackPtr = null; - $patternLen = count($pattern); - - for ($i = $patternInfo['listen_pos']; $i < $patternLen; $i++) { - if (isset($tokens[$stackPtr]) === false) { - break; - } - - if ($pattern[$i]['type'] === 'token') { - if ($pattern[$i]['token'] === T_WHITESPACE) { - if ($this->ignoreComments === true) { - // If we are ignoring comments, check to see if this current - // token is a comment. If so skip it. - if (isset(PHP_CodeSniffer_Tokens::$commentTokens[$tokens[$stackPtr]['code']]) === true) { - continue; - } - - // If the next token is a comment, the we need to skip the - // current token as we should allow a space before a - // comment for readability. - if (isset($tokens[($stackPtr + 1)]) === true - && isset(PHP_CodeSniffer_Tokens::$commentTokens[$tokens[($stackPtr + 1)]['code']]) === true - ) { - continue; - } - } - - $tokenContent = ''; - if ($tokens[$stackPtr]['code'] === T_WHITESPACE) { - if (isset($pattern[($i + 1)]) === false) { - // This is the last token in the pattern, so just compare - // the next token of content. - $tokenContent = $tokens[$stackPtr]['content']; - } else { - // Get all the whitespace to the next token. - $next = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, - $stackPtr, - null, - true - ); - - $tokenContent = $phpcsFile->getTokensAsString( - $stackPtr, - ($next - $stackPtr) - ); - - $lastAddedStackPtr = $stackPtr; - $stackPtr = $next; - }//end if - - if ($stackPtr !== $lastAddedStackPtr) { - $found .= $tokenContent; - } - } else { - if ($stackPtr !== $lastAddedStackPtr) { - $found .= $tokens[$stackPtr]['content']; - $lastAddedStackPtr = $stackPtr; - } - }//end if - - if (isset($pattern[($i + 1)]) === true - && $pattern[($i + 1)]['type'] === 'skip' - ) { - // The next token is a skip token, so we just need to make - // sure the whitespace we found has *at least* the - // whitespace required. - if (strpos($tokenContent, $pattern[$i]['value']) !== 0) { - $hasError = true; - } - } else { - if ($tokenContent !== $pattern[$i]['value']) { - $hasError = true; - } - } - } else { - // Check to see if this important token is the same as the - // next important token in the pattern. If it is not, then - // the pattern cannot be for this piece of code. - $next = $phpcsFile->findNext( - $ignoreTokens, - $stackPtr, - null, - true - ); - - if ($next === false - || $tokens[$next]['code'] !== $pattern[$i]['token'] - ) { - // The next important token did not match the pattern. - return false; - } - - if ($lastAddedStackPtr !== null) { - if (($tokens[$next]['code'] === T_OPEN_CURLY_BRACKET - || $tokens[$next]['code'] === T_CLOSE_CURLY_BRACKET) - && isset($tokens[$next]['scope_condition']) === true - && $tokens[$next]['scope_condition'] > $lastAddedStackPtr - ) { - // This is a brace, but the owner of it is after the current - // token, which means it does not belong to any token in - // our pattern. This means the pattern is not for us. - return false; - } - - if (($tokens[$next]['code'] === T_OPEN_PARENTHESIS - || $tokens[$next]['code'] === T_CLOSE_PARENTHESIS) - && isset($tokens[$next]['parenthesis_owner']) === true - && $tokens[$next]['parenthesis_owner'] > $lastAddedStackPtr - ) { - // This is a bracket, but the owner of it is after the current - // token, which means it does not belong to any token in - // our pattern. This means the pattern is not for us. - return false; - } - }//end if - - // If we skipped past some whitespace tokens, then add them - // to the found string. - if (($next - $stackPtr) > 0) { - $hasComment = false; - for ($j = $stackPtr; $j < $next; $j++) { - $found .= $tokens[$j]['content']; - if (isset(PHP_CodeSniffer_Tokens::$commentTokens[$tokens[$j]['code']]) === true) { - $hasComment = true; - } - } - - // If we are not ignoring comments, this additional - // whitespace or comment is not allowed. If we are - // ignoring comments, there needs to be at least one - // comment for this to be allowed. - if ($this->ignoreComments === false - || ($this->ignoreComments === true - && $hasComment === false) - ) { - $hasError = true; - } - - // Even when ignoring comments, we are not allowed to include - // newlines without the pattern specifying them, so - // everything should be on the same line. - if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) { - $hasError = true; - } - }//end if - - if ($next !== $lastAddedStackPtr) { - $found .= $tokens[$next]['content']; - $lastAddedStackPtr = $next; - } - - if (isset($pattern[($i + 1)]) === true - && $pattern[($i + 1)]['type'] === 'skip' - ) { - $stackPtr = $next; - } else { - $stackPtr = ($next + 1); - } - }//end if - } else if ($pattern[$i]['type'] === 'skip') { - if ($pattern[$i]['to'] === 'unknown') { - $next = $phpcsFile->findNext( - $pattern[($i + 1)]['token'], - $stackPtr - ); - - if ($next === false) { - // Couldn't find the next token, so we must - // be using the wrong pattern. - return false; - } - - $found .= '...'; - $stackPtr = $next; - } else { - // Find the previous opener. - $next = $phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$blockOpeners, - $stackPtr - ); - - if ($next === false - || isset($tokens[$next][$pattern[$i]['to']]) === false - ) { - // If there was not opener, then we must - // be using the wrong pattern. - return false; - } - - $found .= '...'; - if ($pattern[$i]['to'] === 'parenthesis_closer') { - $found .= ')'; - } else { - $found .= '}'; - } - - // Skip to the closing token. - $stackPtr = ($tokens[$next][$pattern[$i]['to']] + 1); - }//end if - } else if ($pattern[$i]['type'] === 'string') { - if ($tokens[$stackPtr]['code'] !== T_STRING) { - $hasError = true; - } - - if ($stackPtr !== $lastAddedStackPtr) { - $found .= 'abc'; - $lastAddedStackPtr = $stackPtr; - } - - $stackPtr++; - } else if ($pattern[$i]['type'] === 'newline') { - // Find the next token that contains a newline character. - $newline = 0; - for ($j = $stackPtr; $j < $phpcsFile->numTokens; $j++) { - if (strpos($tokens[$j]['content'], $phpcsFile->eolChar) !== false) { - $newline = $j; - break; - } - } - - if ($newline === 0) { - // We didn't find a newline character in the rest of the file. - $next = ($phpcsFile->numTokens - 1); - $hasError = true; - } else { - if ($this->ignoreComments === false) { - // The newline character cannot be part of a comment. - if (isset(PHP_CodeSniffer_Tokens::$commentTokens[$tokens[$newline]['code']]) === true) { - $hasError = true; - } - } - - if ($newline === $stackPtr) { - $next = ($stackPtr + 1); - } else { - // Check that there were no significant tokens that we - // skipped over to find our newline character. - $next = $phpcsFile->findNext( - $ignoreTokens, - $stackPtr, - null, - true - ); - - if ($next < $newline) { - // We skipped a non-ignored token. - $hasError = true; - } else { - $next = ($newline + 1); - } - } - }//end if - - if ($stackPtr !== $lastAddedStackPtr) { - $found .= $phpcsFile->getTokensAsString( - $stackPtr, - ($next - $stackPtr) - ); - - $diff = ($next - $stackPtr); - $lastAddedStackPtr = ($next - 1); - } - - $stackPtr = $next; - }//end if - }//end for - - if ($hasError === true) { - $error = $this->prepareError($found, $patternCode); - $errors[$origStackPtr] = $error; - } - - return $errors; - - }//end processPattern() - - - /** - * Prepares an error for the specified patternCode. - * - * @param string $found The actual found string in the code. - * @param string $patternCode The expected pattern code. - * - * @return string The error message. - */ - protected function prepareError($found, $patternCode) - { - $found = str_replace("\r\n", '\n', $found); - $found = str_replace("\n", '\n', $found); - $found = str_replace("\r", '\n', $found); - $found = str_replace("\t", '\t', $found); - $found = str_replace('EOL', '\n', $found); - $expected = str_replace('EOL', '\n', $patternCode); - - $error = "Expected \"$expected\"; found \"$found\""; - - return $error; - - }//end prepareError() - - - /** - * Returns the patterns that should be checked. - * - * @return string[] - */ - protected abstract function getPatterns(); - - - /** - * Registers any supplementary tokens that this test might wish to process. - * - * A sniff may wish to register supplementary tests when it wishes to group - * an arbitrary validation that cannot be performed using a pattern, with - * other pattern tests. - * - * @return int[] - * @see processSupplementary() - */ - protected function registerSupplementary() - { - return array(); - - }//end registerSupplementary() - - - /** - * Processes any tokens registered with registerSupplementary(). - * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where to - * process the skip. - * @param int $stackPtr The position in the tokens stack to - * process. - * - * @return void - * @see registerSupplementary() - */ - protected function processSupplementary( - PHP_CodeSniffer_File $phpcsFile, - $stackPtr - ) { - - }//end processSupplementary() - - - /** - * Parses a pattern string into an array of pattern steps. - * - * @param string $pattern The pattern to parse. - * - * @return array The parsed pattern array. - * @see _createSkipPattern() - * @see _createTokenPattern() - */ - private function _parse($pattern) - { - $patterns = array(); - $length = strlen($pattern); - $lastToken = 0; - $firstToken = 0; - - for ($i = 0; $i < $length; $i++) { - $specialPattern = false; - $isLastChar = ($i === ($length - 1)); - $oldFirstToken = $firstToken; - - if (substr($pattern, $i, 3) === '...') { - // It's a skip pattern. The skip pattern requires the - // content of the token in the "from" position and the token - // to skip to. - $specialPattern = $this->_createSkipPattern($pattern, ($i - 1)); - $lastToken = ($i - $firstToken); - $firstToken = ($i + 3); - $i = ($i + 2); - - if ($specialPattern['to'] !== 'unknown') { - $firstToken++; - } - } else if (substr($pattern, $i, 3) === 'abc') { - $specialPattern = array('type' => 'string'); - $lastToken = ($i - $firstToken); - $firstToken = ($i + 3); - $i = ($i + 2); - } else if (substr($pattern, $i, 3) === 'EOL') { - $specialPattern = array('type' => 'newline'); - $lastToken = ($i - $firstToken); - $firstToken = ($i + 3); - $i = ($i + 2); - }//end if - - if ($specialPattern !== false || $isLastChar === true) { - // If we are at the end of the string, don't worry about a limit. - if ($isLastChar === true) { - // Get the string from the end of the last skip pattern, if any, - // to the end of the pattern string. - $str = substr($pattern, $oldFirstToken); - } else { - // Get the string from the end of the last special pattern, - // if any, to the start of this special pattern. - if ($lastToken === 0) { - // Note that if the last special token was zero characters ago, - // there will be nothing to process so we can skip this bit. - // This happens if you have something like: EOL... in your pattern. - $str = ''; - } else { - $str = substr($pattern, $oldFirstToken, $lastToken); - } - } - - if ($str !== '') { - $tokenPatterns = $this->_createTokenPattern($str); - foreach ($tokenPatterns as $tokenPattern) { - $patterns[] = $tokenPattern; - } - } - - // Make sure we don't skip the last token. - if ($isLastChar === false && $i === ($length - 1)) { - $i--; - } - }//end if - - // Add the skip pattern *after* we have processed - // all the tokens from the end of the last skip pattern - // to the start of this skip pattern. - if ($specialPattern !== false) { - $patterns[] = $specialPattern; - } - }//end for - - return $patterns; - - }//end _parse() - - - /** - * Creates a skip pattern. - * - * @param string $pattern The pattern being parsed. - * @param string $from The token content that the skip pattern starts from. - * - * @return array The pattern step. - * @see _createTokenPattern() - * @see _parse() - */ - private function _createSkipPattern($pattern, $from) - { - $skip = array('type' => 'skip'); - - $nestedParenthesis = 0; - $nestedBraces = 0; - for ($start = $from; $start >= 0; $start--) { - switch ($pattern[$start]) { - case '(': - if ($nestedParenthesis === 0) { - $skip['to'] = 'parenthesis_closer'; - } - - $nestedParenthesis--; - break; - case '{': - if ($nestedBraces === 0) { - $skip['to'] = 'scope_closer'; - } - - $nestedBraces--; - break; - case '}': - $nestedBraces++; - break; - case ')': - $nestedParenthesis++; - break; - }//end switch - - if (isset($skip['to']) === true) { - break; - } - }//end for - - if (isset($skip['to']) === false) { - $skip['to'] = 'unknown'; - } - - return $skip; - - }//end _createSkipPattern() - - - /** - * Creates a token pattern. - * - * @param string $str The tokens string that the pattern should match. - * - * @return array The pattern step. - * @see _createSkipPattern() - * @see _parse() - */ - private function _createTokenPattern($str) - { - // Don't add a space after the closing php tag as it will add a new - // whitespace token. - $tokenizer = new PHP_CodeSniffer_Tokenizers_PHP(); - $tokens = $tokenizer->tokenizeString(''); - - // Remove the 'token', - 'token' => $patternInfo['code'], - 'value' => $patternInfo['content'], - ); - } - - return $patterns; - - }//end _createTokenPattern() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/AbstractScopeSniff.php b/phpcs/CodeSniffer/Standards/AbstractScopeSniff.php deleted file mode 100644 index c17152c..0000000 --- a/phpcs/CodeSniffer/Standards/AbstractScopeSniff.php +++ /dev/null @@ -1,199 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * An AbstractScopeTest allows for tests that extend from this class to - * listen for tokens within a particular scope. - * - * Below is a test that listens to methods that exist only within classes: - * - * class ClassScopeTest extends PHP_CodeSniffer_Standards_AbstractScopeSniff - * { - * public function __construct() - * { - * parent::__construct(array(T_CLASS), array(T_FUNCTION)); - * } - * - * protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $) - * { - * $className = $phpcsFile->getDeclarationName($currScope); - * echo 'encountered a method within class '.$className; - * } - * } - * - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -abstract class PHP_CodeSniffer_Standards_AbstractScopeSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * The token types that this test wishes to listen to within the scope. - * - * @var array - */ - private $_tokens = array(); - - /** - * The type of scope opener tokens that this test wishes to listen to. - * - * @var string - */ - private $_scopeTokens = array(); - - /** - * True if this test should fire on tokens outside of the scope. - * - * @var boolean - */ - private $_listenOutside = false; - - - /** - * Constructs a new AbstractScopeTest. - * - * @param array $scopeTokens The type of scope the test wishes to listen to. - * @param array $tokens The tokens that the test wishes to listen to - * within the scope. - * @param boolean $listenOutside If true this test will also alert the - * extending class when a token is found outside - * the scope, by calling the - * processTokenOutsideScope method. - * - * @see PHP_CodeSniffer.getValidScopeTokeners() - * @throws PHP_CodeSniffer_Exception If the specified tokens array is empty. - */ - public function __construct( - array $scopeTokens, - array $tokens, - $listenOutside=false - ) { - if (empty($scopeTokens) === true) { - $error = 'The scope tokens list cannot be empty'; - throw new PHP_CodeSniffer_Exception($error); - } - - if (empty($tokens) === true) { - $error = 'The tokens list cannot be empty'; - throw new PHP_CodeSniffer_Exception($error); - } - - $invalidScopeTokens = array_intersect($scopeTokens, $tokens); - if (empty($invalidScopeTokens) === false) { - $invalid = implode(', ', $invalidScopeTokens); - $error = "Scope tokens [$invalid] can't be in the tokens array"; - throw new PHP_CodeSniffer_Exception($error); - } - - $this->_listenOutside = $listenOutside; - $this->_scopeTokens = array_flip($scopeTokens); - $this->_tokens = $tokens; - - }//end __construct() - - - /** - * The method that is called to register the tokens this test wishes to - * listen to. - * - * DO NOT OVERRIDE THIS METHOD. Use the constructor of this class to register - * for the desired tokens and scope. - * - * @return int[] - * @see __constructor() - */ - public final function register() - { - return $this->_tokens; - - }//end register() - - - /** - * Processes the tokens that this test is listening for. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position in the stack where this - * token was found. - * - * @return void - * @see processTokenWithinScope() - */ - public final function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $foundScope = false; - foreach ($tokens[$stackPtr]['conditions'] as $scope => $code) { - if (isset($this->_scopeTokens[$code]) === true) { - $this->processTokenWithinScope($phpcsFile, $stackPtr, $scope); - $foundScope = true; - } - } - - if ($this->_listenOutside === true && $foundScope === false) { - $this->processTokenOutsideScope($phpcsFile, $stackPtr); - } - - }//end process() - - - /** - * Processes a token that is found within the scope that this test is - * listening to. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position in the stack where this - * token was found. - * @param int $currScope The position in the tokens array that - * opened the scope that this test is - * listening for. - * - * @return void - */ - protected abstract function processTokenWithinScope( - PHP_CodeSniffer_File $phpcsFile, - $stackPtr, - $currScope - ); - - - /** - * Processes a token that is found outside the scope that this test is - * listening to. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position in the stack where this - * token was found. - * - * @return void - */ - protected function processTokenOutsideScope( - PHP_CodeSniffer_File $phpcsFile, - $stackPtr - ) { - - }//end processTokenOutsideScope() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/AbstractVariableSniff.php b/phpcs/CodeSniffer/Standards/AbstractVariableSniff.php deleted file mode 100644 index 3c41b64..0000000 --- a/phpcs/CodeSniffer/Standards/AbstractVariableSniff.php +++ /dev/null @@ -1,245 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) { - $error = 'Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found'; - throw new PHP_CodeSniffer_Exception($error); -} - -/** - * A class to find T_VARIABLE tokens. - * - * This class can distinguish between normal T_VARIABLE tokens, and those tokens - * that represent class members. If a class member is encountered, then the - * processMemberVar method is called so the extending class can process it. If - * the token is found to be a normal T_VARIABLE token, then processVariable is - * called. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -abstract class PHP_CodeSniffer_Standards_AbstractVariableSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff -{ - - /** - * The end token of the current function that we are in. - * - * @var int - */ - private $_endFunction = -1; - - /** - * TRUE if a function is currently open. - * - * @var boolean - */ - private $_functionOpen = false; - - /** - * The current PHP_CodeSniffer file that we are processing. - * - * @var PHP_CodeSniffer_File - */ - protected $currentFile = null; - - - /** - * Constructs an AbstractVariableTest. - */ - public function __construct() - { - $scopes = array( - T_CLASS, - T_ANON_CLASS, - T_TRAIT, - T_INTERFACE, - ); - - $listen = array( - T_FUNCTION, - T_VARIABLE, - T_DOUBLE_QUOTED_STRING, - T_HEREDOC, - ); - - parent::__construct($scopes, $listen, true); - - }//end __construct() - - - /** - * Processes the token in the specified PHP_CodeSniffer_File. - * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this - * token was found. - * @param int $stackPtr The position where the token was found. - * @param array $currScope The current scope opener token. - * - * @return void - */ - protected final function processTokenWithinScope( - PHP_CodeSniffer_File $phpcsFile, - $stackPtr, - $currScope - ) { - if ($this->currentFile !== $phpcsFile) { - $this->currentFile = $phpcsFile; - $this->_functionOpen = false; - $this->_endFunction = -1; - } - - $tokens = $phpcsFile->getTokens(); - - if ($stackPtr > $this->_endFunction) { - $this->_functionOpen = false; - } - - if ($tokens[$stackPtr]['code'] === T_FUNCTION - && $this->_functionOpen === false - ) { - $this->_functionOpen = true; - - $methodProps = $phpcsFile->getMethodProperties($stackPtr); - - // If the function is abstract, or is in an interface, - // then set the end of the function to it's closing semicolon. - if ($methodProps['is_abstract'] === true - || $tokens[$currScope]['code'] === T_INTERFACE - ) { - $this->_endFunction - = $phpcsFile->findNext(array(T_SEMICOLON), $stackPtr); - } else { - if (isset($tokens[$stackPtr]['scope_closer']) === false) { - $error = 'Possible parse error: non-abstract method defined as abstract'; - $phpcsFile->addWarning($error, $stackPtr); - return; - } - - $this->_endFunction = $tokens[$stackPtr]['scope_closer']; - } - }//end if - - if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING - || $tokens[$stackPtr]['code'] === T_HEREDOC - ) { - // Check to see if this string has a variable in it. - $pattern = '|(?processVariableInString($phpcsFile, $stackPtr); - } - - return; - } - - if ($this->_functionOpen === true) { - if ($tokens[$stackPtr]['code'] === T_VARIABLE) { - $this->processVariable($phpcsFile, $stackPtr); - } - } else { - // What if we assign a member variable to another? - // ie. private $_count = $this->_otherCount + 1;. - $this->processMemberVar($phpcsFile, $stackPtr); - } - - }//end processTokenWithinScope() - - - /** - * Processes the token outside the scope in the file. - * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this - * token was found. - * @param int $stackPtr The position where the token was found. - * - * @return void - */ - protected final function processTokenOutsideScope( - PHP_CodeSniffer_File $phpcsFile, - $stackPtr - ) { - $tokens = $phpcsFile->getTokens(); - // These variables are not member vars. - if ($tokens[$stackPtr]['code'] === T_VARIABLE) { - $this->processVariable($phpcsFile, $stackPtr); - } else if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING - || $tokens[$stackPtr]['code'] === T_HEREDOC - ) { - // Check to see if this string has a variable in it. - $pattern = '|(?processVariableInString($phpcsFile, $stackPtr); - } - } - - }//end processTokenOutsideScope() - - - /** - * Called to process class member vars. - * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this - * token was found. - * @param int $stackPtr The position where the token was found. - * - * @return void - */ - abstract protected function processMemberVar( - PHP_CodeSniffer_File $phpcsFile, - $stackPtr - ); - - - /** - * Called to process normal member vars. - * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this - * token was found. - * @param int $stackPtr The position where the token was found. - * - * @return void - */ - abstract protected function processVariable( - PHP_CodeSniffer_File $phpcsFile, - $stackPtr - ); - - - /** - * Called to process variables found in double quoted strings or heredocs. - * - * Note that there may be more than one variable in the string, which will - * result only in one call for the string or one call per line for heredocs. - * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this - * token was found. - * @param int $stackPtr The position where the double quoted - * string was found. - * - * @return void - */ - abstract protected function processVariableInString( - PHP_CodeSniffer_File - $phpcsFile, - $stackPtr - ); - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Classes/DuplicateClassNameStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Classes/DuplicateClassNameStandard.xml deleted file mode 100644 index 4b0ec96..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Classes/DuplicateClassNameStandard.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - Foo -{ -} - ]]> - - - Foo -{ -} - -class Foo -{ -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Classes/OpeningBraceSameLineStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Classes/OpeningBraceSameLineStandard.xml deleted file mode 100644 index 6226a3f..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Classes/OpeningBraceSameLineStandard.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - { -} - ]]> - - - { -} - ]]> - - - // Start of class. -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/EmptyStatementStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/EmptyStatementStandard.xml deleted file mode 100644 index c400d75..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/EmptyStatementStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - // do nothing -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/ForLoopShouldBeWhileLoopStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/ForLoopShouldBeWhileLoopStandard.xml deleted file mode 100644 index 06f0b7a..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/ForLoopShouldBeWhileLoopStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - $i = 0; $i < 10; $i++) { - echo "{$i}\n"; -} - ]]> - - - ;$test;) { - $test = doSomething(); -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/ForLoopWithTestFunctionCallStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/ForLoopWithTestFunctionCallStandard.xml deleted file mode 100644 index f40d94b..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/ForLoopWithTestFunctionCallStandard.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - $end = count($foo); -for ($i = 0; $i < $end; $i++) { - echo $foo[$i]."\n"; -} - ]]> - - - count($foo); $i++) { - echo $foo[$i]."\n"; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/JumbledIncrementerStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/JumbledIncrementerStandard.xml deleted file mode 100644 index 50f0782..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/JumbledIncrementerStandard.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - $i++) { - for ($j = 0; $j < 10; $j++) { - } -} - ]]> - - - $i++) { - for ($j = 0; $j < 10; $i++) { - } -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/UnconditionalIfStatementStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/UnconditionalIfStatementStandard.xml deleted file mode 100644 index b2eaabe..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/UnconditionalIfStatementStandard.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - $test) { - $var = 1; -} - ]]> - - - true) { - $var = 1; -} - ]]> - - - - - $test) { - $var = 1; -} - ]]> - - - false) { - $var = 1; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/UnnecessaryFinalModifierStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/UnnecessaryFinalModifierStandard.xml deleted file mode 100644 index 8936740..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/UnnecessaryFinalModifierStandard.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - final function bar() - { - } -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/UnusedFunctionParameterStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/UnusedFunctionParameterStandard.xml deleted file mode 100644 index 181dff4..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/UnusedFunctionParameterStandard.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - $a + $b + $c; -} - ]]> - - - $a + $b; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/UselessOverridingMethodStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/UselessOverridingMethodStandard.xml deleted file mode 100644 index ba8bd7e..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/CodeAnalysis/UselessOverridingMethodStandard.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - $this->doSomethingElse(); - } -} - ]]> - - - parent::bar(); - } -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Commenting/FixmeStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Commenting/FixmeStandard.xml deleted file mode 100644 index 451e5fb..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Commenting/FixmeStandard.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - Handle strange case -if ($test) { - $var = 1; -} - ]]> - - - FIXME: This needs to be fixed! -if ($test) { - $var = 1; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Commenting/TodoStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Commenting/TodoStandard.xml deleted file mode 100644 index c9c4fc0..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Commenting/TodoStandard.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - Handle strange case -if ($test) { - $var = 1; -} - ]]> - - - TODO: This needs to be fixed! -if ($test) { - $var = 1; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/ControlStructures/InlineControlStructureStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/ControlStructures/InlineControlStructureStandard.xml deleted file mode 100644 index 06ae14b..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/ControlStructures/InlineControlStructureStandard.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - { - $var = 1; -} - ]]> - - - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Debug/CSSLintStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Debug/CSSLintStandard.xml deleted file mode 100644 index b57a970..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Debug/CSSLintStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - %; } - ]]> - - - %; } - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Debug/ClosureLinterStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Debug/ClosureLinterStandard.xml deleted file mode 100644 index 9df9aec..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Debug/ClosureLinterStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - ]; - ]]> - - - ,]; - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Debug/JSHintStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Debug/JSHintStandard.xml deleted file mode 100644 index 7525e9e..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Debug/JSHintStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - var foo = 5; - ]]> - - - foo = 5; - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/ByteOrderMarkStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Files/ByteOrderMarkStandard.xml deleted file mode 100644 index 88591f9..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/ByteOrderMarkStandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/EndFileNewlineStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Files/EndFileNewlineStandard.xml deleted file mode 100644 index aa757ed..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/EndFileNewlineStandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/EndFileNoNewlineStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Files/EndFileNoNewlineStandard.xml deleted file mode 100644 index 227d562..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/EndFileNoNewlineStandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/InlineHTMLStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Files/InlineHTMLStandard.xml deleted file mode 100644 index 3fbf502..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/InlineHTMLStandard.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - some string here - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/LineEndingsStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Files/LineEndingsStandard.xml deleted file mode 100644 index 4554d0f..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/LineEndingsStandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/LineLengthStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Files/LineLengthStandard.xml deleted file mode 100644 index 31342e3..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/LineLengthStandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/LowercasedFilenameStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Files/LowercasedFilenameStandard.xml deleted file mode 100644 index a1be34c..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/LowercasedFilenameStandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/OneClassPerFileStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Files/OneClassPerFileStandard.xml deleted file mode 100644 index 7b58576..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/OneClassPerFileStandard.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - class Foo -{ -} - ]]> - - - class Foo -{ -} - -class Bar -{ -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/OneInterfacePerFileStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Files/OneInterfacePerFileStandard.xml deleted file mode 100644 index de97531..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Files/OneInterfacePerFileStandard.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - interface Foo -{ -} - ]]> - - - interface Foo -{ -} - -interface Bar -{ -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Formatting/DisallowMultipleStatementsStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Formatting/DisallowMultipleStatementsStandard.xml deleted file mode 100644 index f0d4490..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Formatting/DisallowMultipleStatementsStandard.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Formatting/MultipleStatementAlignmentStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Formatting/MultipleStatementAlignmentStandard.xml deleted file mode 100644 index 9369eeb..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Formatting/MultipleStatementAlignmentStandard.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - = (1 + 2); -$veryLongVarName = 'string'; -$var = foo($bar, $baz, $quux); - ]]> - - - = (1 + 2); -$veryLongVarName = 'string'; -$var = foo($bar, $baz, $quux); - ]]> - - - - - - - - += 1; -$veryLongVarName = 1; - ]]> - - - += 1; -$veryLongVarName = 1; - ]]> - - - - - = 1; -$veryLongVarName -= 1; - ]]> - - - = 1; -$veryLongVarName -= 1; - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Formatting/NoSpaceAfterCastStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Formatting/NoSpaceAfterCastStandard.xml deleted file mode 100644 index 042e4f8..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Formatting/NoSpaceAfterCastStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - 1; - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Formatting/SpaceAfterCastStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Formatting/SpaceAfterCastStandard.xml deleted file mode 100644 index 75eba77..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Formatting/SpaceAfterCastStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - 1; - ]]> - - - 1; - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Functions/CallTimePassByReferenceStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Functions/CallTimePassByReferenceStandard.xml deleted file mode 100644 index 738998d..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Functions/CallTimePassByReferenceStandard.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - &$bar) -{ - $bar++; -} - -$baz = 1; -foo($baz); - ]]> - - - &$baz); - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Functions/FunctionCallArgumentSpacingStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Functions/FunctionCallArgumentSpacingStandard.xml deleted file mode 100644 index 9809844..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Functions/FunctionCallArgumentSpacingStandard.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - $baz) -{ -} - ]]> - - - $baz) -{ -} - ]]> - - - - - = true) -{ -} - ]]> - - - =true) -{ -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Functions/OpeningFunctionBraceBsdAllmanStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Functions/OpeningFunctionBraceBsdAllmanStandard.xml deleted file mode 100644 index 414dc28..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Functions/OpeningFunctionBraceBsdAllmanStandard.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - { - ... -} - ]]> - - - { - ... -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Functions/OpeningFunctionBraceKernighanRitchieStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Functions/OpeningFunctionBraceKernighanRitchieStandard.xml deleted file mode 100644 index 84c2bdd..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Functions/OpeningFunctionBraceKernighanRitchieStandard.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - { - ... -} - ]]> - - - { - ... -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Metrics/CyclomaticComplexityStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Metrics/CyclomaticComplexityStandard.xml deleted file mode 100644 index a928e7d..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Metrics/CyclomaticComplexityStandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Metrics/NestingLevelStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Metrics/NestingLevelStandard.xml deleted file mode 100644 index f66cd92..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Metrics/NestingLevelStandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/NamingConventions/CamelCapsFunctionNameStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/NamingConventions/CamelCapsFunctionNameStandard.xml deleted file mode 100644 index f5345b7..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/NamingConventions/CamelCapsFunctionNameStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - doSomething() -{ -} - ]]> - - - do_something() -{ -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/NamingConventions/ConstructorNameStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/NamingConventions/ConstructorNameStandard.xml deleted file mode 100644 index 9dfc175..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/NamingConventions/ConstructorNameStandard.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - __construct() - { - } -} - ]]> - - - Foo() - { - } -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/NamingConventions/UpperCaseConstantNameStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/NamingConventions/UpperCaseConstantNameStandard.xml deleted file mode 100644 index 6ef61b9..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/NamingConventions/UpperCaseConstantNameStandard.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - FOO_CONSTANT', 'foo'); - -class FooClass -{ - const FOO_CONSTANT = 'foo'; -} - ]]> - - - Foo_Constant', 'foo'); - -class FooClass -{ - const foo_constant = 'foo'; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/BacktickOperatorStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/BacktickOperatorStandard.xml deleted file mode 100644 index 4ebd677..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/BacktickOperatorStandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/CharacterBeforePHPOpeningTagStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/CharacterBeforePHPOpeningTagStandard.xml deleted file mode 100644 index df5a0eb..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/CharacterBeforePHPOpeningTagStandard.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - Beginning content - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/ClosingPHPTagStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/ClosingPHPTagStandard.xml deleted file mode 100644 index 09afb2d..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/ClosingPHPTagStandard.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - -echo 'Foo'; -?> - ]]> - - - -echo 'Foo'; - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/DeprecatedFunctionsStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/DeprecatedFunctionsStandard.xml deleted file mode 100644 index 33b803a..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/DeprecatedFunctionsStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - explode('a', $bar); - ]]> - - - split('a', $bar); - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/DisallowAlternativePHPTagsStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/DisallowAlternativePHPTagsStandard.xml deleted file mode 100644 index bdfd5dc..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/DisallowAlternativePHPTagsStandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - to delimit PHP code, do not use the ASP <% %> style tags nor the tags. This is the most portable way to include PHP code on differing operating systems and setups. - ]]> - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/DisallowShortOpenTagStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/DisallowShortOpenTagStandard.xml deleted file mode 100644 index 8086ea2..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/DisallowShortOpenTagStandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - to delimit PHP code, not the shorthand. This is the most portable way to include PHP code on differing operating systems and setups. - ]]> - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/ForbiddenFunctionsStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/ForbiddenFunctionsStandard.xml deleted file mode 100644 index c0f18b5..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/ForbiddenFunctionsStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - count($bar); - ]]> - - - sizeof($bar); - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/LowerCaseConstantStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/LowerCaseConstantStandard.xml deleted file mode 100644 index ab607c5..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/LowerCaseConstantStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - true, false and null constants must always be lowercase. - ]]> - - - - false || $var === null) { - $var = true; -} - ]]> - - - FALSE || $var === NULL) { - $var = TRUE; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/LowerCaseKeywordStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/LowerCaseKeywordStandard.xml deleted file mode 100644 index 965742d..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/LowerCaseKeywordStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - array(); - ]]> - - - Array(); - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/NoSilencedErrorsStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/NoSilencedErrorsStandard.xml deleted file mode 100644 index df69887..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/NoSilencedErrorsStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - isset($foo) && $foo) { - echo "Hello\n"; -} - ]]> - - - @$foo) { - echo "Hello\n"; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/SAPIUsageStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/SAPIUsageStandard.xml deleted file mode 100644 index e74005a..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/SAPIUsageStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - PHP_SAPI === 'cli') { - echo "Hello, CLI user."; -} - ]]> - - - php_sapi_name() === 'cli') { - echo "Hello, CLI user."; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/UpperCaseConstantStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/UpperCaseConstantStandard.xml deleted file mode 100644 index 2648734..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/PHP/UpperCaseConstantStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - true, false and null constants must always be uppercase. - ]]> - - - - FALSE || $var === NULL) { - $var = TRUE; -} - ]]> - - - false || $var === null) { - $var = true; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/Strings/UnnecessaryStringConcatStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/Strings/UnnecessaryStringConcatStandard.xml deleted file mode 100644 index a4c9887..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/Strings/UnnecessaryStringConcatStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/VersionControl/SubversionPropertiesStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/VersionControl/SubversionPropertiesStandard.xml deleted file mode 100644 index f4f3e19..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/VersionControl/SubversionPropertiesStandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/WhiteSpace/DisallowSpaceIndentStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/WhiteSpace/DisallowSpaceIndentStandard.xml deleted file mode 100644 index 2e399b3..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/WhiteSpace/DisallowSpaceIndentStandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/WhiteSpace/DisallowTabIndentStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/WhiteSpace/DisallowTabIndentStandard.xml deleted file mode 100644 index 7013ffd..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/WhiteSpace/DisallowTabIndentStandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Docs/WhiteSpace/ScopeIndentStandard.xml b/phpcs/CodeSniffer/Standards/Generic/Docs/WhiteSpace/ScopeIndentStandard.xml deleted file mode 100644 index bdd36d4..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Docs/WhiteSpace/ScopeIndentStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - $var = 1; -} - ]]> - - - $var = 1; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Arrays/DisallowLongArraySyntaxSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Arrays/DisallowLongArraySyntaxSniff.php deleted file mode 100644 index 28ca7b5..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Arrays/DisallowLongArraySyntaxSniff.php +++ /dev/null @@ -1,79 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Bans the use of the PHP long array syntax. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Arrays_DisallowLongArraySyntaxSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return int[] - */ - public function register() - { - return array(T_ARRAY); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'no'); - - $error = 'Short array syntax must be used to define arrays'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found'); - - if ($fix === true) { - $tokens = $phpcsFile->getTokens(); - $opener = $tokens[$stackPtr]['parenthesis_opener']; - $closer = $tokens[$stackPtr]['parenthesis_closer']; - - $phpcsFile->fixer->beginChangeset(); - - if ($opener === null) { - $phpcsFile->fixer->replaceToken($stackPtr, '[]'); - } else { - $phpcsFile->fixer->replaceToken($stackPtr, ''); - $phpcsFile->fixer->replaceToken($opener, '['); - $phpcsFile->fixer->replaceToken($closer, ']'); - } - - $phpcsFile->fixer->endChangeset(); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Arrays/DisallowShortArraySyntaxSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Arrays/DisallowShortArraySyntaxSniff.php deleted file mode 100644 index e5743e7..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Arrays/DisallowShortArraySyntaxSniff.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Bans the use of the PHP short array syntax. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Arrays_DisallowShortArraySyntaxSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return int[] - */ - public function register() - { - return array(T_OPEN_SHORT_ARRAY); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'yes'); - - $error = 'Short array syntax is not allowed'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found'); - - if ($fix === true) { - $tokens = $phpcsFile->getTokens(); - $opener = $tokens[$stackPtr]['bracket_opener']; - $closer = $tokens[$stackPtr]['bracket_closer']; - - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->replaceToken($opener, 'array('); - $phpcsFile->fixer->replaceToken($closer, ')'); - $phpcsFile->fixer->endChangeset(); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Classes/DuplicateClassNameSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Classes/DuplicateClassNameSniff.php deleted file mode 100644 index 11db805..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Classes/DuplicateClassNameSniff.php +++ /dev/null @@ -1,127 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Reports errors if the same class or interface name is used in multiple files. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Classes_DuplicateClassNameSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * List of classes that have been found during checking. - * - * @var array - */ - protected $foundClasses = array(); - - - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return int[] - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $namespace = ''; - $findTokens = array( - T_CLASS, - T_INTERFACE, - T_NAMESPACE, - T_CLOSE_TAG, - ); - - $stackPtr = $phpcsFile->findNext($findTokens, ($stackPtr + 1)); - while ($stackPtr !== false) { - if ($tokens[$stackPtr]['code'] === T_CLOSE_TAG) { - // We can stop here. The sniff will continue from the next open - // tag when PHPCS reaches that token, if there is one. - return; - } - - // Keep track of what namespace we are in. - if ($tokens[$stackPtr]['code'] === T_NAMESPACE) { - $nsEnd = $phpcsFile->findNext( - array( - T_NS_SEPARATOR, - T_STRING, - T_WHITESPACE, - ), - ($stackPtr + 1), - null, - true - ); - - $namespace = trim($phpcsFile->getTokensAsString(($stackPtr + 1), ($nsEnd - $stackPtr - 1))); - $stackPtr = $nsEnd; - } else { - $nameToken = $phpcsFile->findNext(T_STRING, $stackPtr); - $name = $tokens[$nameToken]['content']; - if ($namespace !== '') { - $name = $namespace.'\\'.$name; - } - - $compareName = strtolower($name); - if (isset($this->foundClasses[$compareName]) === true) { - $type = strtolower($tokens[$stackPtr]['content']); - $file = $this->foundClasses[$compareName]['file']; - $line = $this->foundClasses[$compareName]['line']; - $error = 'Duplicate %s name "%s" found; first defined in %s on line %s'; - $data = array( - $type, - $name, - $file, - $line, - ); - $phpcsFile->addWarning($error, $stackPtr, 'Found', $data); - } else { - $this->foundClasses[$compareName] = array( - 'file' => $phpcsFile->getFilename(), - 'line' => $tokens[$stackPtr]['line'], - ); - } - }//end if - - $stackPtr = $phpcsFile->findNext($findTokens, ($stackPtr + 1)); - }//end while - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Classes/OpeningBraceSameLineSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Classes/OpeningBraceSameLineSniff.php deleted file mode 100644 index 111784b..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Classes/OpeningBraceSameLineSniff.php +++ /dev/null @@ -1,141 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Classes_OpeningBraceSameLineSniff. - * - * Checks that the opening brace of a class or interface is on the same line - * as the class declaration. - * - * Also checks that the brace is the last thing on that line and has precisely one space before it. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Classes_OpeningBraceSameLineSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_CLASS, - T_INTERFACE, - T_TRAIT, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $scope_identifier = $phpcsFile->findNext(T_STRING, ($stackPtr + 1)); - $errorData = array(strtolower($tokens[$stackPtr]['content']).' '.$tokens[$scope_identifier]['content']); - - if (isset($tokens[$stackPtr]['scope_opener']) === false) { - $error = 'Possible parse error: %s missing opening or closing brace'; - $phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $errorData); - return; - } - - $openingBrace = $tokens[$stackPtr]['scope_opener']; - - // Is the brace on the same line as the class/interface/trait declaration ? - $lastClassLineToken = $phpcsFile->findPrevious(T_STRING, ($openingBrace - 1), $stackPtr); - $lastClassLine = $tokens[$lastClassLineToken]['line']; - $braceLine = $tokens[$openingBrace]['line']; - $lineDifference = ($braceLine - $lastClassLine); - - if ($lineDifference > 0) { - $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'new line'); - $error = 'Opening brace should be on the same line as the declaration for %s'; - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceOnNewLine', $errorData); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->addContent($lastClassLineToken, ' {'); - $phpcsFile->fixer->replaceToken($openingBrace, ''); - $phpcsFile->fixer->endChangeset(); - } - } else { - $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'same line'); - } - - // Is the opening brace the last thing on the line ? - $next = $phpcsFile->findNext(T_WHITESPACE, ($openingBrace + 1), null, true); - if ($tokens[$next]['line'] === $tokens[$openingBrace]['line']) { - if ($next === $tokens[$stackPtr]['scope_closer']) { - // Ignore empty classes. - return; - } - - $error = 'Opening brace must be the last content on the line'; - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'ContentAfterBrace'); - if ($fix === true) { - $phpcsFile->fixer->addNewline($openingBrace); - } - } - - // Only continue checking if the opening brace looks good. - if ($lineDifference > 0) { - return; - } - - // Is there precisely one space before the opening brace ? - if ($tokens[($openingBrace - 1)]['code'] !== T_WHITESPACE) { - $length = 0; - } else if ($tokens[($openingBrace - 1)]['content'] === "\t") { - $length = '\t'; - } else { - $length = strlen($tokens[($openingBrace - 1)]['content']); - } - - if ($length !== 1) { - $error = 'Expected 1 space before opening brace; found %s'; - $data = array($length); - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'SpaceBeforeBrace', $data); - if ($fix === true) { - if ($length === 0 || $length === '\t') { - $phpcsFile->fixer->addContentBefore($openingBrace, ' '); - } else { - $phpcsFile->fixer->replaceToken(($openingBrace - 1), ' '); - } - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/EmptyStatementSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/EmptyStatementSniff.php deleted file mode 100644 index 2020826..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/EmptyStatementSniff.php +++ /dev/null @@ -1,106 +0,0 @@ - - * @author Greg Sherwood - * @copyright 2007-2014 Manuel Pichler. All rights reserved. - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * This sniff class detected empty statement. - * - * This sniff implements the common algorithm for empty statement body detection. - * A body is considered as empty if it is completely empty or it only contains - * whitespace characters and/or comments. - * - * - * stmt { - * // foo - * } - * stmt (conditions) { - * // foo - * } - * - * - * @category PHP - * @package PHP_CodeSniffer - * @author Manuel Pichler - * @author Greg Sherwood - * @copyright 2007-2014 Manuel Pichler. All rights reserved. - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_CodeAnalysis_EmptyStatementSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return int[] - */ - public function register() - { - return array( - T_CATCH, - T_DO, - T_ELSE, - T_ELSEIF, - T_FOR, - T_FOREACH, - T_IF, - T_SWITCH, - T_TRY, - T_WHILE, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; - - // Skip statements without a body. - if (isset($token['scope_opener']) === false) { - return; - } - - $next = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, - ($token['scope_opener'] + 1), - ($token['scope_closer'] - 1), - true - ); - - if ($next !== false) { - return; - } - - // Get token identifier. - $name = strtoupper($token['content']); - $error = 'Empty %s statement detected'; - $phpcsFile->addError($error, $stackPtr, 'Detected'.$name, array($name)); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/ForLoopShouldBeWhileLoopSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/ForLoopShouldBeWhileLoopSniff.php deleted file mode 100644 index 05349e4..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/ForLoopShouldBeWhileLoopSniff.php +++ /dev/null @@ -1,102 +0,0 @@ - - * @author Manuel Pichler - * @copyright 2007-2014 Manuel Pichler. All rights reserved. - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Detects for-loops that can be simplified to a while-loop. - * - * This rule is based on the PMD rule catalog. Detects for-loops that can be - * simplified as a while-loop. - * - * - * class Foo - * { - * public function bar($x) - * { - * for (;true;) true; // No Init or Update part, may as well be: while (true) - * } - * } - * - * - * @category PHP - * @package PHP_CodeSniffer - * @author Manuel Pichler - * @copyright 2007-2014 Manuel Pichler. All rights reserved. - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_CodeAnalysis_ForLoopShouldBeWhileLoopSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return int[] - */ - public function register() - { - return array(T_FOR); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; - - // Skip invalid statement. - if (isset($token['parenthesis_opener']) === false) { - return; - } - - $next = ++$token['parenthesis_opener']; - $end = --$token['parenthesis_closer']; - - $parts = array( - 0, - 0, - 0, - ); - $index = 0; - - for (; $next <= $end; ++$next) { - $code = $tokens[$next]['code']; - if ($code === T_SEMICOLON) { - ++$index; - } else if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$code]) === false) { - ++$parts[$index]; - } - } - - if ($parts[0] === 0 && $parts[2] === 0 && $parts[1] > 0) { - $error = 'This FOR loop can be simplified to a WHILE loop'; - $phpcsFile->addWarning($error, $stackPtr, 'CanSimplify'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/ForLoopWithTestFunctionCallSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/ForLoopWithTestFunctionCallSniff.php deleted file mode 100644 index 9d5c876..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/ForLoopWithTestFunctionCallSniff.php +++ /dev/null @@ -1,111 +0,0 @@ - - * @author Manuel Pichler - * @copyright 2007-2014 Manuel Pichler. All rights reserved. - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Detects for-loops that use a function call in the test expression. - * - * This rule is based on the PMD rule catalog. Detects for-loops that use a - * function call in the test expression. - * - * - * class Foo - * { - * public function bar($x) - * { - * $a = array(1, 2, 3, 4); - * for ($i = 0; $i < count($a); $i++) { - * $a[$i] *= $i; - * } - * } - * } - * - * - * @category PHP - * @package PHP_CodeSniffer - * @author Manuel Pichler - * @copyright 2007-2014 Manuel Pichler. All rights reserved. - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_CodeAnalysis_ForLoopWithTestFunctionCallSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return int[] - */ - public function register() - { - return array(T_FOR); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; - - // Skip invalid statement. - if (isset($token['parenthesis_opener']) === false) { - return; - } - - $next = ++$token['parenthesis_opener']; - $end = --$token['parenthesis_closer']; - - $position = 0; - - for (; $next <= $end; ++$next) { - $code = $tokens[$next]['code']; - if ($code === T_SEMICOLON) { - ++$position; - } - - if ($position < 1) { - continue; - } else if ($position > 1) { - break; - } else if ($code !== T_VARIABLE && $code !== T_STRING) { - continue; - } - - // Find next non empty token, if it is a open curly brace we have a - // function call. - $index = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true); - - if ($tokens[$index]['code'] === T_OPEN_PARENTHESIS) { - $error = 'Avoid function calls in a FOR loop test part'; - $phpcsFile->addWarning($error, $stackPtr, 'NotAllowed'); - break; - } - }//end for - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/JumbledIncrementerSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/JumbledIncrementerSniff.php deleted file mode 100644 index 364586e..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/JumbledIncrementerSniff.php +++ /dev/null @@ -1,146 +0,0 @@ - - * @author Manuel Pichler - * @copyright 2007-2014 Manuel Pichler. All rights reserved. - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Detects incrementer jumbling in for loops. - * - * This rule is based on the PMD rule catalog. The jumbling incrementer sniff - * detects the usage of one and the same incrementer into an outer and an inner - * loop. Even it is intended this is confusing code. - * - * - * class Foo - * { - * public function bar($x) - * { - * for ($i = 0; $i < 10; $i++) - * { - * for ($k = 0; $k < 20; $i++) - * { - * echo 'Hello'; - * } - * } - * } - * } - * - * - * @category PHP - * @package PHP_CodeSniffer - * @author Manuel Pichler - * @copyright 2007-2014 Manuel Pichler. All rights reserved. - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_CodeAnalysis_JumbledIncrementerSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return int[] - */ - public function register() - { - return array(T_FOR); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; - - // Skip for-loop without body. - if (isset($token['scope_opener']) === false) { - return; - } - - // Find incrementors for outer loop. - $outer = $this->findIncrementers($tokens, $token); - - // Skip if empty. - if (count($outer) === 0) { - return; - } - - // Find nested for loops. - $start = ++$token['scope_opener']; - $end = --$token['scope_closer']; - - for (; $start <= $end; ++$start) { - if ($tokens[$start]['code'] !== T_FOR) { - continue; - } - - $inner = $this->findIncrementers($tokens, $tokens[$start]); - $diff = array_intersect($outer, $inner); - - if (count($diff) !== 0) { - $error = 'Loop incrementor (%s) jumbling with inner loop'; - $data = array(join(', ', $diff)); - $phpcsFile->addWarning($error, $stackPtr, 'Found', $data); - } - } - - }//end process() - - - /** - * Get all used variables in the incrementer part of a for statement. - * - * @param array(integer=>array) $tokens Array with all code sniffer tokens. - * @param array(string=>mixed) $token Current for loop token - * - * @return string[] List of all found incrementer variables. - */ - protected function findIncrementers(array $tokens, array $token) - { - // Skip invalid statement. - if (isset($token['parenthesis_opener']) === false) { - return array(); - } - - $start = ++$token['parenthesis_opener']; - $end = --$token['parenthesis_closer']; - - $incrementers = array(); - $semicolons = 0; - for ($next = $start; $next <= $end; ++$next) { - $code = $tokens[$next]['code']; - if ($code === T_SEMICOLON) { - ++$semicolons; - } else if ($semicolons === 2 && $code === T_VARIABLE) { - $incrementers[] = $tokens[$next]['content']; - } - } - - return $incrementers; - - }//end findIncrementers() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php deleted file mode 100644 index 3847016..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php +++ /dev/null @@ -1,104 +0,0 @@ - - * @author Manuel Pichler - * @copyright 2007-2014 Manuel Pichler. All rights reserved. - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Detects unconditional if- and elseif-statements. - * - * This rule is based on the PMD rule catalog. The Unconditional If Statement - * sniff detects statement conditions that are only set to one of the constant - * values true or false - * - * - * class Foo - * { - * public function close() - * { - * if (true) - * { - * // ... - * } - * } - * } - * - * - * @category PHP - * @package PHP_CodeSniffer - * @author Manuel Pichler - * @copyright 2007-2014 Manuel Pichler. All rights reserved. - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_CodeAnalysis_UnconditionalIfStatementSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return int[] - */ - public function register() - { - return array( - T_IF, - T_ELSEIF, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; - - // Skip for-loop without body. - if (isset($token['parenthesis_opener']) === false) { - return; - } - - $next = ++$token['parenthesis_opener']; - $end = --$token['parenthesis_closer']; - - $goodCondition = false; - for (; $next <= $end; ++$next) { - $code = $tokens[$next]['code']; - - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$code]) === true) { - continue; - } else if ($code !== T_TRUE && $code !== T_FALSE) { - $goodCondition = true; - } - } - - if ($goodCondition === false) { - $error = 'Avoid IF statements that are always true or false'; - $phpcsFile->addWarning($error, $stackPtr, 'Found'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnnecessaryFinalModifierSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnnecessaryFinalModifierSniff.php deleted file mode 100644 index 11f8c1b..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnnecessaryFinalModifierSniff.php +++ /dev/null @@ -1,96 +0,0 @@ - - * @author Manuel Pichler - * @copyright 2007-2014 Manuel Pichler. All rights reserved. - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Detects unnecessary final modifiers inside of final classes. - * - * This rule is based on the PMD rule catalog. The Unnecessary Final Modifier - * sniff detects the use of the final modifier inside of a final class which - * is unnecessary. - * - * - * final class Foo - * { - * public final function bar() - * { - * } - * } - * - * - * @category PHP - * @package PHP_CodeSniffer - * @author Manuel Pichler - * @copyright 2007-2014 Manuel Pichler. All rights reserved. - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_CodeAnalysis_UnnecessaryFinalModifierSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return int[] - */ - public function register() - { - return array(T_CLASS); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; - - // Skip for-statements without body. - if (isset($token['scope_opener']) === false) { - return; - } - - // Fetch previous token. - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); - - // Skip for non final class. - if ($prev === false || $tokens[$prev]['code'] !== T_FINAL) { - return; - } - - $next = ++$token['scope_opener']; - $end = --$token['scope_closer']; - - for (; $next <= $end; ++$next) { - if ($tokens[$next]['code'] === T_FINAL) { - $error = 'Unnecessary FINAL modifier in FINAL class'; - $phpcsFile->addWarning($error, $next, 'Found'); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnusedFunctionParameterSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnusedFunctionParameterSniff.php deleted file mode 100644 index f95414a..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnusedFunctionParameterSniff.php +++ /dev/null @@ -1,187 +0,0 @@ - - * @author Manuel Pichler - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Checks the for unused function parameters. - * - * This sniff checks that all function parameters are used in the function body. - * One exception is made for empty function bodies or function bodies that only - * contain comments. This could be useful for the classes that implement an - * interface that defines multiple methods but the implementation only needs some - * of them. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Manuel Pichler - * @author Greg Sherwood - * @copyright 2007-2014 Manuel Pichler. All rights reserved. - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_CodeAnalysis_UnusedFunctionParameterSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_FUNCTION, - T_CLOSURE, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; - - // Skip broken function declarations. - if (isset($token['scope_opener']) === false || isset($token['parenthesis_opener']) === false) { - return; - } - - $params = array(); - foreach ($phpcsFile->getMethodParameters($stackPtr) as $param) { - $params[$param['name']] = $stackPtr; - } - - $next = ++$token['scope_opener']; - $end = --$token['scope_closer']; - - $foundContent = false; - $validTokens = array( - T_HEREDOC => T_HEREDOC, - T_NOWDOC => T_NOWDOC, - T_END_HEREDOC => T_END_HEREDOC, - T_END_NOWDOC => T_END_NOWDOC, - T_DOUBLE_QUOTED_STRING => T_DOUBLE_QUOTED_STRING, - ); - $validTokens += PHP_CodeSniffer_Tokens::$emptyTokens; - - for (; $next <= $end; ++$next) { - $token = $tokens[$next]; - $code = $token['code']; - - // Ignorable tokens. - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$code]) === true) { - continue; - } - - if ($foundContent === false) { - // A throw statement as the first content indicates an interface method. - if ($code === T_THROW) { - return; - } - - // A return statement as the first content indicates an interface method. - if ($code === T_RETURN) { - $tmp = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true); - if ($tmp === false) { - return; - } - - // There is a return. - if ($tokens[$tmp]['code'] === T_SEMICOLON) { - return; - } - - $tmp = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($tmp + 1), null, true); - if ($tmp !== false && $tokens[$tmp]['code'] === T_SEMICOLON) { - // There is a return . - return; - } - }//end if - }//end if - - $foundContent = true; - - if ($code === T_VARIABLE && isset($params[$token['content']]) === true) { - unset($params[$token['content']]); - } else if ($code === T_DOLLAR) { - $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($next + 1), null, true); - if ($tokens[$nextToken]['code'] === T_OPEN_CURLY_BRACKET) { - $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($nextToken + 1), null, true); - if ($tokens[$nextToken]['code'] === T_STRING) { - $varContent = '$'.$tokens[$nextToken]['content']; - if (isset($params[$varContent]) === true) { - unset($params[$varContent]); - } - } - } - } else if ($code === T_DOUBLE_QUOTED_STRING - || $code === T_START_HEREDOC - || $code === T_START_NOWDOC - ) { - // Tokenize strings that can contain variables. - // Make sure the string is re-joined if it occurs over multiple lines. - $content = $token['content']; - for ($i = ($next + 1); $i <= $end; $i++) { - if (isset($validTokens[$tokens[$i]['code']]) === true) { - $content .= $tokens[$i]['content']; - $next++; - } else { - break; - } - } - - $stringTokens = token_get_all(sprintf('', $content)); - foreach ($stringTokens as $stringPtr => $stringToken) { - if (is_array($stringToken) === false) { - continue; - } - - $varContent = ''; - if ($stringToken[0] === T_DOLLAR_OPEN_CURLY_BRACES) { - $varContent = '$'.$stringTokens[($stringPtr + 1)][1]; - } else if ($stringToken[0] === T_VARIABLE) { - $varContent = $stringToken[1]; - } - - if ($varContent !== '' && isset($params[$varContent]) === true) { - unset($params[$varContent]); - } - } - }//end if - }//end for - - if ($foundContent === true && count($params) > 0) { - foreach ($params as $paramName => $position) { - $error = 'The method parameter %s is never used'; - $data = array($paramName); - $phpcsFile->addWarning($error, $position, 'Found', $data); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php deleted file mode 100644 index 27b994d..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php +++ /dev/null @@ -1,172 +0,0 @@ - - * @author Manuel Pichler - * @copyright 2007-2014 Manuel Pichler. All rights reserved. - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Detects unnecessary overridden methods that simply call their parent. - * - * This rule is based on the PMD rule catalog. The Useless Overriding Method - * sniff detects the use of methods that only call their parent classes's method - * with the same name and arguments. These methods are not required. - * - * - * class FooBar { - * public function __construct($a, $b) { - * parent::__construct($a, $b); - * } - * } - * - * - * @category PHP - * @package PHP_CodeSniffer - * @author Manuel Pichler - * @copyright 2007-2014 Manuel Pichler. All rights reserved. - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_CodeAnalysis_UselessOverridingMethodSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return int[] - */ - public function register() - { - return array(T_FUNCTION); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; - - // Skip function without body. - if (isset($token['scope_opener']) === false) { - return; - } - - // Get function name. - $methodName = $phpcsFile->getDeclarationName($stackPtr); - - // Get all parameters from method signature. - $signature = array(); - foreach ($phpcsFile->getMethodParameters($stackPtr) as $param) { - $signature[] = $param['name']; - } - - $next = ++$token['scope_opener']; - $end = --$token['scope_closer']; - - for (; $next <= $end; ++$next) { - $code = $tokens[$next]['code']; - - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$code]) === true) { - continue; - } else if ($code === T_RETURN) { - continue; - } - - break; - } - - // Any token except 'parent' indicates correct code. - if ($tokens[$next]['code'] !== T_PARENT) { - return; - } - - // Find next non empty token index, should be double colon. - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true); - - // Skip for invalid code. - if ($next === false || $tokens[$next]['code'] !== T_DOUBLE_COLON) { - return; - } - - // Find next non empty token index, should be the function name. - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true); - - // Skip for invalid code or other method. - if ($next === false || $tokens[$next]['content'] !== $methodName) { - return; - } - - // Find next non empty token index, should be the open parenthesis. - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true); - - // Skip for invalid code. - if ($next === false || $tokens[$next]['code'] !== T_OPEN_PARENTHESIS) { - return; - } - - $parameters = array(''); - $parenthesisCount = 1; - $count = count($tokens); - for (++$next; $next < $count; ++$next) { - $code = $tokens[$next]['code']; - - if ($code === T_OPEN_PARENTHESIS) { - ++$parenthesisCount; - } else if ($code === T_CLOSE_PARENTHESIS) { - --$parenthesisCount; - } else if ($parenthesisCount === 1 && $code === T_COMMA) { - $parameters[] = ''; - } else if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$code]) === false) { - $parameters[(count($parameters) - 1)] .= $tokens[$next]['content']; - } - - if ($parenthesisCount === 0) { - break; - } - }//end for - - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true); - if ($next === false || $tokens[$next]['code'] !== T_SEMICOLON) { - return; - } - - // Check rest of the scope. - for (++$next; $next <= $end; ++$next) { - $code = $tokens[$next]['code']; - // Skip for any other content. - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$code]) === false) { - return; - } - } - - $parameters = array_map('trim', $parameters); - $parameters = array_filter($parameters); - - if (count($parameters) === count($signature) && $parameters === $signature) { - $phpcsFile->addWarning('Possible useless method overriding detected', $stackPtr, 'Found'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Commenting/FixmeSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Commenting/FixmeSniff.php deleted file mode 100644 index b42fb01..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Commenting/FixmeSniff.php +++ /dev/null @@ -1,91 +0,0 @@ - - * @author Sam Graham - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Commenting_FixmeSniff. - * - * Warns about FIXME comments. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Sam Graham - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Commenting_FixmeSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return PHP_CodeSniffer_Tokens::$commentTokens; - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $content = $tokens[$stackPtr]['content']; - $matches = array(); - preg_match('/(?:\A|[^\p{L}]+)fixme([^\p{L}]+(.*)|\Z)/ui', $content, $matches); - if (empty($matches) === false) { - // Clear whitespace and some common characters not required at - // the end of a fixme message to make the error more informative. - $type = 'CommentFound'; - $fixmeMessage = trim($matches[1]); - $fixmeMessage = trim($fixmeMessage, '-:[](). '); - $error = 'Comment refers to a FIXME task'; - $data = array($fixmeMessage); - if ($fixmeMessage !== '') { - $type = 'TaskFound'; - $error .= ' "%s"'; - } - - $phpcsFile->addError($error, $stackPtr, $type, $data); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Commenting/TodoSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Commenting/TodoSniff.php deleted file mode 100644 index 14acf0e..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Commenting/TodoSniff.php +++ /dev/null @@ -1,89 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Commenting_TodoSniff. - * - * Warns about TODO comments. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Commenting_TodoSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return PHP_CodeSniffer_Tokens::$commentTokens; - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $content = $tokens[$stackPtr]['content']; - $matches = array(); - preg_match('/(?:\A|[^\p{L}]+)todo([^\p{L}]+(.*)|\Z)/ui', $content, $matches); - if (empty($matches) === false) { - // Clear whitespace and some common characters not required at - // the end of a to-do message to make the warning more informative. - $type = 'CommentFound'; - $todoMessage = trim($matches[1]); - $todoMessage = trim($todoMessage, '-:[](). '); - $error = 'Comment refers to a TODO task'; - $data = array($todoMessage); - if ($todoMessage !== '') { - $type = 'TaskFound'; - $error .= ' "%s"'; - } - - $phpcsFile->addWarning($error, $stackPtr, $type, $data); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php deleted file mode 100644 index f35323c..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php +++ /dev/null @@ -1,316 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_ControlStructures_InlineControlStructureSniff. - * - * Verifies that inline control statements are not present. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_ControlStructures_InlineControlStructureSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - /** - * If true, an error will be thrown; otherwise a warning. - * - * @var bool - */ - public $error = true; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_IF, - T_ELSE, - T_ELSEIF, - T_FOREACH, - T_WHILE, - T_DO, - T_SWITCH, - T_FOR, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (isset($tokens[$stackPtr]['scope_opener']) === true) { - $phpcsFile->recordMetric($stackPtr, 'Control structure defined inline', 'no'); - return; - } - - // Ignore the ELSE in ELSE IF. We'll process the IF part later. - if ($tokens[$stackPtr]['code'] === T_ELSE) { - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($tokens[$next]['code'] === T_IF) { - return; - } - } - - if ($tokens[$stackPtr]['code'] === T_WHILE) { - // This could be from a DO WHILE, which doesn't have an opening brace. - $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) { - $brace = $tokens[$lastContent]; - if (isset($brace['scope_condition']) === true) { - $condition = $tokens[$brace['scope_condition']]; - if ($condition['code'] === T_DO) { - return; - } - } - } - - // In Javascript DO WHILE loops without curly braces are legal. This - // is only valid if a single statement is present between the DO and - // the WHILE. We can detect this by checking only a single semicolon - // is present between them. - if ($phpcsFile->tokenizerType === 'JS') { - $lastDo = $phpcsFile->findPrevious(T_DO, ($stackPtr - 1)); - $lastSemicolon = $phpcsFile->findPrevious(T_SEMICOLON, ($stackPtr - 1)); - if ($lastDo !== false && $lastSemicolon !== false && $lastDo < $lastSemicolon) { - $precedingSemicolon = $phpcsFile->findPrevious(T_SEMICOLON, ($lastSemicolon - 1)); - if ($precedingSemicolon === false || $precedingSemicolon < $lastDo) { - return; - } - } - } - }//end if - - // This is a control structure without an opening brace, - // so it is an inline statement. - if ($this->error === true) { - $fix = $phpcsFile->addFixableError('Inline control structures are not allowed', $stackPtr, 'NotAllowed'); - } else { - $fix = $phpcsFile->addFixableWarning('Inline control structures are discouraged', $stackPtr, 'Discouraged'); - } - - $phpcsFile->recordMetric($stackPtr, 'Control structure defined inline', 'yes'); - - // Stop here if we are not fixing the error. - if ($fix !== true) { - return; - } - - $phpcsFile->fixer->beginChangeset(); - if (isset($tokens[$stackPtr]['parenthesis_closer']) === true) { - $closer = $tokens[$stackPtr]['parenthesis_closer']; - } else { - $closer = $stackPtr; - } - - if ($tokens[($closer + 1)]['code'] === T_WHITESPACE - || $tokens[($closer + 1)]['code'] === T_SEMICOLON - ) { - $phpcsFile->fixer->addContent($closer, ' {'); - } else { - $phpcsFile->fixer->addContent($closer, ' { '); - } - - $fixableScopeOpeners = $this->register(); - - $lastNonEmpty = $closer; - for ($end = ($closer + 1); $end < $phpcsFile->numTokens; $end++) { - if ($tokens[$end]['code'] === T_SEMICOLON) { - break; - } - - if ($tokens[$end]['code'] === T_CLOSE_TAG) { - $end = $lastNonEmpty; - break; - } - - if (in_array($tokens[$end]['code'], $fixableScopeOpeners) === true - && isset($tokens[$end]['scope_opener']) === false - ) { - // The best way to fix nested inline scopes is middle-out. - // So skip this one. It will be detected and fixed on a future loop. - $phpcsFile->fixer->rollbackChangeset(); - return; - } - - if (isset($tokens[$end]['scope_opener']) === true) { - $type = $tokens[$end]['code']; - $end = $tokens[$end]['scope_closer']; - if ($type === T_DO || $type === T_IF || $type === T_ELSEIF || $type === T_TRY) { - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($end + 1), null, true); - if ($next === false) { - break; - } - - $nextType = $tokens[$next]['code']; - - // Let additional conditions loop and find their ending. - if (($type === T_IF - || $type === T_ELSEIF) - && ($nextType === T_ELSEIF - || $nextType === T_ELSE) - ) { - continue; - } - - // Account for DO... WHILE conditions. - if ($type === T_DO && $nextType === T_WHILE) { - $end = $phpcsFile->findNext(T_SEMICOLON, ($next + 1)); - } - - // Account for TRY... CATCH statements. - if ($type === T_TRY && $nextType === T_CATCH) { - $end = $tokens[$next]['scope_closer']; - } - }//end if - - if ($tokens[$end]['code'] !== T_END_HEREDOC - && $tokens[$end]['code'] !== T_END_NOWDOC - ) { - break; - } - }//end if - - if (isset($tokens[$end]['parenthesis_closer']) === true) { - $end = $tokens[$end]['parenthesis_closer']; - $lastNonEmpty = $end; - continue; - } - - if ($tokens[$end]['code'] !== T_WHITESPACE) { - $lastNonEmpty = $end; - } - }//end for - - if ($end === $phpcsFile->numTokens) { - $end = $lastNonEmpty; - } - - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($end + 1), null, true); - - if ($next === false || $tokens[$next]['line'] !== $tokens[$end]['line']) { - // Looks for completely empty statements. - $next = $phpcsFile->findNext(T_WHITESPACE, ($closer + 1), ($end + 1), true); - - // Account for a comment on the end of the line. - for ($endLine = $end; $endLine < $phpcsFile->numTokens; $endLine++) { - if (isset($tokens[($endLine + 1)]) === false - || $tokens[$endLine]['line'] !== $tokens[($endLine + 1)]['line'] - ) { - break; - } - } - - if ($tokens[$endLine]['code'] !== T_COMMENT) { - $endLine = $end; - } - } else { - $next = ($end + 1); - $endLine = $end; - } - - if ($next !== $end) { - if ($endLine !== $end) { - $endToken = $endLine; - $addedContent = ''; - } else { - $endToken = $end; - $addedContent = $phpcsFile->eolChar; - - if ($tokens[$end]['code'] !== T_SEMICOLON - && $tokens[$end]['code'] !== T_CLOSE_CURLY_BRACKET - ) { - $phpcsFile->fixer->addContent($end, '; '); - } - } - - $next = $phpcsFile->findNext(T_WHITESPACE, ($endToken + 1), null, true); - if ($next !== false - && ($tokens[$next]['code'] === T_ELSE - || $tokens[$next]['code'] === T_ELSEIF) - ) { - $phpcsFile->fixer->addContentBefore($next, '} '); - } else { - $indent = ''; - for ($first = $stackPtr; $first > 0; $first--) { - if ($first === 1 - || $tokens[($first - 1)]['line'] !== $tokens[$first]['line'] - ) { - break; - } - } - - if ($tokens[$first]['code'] === T_WHITESPACE) { - $indent = $tokens[$first]['content']; - } else if ($tokens[$first]['code'] === T_INLINE_HTML - || $tokens[$first]['code'] === T_OPEN_TAG - ) { - $addedContent = ''; - } - - $addedContent .= $indent.'}'; - if ($next !== false && $tokens[$endToken]['code'] === T_COMMENT) { - $addedContent .= $phpcsFile->eolChar; - } - - $phpcsFile->fixer->addContent($endToken, $addedContent); - }//end if - } else { - if ($endLine !== $end) { - $phpcsFile->fixer->replaceToken($end, ''); - $phpcsFile->fixer->addNewlineBefore($endLine); - $phpcsFile->fixer->addContent($endLine, '}'); - } else { - $phpcsFile->fixer->replaceToken($end, '}'); - } - }//end if - - $phpcsFile->fixer->endChangeset(); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Debug/CSSLintSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Debug/CSSLintSniff.php deleted file mode 100644 index d73fd3d..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Debug/CSSLintSniff.php +++ /dev/null @@ -1,107 +0,0 @@ - - * @copyright 2013-2014 Roman Levishchenko - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Debug_CSSLintSniff. - * - * Runs csslint on the file. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Roman Levishchenko - * @copyright 2013-2014 Roman Levishchenko - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Debug_CSSLintSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $fileName = $phpcsFile->getFilename(); - - $csslintPath = PHP_CodeSniffer::getConfigData('csslint_path'); - if ($csslintPath === null) { - return; - } - - $cmd = escapeshellcmd($csslintPath).' '.escapeshellarg($fileName).' 2>&1'; - exec($cmd, $output, $retval); - - if (is_array($output) === false) { - return; - } - - $count = count($output); - - for ($i = 0; $i < $count; $i++) { - $matches = array(); - $numMatches = preg_match( - '/(error|warning) at line (\d+)/', - $output[$i], - $matches - ); - - if ($numMatches === 0) { - continue; - } - - $line = (int) $matches[2]; - $message = 'csslint says: '.$output[($i + 1)]; - // First line is message with error line and error code. - // Second is error message. - // Third is wrong line in file. - // Fourth is empty line. - $i += 4; - - $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool'); - }//end for - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Debug/ClosureLinterSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Debug/ClosureLinterSniff.php deleted file mode 100644 index 8ef1946..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Debug/ClosureLinterSniff.php +++ /dev/null @@ -1,128 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Debug_ClosureLinterSniff. - * - * Runs gjslint on the file. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Debug_ClosureLinterSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of error codes that should show errors. - * - * All other error codes will show warnings. - * - * @var int - */ - public $errorCodes = array(); - - /** - * A list of error codes to ignore. - * - * @var int - */ - public $ignoreCodes = array(); - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('JS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - * @throws PHP_CodeSniffer_Exception If jslint.js could not be run - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $fileName = $phpcsFile->getFilename(); - - $lintPath = PHP_CodeSniffer::getConfigData('gjslint_path'); - if ($lintPath === null) { - return; - } - - $lintPath = escapeshellcmd($lintPath); - $cmd = '$lintPath --nosummary --notime --unix_mode '.escapeshellarg($fileName); - $msg = exec($cmd, $output, $retval); - - if (is_array($output) === false) { - return; - } - - foreach ($output as $finding) { - $matches = array(); - $numMatches = preg_match('/^(.*):([0-9]+):\(.*?([0-9]+)\)(.*)$/', $finding, $matches); - if ($numMatches === 0) { - continue; - } - - // Skip error codes we are ignoring. - $code = $matches[3]; - if (in_array($code, $this->ignoreCodes) === true) { - continue; - } - - $line = (int) $matches[2]; - $error = trim($matches[4]); - - $message = 'gjslint says: (%s) %s'; - $data = array( - $code, - $error, - ); - if (in_array($code, $this->errorCodes) === true) { - $phpcsFile->addErrorOnLine($message, $line, 'ExternalToolError', $data); - } else { - $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool', $data); - } - }//end foreach - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Debug/JSHintSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Debug/JSHintSniff.php deleted file mode 100644 index 3c7c9b6..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Debug/JSHintSniff.php +++ /dev/null @@ -1,99 +0,0 @@ - - * @author Alexander Wei§ - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Debug_JSHintSniff. - * - * Runs jshint.js on the file. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Alexander Wei§ - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Debug_JSHintSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('JS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - * @throws PHP_CodeSniffer_Exception If jshint.js could not be run - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $fileName = $phpcsFile->getFilename(); - - $rhinoPath = PHP_CodeSniffer::getConfigData('rhino_path'); - $jshintPath = PHP_CodeSniffer::getConfigData('jshint_path'); - if ($rhinoPath === null || $jshintPath === null) { - return; - } - - $rhinoPath = escapeshellcmd($rhinoPath); - $jshintPath = escapeshellcmd($jshintPath); - - $cmd = "$rhinoPath \"$jshintPath\" ".escapeshellarg($fileName); - $msg = exec($cmd, $output, $retval); - - if (is_array($output) === true) { - foreach ($output as $finding) { - $matches = array(); - $numMatches = preg_match('/^(.+)\(.+:([0-9]+).*:[0-9]+\)$/', $finding, $matches); - if ($numMatches === 0) { - continue; - } - - $line = (int) $matches[2]; - $message = 'jshint says: '.trim($matches[1]); - $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool'); - } - } - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/ByteOrderMarkSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/ByteOrderMarkSniff.php deleted file mode 100644 index d214364..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/ByteOrderMarkSniff.php +++ /dev/null @@ -1,94 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Files_ByteOrderMarkSniff. - * - * A simple sniff for detecting BOMs that may corrupt application work. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Piotr Karas - * @author Greg Sherwood - * @copyright 2010-2014 mediaSELF Sp. z o.o. - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - * @see http://en.wikipedia.org/wiki/Byte_order_mark - */ -class Generic_Sniffs_Files_ByteOrderMarkSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * List of supported BOM definitions. - * - * Use encoding names as keys and hex BOM representations as values. - * - * @var array - */ - protected $bomDefinitions = array( - 'UTF-8' => 'efbbbf', - 'UTF-16 (BE)' => 'feff', - 'UTF-16 (LE)' => 'fffe', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_INLINE_HTML); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - // The BOM will be the very first token in the file. - if ($stackPtr !== 0) { - return; - } - - $tokens = $phpcsFile->getTokens(); - - foreach ($this->bomDefinitions as $bomName => $expectedBomHex) { - $bomByteLength = (strlen($expectedBomHex) / 2); - $htmlBomHex = bin2hex(substr($tokens[$stackPtr]['content'], 0, $bomByteLength)); - if ($htmlBomHex === $expectedBomHex) { - $errorData = array($bomName); - $error = 'File contains %s byte order mark, which may corrupt your application'; - $phpcsFile->addError($error, $stackPtr, 'Found', $errorData); - $phpcsFile->recordMetric($stackPtr, 'Using byte order mark', 'yes'); - return; - } - } - - $phpcsFile->recordMetric($stackPtr, 'Using byte order mark', 'no'); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/EndFileNewlineSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/EndFileNewlineSniff.php deleted file mode 100644 index 9b2853b..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/EndFileNewlineSniff.php +++ /dev/null @@ -1,94 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Files_EndFileNewlineSniff. - * - * Ensures the file ends with a newline character. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Files_EndFileNewlineSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - 'CSS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return int - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - // Skip to the end of the file. - $tokens = $phpcsFile->getTokens(); - $stackPtr = ($phpcsFile->numTokens - 1); - - if ($tokens[$stackPtr]['content'] === '') { - $stackPtr--; - } - - $eolCharLen = strlen($phpcsFile->eolChar); - $lastChars = substr($tokens[$stackPtr]['content'], ($eolCharLen * -1)); - if ($lastChars !== $phpcsFile->eolChar) { - $phpcsFile->recordMetric($stackPtr, 'Newline at EOF', 'no'); - - $error = 'File must end with a newline character'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotFound'); - if ($fix === true) { - $phpcsFile->fixer->addNewline($stackPtr); - } - } else { - $phpcsFile->recordMetric($stackPtr, 'Newline at EOF', 'yes'); - } - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/EndFileNoNewlineSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/EndFileNoNewlineSniff.php deleted file mode 100644 index d2e1ca9..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/EndFileNoNewlineSniff.php +++ /dev/null @@ -1,91 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Files_EndFileNoNewlineSniff. - * - * Ensures the file does not end with a newline character. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Files_EndFileNoNewlineSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - 'CSS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return int - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - // Skip to the end of the file. - $tokens = $phpcsFile->getTokens(); - $stackPtr = ($phpcsFile->numTokens - 1); - - if ($tokens[$stackPtr]['content'] === '') { - $stackPtr--; - } - - $eolCharLen = strlen($phpcsFile->eolChar); - $lastChars = substr($tokens[$stackPtr]['content'], ($eolCharLen * -1)); - if ($lastChars === $phpcsFile->eolChar) { - $error = 'File must not end with a newline character'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found'); - if ($fix === true) { - $newContent = substr($tokens[$stackPtr]['content'], 0, ($eolCharLen * -1)); - $phpcsFile->fixer->replaceToken($stackPtr, $newContent); - } - } - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/InlineHTMLSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/InlineHTMLSniff.php deleted file mode 100644 index 1434165..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/InlineHTMLSniff.php +++ /dev/null @@ -1,70 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Files_InlineHTMLSniff. - * - * Ensures the whole file is PHP only, with no whitespace or inline HTML anywhere - * in the file. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Files_InlineHTMLSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_INLINE_HTML); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - // Ignore shebang lines. - $tokens = $phpcsFile->getTokens(); - if (substr($tokens[$stackPtr]['content'], 0, 2) === '#!') { - return; - } - - $error = 'PHP files must only contain PHP code'; - $phpcsFile->addError($error, $stackPtr, 'Found'); - - return $phpcsFile->numTokens; - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/LineEndingsSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/LineEndingsSniff.php deleted file mode 100644 index dc092e9..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/LineEndingsSniff.php +++ /dev/null @@ -1,151 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Files_LineEndingsSniff. - * - * Checks that end of line characters are correct. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Files_LineEndingsSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - 'CSS', - ); - - /** - * The valid EOL character. - * - * @var string - */ - public $eolChar = '\n'; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return int - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $found = $phpcsFile->eolChar; - $found = str_replace("\n", '\n', $found); - $found = str_replace("\r", '\r', $found); - - $phpcsFile->recordMetric($stackPtr, 'EOL char', $found); - - if ($found === $this->eolChar) { - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - } - - // Check for single line files without an EOL. This is a very special - // case and the EOL char is set to \n when this happens. - if ($found === '\n') { - $tokens = $phpcsFile->getTokens(); - $lastToken = ($phpcsFile->numTokens - 1); - if ($tokens[$lastToken]['line'] === 1 - && $tokens[$lastToken]['content'] !== "\n" - ) { - return; - } - } - - $error = 'End of line character is invalid; expected "%s" but found "%s"'; - $expected = $this->eolChar; - $expected = str_replace("\n", '\n', $expected); - $expected = str_replace("\r", '\r', $expected); - $data = array( - $expected, - $found, - ); - - // Errors are always reported on line 1, no matter where the first PHP tag is. - $fix = $phpcsFile->addFixableError($error, 0, 'InvalidEOLChar', $data); - - if ($fix === true) { - $tokens = $phpcsFile->getTokens(); - switch ($this->eolChar) { - case '\n': - $eolChar = "\n"; - break; - case '\r': - $eolChar = "\r"; - break; - case '\r\n': - $eolChar = "\r\n"; - break; - default: - $eolChar = $this->eolChar; - break; - } - - for ($i = 0; $i < $phpcsFile->numTokens; $i++) { - if (isset($tokens[($i + 1)]) === false - || $tokens[($i + 1)]['line'] > $tokens[$i]['line'] - ) { - // Token is the last on a line. - if (isset($tokens[$i]['orig_content']) === true) { - $tokenContent = $tokens[$i]['orig_content']; - } else { - $tokenContent = $tokens[$i]['content']; - } - - $newContent = rtrim($tokenContent, "\r\n"); - $newContent .= $eolChar; - $phpcsFile->fixer->replaceToken($i, $newContent); - } - } - }//end if - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/LineLengthSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/LineLengthSniff.php deleted file mode 100644 index d64c2ad..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/LineLengthSniff.php +++ /dev/null @@ -1,177 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Files_LineLengthSniff. - * - * Checks all lines in the file, and throws warnings if they are over 80 - * characters in length and errors if they are over 100. Both these - * figures can be changed by extending this sniff in your own standard. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Files_LineLengthSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * The limit that the length of a line should not exceed. - * - * @var int - */ - public $lineLimit = 80; - - /** - * The limit that the length of a line must not exceed. - * - * Set to zero (0) to disable. - * - * @var int - */ - public $absoluteLineLimit = 100; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return int - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - for ($i = 1; $i < $phpcsFile->numTokens; $i++) { - if ($tokens[$i]['column'] === 1) { - $this->checkLineLength($phpcsFile, $tokens, $i); - } - } - - $this->checkLineLength($phpcsFile, $tokens, $i); - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - - /** - * Checks if a line is too long. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tokens The token stack. - * @param int $stackPtr The first token on the next line. - * - * @return null|false - */ - protected function checkLineLength(PHP_CodeSniffer_File $phpcsFile, $tokens, $stackPtr) - { - // The passed token is the first on the line. - $stackPtr--; - - if ($tokens[$stackPtr]['column'] === 1 - && $tokens[$stackPtr]['length'] === 0 - ) { - // Blank line. - return; - } - - if ($tokens[$stackPtr]['column'] !== 1 - && $tokens[$stackPtr]['content'] === $phpcsFile->eolChar - ) { - $stackPtr--; - } - - $lineLength = ($tokens[$stackPtr]['column'] + $tokens[$stackPtr]['length'] - 1); - - // Record metrics for common line length groupings. - if ($lineLength <= 80) { - $phpcsFile->recordMetric($stackPtr, 'Line length', '80 or less'); - } else if ($lineLength <= 120) { - $phpcsFile->recordMetric($stackPtr, 'Line length', '81-120'); - } else if ($lineLength <= 150) { - $phpcsFile->recordMetric($stackPtr, 'Line length', '121-150'); - } else { - $phpcsFile->recordMetric($stackPtr, 'Line length', '151 or more'); - } - - // If this is a long comment, check if it can be broken up onto multiple lines. - // Some comments contain unbreakable strings like URLs and so it makes sense - // to ignore the line length in these cases if the URL would be longer than the max - // line length once you indent it to the correct level. - if ($lineLength > $this->lineLimit - && ($tokens[$stackPtr]['code'] === T_COMMENT - || $tokens[$stackPtr]['code'] === T_DOC_COMMENT_STRING) - ) { - $oldLength = strlen($tokens[$stackPtr]['content']); - $newLength = strlen(ltrim($tokens[$stackPtr]['content'], "/#\t ")); - $indent = (($tokens[$stackPtr]['column'] - 1) + ($oldLength - $newLength)); - - $nonBreakingLength = $tokens[$stackPtr]['length']; - - $space = strrpos($tokens[$stackPtr]['content'], ' '); - if ($space !== false) { - $nonBreakingLength -= ($space + 1); - } - - if (($nonBreakingLength + $indent) > $this->lineLimit) { - return; - } - } - - if ($this->absoluteLineLimit > 0 - && $lineLength > $this->absoluteLineLimit - ) { - $data = array( - $this->absoluteLineLimit, - $lineLength, - ); - - $error = 'Line exceeds maximum limit of %s characters; contains %s characters'; - $phpcsFile->addError($error, $stackPtr, 'MaxExceeded', $data); - } else if ($lineLength > $this->lineLimit) { - $data = array( - $this->lineLimit, - $lineLength, - ); - - $warning = 'Line exceeds %s characters; contains %s characters'; - $phpcsFile->addWarning($warning, $stackPtr, 'TooLong', $data); - } - - }//end checkLineLength() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/LowercasedFilenameSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/LowercasedFilenameSniff.php deleted file mode 100644 index 3216c4a..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/LowercasedFilenameSniff.php +++ /dev/null @@ -1,78 +0,0 @@ - - * @copyright 2010-2014 Andy Grunwald - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Checks that all file names are lowercased. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Andy Grunwald - * @copyright 2010-2014 Andy Grunwald - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Files_LowercasedFilenameSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return int - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $filename = $phpcsFile->getFilename(); - if ($filename === 'STDIN') { - return; - } - - $filename = basename($filename); - $lowercaseFilename = strtolower($filename); - if ($filename !== $lowercaseFilename) { - $data = array( - $filename, - $lowercaseFilename, - ); - $error = 'Filename "%s" doesn\'t match the expected filename "%s"'; - $phpcsFile->addError($error, $stackPtr, 'NotFound', $data); - $phpcsFile->recordMetric($stackPtr, 'Lowercase filename', 'no'); - } else { - $phpcsFile->recordMetric($stackPtr, 'Lowercase filename', 'yes'); - } - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/OneClassPerFileSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/OneClassPerFileSniff.php deleted file mode 100644 index eacd411..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/OneClassPerFileSniff.php +++ /dev/null @@ -1,62 +0,0 @@ - - * @copyright 2010-2014 Andy Grunwald - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Checks that only one class is declared per file. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Andy Grunwald - * @copyright 2010-2014 Andy Grunwald - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Files_OneClassPerFileSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_CLASS); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1)); - if ($nextClass !== false) { - $error = 'Only one class is allowed in a file'; - $phpcsFile->addError($error, $nextClass, 'MultipleFound'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/OneInterfacePerFileSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/OneInterfacePerFileSniff.php deleted file mode 100644 index 714b299..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/OneInterfacePerFileSniff.php +++ /dev/null @@ -1,62 +0,0 @@ - - * @copyright 2010-2014 Andy Grunwald - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Checks that only one interface is declared per file. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Andy Grunwald - * @copyright 2010-2014 Andy Grunwald - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Files_OneInterfacePerFileSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_INTERFACE); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $nextInterface = $phpcsFile->findNext($this->register(), ($stackPtr + 1)); - if ($nextInterface !== false) { - $error = 'Only one interface is allowed in a file'; - $phpcsFile->addError($error, $nextInterface, 'MultipleFound'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/OneTraitPerFileSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/OneTraitPerFileSniff.php deleted file mode 100644 index 5c5deb0..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Files/OneTraitPerFileSniff.php +++ /dev/null @@ -1,62 +0,0 @@ - - * @copyright 2010-2014 Alexander Obuhovich - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Checks that only one trait is declared per file. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Alexander Obuhovich - * @copyright 2010-2014 Alexander Obuhovich - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Files_OneTraitPerFileSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_TRAIT); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1)); - if ($nextClass !== false) { - $error = 'Only one trait is allowed in a file'; - $phpcsFile->addError($error, $nextClass, 'MultipleFound'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/DisallowMultipleStatementsSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/DisallowMultipleStatementsSniff.php deleted file mode 100644 index 2583065..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/DisallowMultipleStatementsSniff.php +++ /dev/null @@ -1,102 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Formatting_DisallowMultipleStatementsSniff. - * - * Ensures each statement is on a line by itself. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Formatting_DisallowMultipleStatementsSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_SEMICOLON); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $prev = $phpcsFile->findPrevious(array(T_SEMICOLON, T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO), ($stackPtr - 1)); - if ($prev === false - || $tokens[$prev]['code'] === T_OPEN_TAG - || $tokens[$prev]['code'] === T_OPEN_TAG_WITH_ECHO - ) { - $phpcsFile->recordMetric($stackPtr, 'Multiple statements on same line', 'no'); - return; - } - - // Ignore multiple statements in a FOR condition. - if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) { - foreach ($tokens[$stackPtr]['nested_parenthesis'] as $bracket) { - if (isset($tokens[$bracket]['parenthesis_owner']) === false) { - // Probably a closure sitting inside a function call. - continue; - } - - $owner = $tokens[$bracket]['parenthesis_owner']; - if ($tokens[$owner]['code'] === T_FOR) { - return; - } - } - } - - if ($tokens[$prev]['line'] === $tokens[$stackPtr]['line']) { - $phpcsFile->recordMetric($stackPtr, 'Multiple statements on same line', 'yes'); - - $error = 'Each PHP statement must be on a line by itself'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SameLine'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->addNewline($prev); - if ($tokens[($prev + 1)]['code'] === T_WHITESPACE) { - $phpcsFile->fixer->replaceToken(($prev + 1), ''); - } - - $phpcsFile->fixer->endChangeset(); - } - } else { - $phpcsFile->recordMetric($stackPtr, 'Multiple statements on same line', 'no'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php deleted file mode 100644 index 8ead992..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php +++ /dev/null @@ -1,330 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Formatting_MultipleStatementAlignmentSniff. - * - * Checks alignment of assignments. If there are multiple adjacent assignments, - * it will check that the equals signs of each assignment are aligned. It will - * display a warning to advise that the signs should be aligned. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Formatting_MultipleStatementAlignmentSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - /** - * If true, an error will be thrown; otherwise a warning. - * - * @var bool - */ - public $error = false; - - /** - * The maximum amount of padding before the alignment is ignored. - * - * If the amount of padding required to align this assignment with the - * surrounding assignments exceeds this number, the assignment will be - * ignored and no errors or warnings will be thrown. - * - * @var int - */ - public $maxPadding = 1000; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - $tokens = PHP_CodeSniffer_Tokens::$assignmentTokens; - unset($tokens[T_DOUBLE_ARROW]); - return $tokens; - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return int - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Ignore assignments used in a condition, like an IF or FOR. - if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) { - foreach ($tokens[$stackPtr]['nested_parenthesis'] as $start => $end) { - if (isset($tokens[$start]['parenthesis_owner']) === true) { - return; - } - } - } - - $lastAssign = $this->checkAlignment($phpcsFile, $stackPtr); - return ($lastAssign + 1); - - }//end process() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return int - */ - public function checkAlignment(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $assignments = array(); - $prevAssign = null; - $lastLine = $tokens[$stackPtr]['line']; - $maxPadding = null; - $stopped = null; - $lastCode = $stackPtr; - $lastSemi = null; - - $find = PHP_CodeSniffer_Tokens::$assignmentTokens; - unset($find[T_DOUBLE_ARROW]); - - for ($assign = $stackPtr; $assign < $phpcsFile->numTokens; $assign++) { - if (isset($find[$tokens[$assign]['code']]) === false) { - // A blank line indicates that the assignment block has ended. - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$assign]['code']]) === false) { - if (($tokens[$assign]['line'] - $tokens[$lastCode]['line']) > 1) { - break; - } - - $lastCode = $assign; - - if ($tokens[$assign]['code'] === T_SEMICOLON) { - if ($tokens[$assign]['conditions'] === $tokens[$stackPtr]['conditions']) { - if ($lastSemi !== null && $prevAssign !== null && $lastSemi > $prevAssign) { - // This statement did not have an assignment operator in it. - break; - } else { - $lastSemi = $assign; - } - } else { - // Statement is in a different context, so the block is over. - break; - } - } - }//end if - - continue; - } else if ($assign !== $stackPtr && $tokens[$assign]['line'] === $lastLine) { - // Skip multiple assignments on the same line. We only need to - // try and align the first assignment. - continue; - }//end if - - if ($assign !== $stackPtr) { - // Has to be nested inside the same conditions as the first assignment. - if ($tokens[$assign]['conditions'] !== $tokens[$stackPtr]['conditions']) { - break; - } - - // Make sure it is not assigned inside a condition (eg. IF, FOR). - if (isset($tokens[$assign]['nested_parenthesis']) === true) { - foreach ($tokens[$assign]['nested_parenthesis'] as $start => $end) { - if (isset($tokens[$start]['parenthesis_owner']) === true) { - break(2); - } - } - } - }//end if - - $var = $phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, - ($assign - 1), - null, - true - ); - - // Make sure we wouldn't break our max padding length if we - // aligned with this statement, or they wouldn't break the max - // padding length if they aligned with us. - $varEnd = $tokens[($var + 1)]['column']; - $assignLen = $tokens[$assign]['length']; - if ($assign !== $stackPtr) { - if (($varEnd + 1) > $assignments[$prevAssign]['assign_col']) { - $padding = 1; - $assignColumn = ($varEnd + 1); - } else { - $padding = ($assignments[$prevAssign]['assign_col'] - $varEnd + $assignments[$prevAssign]['assign_len'] - $assignLen); - if ($padding === 0) { - $padding = 1; - } - - if ($padding > $this->maxPadding) { - $stopped = $assign; - break; - } - - $assignColumn = ($varEnd + $padding); - }//end if - - if (($assignColumn + $assignLen) > ($assignments[$maxPadding]['assign_col'] + $assignments[$maxPadding]['assign_len'])) { - $newPadding = ($varEnd - $assignments[$maxPadding]['var_end'] + $assignLen - $assignments[$maxPadding]['assign_len'] + 1); - if ($newPadding > $this->maxPadding) { - $stopped = $assign; - break; - } else { - // New alignment settings for previous assignments. - foreach ($assignments as $i => $data) { - if ($i === $assign) { - break; - } - - $newPadding = ($varEnd - $data['var_end'] + $assignLen - $data['assign_len'] + 1); - $assignments[$i]['expected'] = $newPadding; - $assignments[$i]['assign_col'] = ($data['var_end'] + $newPadding); - } - - $padding = 1; - $assignColumn = ($varEnd + 1); - } - } else if ($padding > $assignments[$maxPadding]['expected']) { - $maxPadding = $assign; - }//end if - } else { - $padding = 1; - $assignColumn = ($varEnd + 1); - $maxPadding = $assign; - }//end if - - $found = 0; - if ($tokens[($var + 1)]['code'] === T_WHITESPACE) { - $found = $tokens[($var + 1)]['length']; - if ($found === 0) { - // This means a newline was found. - $found = 1; - } - } - - $assignments[$assign] = array( - 'var_end' => $varEnd, - 'assign_len' => $assignLen, - 'assign_col' => $assignColumn, - 'expected' => $padding, - 'found' => $found, - ); - - $lastLine = $tokens[$assign]['line']; - $prevAssign = $assign; - }//end for - - if (empty($assignments) === true) { - return $stackPtr; - } - - $numAssignments = count($assignments); - - $errorGenerated = false; - foreach ($assignments as $assignment => $data) { - if ($data['found'] === $data['expected']) { - continue; - } - - $expectedText = $data['expected'].' space'; - if ($data['expected'] !== 1) { - $expectedText .= 's'; - } - - if ($data['found'] === null) { - $foundText = 'a new line'; - } else { - $foundText = $data['found'].' space'; - if ($data['found'] !== 1) { - $foundText .= 's'; - } - } - - if ($numAssignments === 1) { - $type = 'Incorrect'; - $error = 'Equals sign not aligned correctly; expected %s but found %s'; - } else { - $type = 'NotSame'; - $error = 'Equals sign not aligned with surrounding assignments; expected %s but found %s'; - } - - $errorData = array( - $expectedText, - $foundText, - ); - - if ($this->error === true) { - $fix = $phpcsFile->addFixableError($error, $assignment, $type, $errorData); - } else { - $fix = $phpcsFile->addFixableWarning($error, $assignment, $type.'Warning', $errorData); - } - - $errorGenerated = true; - - if ($fix === true && $data['found'] !== null) { - $newContent = str_repeat(' ', $data['expected']); - if ($data['found'] === 0) { - $phpcsFile->fixer->addContentBefore($assignment, $newContent); - } else { - $phpcsFile->fixer->replaceToken(($assignment - 1), $newContent); - } - } - }//end foreach - - if ($numAssignments > 1) { - if ($errorGenerated === true) { - $phpcsFile->recordMetric($stackPtr, 'Adjacent assignments aligned', 'no'); - } else { - $phpcsFile->recordMetric($stackPtr, 'Adjacent assignments aligned', 'yes'); - } - } - - if ($stopped !== null) { - return $this->checkAlignment($phpcsFile, $stopped); - } else { - return $assignment; - } - - }//end checkAlignment() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/NoSpaceAfterCastSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/NoSpaceAfterCastSniff.php deleted file mode 100644 index baf3289..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/NoSpaceAfterCastSniff.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Formatting_NoSpaceAfterCastSniff. - * - * Ensures there is no space after cast tokens. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Formatting_NoSpaceAfterCastSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return PHP_CodeSniffer_Tokens::$castTokens; - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { - return; - } - - $error = 'A cast statement must not be followed by a space'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceFound'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ''); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/SpaceAfterCastSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/SpaceAfterCastSniff.php deleted file mode 100644 index b1e1308..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/SpaceAfterCastSniff.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Formatting_SpaceAfterCastSniff. - * - * Ensures there is a single space after cast tokens. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Formatting_SpaceAfterCastSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return PHP_CodeSniffer_Tokens::$castTokens; - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { - $error = 'A cast statement must be followed by a single space'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpace'); - if ($fix === true) { - $phpcsFile->fixer->addContent($stackPtr, ' '); - } - - $phpcsFile->recordMetric($stackPtr, 'Spacing after cast statement', 0); - return; - } - - $phpcsFile->recordMetric($stackPtr, 'Spacing after cast statement', $tokens[($stackPtr + 1)]['length']); - - if ($tokens[($stackPtr + 1)]['length'] !== 1) { - $error = 'A cast statement must be followed by a single space'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'TooMuchSpace'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/SpaceAfterNotSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/SpaceAfterNotSniff.php deleted file mode 100644 index 3620926..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Formatting/SpaceAfterNotSniff.php +++ /dev/null @@ -1,90 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Formatting_SpaceAfterNotSniff. - * - * Ensures there is a single space after a NOT operator. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Formatting_SpaceAfterNotSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_BOOLEAN_NOT); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $spacing = 0; - if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) { - $spacing = $tokens[($stackPtr + 1)]['length']; - } - - if ($spacing === 1) { - return; - } - - $message = 'There must be a single space after a NOT operator; %s found'; - $fix = $phpcsFile->addFixableError($message, $stackPtr, 'Incorrect', array($spacing)); - - if ($fix === true) { - if ($spacing === 0) { - $phpcsFile->fixer->addContent($stackPtr, ' '); - } else { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Functions/CallTimePassByReferenceSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Functions/CallTimePassByReferenceSniff.php deleted file mode 100644 index b949a0d..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Functions/CallTimePassByReferenceSniff.php +++ /dev/null @@ -1,159 +0,0 @@ - - * @copyright 2009-2014 Florian Grandel - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Functions_CallTimePassByReferenceSniff. - * - * Ensures that variables are not passed by reference when calling a function. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Florian Grandel - * @copyright 2009-2014 Florian Grandel - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Functions_CallTimePassByReferenceSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_STRING, - T_VARIABLE, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $findTokens = array_merge( - PHP_CodeSniffer_Tokens::$emptyTokens, - array(T_BITWISE_AND) - ); - - $prev = $phpcsFile->findPrevious($findTokens, ($stackPtr - 1), null, true); - - // Skip tokens that are the names of functions or classes - // within their definitions. For example: function myFunction... - // "myFunction" is T_STRING but we should skip because it is not a - // function or method *call*. - $prevCode = $tokens[$prev]['code']; - if ($prevCode === T_FUNCTION || $prevCode === T_CLASS) { - return; - } - - // If the next non-whitespace token after the function or method call - // is not an opening parenthesis then it cant really be a *call*. - $functionName = $stackPtr; - $openBracket = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, - ($functionName + 1), - null, - true - ); - - if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) { - return; - } - - if (isset($tokens[$openBracket]['parenthesis_closer']) === false) { - return; - } - - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; - - $nextSeparator = $openBracket; - $find = array( - T_VARIABLE, - T_OPEN_SHORT_ARRAY, - ); - - while (($nextSeparator = $phpcsFile->findNext($find, ($nextSeparator + 1), $closeBracket)) !== false) { - if (isset($tokens[$nextSeparator]['nested_parenthesis']) === false) { - continue; - } - - if ($tokens[$nextSeparator]['code'] === T_OPEN_SHORT_ARRAY) { - $nextSeparator = $tokens[$nextSeparator]['bracket_closer']; - continue; - } - - // Make sure the variable belongs directly to this function call - // and is not inside a nested function call or array. - $brackets = $tokens[$nextSeparator]['nested_parenthesis']; - $lastBracket = array_pop($brackets); - if ($lastBracket !== $closeBracket) { - continue; - } - - // Checking this: $value = my_function(...[*]$arg...). - $tokenBefore = $phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, - ($nextSeparator - 1), - null, - true - ); - - if ($tokens[$tokenBefore]['code'] === T_BITWISE_AND) { - // Checking this: $value = my_function(...[*]&$arg...). - $tokenBefore = $phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, - ($tokenBefore - 1), - null, - true - ); - - // We have to exclude all uses of T_BITWISE_AND that are not - // references. We use a blacklist approach as we prefer false - // positives to not identifying a pass-by-reference call at all. - $tokenCode = $tokens[$tokenBefore]['code']; - if ($tokenCode === T_VARIABLE - || $tokenCode === T_CLOSE_PARENTHESIS - || $tokenCode === T_CLOSE_SQUARE_BRACKET - || $tokenCode === T_LNUMBER - || isset(PHP_CodeSniffer_Tokens::$assignmentTokens[$tokenCode]) === true - ) { - continue; - } - - // T_BITWISE_AND represents a pass-by-reference. - $error = 'Call-time pass-by-reference calls are prohibited'; - $phpcsFile->addError($error, $tokenBefore, 'NotAllowed'); - }//end if - }//end while - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php deleted file mode 100644 index 110bc7e..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php +++ /dev/null @@ -1,179 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Functions_FunctionCallArgumentSpacingSniff. - * - * Checks that calls to methods and functions are spaced correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Functions_FunctionCallArgumentSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - $tokens = PHP_CodeSniffer_Tokens::$functionNameTokens; - - // For calling closures. - $tokens[] = T_VARIABLE; - - return $tokens; - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Skip tokens that are the names of functions or classes - // within their definitions. For example: - // function myFunction... - // "myFunction" is T_STRING but we should skip because it is not a - // function or method *call*. - $functionName = $stackPtr; - $ignoreTokens = PHP_CodeSniffer_Tokens::$emptyTokens; - $ignoreTokens[] = T_BITWISE_AND; - $functionKeyword = $phpcsFile->findPrevious($ignoreTokens, ($stackPtr - 1), null, true); - if ($tokens[$functionKeyword]['code'] === T_FUNCTION || $tokens[$functionKeyword]['code'] === T_CLASS) { - return; - } - - // If the next non-whitespace token after the function or method call - // is not an opening parenthesis then it cant really be a *call*. - $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($functionName + 1), null, true); - if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) { - return; - } - - if (isset($tokens[$openBracket]['parenthesis_closer']) === false) { - return; - } - - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; - $nextSeparator = $openBracket; - - $find = array( - T_COMMA, - T_VARIABLE, - T_CLOSURE, - T_OPEN_SHORT_ARRAY, - ); - - while (($nextSeparator = $phpcsFile->findNext($find, ($nextSeparator + 1), $closeBracket)) !== false) { - if ($tokens[$nextSeparator]['code'] === T_CLOSURE) { - // Skip closures. - $nextSeparator = $tokens[$nextSeparator]['scope_closer']; - continue; - } else if ($tokens[$nextSeparator]['code'] === T_OPEN_SHORT_ARRAY) { - // Skips arrays using short notation. - $nextSeparator = $tokens[$nextSeparator]['bracket_closer']; - continue; - } - - // Make sure the comma or variable belongs directly to this function call, - // and is not inside a nested function call or array. - $brackets = $tokens[$nextSeparator]['nested_parenthesis']; - $lastBracket = array_pop($brackets); - if ($lastBracket !== $closeBracket) { - continue; - } - - if ($tokens[$nextSeparator]['code'] === T_COMMA) { - if ($tokens[($nextSeparator - 1)]['code'] === T_WHITESPACE) { - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($nextSeparator - 2), null, true); - if (isset(PHP_CodeSniffer_Tokens::$heredocTokens[$tokens[$prev]['code']]) === false) { - $error = 'Space found before comma in function call'; - $fix = $phpcsFile->addFixableError($error, $nextSeparator, 'SpaceBeforeComma'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($nextSeparator - 1), ''); - } - } - } - - if ($tokens[($nextSeparator + 1)]['code'] !== T_WHITESPACE) { - $error = 'No space found after comma in function call'; - $fix = $phpcsFile->addFixableError($error, $nextSeparator, 'NoSpaceAfterComma'); - if ($fix === true) { - $phpcsFile->fixer->addContent($nextSeparator, ' '); - } - } else { - // If there is a newline in the space, then they must be formatting - // each argument on a newline, which is valid, so ignore it. - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($nextSeparator + 1), null, true); - if ($tokens[$next]['line'] === $tokens[$nextSeparator]['line']) { - $space = strlen($tokens[($nextSeparator + 1)]['content']); - if ($space > 1) { - $error = 'Expected 1 space after comma in function call; %s found'; - $data = array($space); - $fix = $phpcsFile->addFixableError($error, $nextSeparator, 'TooMuchSpaceAfterComma', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($nextSeparator + 1), ' '); - } - } - } - }//end if - } else { - // Token is a variable. - $nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($nextSeparator + 1), $closeBracket, true); - if ($nextToken !== false) { - if ($tokens[$nextToken]['code'] === T_EQUAL) { - if (($tokens[($nextToken - 1)]['code']) !== T_WHITESPACE) { - $error = 'Expected 1 space before = sign of default value'; - $fix = $phpcsFile->addFixableError($error, $nextToken, 'NoSpaceBeforeEquals'); - if ($fix === true) { - $phpcsFile->fixer->addContentBefore($nextToken, ' '); - } - } - - if ($tokens[($nextToken + 1)]['code'] !== T_WHITESPACE) { - $error = 'Expected 1 space after = sign of default value'; - $fix = $phpcsFile->addFixableError($error, $nextToken, 'NoSpaceAfterEquals'); - if ($fix === true) { - $phpcsFile->fixer->addContent($nextToken, ' '); - } - } - } - } - }//end if - }//end while - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php deleted file mode 100644 index 017ea78..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php +++ /dev/null @@ -1,191 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff. - * - * Checks that the opening brace of a function is on the line after the - * function declaration. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * Should this sniff check function braces? - * - * @var bool - */ - public $checkFunctions = true; - - /** - * Should this sniff check closure braces? - * - * @var bool - */ - public $checkClosures = false; - - - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return void - */ - public function register() - { - return array( - T_FUNCTION, - T_CLOSURE, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (isset($tokens[$stackPtr]['scope_opener']) === false) { - return; - } - - if (($tokens[$stackPtr]['code'] === T_FUNCTION - && (bool) $this->checkFunctions === false) - || ($tokens[$stackPtr]['code'] === T_CLOSURE - && (bool) $this->checkClosures === false) - ) { - return; - } - - $openingBrace = $tokens[$stackPtr]['scope_opener']; - $closeBracket = $tokens[$stackPtr]['parenthesis_closer']; - if ($tokens[$stackPtr]['code'] === T_CLOSURE) { - $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']); - if ($use !== false) { - $openBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1)); - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; - } - } - - $functionLine = $tokens[$closeBracket]['line']; - $braceLine = $tokens[$openingBrace]['line']; - - $lineDifference = ($braceLine - $functionLine); - - if ($lineDifference === 0) { - $error = 'Opening brace should be on a new line'; - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceOnSameLine'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $indent = $phpcsFile->findFirstOnLine(array(), $openingBrace); - if ($tokens[$indent]['code'] === T_WHITESPACE) { - $phpcsFile->fixer->addContentBefore($openingBrace, $tokens[$indent]['content']); - } - - $phpcsFile->fixer->addNewlineBefore($openingBrace); - $phpcsFile->fixer->endChangeset(); - } - - $phpcsFile->recordMetric($stackPtr, 'Function opening brace placement', 'same line'); - } else if ($lineDifference > 1) { - $error = 'Opening brace should be on the line after the declaration; found %s blank line(s)'; - $data = array(($lineDifference - 1)); - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceSpacing', $data); - if ($fix === true) { - for ($i = ($tokens[$stackPtr]['parenthesis_closer'] + 1); $i < $openingBrace; $i++) { - if ($tokens[$i]['line'] === $braceLine) { - $phpcsFile->fixer->addNewLineBefore($i); - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - } - }//end if - - $next = $phpcsFile->findNext(T_WHITESPACE, ($openingBrace + 1), null, true); - if ($tokens[$next]['line'] === $tokens[$openingBrace]['line']) { - if ($next === $tokens[$stackPtr]['scope_closer']) { - // Ignore empty functions. - return; - } - - $error = 'Opening brace must be the last content on the line'; - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'ContentAfterBrace'); - if ($fix === true) { - $phpcsFile->fixer->addNewline($openingBrace); - } - } - - // Only continue checking if the opening brace looks good. - if ($lineDifference !== 1) { - return; - } - - // We need to actually find the first piece of content on this line, - // as if this is a method with tokens before it (public, static etc) - // or an if with an else before it, then we need to start the scope - // checking from there, rather than the current token. - $lineStart = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true); - - // The opening brace is on the correct line, now it needs to be - // checked to be correctly indented. - $startColumn = $tokens[$lineStart]['column']; - $braceIndent = $tokens[$openingBrace]['column']; - - if ($braceIndent !== $startColumn) { - $expected = ($startColumn - 1); - $found = ($braceIndent - 1); - - $error = 'Opening brace indented incorrectly; expected %s spaces, found %s'; - $data = array( - $expected, - $found, - ); - - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceIndent', $data); - if ($fix === true) { - $indent = str_repeat(' ', $expected); - if ($found === 0) { - $phpcsFile->fixer->addContentBefore($openingBrace, $indent); - } else { - $phpcsFile->fixer->replaceToken(($openingBrace - 1), $indent); - } - } - }//end if - - $phpcsFile->recordMetric($stackPtr, 'Function opening brace placement', 'new line'); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceKernighanRitchieSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceKernighanRitchieSniff.php deleted file mode 100644 index 8d10a8b..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceKernighanRitchieSniff.php +++ /dev/null @@ -1,180 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Functions_OpeningFunctionBraceKernighanRitchieSniff. - * - * Checks that the opening brace of a function is on the same line - * as the function declaration. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Functions_OpeningFunctionBraceKernighanRitchieSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Should this sniff check function braces? - * - * @var bool - */ - public $checkFunctions = true; - - /** - * Should this sniff check closure braces? - * - * @var bool - */ - public $checkClosures = false; - - - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return void - */ - public function register() - { - return array( - T_FUNCTION, - T_CLOSURE, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (isset($tokens[$stackPtr]['scope_opener']) === false) { - return; - } - - if (($tokens[$stackPtr]['code'] === T_FUNCTION - && (bool) $this->checkFunctions === false) - || ($tokens[$stackPtr]['code'] === T_CLOSURE - && (bool) $this->checkClosures === false) - ) { - return; - } - - $openingBrace = $tokens[$stackPtr]['scope_opener']; - $closeBracket = $tokens[$stackPtr]['parenthesis_closer']; - if ($tokens[$stackPtr]['code'] === T_CLOSURE) { - $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']); - if ($use !== false) { - $openBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1)); - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; - } - } - - $functionLine = $tokens[$closeBracket]['line']; - $braceLine = $tokens[$openingBrace]['line']; - - $lineDifference = ($braceLine - $functionLine); - - if ($lineDifference > 0) { - $phpcsFile->recordMetric($stackPtr, 'Function opening brace placement', 'new line'); - $error = 'Opening brace should be on the same line as the declaration'; - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceOnNewLine'); - if ($fix === true) { - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($openingBrace - 1), $closeBracket, true); - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->addContent($prev, ' {'); - $phpcsFile->fixer->replaceToken($openingBrace, ''); - if ($tokens[($openingBrace + 1)]['code'] === T_WHITESPACE - && $tokens[($openingBrace + 2)]['line'] > $tokens[$openingBrace]['line'] - ) { - // Brace is followed by a new line, so remove it to ensure we don't - // leave behind a blank line at the top of the block. - $phpcsFile->fixer->replaceToken(($openingBrace + 1), ''); - - if ($tokens[($openingBrace - 1)]['code'] === T_WHITESPACE - && $tokens[($openingBrace - 1)]['line'] === $tokens[$openingBrace]['line'] - && $tokens[($openingBrace - 2)]['line'] < $tokens[$openingBrace]['line'] - ) { - // Brace is preceeded by indent, so remove it to ensure we don't - // leave behind more indent than is required for the first line. - $phpcsFile->fixer->replaceToken(($openingBrace - 1), ''); - } - } - - $phpcsFile->fixer->endChangeset(); - }//end if - }//end if - - $phpcsFile->recordMetric($stackPtr, 'Function opening brace placement', 'same line'); - - $next = $phpcsFile->findNext(T_WHITESPACE, ($openingBrace + 1), null, true); - if ($tokens[$next]['line'] === $tokens[$openingBrace]['line']) { - if ($next === $tokens[$stackPtr]['scope_closer']) { - // Ignore empty functions. - return; - } - - $error = 'Opening brace must be the last content on the line'; - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'ContentAfterBrace'); - if ($fix === true) { - $phpcsFile->fixer->addNewline($openingBrace); - } - } - - // Only continue checking if the opening brace looks good. - if ($lineDifference > 0) { - return; - } - - if ($tokens[($openingBrace - 1)]['code'] !== T_WHITESPACE) { - $length = 0; - } else if ($tokens[($openingBrace - 1)]['content'] === "\t") { - $length = '\t'; - } else { - $length = strlen($tokens[($openingBrace - 1)]['content']); - } - - if ($length !== 1) { - $error = 'Expected 1 space before opening brace; found %s'; - $data = array($length); - $fix = $phpcsFile->addFixableError($error, $closeBracket, 'SpaceBeforeBrace', $data); - if ($fix === true) { - if ($length === 0 || $length === '\t') { - $phpcsFile->fixer->addContentBefore($openingBrace, ' '); - } else { - $phpcsFile->fixer->replaceToken(($openingBrace - 1), ' '); - } - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php deleted file mode 100644 index ccb59ac..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php +++ /dev/null @@ -1,127 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Checks the cyclomatic complexity (McCabe) for functions. - * - * The cyclomatic complexity (also called McCabe code metrics) - * indicates the complexity within a function by counting - * the different paths the function includes. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Johann-Peter Hartmann - * @author Greg Sherwood - * @copyright 2007-2014 Mayflower GmbH - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Metrics_CyclomaticComplexitySniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A complexity higher than this value will throw a warning. - * - * @var int - */ - public $complexity = 10; - - /** - * A complexity higher than this value will throw an error. - * - * @var int - */ - public $absoluteComplexity = 20; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_FUNCTION); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $this->currentFile = $phpcsFile; - - $tokens = $phpcsFile->getTokens(); - - // Ignore abstract methods. - if (isset($tokens[$stackPtr]['scope_opener']) === false) { - return; - } - - // Detect start and end of this function definition. - $start = $tokens[$stackPtr]['scope_opener']; - $end = $tokens[$stackPtr]['scope_closer']; - - // Predicate nodes for PHP. - $find = array( - T_CASE => true, - T_DEFAULT => true, - T_CATCH => true, - T_IF => true, - T_FOR => true, - T_FOREACH => true, - T_WHILE => true, - T_DO => true, - T_ELSEIF => true, - ); - - $complexity = 1; - - // Iterate from start to end and count predicate nodes. - for ($i = ($start + 1); $i < $end; $i++) { - if (isset($find[$tokens[$i]['code']]) === true) { - $complexity++; - } - } - - if ($complexity > $this->absoluteComplexity) { - $error = 'Function\'s cyclomatic complexity (%s) exceeds allowed maximum of %s'; - $data = array( - $complexity, - $this->absoluteComplexity, - ); - $phpcsFile->addError($error, $stackPtr, 'MaxExceeded', $data); - } else if ($complexity > $this->complexity) { - $warning = 'Function\'s cyclomatic complexity (%s) exceeds %s; consider refactoring the function'; - $data = array( - $complexity, - $this->complexity, - ); - $phpcsFile->addWarning($warning, $stackPtr, 'TooHigh', $data); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Metrics/NestingLevelSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Metrics/NestingLevelSniff.php deleted file mode 100644 index 2de74d8..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Metrics/NestingLevelSniff.php +++ /dev/null @@ -1,112 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Checks the nesting level for methods. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Johann-Peter Hartmann - * @author Greg Sherwood - * @copyright 2007-2014 Mayflower GmbH - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Metrics_NestingLevelSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A nesting level higher than this value will throw a warning. - * - * @var int - */ - public $nestingLevel = 5; - - /** - * A nesting level higher than this value will throw an error. - * - * @var int - */ - public $absoluteNestingLevel = 10; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_FUNCTION); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Ignore abstract methods. - if (isset($tokens[$stackPtr]['scope_opener']) === false) { - return; - } - - // Detect start and end of this function definition. - $start = $tokens[$stackPtr]['scope_opener']; - $end = $tokens[$stackPtr]['scope_closer']; - - $nestingLevel = 0; - - // Find the maximum nesting level of any token in the function. - for ($i = ($start + 1); $i < $end; $i++) { - $level = $tokens[$i]['level']; - if ($nestingLevel < $level) { - $nestingLevel = $level; - } - } - - // We subtract the nesting level of the function itself. - $nestingLevel = ($nestingLevel - $tokens[$stackPtr]['level'] - 1); - - if ($nestingLevel > $this->absoluteNestingLevel) { - $error = 'Function\'s nesting level (%s) exceeds allowed maximum of %s'; - $data = array( - $nestingLevel, - $this->absoluteNestingLevel, - ); - $phpcsFile->addError($error, $stackPtr, 'MaxExceeded', $data); - } else if ($nestingLevel > $this->nestingLevel) { - $warning = 'Function\'s nesting level (%s) exceeds %s; consider refactoring the function'; - $data = array( - $nestingLevel, - $this->nestingLevel, - ); - $phpcsFile->addWarning($warning, $stackPtr, 'TooHigh', $data); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/CamelCapsFunctionNameSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/CamelCapsFunctionNameSniff.php deleted file mode 100644 index 636efc4..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/CamelCapsFunctionNameSniff.php +++ /dev/null @@ -1,221 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found'); -} - -/** - * Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff. - * - * Ensures method names are correct depending on whether they are public - * or private, and that functions are named correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff -{ - - /** - * A list of all PHP magic methods. - * - * @var array - */ - protected $magicMethods = array( - 'construct' => true, - 'destruct' => true, - 'call' => true, - 'callstatic' => true, - 'get' => true, - 'set' => true, - 'isset' => true, - 'unset' => true, - 'sleep' => true, - 'wakeup' => true, - 'tostring' => true, - 'set_state' => true, - 'clone' => true, - 'invoke' => true, - 'debuginfo' => true, - ); - - /** - * A list of all PHP non-magic methods starting with a double underscore. - * - * These come from PHP modules such as SOAPClient. - * - * @var array - */ - protected $methodsDoubleUnderscore = array( - 'soapcall' => true, - 'getlastrequest' => true, - 'getlastresponse' => true, - 'getlastrequestheaders' => true, - 'getlastresponseheaders' => true, - 'getfunctions' => true, - 'gettypes' => true, - 'dorequest' => true, - 'setcookie' => true, - 'setlocation' => true, - 'setsoapheaders' => true, - ); - - /** - * A list of all PHP magic functions. - * - * @var array - */ - protected $magicFunctions = array('autoload' => true); - - /** - * If TRUE, the string must not have two capital letters next to each other. - * - * @var bool - */ - public $strict = true; - - - /** - * Constructs a Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff. - */ - public function __construct() - { - parent::__construct(array(T_CLASS, T_ANON_CLASS, T_INTERFACE, T_TRAIT), array(T_FUNCTION), true); - - }//end __construct() - - - /** - * Processes the tokens within the scope. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being processed. - * @param int $stackPtr The position where this token was - * found. - * @param int $currScope The position of the current scope. - * - * @return void - */ - protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) - { - $methodName = $phpcsFile->getDeclarationName($stackPtr); - if ($methodName === null) { - // Ignore closures. - return; - } - - $className = $phpcsFile->getDeclarationName($currScope); - $errorData = array($className.'::'.$methodName); - - // Is this a magic method. i.e., is prefixed with "__" ? - if (preg_match('|^__[^_]|', $methodName) !== 0) { - $magicPart = strtolower(substr($methodName, 2)); - if (isset($this->magicMethods[$magicPart]) === false - && isset($this->methodsDoubleUnderscore[$magicPart]) === false - ) { - $error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore'; - $phpcsFile->addError($error, $stackPtr, 'MethodDoubleUnderscore', $errorData); - } - - return; - } - - // PHP4 constructors are allowed to break our rules. - if ($methodName === $className) { - return; - } - - // PHP4 destructors are allowed to break our rules. - if ($methodName === '_'.$className) { - return; - } - - // Ignore first underscore in methods prefixed with "_". - $methodName = ltrim($methodName, '_'); - - $methodProps = $phpcsFile->getMethodProperties($stackPtr); - if (PHP_CodeSniffer::isCamelCaps($methodName, false, true, $this->strict) === false) { - if ($methodProps['scope_specified'] === true) { - $error = '%s method name "%s" is not in camel caps format'; - $data = array( - ucfirst($methodProps['scope']), - $errorData[0], - ); - $phpcsFile->addError($error, $stackPtr, 'ScopeNotCamelCaps', $data); - } else { - $error = 'Method name "%s" is not in camel caps format'; - $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData); - } - - $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no'); - return; - } else { - $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes'); - } - - }//end processTokenWithinScope() - - - /** - * Processes the tokens outside the scope. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being processed. - * @param int $stackPtr The position where this token was - * found. - * - * @return void - */ - protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $functionName = $phpcsFile->getDeclarationName($stackPtr); - if ($functionName === null) { - // Ignore closures. - return; - } - - $errorData = array($functionName); - - // Is this a magic function. i.e., it is prefixed with "__". - if (preg_match('|^__[^_]|', $functionName) !== 0) { - $magicPart = strtolower(substr($functionName, 2)); - if (isset($this->magicFunctions[$magicPart]) === false) { - $error = 'Function name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore'; - $phpcsFile->addError($error, $stackPtr, 'FunctionDoubleUnderscore', $errorData); - } - - return; - } - - // Ignore first underscore in functions prefixed with "_". - $functionName = ltrim($functionName, '_'); - - if (PHP_CodeSniffer::isCamelCaps($functionName, false, true, $this->strict) === false) { - $error = 'Function name "%s" is not in camel caps format'; - $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData); - $phpcsFile->recordMetric($stackPtr, 'CamelCase function name', 'no'); - } else { - $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes'); - } - - }//end processTokenOutsideScope() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php deleted file mode 100644 index a69f949..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php +++ /dev/null @@ -1,148 +0,0 @@ - - * @author Leif Wickland - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) { - $error = 'Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found'; - throw new PHP_CodeSniffer_Exception($error); -} - -/** - * Generic_Sniffs_NamingConventions_ConstructorNameSniff. - * - * Favor PHP 5 constructor syntax, which uses "function __construct()". - * Avoid PHP 4 constructor syntax, which uses "function ClassName()". - * - * @category PHP - * @package PHP_CodeSniffer - * @author Leif Wickland - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_NamingConventions_ConstructorNameSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff -{ - - /** - * The name of the class we are currently checking. - * - * @var string - */ - private $_currentClass = ''; - - /** - * A list of functions in the current class. - * - * @var string[] - */ - private $_functionList = array(); - - - /** - * Constructs the test with the tokens it wishes to listen for. - */ - public function __construct() - { - parent::__construct(array(T_CLASS, T_ANON_CLASS, T_INTERFACE), array(T_FUNCTION), true); - - }//end __construct() - - - /** - * Processes this test when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The current file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $currScope A pointer to the start of the scope. - * - * @return void - */ - protected function processTokenWithinScope( - PHP_CodeSniffer_File $phpcsFile, - $stackPtr, - $currScope - ) { - $className = $phpcsFile->getDeclarationName($currScope); - if ($className !== $this->_currentClass) { - $this->loadFunctionNamesInScope($phpcsFile, $currScope); - $this->_currentClass = $className; - } - - $methodName = $phpcsFile->getDeclarationName($stackPtr); - - if (strcasecmp($methodName, $className) === 0) { - if (in_array('__construct', $this->_functionList) === false) { - $error = 'PHP4 style constructors are not allowed; use "__construct()" instead'; - $phpcsFile->addError($error, $stackPtr, 'OldStyle'); - } - } else if (strcasecmp($methodName, '__construct') !== 0) { - // Not a constructor. - return; - } - - $tokens = $phpcsFile->getTokens(); - - $parentClassName = $phpcsFile->findExtendedClassName($currScope); - if ($parentClassName === false) { - return; - } - - // Stop if the constructor doesn't have a body, like when it is abstract. - if (isset($tokens[$stackPtr]['scope_closer']) === false) { - return; - } - - $endFunctionIndex = $tokens[$stackPtr]['scope_closer']; - $startIndex = $stackPtr; - while (($doubleColonIndex = $phpcsFile->findNext(T_DOUBLE_COLON, $startIndex, $endFunctionIndex)) !== false) { - if ($tokens[($doubleColonIndex + 1)]['code'] === T_STRING - && $tokens[($doubleColonIndex + 1)]['content'] === $parentClassName - ) { - $error = 'PHP4 style calls to parent constructors are not allowed; use "parent::__construct()" instead'; - $phpcsFile->addError($error, ($doubleColonIndex + 1), 'OldStyleCall'); - } - - $startIndex = ($doubleColonIndex + 1); - } - - }//end processTokenWithinScope() - - - /** - * Extracts all the function names found in the given scope. - * - * @param PHP_CodeSniffer_File $phpcsFile The current file being scanned. - * @param int $currScope A pointer to the start of the scope. - * - * @return void - */ - protected function loadFunctionNamesInScope(PHP_CodeSniffer_File $phpcsFile, $currScope) - { - $this->_functionList = array(); - $tokens = $phpcsFile->getTokens(); - - for ($i = ($tokens[$currScope]['scope_opener'] + 1); $i < $tokens[$currScope]['scope_closer']; $i++) { - if ($tokens[$i]['code'] !== T_FUNCTION) { - continue; - } - - $next = $phpcsFile->findNext(T_STRING, $i); - $this->_functionList[] = trim($tokens[$next]['content']); - } - - }//end loadFunctionNamesInScope() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php deleted file mode 100644 index d880c16..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php +++ /dev/null @@ -1,187 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_NamingConventions_UpperCaseConstantNameSniff. - * - * Ensures that constant names are all uppercase. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_NamingConventions_UpperCaseConstantNameSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_STRING); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $constName = $tokens[$stackPtr]['content']; - - // If this token is in a heredoc, ignore it. - if ($phpcsFile->hasCondition($stackPtr, T_START_HEREDOC) === true) { - return; - } - - // Special case for PHP 5.5 class name resolution. - if (strtolower($constName) === 'class' - && $tokens[($stackPtr - 1)]['code'] === T_DOUBLE_COLON - ) { - return; - } - - // Special case for PHPUnit. - if ($constName === 'PHPUnit_MAIN_METHOD') { - return; - } - - // If the next non-whitespace token after this token - // is not an opening parenthesis then it is not a function call. - for ($openBracket = ($stackPtr + 1); $openBracket < $phpcsFile->numTokens; $openBracket++) { - if ($tokens[$openBracket]['code'] !== T_WHITESPACE) { - break; - } - } - - if ($openBracket === $phpcsFile->numTokens) { - return; - } - - if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) { - $functionKeyword = $phpcsFile->findPrevious( - array( - T_WHITESPACE, - T_COMMA, - T_COMMENT, - T_STRING, - T_NS_SEPARATOR, - ), - ($stackPtr - 1), - null, - true - ); - - if ($tokens[$functionKeyword]['code'] !== T_CONST) { - return; - } - - // This is a class constant. - if (strtoupper($constName) !== $constName) { - if (strtolower($constName) === $constName) { - $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'lower'); - } else { - $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'mixed'); - } - - $error = 'Class constants must be uppercase; expected %s but found %s'; - $data = array( - strtoupper($constName), - $constName, - ); - $phpcsFile->addError($error, $stackPtr, 'ClassConstantNotUpperCase', $data); - } else { - $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'upper'); - } - - return; - }//end if - - if (strtolower($constName) !== 'define') { - return; - } - - /* - This may be a "define" function call. - */ - - // Make sure this is not a method call. - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if ($tokens[$prev]['code'] === T_OBJECT_OPERATOR - || $tokens[$prev]['code'] === T_DOUBLE_COLON - ) { - return; - } - - // The next non-whitespace token must be the constant name. - $constPtr = $phpcsFile->findNext(T_WHITESPACE, ($openBracket + 1), null, true); - if ($tokens[$constPtr]['code'] !== T_CONSTANT_ENCAPSED_STRING) { - return; - } - - $constName = $tokens[$constPtr]['content']; - - // Check for constants like self::CONSTANT. - $prefix = ''; - $splitPos = strpos($constName, '::'); - if ($splitPos !== false) { - $prefix = substr($constName, 0, ($splitPos + 2)); - $constName = substr($constName, ($splitPos + 2)); - } - - // Strip namesspace from constant like /foo/bar/CONSTANT. - $splitPos = strrpos($constName, '\\'); - if ($splitPos !== false) { - $prefix = substr($constName, 0, ($splitPos + 1)); - $constName = substr($constName, ($splitPos + 1)); - } - - if (strtoupper($constName) !== $constName) { - if (strtolower($constName) === $constName) { - $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'lower'); - } else { - $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'mixed'); - } - - $error = 'Constants must be uppercase; expected %s but found %s'; - $data = array( - $prefix.strtoupper($constName), - $prefix.$constName, - ); - $phpcsFile->addError($error, $stackPtr, 'ConstantNotUpperCase', $data); - } else { - $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'upper'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/BacktickOperatorSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/BacktickOperatorSniff.php deleted file mode 100644 index f350a86..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/BacktickOperatorSniff.php +++ /dev/null @@ -1,63 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_PHP_BacktickOperatorSniff. - * - * Checks for the use of the backtick execution operator. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_PHP_BacktickOperatorSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_BACKTICK); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $error = 'Use of the backtick operator is forbidden'; - $phpcsFile->addError($error, $stackPtr, 'Found'); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/CharacterBeforePHPOpeningTagSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/CharacterBeforePHPOpeningTagSniff.php deleted file mode 100644 index b685e1b..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/CharacterBeforePHPOpeningTagSniff.php +++ /dev/null @@ -1,74 +0,0 @@ - - * @copyright 2010-2014 Andy Grunwald - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Checks that the opening PHP tag is the first content in a file. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Andy Grunwald - * @copyright 2010-2014 Andy Grunwald - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_PHP_CharacterBeforePHPOpeningTagSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $expected = 0; - if ($stackPtr > 0) { - // Allow a shebang line. - $tokens = $phpcsFile->getTokens(); - if (substr($tokens[0]['content'], 0, 2) === '#!') { - $expected = 1; - } - } - - if ($stackPtr !== $expected) { - $error = 'The opening PHP tag must be the first content in the file'; - $phpcsFile->addError($error, $stackPtr, 'Found'); - } - - // Skip the rest of the file so we don't pick up additional - // open tags, typically embedded in HTML. - return $phpcsFile->numTokens; - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/ClosingPHPTagSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/ClosingPHPTagSniff.php deleted file mode 100644 index a2eb5b9..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/ClosingPHPTagSniff.php +++ /dev/null @@ -1,62 +0,0 @@ - - * @copyright 2010-2014 Stefano Kowalke - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Checks that open PHP tags are paired with closing tags. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Stefano Kowalke - * @copyright 2010-2014 Stefano Kowalke - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_PHP_ClosingPHPTagSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr); - if ($closeTag === false) { - $error = 'The PHP open tag does not have a corresponding PHP close tag'; - $phpcsFile->addError($error, $stackPtr, 'NotFound'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/DeprecatedFunctionsSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/DeprecatedFunctionsSniff.php deleted file mode 100644 index 9f8a333..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/DeprecatedFunctionsSniff.php +++ /dev/null @@ -1,95 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_PHP_DeprecatedFunctionsSniff. - * - * Discourages the use of deprecated functions that are kept in PHP for - * compatibility with older versions. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Sebastian Bergmann - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_PHP_DeprecatedFunctionsSniff extends Generic_Sniffs_PHP_ForbiddenFunctionsSniff -{ - - /** - * A list of forbidden functions with their alternatives. - * - * The value is NULL if no alternative exists. IE, the - * function should just not be used. - * - * @var array(string => string|null) - */ - public $forbiddenFunctions = array(); - - - /** - * Constructor. - * - * Uses the Reflection API to get a list of deprecated functions. - */ - public function __construct() - { - $functions = get_defined_functions(); - - foreach ($functions['internal'] as $functionName) { - $function = new ReflectionFunction($functionName); - if (method_exists($function, 'isDeprecated') === false) { - break; - } - - if ($function->isDeprecated() === true) { - $this->forbiddenFunctions[$functionName] = null; - } - } - - }//end __construct() - - - /** - * Generates the error or warning for this sniff. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the forbidden function - * in the token array. - * @param string $function The name of the forbidden function. - * @param string $pattern The pattern used for the match. - * - * @return void - */ - protected function addError($phpcsFile, $stackPtr, $function, $pattern=null) - { - $data = array($function); - $error = 'Function %s() has been deprecated'; - $type = 'Deprecated'; - - if ($this->error === true) { - $phpcsFile->addError($error, $stackPtr, $type, $data); - } else { - $phpcsFile->addWarning($error, $stackPtr, $type, $data); - } - - }//end addError() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/DisallowAlternativePHPTagsSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/DisallowAlternativePHPTagsSniff.php deleted file mode 100644 index 8a13547..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/DisallowAlternativePHPTagsSniff.php +++ /dev/null @@ -1,269 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_PHP_DisallowAlternativePHPTagsSniff. - * - * Verifies that no alternative PHP tags are used. - * - * If alternative PHP open tags are found, this sniff can fix both the open and close tags. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_PHP_DisallowAlternativePHPTagsSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Whether ASP tags are enabled or not. - * - * @var bool - */ - private $_aspTags = false; - - /** - * The current PHP version. - * - * @var integer - */ - private $_phpVersion = null; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - if ($this->_phpVersion === null) { - $this->_phpVersion = PHP_CodeSniffer::getConfigData('php_version'); - if ($this->_phpVersion === null) { - $this->_phpVersion = PHP_VERSION_ID; - } - } - - if ($this->_phpVersion < 70000) { - $this->_aspTags = (boolean) ini_get('asp_tags'); - } - - return array( - T_OPEN_TAG, - T_OPEN_TAG_WITH_ECHO, - T_INLINE_HTML, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $openTag = $tokens[$stackPtr]; - $content = $openTag['content']; - - if (trim($content) === '') { - return; - } - - if ($openTag['code'] === T_OPEN_TAG) { - if ($content === '<%') { - $error = 'ASP style opening tag used; expected "findClosingTag($phpcsFile, $tokens, $stackPtr, '%>'); - $errorCode = 'ASPOpenTagFound'; - } else if (strpos($content, ''); - $errorCode = 'ScriptOpenTagFound'; - } - - if (isset($error, $closer, $errorCode) === true) { - $data = array($content); - - if ($closer === false) { - $phpcsFile->addError($error, $stackPtr, $errorCode, $data); - } else { - $fix = $phpcsFile->addFixableError($error, $stackPtr, $errorCode, $data); - if ($fix === true) { - $this->addChangeset($phpcsFile, $tokens, $stackPtr, $closer); - } - } - } - - return; - }//end if - - if ($openTag['code'] === T_OPEN_TAG_WITH_ECHO && $content === '<%=') { - $error = 'ASP style opening tag used with echo; expected "findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - $snippet = $this->getSnippet($tokens[$nextVar]['content']); - $data = array( - $snippet, - $content, - $snippet, - ); - - $closer = $this->findClosingTag($phpcsFile, $tokens, $stackPtr, '%>'); - - if ($closer === false) { - $phpcsFile->addError($error, $stackPtr, 'ASPShortOpenTagFound', $data); - } else { - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'ASPShortOpenTagFound', $data); - if ($fix === true) { - $this->addChangeset($phpcsFile, $tokens, $stackPtr, $closer, true); - } - } - - return; - }//end if - - // Account for incorrect script open tags. - // The "(?:]+)?language=[\'"]?php[\'"]?(?:[^>]+)?>)`i', $content, $match) === 1 - ) { - $error = 'Script style opening tag used; expected "getSnippet($content, $match[1]); - $data = array($match[1].$snippet); - - $phpcsFile->addError($error, $stackPtr, 'ScriptOpenTagFound', $data); - return; - } - - if ($openTag['code'] === T_INLINE_HTML && $this->_aspTags === false) { - if (strpos($content, '<%=') !== false) { - $error = 'Possible use of ASP style short opening tags detected. Needs manual inspection. Found: %s'; - $snippet = $this->getSnippet($content, '<%='); - $data = array('<%='.$snippet); - - $phpcsFile->addWarning($error, $stackPtr, 'MaybeASPShortOpenTagFound', $data); - } else if (strpos($content, '<%') !== false) { - $error = 'Possible use of ASP style opening tags detected. Needs manual inspection. Found: %s'; - $snippet = $this->getSnippet($content, '<%'); - $data = array('<%'.$snippet); - - $phpcsFile->addWarning($error, $stackPtr, 'MaybeASPOpenTagFound', $data); - } - } - - }//end process() - - - /** - * Get a snippet from a HTML token. - * - * @param string $content The content of the HTML token. - * @param string $start_at Partial string to use as a starting point for the snippet. - * @param int $length The target length of the snippet to get. Defaults to 40. - * - * @return string - */ - protected function getSnippet($content, $start_at = '', $length = 40) - { - $start_pos = 0; - - if ($start_at !== '') { - $start_pos = strpos($content, $start_at); - if ($start_pos !== false) { - $start_pos += strlen($start_at); - } - } - - $snippet = substr($content, $start_pos, $length); - if ((strlen($content) - $start_pos) > $length) { - $snippet .= '...'; - } - - return $snippet; - - }//end getSnippet() - - - /** - * Try and find a matching PHP closing tag. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tokens The token stack. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param string $content The expected content of the closing tag to match the opener. - * - * @return int|false Pointer to the position in the stack for the closing tag or false if not found. - */ - protected function findClosingTag(PHP_CodeSniffer_File $phpcsFile, $tokens, $stackPtr, $content) - { - $closer = $phpcsFile->findNext(T_CLOSE_TAG, ($stackPtr + 1)); - - if ($closer !== false && $content === trim($tokens[$closer]['content'])) { - return $closer; - } - - return false; - - }//end findClosingTag() - - - /** - * Add a changeset to replace the alternative PHP tags. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tokens The token stack. - * @param int $open_tag_pointer Stack pointer to the PHP open tag. - * @param int $close_tag_pointer Stack pointer to the PHP close tag. - * @param bool $echo Whether to add 'echo' or not. - * - * @return void - */ - protected function addChangeset(PHP_CodeSniffer_File $phpcsFile, $tokens, $open_tag_pointer, $close_tag_pointer, $echo = false) - { - // Build up the open tag replacement and make sure there's always whitespace behind it. - $open_replacement = '', $tokens[$close_tag_pointer]['content']); - - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->replaceToken($open_tag_pointer, $open_replacement); - $phpcsFile->fixer->replaceToken($close_tag_pointer, $close_replacement); - $phpcsFile->fixer->endChangeset(); - - }//end addChangeset() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php deleted file mode 100644 index 7dbf4f2..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php +++ /dev/null @@ -1,97 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_PHP_DisallowShortOpenTagSniff. - * - * Makes sure that shorthand PHP open tags are not used. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_PHP_DisallowShortOpenTagSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_OPEN_TAG, - T_OPEN_TAG_WITH_ECHO, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $openTag = $tokens[$stackPtr]; - - if ($openTag['content'] === 'addFixableError($error, $stackPtr, 'Found', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, 'recordMetric($stackPtr, 'PHP short open tag used', 'yes'); - } else { - $phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'no'); - } - - if ($openTag['code'] === T_OPEN_TAG_WITH_ECHO) { - $nextVar = $tokens[$phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true)]; - $error = 'Short PHP opening tag used with echo; expected "addFixableError($error, $stackPtr, 'EchoFound', $data); - if ($fix === true) { - if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { - $phpcsFile->fixer->replaceToken($stackPtr, 'fixer->replaceToken($stackPtr, ' - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_PHP_ForbiddenFunctionsSniff. - * - * Discourages the use of alias functions that are kept in PHP for compatibility - * with older versions. Can be used to forbid the use of any function. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_PHP_ForbiddenFunctionsSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of forbidden functions with their alternatives. - * - * The value is NULL if no alternative exists. IE, the - * function should just not be used. - * - * @var array(string => string|null) - */ - public $forbiddenFunctions = array( - 'sizeof' => 'count', - 'delete' => 'unset', - ); - - /** - * A cache of forbidden function names, for faster lookups. - * - * @var array(string) - */ - protected $forbiddenFunctionNames = array(); - - /** - * If true, forbidden functions will be considered regular expressions. - * - * @var bool - */ - protected $patternMatch = false; - - /** - * If true, an error will be thrown; otherwise a warning. - * - * @var bool - */ - public $error = true; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - // Everyone has had a chance to figure out what forbidden functions - // they want to check for, so now we can cache out the list. - $this->forbiddenFunctionNames = array_keys($this->forbiddenFunctions); - - if ($this->patternMatch === true) { - foreach ($this->forbiddenFunctionNames as $i => $name) { - $this->forbiddenFunctionNames[$i] = '/'.$name.'/i'; - } - - return array(T_STRING); - } - - // If we are not pattern matching, we need to work out what - // tokens to listen for. - $string = 'forbiddenFunctionNames as $name) { - $string .= $name.'();'; - } - - $register = array(); - - $tokens = token_get_all($string); - array_shift($tokens); - foreach ($tokens as $token) { - if (is_array($token) === true) { - $register[] = $token[0]; - } - } - - $this->forbiddenFunctionNames = array_map('strtolower', $this->forbiddenFunctionNames); - $this->forbiddenFunctions = array_combine($this->forbiddenFunctionNames, $this->forbiddenFunctions); - - return array_unique($register); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $ignore = array( - T_DOUBLE_COLON => true, - T_OBJECT_OPERATOR => true, - T_FUNCTION => true, - T_CONST => true, - T_PUBLIC => true, - T_PRIVATE => true, - T_PROTECTED => true, - T_AS => true, - T_NEW => true, - T_INSTEADOF => true, - T_NS_SEPARATOR => true, - T_IMPLEMENTS => true, - ); - - $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - - // If function call is directly preceded by a NS_SEPARATOR it points to the - // global namespace, so we should still catch it. - if ($tokens[$prevToken]['code'] === T_NS_SEPARATOR) { - $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($prevToken - 1), null, true); - if ($tokens[$prevToken]['code'] === T_STRING) { - // Not in the global namespace. - return; - } - } - - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { - // Not a call to a PHP function. - return; - } - - $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if (isset($ignore[$tokens[$nextToken]['code']]) === true) { - // Not a call to a PHP function. - return; - } - - if ($tokens[$stackPtr]['code'] === T_STRING && $tokens[$nextToken]['code'] !== T_OPEN_PARENTHESIS) { - // Not a call to a PHP function. - return; - } - - $function = strtolower($tokens[$stackPtr]['content']); - $pattern = null; - - if ($this->patternMatch === true) { - $count = 0; - $pattern = preg_replace( - $this->forbiddenFunctionNames, - $this->forbiddenFunctionNames, - $function, - 1, - $count - ); - - if ($count === 0) { - return; - } - - // Remove the pattern delimiters and modifier. - $pattern = substr($pattern, 1, -2); - } else { - if (in_array($function, $this->forbiddenFunctionNames) === false) { - return; - } - }//end if - - $this->addError($phpcsFile, $stackPtr, $tokens[$stackPtr]['content'], $pattern); - - }//end process() - - - /** - * Generates the error or warning for this sniff. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the forbidden function - * in the token array. - * @param string $function The name of the forbidden function. - * @param string $pattern The pattern used for the match. - * - * @return void - */ - protected function addError($phpcsFile, $stackPtr, $function, $pattern=null) - { - $data = array($function); - $error = 'The use of function %s() is '; - if ($this->error === true) { - $type = 'Found'; - $error .= 'forbidden'; - } else { - $type = 'Discouraged'; - $error .= 'discouraged'; - } - - if ($pattern === null) { - $pattern = strtolower($function); - } - - if ($this->forbiddenFunctions[$pattern] !== null - && $this->forbiddenFunctions[$pattern] !== 'null' - ) { - $type .= 'WithAlternative'; - $data[] = $this->forbiddenFunctions[$pattern]; - $error .= '; use %s() instead'; - } - - if ($this->error === true) { - $phpcsFile->addError($error, $stackPtr, $type, $data); - } else { - $phpcsFile->addWarning($error, $stackPtr, $type, $data); - } - - }//end addError() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/LowerCaseConstantSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/LowerCaseConstantSniff.php deleted file mode 100644 index e8cd8af..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/LowerCaseConstantSniff.php +++ /dev/null @@ -1,98 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_PHP_LowerCaseConstantSniff. - * - * Checks that all uses of true, false and null are lowercase. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_PHP_LowerCaseConstantSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_TRUE, - T_FALSE, - T_NULL, - ); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $keyword = $tokens[$stackPtr]['content']; - $expected = strtolower($keyword); - if ($keyword !== $expected) { - if ($keyword === strtoupper($keyword)) { - $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'upper'); - } else { - $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'mixed'); - } - - $error = 'TRUE, FALSE and NULL must be lowercase; expected "%s" but found "%s"'; - $data = array( - $expected, - $keyword, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, $expected); - } - } else { - $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'lower'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/LowerCaseKeywordSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/LowerCaseKeywordSniff.php deleted file mode 100644 index 460e809..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/LowerCaseKeywordSniff.php +++ /dev/null @@ -1,148 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_PHP_LowerCaseKeywordSniff. - * - * Checks that all PHP keywords are lowercase. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_PHP_LowerCaseKeywordSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_HALT_COMPILER, - T_ABSTRACT, - T_ARRAY, - T_ARRAY_HINT, - T_AS, - T_BREAK, - T_CALLABLE, - T_CASE, - T_CATCH, - T_CLASS, - T_CLONE, - T_CONST, - T_CONTINUE, - T_DECLARE, - T_DEFAULT, - T_DO, - T_ECHO, - T_ELSE, - T_ELSEIF, - T_EMPTY, - T_ENDDECLARE, - T_ENDFOR, - T_ENDFOREACH, - T_ENDIF, - T_ENDSWITCH, - T_ENDWHILE, - T_EVAL, - T_EXIT, - T_EXTENDS, - T_FINAL, - T_FINALLY, - T_FOR, - T_FOREACH, - T_FUNCTION, - T_GLOBAL, - T_GOTO, - T_IF, - T_IMPLEMENTS, - T_INCLUDE, - T_INCLUDE_ONCE, - T_INSTANCEOF, - T_INSTEADOF, - T_INTERFACE, - T_ISSET, - T_LIST, - T_LOGICAL_AND, - T_LOGICAL_OR, - T_LOGICAL_XOR, - T_NAMESPACE, - T_NEW, - T_PRINT, - T_PRIVATE, - T_PROTECTED, - T_PUBLIC, - T_REQUIRE, - T_REQUIRE_ONCE, - T_RETURN, - T_STATIC, - T_SWITCH, - T_THROW, - T_TRAIT, - T_TRY, - T_UNSET, - T_USE, - T_VAR, - T_WHILE, - ); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $keyword = $tokens[$stackPtr]['content']; - if (strtolower($keyword) !== $keyword) { - if ($keyword === strtoupper($keyword)) { - $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'upper'); - } else { - $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'mixed'); - } - - $error = 'PHP keywords must be lowercase; expected "%s" but found "%s"'; - $data = array( - strtolower($keyword), - $keyword, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, strtolower($keyword)); - } - } else { - $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'lower'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/NoSilencedErrorsSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/NoSilencedErrorsSniff.php deleted file mode 100644 index 6c393f3..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/NoSilencedErrorsSniff.php +++ /dev/null @@ -1,79 +0,0 @@ - - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_PHP_NoSilencedErrorsSniff. - * - * Throws an error or warning when any code prefixed with an asperand is encountered. - * - * - * if (@in_array($array, $needle)) - * { - * doSomething(); - * } - * - * - * @category PHP - * @package PHP_CodeSniffer - * @author Andy Brockhurst - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_PHP_NoSilencedErrorsSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * If true, an error will be thrown; otherwise a warning. - * - * @var bool - */ - public $error = false; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_ASPERAND); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $error = 'Silencing errors is forbidden'; - if ($this->error === true) { - $error = 'Silencing errors is forbidden'; - $phpcsFile->addError($error, $stackPtr, 'Forbidden'); - } else { - $error = 'Silencing errors is discouraged'; - $phpcsFile->addWarning($error, $stackPtr, 'Discouraged'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/SAPIUsageSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/SAPIUsageSniff.php deleted file mode 100644 index de1debc..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/SAPIUsageSniff.php +++ /dev/null @@ -1,79 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_PHP_SAPIUsageSniff. - * - * Ensures the PHP_SAPI constant is used instead of php_sapi_name(). - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_PHP_SAPIUsageSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_STRING); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $ignore = array( - T_DOUBLE_COLON => true, - T_OBJECT_OPERATOR => true, - T_FUNCTION => true, - T_CONST => true, - ); - - $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { - // Not a call to a PHP function. - return; - } - - $function = strtolower($tokens[$stackPtr]['content']); - if ($function === 'php_sapi_name') { - $error = 'Use the PHP_SAPI constant instead of calling php_sapi_name()'; - $phpcsFile->addError($error, $stackPtr, 'FunctionFound'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/SyntaxSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/SyntaxSniff.php deleted file mode 100644 index 3f76e84..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/SyntaxSniff.php +++ /dev/null @@ -1,97 +0,0 @@ - - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_PHP_SyntaxSniff. - * - * Ensures PHP believes the syntax is clean. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Blaine Schmeisser - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_PHP_SyntaxSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * The path to the PHP version we are checking with. - * - * @var string - */ - private $_phpPath = null; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - if ($this->_phpPath === null) { - $this->_phpPath = PHP_CodeSniffer::getConfigData('php_path'); - if ($this->_phpPath === null) { - // PHP_BINARY is available in PHP 5.4+. - if (defined('PHP_BINARY') === true) { - $this->_phpPath = PHP_BINARY; - } else { - return; - } - } - } - - $fileName = escapeshellarg($phpcsFile->getFilename()); - if (defined('HHVM_VERSION') === false) { - $cmd = escapeshellcmd($this->_phpPath)." -l -d error_prepend_string='' $fileName 2>&1"; - } else { - $cmd = escapeshellcmd($this->_phpPath)." -l $fileName 2>&1"; - } - - $output = shell_exec($cmd); - $matches = array(); - if (preg_match('/^.*error:(.*) in .* on line ([0-9]+)/m', trim($output), $matches) === 1) { - $error = trim($matches[1]); - $line = (int) $matches[2]; - $phpcsFile->addErrorOnLine("PHP syntax error: $error", $line, 'PHPSyntax'); - } - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/UpperCaseConstantSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/UpperCaseConstantSniff.php deleted file mode 100644 index b29efe4..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/PHP/UpperCaseConstantSniff.php +++ /dev/null @@ -1,88 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_PHP_UpperCaseConstantSniff. - * - * Checks that all uses of TRUE, FALSE and NULL are uppercase. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_PHP_UpperCaseConstantSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_TRUE, - T_FALSE, - T_NULL, - ); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $keyword = $tokens[$stackPtr]['content']; - $expected = strtoupper($keyword); - if ($keyword !== $expected) { - if ($keyword === strtolower($keyword)) { - $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'lower'); - } else { - $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'mixed'); - } - - $error = 'TRUE, FALSE and NULL must be uppercase; expected "%s" but found "%s"'; - $data = array( - $expected, - $keyword, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, $expected); - } - } else { - $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'upper'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Strings/UnnecessaryStringConcatSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/Strings/UnnecessaryStringConcatSniff.php deleted file mode 100644 index a93c394..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/Strings/UnnecessaryStringConcatSniff.php +++ /dev/null @@ -1,138 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Strings_UnnecessaryStringConcatSniff. - * - * Checks that two strings are not concatenated together; suggests - * using one string instead. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_Strings_UnnecessaryStringConcatSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - /** - * If true, an error will be thrown; otherwise a warning. - * - * @var bool - */ - public $error = true; - - /** - * If true, strings concatenated over multiple lines are allowed. - * - * Useful if you break strings over multiple lines to work - * within a max line length. - * - * @var bool - */ - public $allowMultiline = false; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_STRING_CONCAT, - T_PLUS, - ); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - // Work out which type of file this is for. - $tokens = $phpcsFile->getTokens(); - if ($tokens[$stackPtr]['code'] === T_STRING_CONCAT) { - if ($phpcsFile->tokenizerType === 'JS') { - return; - } - } else { - if ($phpcsFile->tokenizerType === 'PHP') { - return; - } - } - - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($prev === false || $next === false) { - return; - } - - if (isset(PHP_CodeSniffer_Tokens::$stringTokens[$tokens[$prev]['code']]) === true - && isset(PHP_CodeSniffer_Tokens::$stringTokens[$tokens[$next]['code']]) === true - ) { - if ($tokens[$prev]['content'][0] === $tokens[$next]['content'][0]) { - // Before we throw an error for PHP, allow strings to be - // combined if they would have < and ? next to each other because - // this trick is sometimes required in PHP strings. - if ($phpcsFile->tokenizerType === 'PHP') { - $prevChar = substr($tokens[$prev]['content'], -2, 1); - $nextChar = $tokens[$next]['content'][1]; - $combined = $prevChar.$nextChar; - if ($combined === '?'.'>' || $combined === '<'.'?') { - return; - } - } - - if ($this->allowMultiline === true - && $tokens[$prev]['line'] !== $tokens[$next]['line'] - ) { - return; - } - - $error = 'String concat is not required here; use a single string instead'; - if ($this->error === true) { - $phpcsFile->addError($error, $stackPtr, 'Found'); - } else { - $phpcsFile->addWarning($error, $stackPtr, 'Found'); - } - }//end if - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/VersionControl/SubversionPropertiesSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/VersionControl/SubversionPropertiesSniff.php deleted file mode 100644 index 516c026..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/VersionControl/SubversionPropertiesSniff.php +++ /dev/null @@ -1,204 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_VersionControl_SubversionPropertiesSniff. - * - * Tests that the correct Subversion properties are set. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Jack Bates - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_VersionControl_SubversionPropertiesSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * The Subversion properties that should be set. - * - * Key of array is the SVN property and the value is the - * exact value the property should have or NULL if the - * property should just be set but the value is not fixed. - * - * @var array - */ - protected $properties = array( - 'svn:keywords' => 'Author Id Revision', - 'svn:eol-style' => 'native', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Make sure this is the first PHP open tag so we don't process the - // same file twice. - $prevOpenTag = $phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)); - if ($prevOpenTag !== false) { - return; - } - - $path = $phpcsFile->getFileName(); - $properties = $this->getProperties($path); - if ($properties === null) { - // Not under version control. - return; - } - - $allProperties = ($properties + $this->properties); - foreach ($allProperties as $key => $value) { - if (isset($properties[$key]) === true - && isset($this->properties[$key]) === false - ) { - $error = 'Unexpected Subversion property "%s" = "%s"'; - $data = array( - $key, - $properties[$key], - ); - $phpcsFile->addError($error, $stackPtr, 'Unexpected', $data); - continue; - } - - if (isset($properties[$key]) === false - && isset($this->properties[$key]) === true - ) { - $error = 'Missing Subversion property "%s" = "%s"'; - $data = array( - $key, - $this->properties[$key], - ); - $phpcsFile->addError($error, $stackPtr, 'Missing', $data); - continue; - } - - if ($properties[$key] !== null - && $properties[$key] !== $this->properties[$key] - ) { - $error = 'Subversion property "%s" = "%s" does not match "%s"'; - $data = array( - $key, - $properties[$key], - $this->properties[$key], - ); - $phpcsFile->addError($error, $stackPtr, 'NoMatch', $data); - } - }//end foreach - - }//end process() - - - /** - * Returns the Subversion properties which are actually set on a path. - * - * Returns NULL if the file is not under version control. - * - * @param string $path The path to return Subversion properties on. - * - * @return array - * @throws PHP_CodeSniffer_Exception If Subversion properties file could - * not be opened. - */ - protected function getProperties($path) - { - $properties = array(); - - $paths = array(); - $paths[] = dirname($path).'/.svn/props/'.basename($path).'.svn-work'; - $paths[] = dirname($path).'/.svn/prop-base/'.basename($path).'.svn-base'; - - $foundPath = false; - foreach ($paths as $path) { - if (file_exists($path) === true) { - $foundPath = true; - - $handle = fopen($path, 'r'); - if ($handle === false) { - $error = 'Error opening file; could not get Subversion properties'; - throw new PHP_CodeSniffer_Exception($error); - } - - while (feof($handle) === false) { - // Read a key length line. Might be END, though. - $buffer = trim(fgets($handle)); - - // Check for the end of the hash. - if ($buffer === 'END') { - break; - } - - // Now read that much into a buffer. - $key = fread($handle, substr($buffer, 2)); - - // Suck up extra newline after key data. - fgetc($handle); - - // Read a value length line. - $buffer = trim(fgets($handle)); - - // Now read that much into a buffer. - $length = substr($buffer, 2); - if ($length === '0') { - // Length of value is ZERO characters, so - // value is actually empty. - $value = ''; - } else { - $value = fread($handle, $length); - } - - // Suck up extra newline after value data. - fgetc($handle); - - $properties[$key] = $value; - }//end while - - fclose($handle); - }//end if - }//end foreach - - if ($foundPath === false) { - return null; - } - - return $properties; - - }//end getProperties() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php deleted file mode 100644 index 7359cc2..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php +++ /dev/null @@ -1,141 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_WhiteSpace_DisallowSpaceIndentSniff. - * - * Throws errors if spaces are used for indentation. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_WhiteSpace_DisallowSpaceIndentSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - 'CSS', - ); - - /** - * The --tab-width CLI value that is being used. - * - * @var int - */ - private $_tabWidth = null; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - if ($this->_tabWidth === null) { - $cliValues = $phpcsFile->phpcs->cli->getCommandLineValues(); - if (isset($cliValues['tabWidth']) === false || $cliValues['tabWidth'] === 0) { - // We have no idea how wide tabs are, so assume 4 spaces for fixing. - // It shouldn't really matter because indent checks elsewhere in the - // standard should fix things up. - $this->_tabWidth = 4; - } else { - $this->_tabWidth = $cliValues['tabWidth']; - } - } - - $checkTokens = array( - T_WHITESPACE => true, - T_INLINE_HTML => true, - T_DOC_COMMENT_WHITESPACE => true, - ); - - $tokens = $phpcsFile->getTokens(); - for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) { - if ($tokens[$i]['column'] !== 1 || isset($checkTokens[$tokens[$i]['code']]) === false) { - continue; - } - - // If tabs are being converted to spaces, the original content - // should be used instead of the converted content. - if (isset($tokens[$i]['orig_content']) === true) { - $content = $tokens[$i]['orig_content']; - } else { - $content = $tokens[$i]['content']; - } - - if ($content[0] === ' ') { - if ($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE && $content === ' ') { - // Ignore file/class-level DocBlock. - continue; - } - - // Space are considered ok if they are proceeded by tabs and not followed - // by tabs, as is the case with standard docblock comments. - $phpcsFile->recordMetric($i, 'Line indent', 'spaces'); - $error = 'Tabs must be used to indent lines; spaces are not allowed'; - $fix = $phpcsFile->addFixableError($error, $i, 'SpacesUsed'); - if ($fix === true) { - $trimmed = ltrim($content, ' '); - $numSpaces = (strlen($content) - strlen($trimmed)); - if ($numSpaces < $this->_tabWidth) { - $numTabs = 1; - $padding = "\t"; - } else { - $numTabs = floor($numSpaces / $this->_tabWidth); - $remaining = ($numSpaces - ($numTabs * $this->_tabWidth)); - $padding = str_repeat("\t", $numTabs).$padding = str_repeat(' ', $remaining); - } - - $phpcsFile->fixer->replaceToken($i, $padding.$trimmed); - } - } else if ($content[0] === "\t") { - $phpcsFile->recordMetric($i, 'Line indent', 'tabs'); - }//end if - }//end for - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php deleted file mode 100644 index 4d79323..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php +++ /dev/null @@ -1,149 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_WhiteSpace_DisallowTabIndentSniff. - * - * Throws errors if tabs are used for indentation. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_WhiteSpace_DisallowTabIndentSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - 'CSS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $error = 'Spaces must be used to indent lines; tabs are not allowed'; - $errorCode = 'TabsUsed'; - - $checkTokens = array( - T_WHITESPACE => true, - T_INLINE_HTML => true, - T_DOC_COMMENT_WHITESPACE => true, - T_DOC_COMMENT_STRING => true, - ); - - for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) { - if (isset($checkTokens[$tokens[$i]['code']]) === false) { - continue; - } - - // If tabs are being converted to spaces by PHPCS, the - // original content should be checked instead of the converted content. - if (isset($tokens[$i]['orig_content']) === true) { - $content = $tokens[$i]['orig_content']; - } else { - $content = $tokens[$i]['content']; - } - - if ($content === '') { - continue; - } - - if ($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE && $content === ' ') { - // Ignore file/class-level DocBlock, especially for recording metrics. - continue; - } - - $tabFound = false; - if ($tokens[$i]['column'] === 1) { - if ($content[0] === "\t") { - $phpcsFile->recordMetric($i, 'Line indent', 'tabs'); - $tabFound = true; - } else if ($content[0] === ' ') { - if (strpos($content, "\t") !== false) { - $phpcsFile->recordMetric($i, 'Line indent', 'mixed'); - $tabFound = true; - } else { - $phpcsFile->recordMetric($i, 'Line indent', 'spaces'); - } - } - } else { - // Look for tabs so we can report and replace, but don't - // record any metrics about them because they aren't - // line indent tokens. - if (strpos($content, "\t") !== false) { - $tabFound = true; - $error = 'Spaces must be used for alignment; tabs are not allowed'; - $errorCode = 'NonIndentTabsUsed'; - } - }//end if - - if ($tabFound === false) { - continue; - } - - $fix = $phpcsFile->addFixableError($error, $i, $errorCode); - if ($fix === true) { - if (isset($tokens[$i]['orig_content']) === true) { - // Use the replacement that PHPCS has already done. - $phpcsFile->fixer->replaceToken($i, $tokens[$i]['content']); - } else { - // Replace tabs with spaces, using an indent of 4 spaces. - // Other sniffs can then correct the indent if they need to. - $newContent = str_replace("\t", ' ', $tokens[$i]['content']); - $phpcsFile->fixer->replaceToken($i, $newContent); - } - } - }//end for - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php b/phpcs/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php deleted file mode 100644 index 6dcd3ae..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php +++ /dev/null @@ -1,1274 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Whitespace_ScopeIndentSniff. - * - * Checks that control structures are structured correctly, and their content - * is indented correctly. This sniff will throw errors if tabs are used - * for indentation rather than spaces. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Generic_Sniffs_WhiteSpace_ScopeIndentSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - /** - * The number of spaces code should be indented. - * - * @var int - */ - public $indent = 4; - - /** - * Does the indent need to be exactly right? - * - * If TRUE, indent needs to be exactly $indent spaces. If FALSE, - * indent needs to be at least $indent spaces (but can be more). - * - * @var bool - */ - public $exact = false; - - /** - * Should tabs be used for indenting? - * - * If TRUE, fixes will be made using tabs instead of spaces. - * The size of each tab is important, so it should be specified - * using the --tab-width CLI argument. - * - * @var bool - */ - public $tabIndent = false; - - /** - * The --tab-width CLI value that is being used. - * - * @var int - */ - private $_tabWidth = null; - - /** - * List of tokens not needing to be checked for indentation. - * - * Useful to allow Sniffs based on this to easily ignore/skip some - * tokens from verification. For example, inline HTML sections - * or PHP open/close tags can escape from here and have their own - * rules elsewhere. - * - * @var int[] - */ - public $ignoreIndentationTokens = array(); - - /** - * List of tokens not needing to be checked for indentation. - * - * This is a cached copy of the public version of this var, which - * can be set in a ruleset file, and some core ignored tokens. - * - * @var int[] - */ - private $_ignoreIndentationTokens = array(); - - /** - * Any scope openers that should not cause an indent. - * - * @var int[] - */ - protected $nonIndentingScopes = array(); - - /** - * Show debug output for this sniff. - * - * @var bool - */ - private $_debug = false; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - if (defined('PHP_CODESNIFFER_IN_TESTS') === true) { - $this->_debug = false; - } - - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $debug = PHP_CodeSniffer::getConfigData('scope_indent_debug'); - if ($debug !== null) { - $this->_debug = (bool) $debug; - } - - if ($this->_tabWidth === null) { - $cliValues = $phpcsFile->phpcs->cli->getCommandLineValues(); - if (isset($cliValues['tabWidth']) === false || $cliValues['tabWidth'] === 0) { - // We have no idea how wide tabs are, so assume 4 spaces for fixing. - // It shouldn't really matter because indent checks elsewhere in the - // standard should fix things up. - $this->_tabWidth = 4; - } else { - $this->_tabWidth = $cliValues['tabWidth']; - } - } - - $currentIndent = 0; - $lastOpenTag = $stackPtr; - $lastCloseTag = null; - $openScopes = array(); - $adjustments = array(); - $setIndents = array(); - - $tokens = $phpcsFile->getTokens(); - $first = $phpcsFile->findFirstOnLine(T_INLINE_HTML, $stackPtr); - $trimmed = ltrim($tokens[$first]['content']); - if ($trimmed === '') { - $currentIndent = ($tokens[$stackPtr]['column'] - 1); - } else { - $currentIndent = (strlen($tokens[$first]['content']) - strlen($trimmed)); - } - - if ($this->_debug === true) { - $line = $tokens[$stackPtr]['line']; - echo "Start with token $stackPtr on line $line with indent $currentIndent".PHP_EOL; - } - - if (empty($this->_ignoreIndentationTokens) === true) { - $this->_ignoreIndentationTokens = array(T_INLINE_HTML => true); - foreach ($this->ignoreIndentationTokens as $token) { - if (is_int($token) === false) { - if (defined($token) === false) { - continue; - } - - $token = constant($token); - } - - $this->_ignoreIndentationTokens[$token] = true; - } - }//end if - - $this->exact = (bool) $this->exact; - $this->tabIndent = (bool) $this->tabIndent; - - for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) { - if ($i === false) { - // Something has gone very wrong; maybe a parse error. - break; - } - - $checkToken = null; - $checkIndent = null; - - $exact = (bool) $this->exact; - if ($exact === true && isset($tokens[$i]['nested_parenthesis']) === true) { - // Don't check indents exactly between parenthesis as they - // tend to have custom rules, such as with multi-line function calls - // and control structure conditions. - $exact = false; - } - - // Detect line changes and figure out where the indent is. - if ($tokens[$i]['column'] === 1) { - $trimmed = ltrim($tokens[$i]['content']); - if ($trimmed === '') { - if (isset($tokens[($i + 1)]) === true - && $tokens[$i]['line'] === $tokens[($i + 1)]['line'] - ) { - $checkToken = ($i + 1); - $tokenIndent = ($tokens[($i + 1)]['column'] - 1); - } - } else { - $checkToken = $i; - $tokenIndent = (strlen($tokens[$i]['content']) - strlen($trimmed)); - } - } - - // Closing parenthesis should just be indented to at least - // the same level as where they were opened (but can be more). - if (($checkToken !== null - && $tokens[$checkToken]['code'] === T_CLOSE_PARENTHESIS - && isset($tokens[$checkToken]['parenthesis_opener']) === true) - || ($tokens[$i]['code'] === T_CLOSE_PARENTHESIS - && isset($tokens[$i]['parenthesis_opener']) === true) - ) { - if ($checkToken !== null) { - $parenCloser = $checkToken; - } else { - $parenCloser = $i; - } - - if ($this->_debug === true) { - $line = $tokens[$i]['line']; - echo "Closing parenthesis found on line $line".PHP_EOL; - } - - $parenOpener = $tokens[$parenCloser]['parenthesis_opener']; - if ($tokens[$parenCloser]['line'] !== $tokens[$parenOpener]['line']) { - $parens = 0; - if (isset($tokens[$parenCloser]['nested_parenthesis']) === true - && empty($tokens[$parenCloser]['nested_parenthesis']) === false - ) { - end($tokens[$parenCloser]['nested_parenthesis']); - $parens = key($tokens[$parenCloser]['nested_parenthesis']); - if ($this->_debug === true) { - $line = $tokens[$parens]['line']; - echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL; - } - } - - $condition = 0; - if (isset($tokens[$parenCloser]['conditions']) === true - && empty($tokens[$parenCloser]['conditions']) === false - ) { - end($tokens[$parenCloser]['conditions']); - $condition = key($tokens[$parenCloser]['conditions']); - if ($this->_debug === true) { - $line = $tokens[$condition]['line']; - $type = $tokens[$condition]['type']; - echo "\t* token is inside condition $condition ($type) on line $line *".PHP_EOL; - } - } - - if ($parens > $condition) { - if ($this->_debug === true) { - echo "\t* using parenthesis *".PHP_EOL; - } - - $parenOpener = $parens; - $condition = 0; - } else if ($condition > 0) { - if ($this->_debug === true) { - echo "\t* using condition *".PHP_EOL; - } - - $parenOpener = $condition; - $parens = 0; - } - - $exact = false; - - $lastOpenTagConditions = array_keys($tokens[$lastOpenTag]['conditions']); - $lastOpenTagCondition = array_pop($lastOpenTagConditions); - - if ($condition > 0 && $lastOpenTagCondition === $condition) { - if ($this->_debug === true) { - echo "\t* open tag is inside condition; using open tag *".PHP_EOL; - } - - $checkIndent = ($tokens[$lastOpenTag]['column'] - 1); - if (isset($adjustments[$condition]) === true) { - $checkIndent += $adjustments[$condition]; - } - - $currentIndent = $checkIndent; - - if ($this->_debug === true) { - $type = $tokens[$lastOpenTag]['type']; - echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $lastOpenTag ($type)".PHP_EOL; - } - } else if ($condition > 0 - && isset($tokens[$condition]['scope_opener']) === true - && isset($setIndents[$tokens[$condition]['scope_opener']]) === true - ) { - $checkIndent = $setIndents[$tokens[$condition]['scope_opener']]; - if (isset($adjustments[$condition]) === true) { - $checkIndent += $adjustments[$condition]; - } - - $currentIndent = $checkIndent; - - if ($this->_debug === true) { - $type = $tokens[$condition]['type']; - echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $condition ($type)".PHP_EOL; - } - } else { - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $parenOpener, true); - - $checkIndent = ($tokens[$first]['column'] - 1); - if (isset($adjustments[$first]) === true) { - $checkIndent += $adjustments[$first]; - } - - if ($this->_debug === true) { - $line = $tokens[$first]['line']; - $type = $tokens[$first]['type']; - echo "\t* first token on line $line is $first ($type) *".PHP_EOL; - } - - if ($first === $tokens[$parenCloser]['parenthesis_opener']) { - // This is unlikely to be the start of the statement, so look - // back further to find it. - $first--; - } - - $prev = $phpcsFile->findStartOfStatement($first, T_COMMA); - if ($prev !== $first) { - // This is not the start of the statement. - if ($this->_debug === true) { - $line = $tokens[$prev]['line']; - $type = $tokens[$prev]['type']; - echo "\t* previous is $type on line $line *".PHP_EOL; - } - - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true); - $prev = $phpcsFile->findStartOfStatement($first, T_COMMA); - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true); - if ($this->_debug === true) { - $line = $tokens[$first]['line']; - $type = $tokens[$first]['type']; - echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL; - } - } - - if (isset($tokens[$first]['scope_closer']) === true - && $tokens[$first]['scope_closer'] === $first - ) { - if ($this->_debug === true) { - echo "\t* first token is a scope closer *".PHP_EOL; - } - - if (isset($tokens[$first]['scope_condition']) === true) { - $scopeCloser = $first; - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $tokens[$scopeCloser]['scope_condition'], true); - - $currentIndent = ($tokens[$first]['column'] - 1); - if (isset($adjustments[$first]) === true) { - $currentIndent += $adjustments[$first]; - } - - // Make sure it is divisible by our expected indent. - if ($tokens[$tokens[$scopeCloser]['scope_condition']]['code'] !== T_CLOSURE) { - $currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent); - } - - $setIndents[$first] = $currentIndent; - - if ($this->_debug === true) { - $type = $tokens[$first]['type']; - echo "\t=> indent set to $currentIndent by token $first ($type)".PHP_EOL; - } - }//end if - } else { - // Don't force current indent to divisible because there could be custom - // rules in place between parenthesis, such as with arrays. - $currentIndent = ($tokens[$first]['column'] - 1); - if (isset($adjustments[$first]) === true) { - $currentIndent += $adjustments[$first]; - } - - $setIndents[$first] = $currentIndent; - - if ($this->_debug === true) { - $type = $tokens[$first]['type']; - echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)".PHP_EOL; - } - }//end if - }//end if - } else if ($this->_debug === true) { - echo "\t * ignoring single-line definition *".PHP_EOL; - }//end if - }//end if - - // Closing short array bracket should just be indented to at least - // the same level as where it was opened (but can be more). - if ($tokens[$i]['code'] === T_CLOSE_SHORT_ARRAY - || ($checkToken !== null - && $tokens[$checkToken]['code'] === T_CLOSE_SHORT_ARRAY) - ) { - if ($checkToken !== null) { - $arrayCloser = $checkToken; - } else { - $arrayCloser = $i; - } - - if ($this->_debug === true) { - $line = $tokens[$arrayCloser]['line']; - echo "Closing short array bracket found on line $line".PHP_EOL; - } - - $arrayOpener = $tokens[$arrayCloser]['bracket_opener']; - if ($tokens[$arrayCloser]['line'] !== $tokens[$arrayOpener]['line']) { - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $arrayOpener, true); - $checkIndent = ($tokens[$first]['column'] - 1); - if (isset($adjustments[$first]) === true) { - $checkIndent += $adjustments[$first]; - } - - $exact = false; - - if ($this->_debug === true) { - $line = $tokens[$first]['line']; - $type = $tokens[$first]['type']; - echo "\t* first token on line $line is $first ($type) *".PHP_EOL; - } - - if ($first === $tokens[$arrayCloser]['bracket_opener']) { - // This is unlikely to be the start of the statement, so look - // back further to find it. - $first--; - } - - $prev = $phpcsFile->findStartOfStatement($first, T_COMMA); - if ($prev !== $first) { - // This is not the start of the statement. - if ($this->_debug === true) { - $line = $tokens[$prev]['line']; - $type = $tokens[$prev]['type']; - echo "\t* previous is $type on line $line *".PHP_EOL; - } - - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true); - $prev = $phpcsFile->findStartOfStatement($first, T_COMMA); - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true); - if ($this->_debug === true) { - $line = $tokens[$first]['line']; - $type = $tokens[$first]['type']; - echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL; - } - } - - if (isset($tokens[$first]['scope_closer']) === true - && $tokens[$first]['scope_closer'] === $first - ) { - // The first token is a scope closer and would have already - // been processed and set the indent level correctly, so - // don't adjust it again. - if ($this->_debug === true) { - echo "\t* first token is a scope closer; ignoring closing short array bracket *".PHP_EOL; - } - - if (isset($setIndents[$first]) === true) { - $currentIndent = $setIndents[$first]; - if ($this->_debug === true) { - echo "\t=> indent reset to $currentIndent".PHP_EOL; - } - } - } else { - // Don't force current indent to be divisible because there could be custom - // rules in place for arrays. - $currentIndent = ($tokens[$first]['column'] - 1); - if (isset($adjustments[$first]) === true) { - $currentIndent += $adjustments[$first]; - } - - $setIndents[$first] = $currentIndent; - - if ($this->_debug === true) { - $type = $tokens[$first]['type']; - echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)".PHP_EOL; - } - }//end if - } else if ($this->_debug === true) { - echo "\t * ignoring single-line definition *".PHP_EOL; - }//end if - }//end if - - // Adjust lines within scopes while auto-fixing. - if ($checkToken !== null - && $exact === false - && (empty($tokens[$checkToken]['conditions']) === false - || (isset($tokens[$checkToken]['scope_opener']) === true - && $tokens[$checkToken]['scope_opener'] === $checkToken)) - ) { - if (empty($tokens[$checkToken]['conditions']) === false) { - end($tokens[$checkToken]['conditions']); - $condition = key($tokens[$checkToken]['conditions']); - } else { - $condition = $tokens[$checkToken]['scope_condition']; - } - - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $condition, true); - - if (isset($adjustments[$first]) === true - && (($adjustments[$first] < 0 && $tokenIndent > $currentIndent) - || ($adjustments[$first] > 0 && $tokenIndent < $currentIndent)) - ) { - $padding = ($tokenIndent + $adjustments[$first]); - if ($padding > 0) { - if ($this->tabIndent === true) { - $numTabs = floor($padding / $this->_tabWidth); - $numSpaces = ($padding - ($numTabs * $this->_tabWidth)); - $padding = str_repeat("\t", $numTabs).str_repeat(' ', $numSpaces); - } else { - $padding = str_repeat(' ', $padding); - } - } else { - $padding = ''; - } - - if ($checkToken === $i) { - $phpcsFile->fixer->replaceToken($checkToken, $padding.$trimmed); - } else { - // Easier to just replace the entire indent. - $phpcsFile->fixer->replaceToken(($checkToken - 1), $padding); - } - - if ($this->_debug === true) { - $length = strlen($padding); - $line = $tokens[$checkToken]['line']; - $type = $tokens[$checkToken]['type']; - echo "Indent adjusted to $length for $type on line $line".PHP_EOL; - } - - $adjustments[$checkToken] = $adjustments[$first]; - - if ($this->_debug === true) { - $line = $tokens[$checkToken]['line']; - $type = $tokens[$checkToken]['type']; - echo "\t=> Add adjustment of ".$adjustments[$checkToken]." for token $checkToken ($type) on line $line".PHP_EOL; - } - }//end if - }//end if - - // Scope closers reset the required indent to the same level as the opening condition. - if (($checkToken !== null - && isset($openScopes[$checkToken]) === true - || (isset($tokens[$checkToken]['scope_condition']) === true - && isset($tokens[$checkToken]['scope_closer']) === true - && $tokens[$checkToken]['scope_closer'] === $checkToken - && $tokens[$checkToken]['line'] !== $tokens[$tokens[$checkToken]['scope_opener']]['line'])) - || ($checkToken === null - && isset($openScopes[$i]) === true - || (isset($tokens[$i]['scope_condition']) === true - && isset($tokens[$i]['scope_closer']) === true - && $tokens[$i]['scope_closer'] === $i - && $tokens[$i]['line'] !== $tokens[$tokens[$i]['scope_opener']]['line'])) - ) { - if ($this->_debug === true) { - if ($checkToken === null) { - $type = $tokens[$tokens[$i]['scope_condition']]['type']; - $line = $tokens[$i]['line']; - } else { - $type = $tokens[$tokens[$checkToken]['scope_condition']]['type']; - $line = $tokens[$checkToken]['line']; - } - - echo "Close scope ($type) on line $line".PHP_EOL; - } - - $scopeCloser = $checkToken; - if ($scopeCloser === null) { - $scopeCloser = $i; - } else { - array_pop($openScopes); - } - - if (isset($tokens[$scopeCloser]['scope_condition']) === true) { - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $tokens[$scopeCloser]['scope_condition'], true); - - $currentIndent = ($tokens[$first]['column'] - 1); - if (isset($adjustments[$first]) === true) { - $currentIndent += $adjustments[$first]; - } - - // Make sure it is divisible by our expected indent. - if ($tokens[$tokens[$scopeCloser]['scope_condition']]['code'] !== T_CLOSURE) { - $currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent); - } - - $setIndents[$scopeCloser] = $currentIndent; - - if ($this->_debug === true) { - $type = $tokens[$scopeCloser]['type']; - echo "\t=> indent set to $currentIndent by token $scopeCloser ($type)".PHP_EOL; - } - - // We only check the indent of scope closers if they are - // curly braces because other constructs tend to have different rules. - if ($tokens[$scopeCloser]['code'] === T_CLOSE_CURLY_BRACKET) { - $exact = true; - } else { - $checkToken = null; - } - }//end if - }//end if - - // Handle scope for JS object notation. - if ($phpcsFile->tokenizerType === 'JS' - && (($checkToken !== null - && $tokens[$checkToken]['code'] === T_CLOSE_OBJECT - && $tokens[$checkToken]['line'] !== $tokens[$tokens[$checkToken]['bracket_opener']]['line']) - || ($checkToken === null - && $tokens[$i]['code'] === T_CLOSE_OBJECT - && $tokens[$i]['line'] !== $tokens[$tokens[$i]['bracket_opener']]['line'])) - ) { - if ($this->_debug === true) { - $line = $tokens[$i]['line']; - echo "Close JS object on line $line".PHP_EOL; - } - - $scopeCloser = $checkToken; - if ($scopeCloser === null) { - $scopeCloser = $i; - } else { - array_pop($openScopes); - } - - $parens = 0; - if (isset($tokens[$scopeCloser]['nested_parenthesis']) === true - && empty($tokens[$scopeCloser]['nested_parenthesis']) === false - ) { - end($tokens[$scopeCloser]['nested_parenthesis']); - $parens = key($tokens[$scopeCloser]['nested_parenthesis']); - if ($this->_debug === true) { - $line = $tokens[$parens]['line']; - echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL; - } - } - - $condition = 0; - if (isset($tokens[$scopeCloser]['conditions']) === true - && empty($tokens[$scopeCloser]['conditions']) === false - ) { - end($tokens[$scopeCloser]['conditions']); - $condition = key($tokens[$scopeCloser]['conditions']); - if ($this->_debug === true) { - $line = $tokens[$condition]['line']; - $type = $tokens[$condition]['type']; - echo "\t* token is inside condition $condition ($type) on line $line *".PHP_EOL; - } - } - - if ($parens > $condition) { - if ($this->_debug === true) { - echo "\t* using parenthesis *".PHP_EOL; - } - - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $parens, true); - $condition = 0; - } else if ($condition > 0) { - if ($this->_debug === true) { - echo "\t* using condition *".PHP_EOL; - } - - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $condition, true); - $parens = 0; - } else { - if ($this->_debug === true) { - $line = $tokens[$tokens[$scopeCloser]['bracket_opener']]['line']; - echo "\t* token is not in parenthesis or condition; using opener on line $line *".PHP_EOL; - } - - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $tokens[$scopeCloser]['bracket_opener'], true); - }//end if - - $currentIndent = ($tokens[$first]['column'] - 1); - if (isset($adjustments[$first]) === true) { - $currentIndent += $adjustments[$first]; - } - - if ($parens > 0 || $condition > 0) { - $checkIndent = ($tokens[$first]['column'] - 1); - if (isset($adjustments[$first]) === true) { - $checkIndent += $adjustments[$first]; - } - - if ($condition > 0) { - $checkIndent += $this->indent; - $currentIndent += $this->indent; - $exact = true; - } - } else { - $checkIndent = $currentIndent; - } - - // Make sure it is divisible by our expected indent. - $currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent); - $checkIndent = (int) (ceil($checkIndent / $this->indent) * $this->indent); - $setIndents[$first] = $currentIndent; - - if ($this->_debug === true) { - $type = $tokens[$first]['type']; - echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)".PHP_EOL; - } - }//end if - - if ($checkToken !== null - && isset(PHP_CodeSniffer_Tokens::$scopeOpeners[$tokens[$checkToken]['code']]) === true - && in_array($tokens[$checkToken]['code'], $this->nonIndentingScopes) === false - && isset($tokens[$checkToken]['scope_opener']) === true - ) { - $exact = true; - - $lastOpener = null; - if (empty($openScopes) === false) { - end($openScopes); - $lastOpener = current($openScopes); - } - - // A scope opener that shares a closer with another token (like multiple - // CASEs using the same BREAK) needs to reduce the indent level so its - // indent is checked correctly. It will then increase the indent again - // (as all openers do) after being checked. - if ($lastOpener !== null - && isset($tokens[$lastOpener]['scope_closer']) === true - && $tokens[$lastOpener]['level'] === $tokens[$checkToken]['level'] - && $tokens[$lastOpener]['scope_closer'] === $tokens[$checkToken]['scope_closer'] - ) { - $currentIndent -= $this->indent; - $setIndents[$lastOpener] = $currentIndent; - if ($this->_debug === true) { - $line = $tokens[$i]['line']; - $type = $tokens[$lastOpener]['type']; - echo "Shared closer found on line $line".PHP_EOL; - echo "\t=> indent set to $currentIndent by token $lastOpener ($type)".PHP_EOL; - } - } - - if ($tokens[$checkToken]['code'] === T_CLOSURE - && $tokenIndent > $currentIndent - ) { - // The opener is indented more than needed, which is fine. - // But just check that it is divisible by our expected indent. - $checkIndent = (int) (ceil($tokenIndent / $this->indent) * $this->indent); - $exact = false; - - if ($this->_debug === true) { - $line = $tokens[$i]['line']; - echo "Closure found on line $line".PHP_EOL; - echo "\t=> checking indent of $checkIndent; main indent remains at $currentIndent".PHP_EOL; - } - } - }//end if - - // Method prefix indentation has to be exact or else if will break - // the rest of the function declaration, and potentially future ones. - if ($checkToken !== null - && isset(PHP_CodeSniffer_Tokens::$methodPrefixes[$tokens[$checkToken]['code']]) === true - && $tokens[($checkToken + 1)]['code'] !== T_DOUBLE_COLON - ) { - $exact = true; - } - - // JS property indentation has to be exact or else if will break - // things like function and object indentation. - if ($checkToken !== null && $tokens[$checkToken]['code'] === T_PROPERTY) { - $exact = true; - } - - // PHP tags needs to be indented to exact column positions - // so they don't cause problems with indent checks for the code - // within them, but they don't need to line up with the current indent. - if ($checkToken !== null - && ($tokens[$checkToken]['code'] === T_OPEN_TAG - || $tokens[$checkToken]['code'] === T_OPEN_TAG_WITH_ECHO - || $tokens[$checkToken]['code'] === T_CLOSE_TAG) - ) { - $exact = true; - $checkIndent = ($tokens[$checkToken]['column'] - 1); - $checkIndent = (int) (ceil($checkIndent / $this->indent) * $this->indent); - } - - // Special case for ELSE statements that are not on the same - // line as the previous IF statements closing brace. They still need - // to have the same indent or it will break code after the block. - if ($checkToken !== null && $tokens[$checkToken]['code'] === T_ELSE) { - $exact = true; - } - - if ($checkIndent === null) { - $checkIndent = $currentIndent; - } - - /* - The indent of the line is checked by the following IF block. - - Up until now, we've just been figuring out what the indent - of this line should be. - - After this IF block, we adjust the indent again for - the checking of future line. - */ - - $adjusted = false; - if ($checkToken !== null - && isset($this->_ignoreIndentationTokens[$tokens[$checkToken]['code']]) === false - && (($tokenIndent !== $checkIndent && $exact === true) - || ($tokenIndent < $checkIndent && $exact === false)) - ) { - $type = 'IncorrectExact'; - $error = 'Line indented incorrectly; expected '; - if ($exact === false) { - $error .= 'at least '; - $type = 'Incorrect'; - } - - if ($this->tabIndent === true) { - $error .= '%s tabs, found %s'; - $data = array( - floor($checkIndent / $this->_tabWidth), - floor($tokenIndent / $this->_tabWidth), - ); - } else { - $error .= '%s spaces, found %s'; - $data = array( - $checkIndent, - $tokenIndent, - ); - } - - if ($this->_debug === true) { - $line = $tokens[$checkToken]['line']; - $message = vsprintf($error, $data); - echo "[Line $line] $message".PHP_EOL; - } - - $fix = $phpcsFile->addFixableError($error, $checkToken, $type, $data); - if ($fix === true || $this->_debug === true) { - $padding = ''; - if ($this->tabIndent === true) { - $numTabs = floor($checkIndent / $this->_tabWidth); - if ($numTabs > 0) { - $numSpaces = ($checkIndent - ($numTabs * $this->_tabWidth)); - $padding = str_repeat("\t", $numTabs).str_repeat(' ', $numSpaces); - } - } else if ($checkIndent > 0) { - $padding = str_repeat(' ', $checkIndent); - } - - if ($checkToken === $i) { - $accepted = $phpcsFile->fixer->replaceToken($checkToken, $padding.$trimmed); - } else { - // Easier to just replace the entire indent. - $accepted = $phpcsFile->fixer->replaceToken(($checkToken - 1), $padding); - } - - if ($accepted === true) { - $adjustments[$checkToken] = ($checkIndent - $tokenIndent); - if ($this->_debug === true) { - $line = $tokens[$checkToken]['line']; - $type = $tokens[$checkToken]['type']; - echo "\t=> Add adjustment of ".$adjustments[$checkToken]." for token $checkToken ($type) on line $line".PHP_EOL; - } - } - } else { - // Assume the change would be applied and continue - // checking indents under this assumption. This gives more - // technically accurate error messages. - $adjustments[$checkToken] = ($checkIndent - $tokenIndent); - }//end if - }//end if - - if ($checkToken !== null) { - $i = $checkToken; - } - - // Completely skip here/now docs as the indent is a part of the - // content itself. - if ($tokens[$i]['code'] === T_START_HEREDOC - || $tokens[$i]['code'] === T_START_NOWDOC - ) { - $i = $phpcsFile->findNext(array(T_END_HEREDOC, T_END_NOWDOC), ($i + 1)); - continue; - } - - // Completely skip multi-line strings as the indent is a part of the - // content itself. - if ($tokens[$i]['code'] === T_CONSTANT_ENCAPSED_STRING - || $tokens[$i]['code'] === T_DOUBLE_QUOTED_STRING - ) { - $i = $phpcsFile->findNext($tokens[$i]['code'], ($i + 1), null, true); - $i--; - continue; - } - - // Completely skip doc comments as they tend to have complex - // indentation rules. - if ($tokens[$i]['code'] === T_DOC_COMMENT_OPEN_TAG) { - $i = $tokens[$i]['comment_closer']; - continue; - } - - // Open tags reset the indent level. - if ($tokens[$i]['code'] === T_OPEN_TAG - || $tokens[$i]['code'] === T_OPEN_TAG_WITH_ECHO - ) { - if ($this->_debug === true) { - $line = $tokens[$i]['line']; - echo "Open PHP tag found on line $line".PHP_EOL; - } - - if ($checkToken === null) { - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true); - $currentIndent = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content']))); - } else { - $currentIndent = ($tokens[$i]['column'] - 1); - } - - $lastOpenTag = $i; - - if (isset($adjustments[$i]) === true) { - $currentIndent += $adjustments[$i]; - } - - // Make sure it is divisible by our expected indent. - $currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent); - $setIndents[$i] = $currentIndent; - - if ($this->_debug === true) { - $type = $tokens[$i]['type']; - echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL; - } - - continue; - }//end if - - // Close tags reset the indent level, unless they are closing a tag - // opened on the same line. - if ($tokens[$i]['code'] === T_CLOSE_TAG) { - if ($this->_debug === true) { - $line = $tokens[$i]['line']; - echo "Close PHP tag found on line $line".PHP_EOL; - } - - if ($tokens[$lastOpenTag]['line'] !== $tokens[$i]['line']) { - $currentIndent = ($tokens[$i]['column'] - 1); - $lastCloseTag = $i; - } else { - if ($lastCloseTag === null) { - $currentIndent = 0; - } else { - $currentIndent = ($tokens[$lastCloseTag]['column'] - 1); - } - } - - if (isset($adjustments[$i]) === true) { - $currentIndent += $adjustments[$i]; - } - - // Make sure it is divisible by our expected indent. - $currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent); - $setIndents[$i] = $currentIndent; - - if ($this->_debug === true) { - $type = $tokens[$i]['type']; - echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL; - } - - continue; - }//end if - - // Anon classes and functions set the indent based on their own indent level. - if ($tokens[$i]['code'] === T_CLOSURE || $tokens[$i]['code'] === T_ANON_CLASS) { - $closer = $tokens[$i]['scope_closer']; - if ($tokens[$i]['line'] === $tokens[$closer]['line']) { - if ($this->_debug === true) { - $type = str_replace('_', ' ', strtolower(substr($tokens[$i]['type'], 2))); - $line = $tokens[$i]['line']; - echo "* ignoring single-line $type on line $line".PHP_EOL; - } - - $i = $closer; - continue; - } - - if ($this->_debug === true) { - $type = str_replace('_', ' ', strtolower(substr($tokens[$i]['type'], 2))); - $line = $tokens[$i]['line']; - echo "Open $type on line $line".PHP_EOL; - } - - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true); - $currentIndent = (($tokens[$first]['column'] - 1) + $this->indent); - - if (isset($adjustments[$first]) === true) { - $currentIndent += $adjustments[$first]; - } - - // Make sure it is divisible by our expected indent. - $currentIndent = (int) (floor($currentIndent / $this->indent) * $this->indent); - $i = $tokens[$i]['scope_opener']; - $setIndents[$i] = $currentIndent; - - if ($this->_debug === true) { - $type = $tokens[$i]['type']; - echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL; - } - - continue; - }//end if - - // Scope openers increase the indent level. - if (isset($tokens[$i]['scope_condition']) === true - && isset($tokens[$i]['scope_opener']) === true - && $tokens[$i]['scope_opener'] === $i - ) { - $closer = $tokens[$i]['scope_closer']; - if ($tokens[$i]['line'] === $tokens[$closer]['line']) { - if ($this->_debug === true) { - $line = $tokens[$i]['line']; - $type = $tokens[$i]['type']; - echo "* ignoring single-line $type on line $line".PHP_EOL; - } - - $i = $closer; - continue; - } - - $condition = $tokens[$tokens[$i]['scope_condition']]['code']; - if (isset(PHP_CodeSniffer_Tokens::$scopeOpeners[$condition]) === true - && in_array($condition, $this->nonIndentingScopes) === false - ) { - if ($this->_debug === true) { - $line = $tokens[$i]['line']; - $type = $tokens[$tokens[$i]['scope_condition']]['type']; - echo "Open scope ($type) on line $line".PHP_EOL; - } - - $currentIndent += $this->indent; - $setIndents[$i] = $currentIndent; - $openScopes[$tokens[$i]['scope_closer']] = $tokens[$i]['scope_condition']; - - if ($this->_debug === true) { - $type = $tokens[$i]['type']; - echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL; - } - - continue; - } - }//end if - - // JS objects set the indent level. - if ($phpcsFile->tokenizerType === 'JS' - && $tokens[$i]['code'] === T_OBJECT - ) { - $closer = $tokens[$i]['bracket_closer']; - if ($tokens[$i]['line'] === $tokens[$closer]['line']) { - if ($this->_debug === true) { - $line = $tokens[$i]['line']; - echo "* ignoring single-line JS object on line $line".PHP_EOL; - } - - $i = $closer; - continue; - } - - if ($this->_debug === true) { - $line = $tokens[$i]['line']; - echo "Open JS object on line $line".PHP_EOL; - } - - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true); - $currentIndent = (($tokens[$first]['column'] - 1) + $this->indent); - if (isset($adjustments[$first]) === true) { - $currentIndent += $adjustments[$first]; - } - - // Make sure it is divisible by our expected indent. - $currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent); - $setIndents[$first] = $currentIndent; - - if ($this->_debug === true) { - $type = $tokens[$first]['type']; - echo "\t=> indent set to $currentIndent by token $first ($type)".PHP_EOL; - } - - continue; - }//end if - - // Closing an anon class or function. - if (isset($tokens[$i]['scope_condition']) === true - && $tokens[$i]['scope_closer'] === $i - && ($tokens[$tokens[$i]['scope_condition']]['code'] === T_CLOSURE - || $tokens[$tokens[$i]['scope_condition']]['code'] === T_ANON_CLASS) - ) { - if ($this->_debug === true) { - $type = str_replace('_', ' ', strtolower(substr($tokens[$tokens[$i]['scope_condition']]['type'], 2))); - $line = $tokens[$i]['line']; - echo "Close $type on line $line".PHP_EOL; - } - - $prev = false; - - $object = 0; - if ($phpcsFile->tokenizerType === 'JS') { - $conditions = $tokens[$i]['conditions']; - krsort($conditions, SORT_NUMERIC); - foreach ($conditions as $token => $condition) { - if ($condition === T_OBJECT) { - $object = $token; - break; - } - } - - if ($this->_debug === true && $object !== 0) { - $line = $tokens[$object]['line']; - echo "\t* token is inside JS object $object on line $line *".PHP_EOL; - } - } - - $parens = 0; - if (isset($tokens[$i]['nested_parenthesis']) === true - && empty($tokens[$i]['nested_parenthesis']) === false - ) { - end($tokens[$i]['nested_parenthesis']); - $parens = key($tokens[$i]['nested_parenthesis']); - if ($this->_debug === true) { - $line = $tokens[$parens]['line']; - echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL; - } - } - - $condition = 0; - if (isset($tokens[$i]['conditions']) === true - && empty($tokens[$i]['conditions']) === false - ) { - end($tokens[$i]['conditions']); - $condition = key($tokens[$i]['conditions']); - if ($this->_debug === true) { - $line = $tokens[$condition]['line']; - $type = $tokens[$condition]['type']; - echo "\t* token is inside condition $condition ($type) on line $line *".PHP_EOL; - } - } - - if ($parens > $object && $parens > $condition) { - if ($this->_debug === true) { - echo "\t* using parenthesis *".PHP_EOL; - } - - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($parens - 1), null, true); - $object = 0; - $condition = 0; - } else if ($object > 0 && $object >= $condition) { - if ($this->_debug === true) { - echo "\t* using object *".PHP_EOL; - } - - $prev = $object; - $parens = 0; - $condition = 0; - } else if ($condition > 0) { - if ($this->_debug === true) { - echo "\t* using condition *".PHP_EOL; - } - - $prev = $condition; - $object = 0; - $parens = 0; - }//end if - - if ($prev === false) { - $prev = $phpcsFile->findPrevious(array(T_EQUAL, T_RETURN), ($tokens[$i]['scope_condition'] - 1), null, false, null, true); - if ($prev === false) { - $prev = $i; - if ($this->_debug === true) { - echo "\t* could not find a previous T_EQUAL or T_RETURN token; will use current token *".PHP_EOL; - } - } - } - - if ($this->_debug === true) { - $line = $tokens[$prev]['line']; - $type = $tokens[$prev]['type']; - echo "\t* previous token is $type on line $line *".PHP_EOL; - } - - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true); - if ($this->_debug === true) { - $line = $tokens[$first]['line']; - $type = $tokens[$first]['type']; - echo "\t* first token on line $line is $first ($type) *".PHP_EOL; - } - - $prev = $phpcsFile->findStartOfStatement($first); - if ($prev !== $first) { - // This is not the start of the statement. - if ($this->_debug === true) { - $line = $tokens[$prev]['line']; - $type = $tokens[$prev]['type']; - echo "\t* amended previous is $type on line $line *".PHP_EOL; - } - - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true); - if ($this->_debug === true) { - $line = $tokens[$first]['line']; - $type = $tokens[$first]['type']; - echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL; - } - } - - $currentIndent = ($tokens[$first]['column'] - 1); - if ($object > 0 || $condition > 0) { - $currentIndent += $this->indent; - } - - if (isset($tokens[$first]['scope_closer']) === true - && $tokens[$first]['scope_closer'] === $first - ) { - if ($this->_debug === true) { - echo "\t* first token is a scope closer *".PHP_EOL; - } - - if ($condition === 0 || $tokens[$condition]['scope_opener'] < $first) { - $currentIndent = $setIndents[$first]; - } else if ($this->_debug === true) { - echo "\t* ignoring scope closer *".PHP_EOL; - } - } - - // Make sure it is divisible by our expected indent. - $currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent); - $setIndents[$first] = $currentIndent; - - if ($this->_debug === true) { - $type = $tokens[$first]['type']; - echo "\t=> indent set to $currentIndent by token $first ($type)".PHP_EOL; - } - }//end if - }//end for - - // Don't process the rest of the file. - return $phpcsFile->numTokens; - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Generic/ruleset.xml b/phpcs/CodeSniffer/Standards/Generic/ruleset.xml deleted file mode 100644 index aeb5545..0000000 --- a/phpcs/CodeSniffer/Standards/Generic/ruleset.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - A collection of generic sniffs. This standard is not designed to be used to check code. - diff --git a/phpcs/CodeSniffer/Standards/IncorrectPatternException.php b/phpcs/CodeSniffer/Standards/IncorrectPatternException.php deleted file mode 100644 index d9c8aa9..0000000 --- a/phpcs/CodeSniffer/Standards/IncorrectPatternException.php +++ /dev/null @@ -1,33 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * An exception thrown if the pattern being processed is not supposed to be - * validating the code in question. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Standards_IncorrectPatternException extends Exception -{ - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/Sniffs/CSS/BrowserSpecificStylesSniff.php b/phpcs/CodeSniffer/Standards/MySource/Sniffs/CSS/BrowserSpecificStylesSniff.php deleted file mode 100644 index 7feecb7..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/Sniffs/CSS/BrowserSpecificStylesSniff.php +++ /dev/null @@ -1,100 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * MySource_Sniffs_CSS_BrowserSpecificStylesSniff. - * - * Ensure that browser-specific styles are not used. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class MySource_Sniffs_CSS_BrowserSpecificStylesSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - /** - * A list of specific stylesheet suffixes we allow. - * - * These stylesheets contain browser specific styles - * so this sniff ignore them files in the form: - * *_moz.css and *_ie7.css etc. - * - * @var array - */ - protected $specificStylesheets = array( - 'moz' => true, - 'ie' => true, - 'ie7' => true, - 'ie8' => true, - 'webkit' => true, - ); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_STYLE); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - // Ignore files with browser-specific suffixes. - $filename = $phpcsFile->getFilename(); - $breakChar = strrpos($filename, '_'); - if ($breakChar !== false && substr($filename, -4) === '.css') { - $specific = substr($filename, ($breakChar + 1), -4); - if (isset($this->specificStylesheets[$specific]) === true) { - return; - } - } - - $tokens = $phpcsFile->getTokens(); - $content = $tokens[$stackPtr]['content']; - - if ($content{0} === '-') { - $error = 'Browser-specific styles are not allowed'; - $phpcsFile->addError($error, $stackPtr, 'ForbiddenStyle'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Channels/DisallowSelfActionsSniff.php b/phpcs/CodeSniffer/Standards/MySource/Sniffs/Channels/DisallowSelfActionsSniff.php deleted file mode 100644 index a0544ca..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Channels/DisallowSelfActionsSniff.php +++ /dev/null @@ -1,135 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Ensures that self and static are not used to call public methods in action classes. - * - * @category PHP - * @package PHP_CodeSniffer_MySource - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class MySource_Sniffs_Channels_DisallowSelfActionsSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_CLASS); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // We are not interested in abstract classes. - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if ($prev !== false && $tokens[$prev]['code'] === T_ABSTRACT) { - return; - } - - // We are only interested in Action classes. - $classNameToken = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - $className = $tokens[$classNameToken]['content']; - if (substr($className, -7) !== 'Actions') { - return; - } - - $foundFunctions = array(); - $foundCalls = array(); - - // Find all static method calls in the form self::method() in the class. - $classEnd = $tokens[$stackPtr]['scope_closer']; - for ($i = ($classNameToken + 1); $i < $classEnd; $i++) { - if ($tokens[$i]['code'] !== T_DOUBLE_COLON) { - if ($tokens[$i]['code'] === T_FUNCTION) { - // Cache the function information. - $funcName = $phpcsFile->findNext(T_STRING, ($i + 1)); - $funcScope = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$scopeModifiers, ($i - 1)); - - $foundFunctions[$tokens[$funcName]['content']] = strtolower($tokens[$funcScope]['content']); - } - - continue; - } - - $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($i - 1), null, true); - if ($tokens[$prevToken]['content'] !== 'self' - && $tokens[$prevToken]['content'] !== 'static' - ) { - continue; - } - - $funcNameToken = $phpcsFile->findNext(T_WHITESPACE, ($i + 1), null, true); - if ($tokens[$funcNameToken]['code'] === T_VARIABLE) { - // We are only interested in function calls. - continue; - } - - $funcName = $tokens[$funcNameToken]['content']; - - // We've found the function, now we need to find it and see if it is - // public, private or protected. If it starts with an underscore we - // can assume it is private. - if ($funcName{0} === '_') { - continue; - } - - $foundCalls[$i] = array( - 'name' => $funcName, - 'type' => strtolower($tokens[$prevToken]['content']), - ); - }//end for - - $errorClassName = substr($className, 0, -7); - - foreach ($foundCalls as $token => $funcData) { - if (isset($foundFunctions[$funcData['name']]) === false) { - // Function was not in this class, might have come from the parent. - // Either way, we can't really check this. - continue; - } else if ($foundFunctions[$funcData['name']] === 'public') { - $type = $funcData['type']; - $error = "Static calls to public methods in Action classes must not use the $type keyword; use %s::%s() instead"; - $data = array( - $errorClassName, - $funcName, - ); - $phpcsFile->addError($error, $token, 'Found'.ucfirst($funcData['type']), $data); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Channels/IncludeOwnSystemSniff.php b/phpcs/CodeSniffer/Standards/MySource/Sniffs/Channels/IncludeOwnSystemSniff.php deleted file mode 100644 index ee27bb8..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Channels/IncludeOwnSystemSniff.php +++ /dev/null @@ -1,109 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Ensures that a system does not include itself. - * - * @category PHP - * @package PHP_CodeSniffer_MySource - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class MySource_Sniffs_Channels_IncludeOwnSystemSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_DOUBLE_COLON); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $fileName = $phpcsFile->getFilename(); - $matches = array(); - if (preg_match('|/systems/(.*)/([^/]+)?actions.inc$|i', $fileName, $matches) === 0) { - // Not an actions file. - return; - } - - $ownClass = $matches[2]; - $tokens = $phpcsFile->getTokens(); - - $typeName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, ($stackPtr + 2), null, false, true); - $typeName = trim($tokens[$typeName]['content'], " '"); - switch (strtolower($tokens[($stackPtr + 1)]['content'])) { - case 'includesystem' : - $included = strtolower($typeName); - break; - case 'includeasset' : - $included = strtolower($typeName).'assettype'; - break; - case 'includewidget' : - $included = strtolower($typeName).'widgettype'; - break; - default: - return; - } - - if ($included === strtolower($ownClass)) { - $error = "You do not need to include \"%s\" from within the system's own actions file"; - $data = array($ownClass); - $phpcsFile->addError($error, $stackPtr, 'NotRequired', $data); - } - - }//end process() - - - /** - * Determines the included class name from given token. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param array $tokens The array of file tokens. - * @param int $stackPtr The position in the tokens array of the - * potentially included class. - * - * @return string - */ - protected function getIncludedClassFromToken( - PHP_CodeSniffer_File $phpcsFile, - array $tokens, - $stackPtr - ) { - - return false; - - }//end getIncludedClassFromToken() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Channels/IncludeSystemSniff.php b/phpcs/CodeSniffer/Standards/MySource/Sniffs/Channels/IncludeSystemSniff.php deleted file mode 100644 index 05ea6f2..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Channels/IncludeSystemSniff.php +++ /dev/null @@ -1,335 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) { - $error = 'Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found'; - throw new PHP_CodeSniffer_Exception($error); -} - -/** - * Ensures that systems, asset types and libs are included before they are used. - * - * @category PHP - * @package PHP_CodeSniffer_MySource - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class MySource_Sniffs_Channels_IncludeSystemSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff -{ - - /** - * A list of classes that don't need to be included. - * - * @var array(string) - */ - private $_ignore = array( - 'self' => true, - 'static' => true, - 'parent' => true, - 'channels' => true, - 'basesystem' => true, - 'dal' => true, - 'init' => true, - 'pdo' => true, - 'util' => true, - 'ziparchive' => true, - 'phpunit_framework_assert' => true, - 'abstractmysourceunittest' => true, - 'abstractdatacleanunittest' => true, - 'exception' => true, - 'abstractwidgetwidgettype' => true, - 'domdocument' => true, - ); - - - /** - * Constructs a Squiz_Sniffs_Scope_MethodScopeSniff. - */ - public function __construct() - { - parent::__construct(array(T_FUNCTION), array(T_DOUBLE_COLON, T_EXTENDS), true); - - }//end __construct() - - - /** - * Processes the function tokens within the class. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param integer $stackPtr The position where the token was found. - * @param integer $currScope The current scope opener token. - * - * @return void - */ - protected function processTokenWithinScope( - PHP_CodeSniffer_File $phpcsFile, - $stackPtr, - $currScope - ) { - $tokens = $phpcsFile->getTokens(); - - // Determine the name of the class that the static function - // is being called on. - $classNameToken = $phpcsFile->findPrevious( - T_WHITESPACE, - ($stackPtr - 1), - null, - true - ); - - // Don't process class names represented by variables as this can be - // an inexact science. - if ($tokens[$classNameToken]['code'] === T_VARIABLE) { - return; - } - - $className = $tokens[$classNameToken]['content']; - if (isset($this->_ignore[strtolower($className)]) === true) { - return; - } - - $includedClasses = array(); - - $fileName = strtolower($phpcsFile->getFilename()); - $matches = array(); - if (preg_match('|/systems/(.*)/([^/]+)?actions.inc$|', $fileName, $matches) !== 0) { - // This is an actions file, which means we don't - // have to include the system in which it exists. - $includedClasses[$matches[2]] = true; - - // Or a system it implements. - $class = $phpcsFile->getCondition($stackPtr, T_CLASS); - $implements = $phpcsFile->findNext(T_IMPLEMENTS, $class, ($class + 10)); - if ($implements !== false) { - $implementsClass = $phpcsFile->findNext(T_STRING, $implements); - $implementsClassName = strtolower($tokens[$implementsClass]['content']); - if (substr($implementsClassName, -7) === 'actions') { - $includedClasses[substr($implementsClassName, 0, -7)] = true; - } - } - } - - // Go searching for includeSystem and includeAsset calls within this - // function, or the inclusion of .inc files, which - // would be library files. - for ($i = ($currScope + 1); $i < $stackPtr; $i++) { - $name = $this->getIncludedClassFromToken($phpcsFile, $tokens, $i); - if ($name !== false) { - $includedClasses[$name] = true; - // Special case for Widgets cause they are, well, special. - } else if (strtolower($tokens[$i]['content']) === 'includewidget') { - $typeName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, ($i + 1)); - $typeName = trim($tokens[$typeName]['content'], " '"); - $includedClasses[strtolower($typeName).'widgettype'] = true; - } - } - - // Now go searching for includeSystem, includeAsset or require/include - // calls outside our scope. If we are in a class, look outside the - // class. If we are not, look outside the function. - $condPtr = $currScope; - if ($phpcsFile->hasCondition($stackPtr, T_CLASS) === true) { - foreach ($tokens[$stackPtr]['conditions'] as $condPtr => $condType) { - if ($condType === T_CLASS) { - break; - } - } - } - - for ($i = 0; $i < $condPtr; $i++) { - // Skip other scopes. - if (isset($tokens[$i]['scope_closer']) === true) { - $i = $tokens[$i]['scope_closer']; - continue; - } - - $name = $this->getIncludedClassFromToken($phpcsFile, $tokens, $i); - if ($name !== false) { - $includedClasses[$name] = true; - } - } - - // If we are in a testing class, we might have also included - // some systems and classes in our setUp() method. - $setupFunction = null; - if ($phpcsFile->hasCondition($stackPtr, T_CLASS) === true) { - foreach ($tokens[$stackPtr]['conditions'] as $condPtr => $condType) { - if ($condType === T_CLASS) { - // Is this is a testing class? - $name = $phpcsFile->findNext(T_STRING, $condPtr); - $name = $tokens[$name]['content']; - if (substr($name, -8) === 'UnitTest') { - // Look for a method called setUp(). - $end = $tokens[$condPtr]['scope_closer']; - $function = $phpcsFile->findNext(T_FUNCTION, ($condPtr + 1), $end); - while ($function !== false) { - $name = $phpcsFile->findNext(T_STRING, $function); - if ($tokens[$name]['content'] === 'setUp') { - $setupFunction = $function; - break; - } - - $function = $phpcsFile->findNext(T_FUNCTION, ($function + 1), $end); - } - } - } - }//end foreach - }//end if - - if ($setupFunction !== null) { - $start = ($tokens[$setupFunction]['scope_opener'] + 1); - $end = $tokens[$setupFunction]['scope_closer']; - for ($i = $start; $i < $end; $i++) { - $name = $this->getIncludedClassFromToken($phpcsFile, $tokens, $i); - if ($name !== false) { - $includedClasses[$name] = true; - } - } - }//end if - - if (isset($includedClasses[strtolower($className)]) === false) { - $error = 'Static method called on non-included class or system "%s"; include system with Channels::includeSystem() or include class with require_once'; - $data = array($className); - $phpcsFile->addError($error, $stackPtr, 'NotIncludedCall', $data); - } - - }//end processTokenWithinScope() - - - /** - * Processes a token within the scope that this test is listening to. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * this token was found. - * - * @return void - */ - protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[$stackPtr]['code'] === T_EXTENDS) { - // Find the class name. - $classNameToken = $phpcsFile->findNext(T_STRING, ($stackPtr + 1)); - $className = $tokens[$classNameToken]['content']; - } else { - // Determine the name of the class that the static function - // is being called on. But don't process class names represented by - // variables as this can be an inexact science. - $classNameToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if ($tokens[$classNameToken]['code'] === T_VARIABLE) { - return; - } - - $className = $tokens[$classNameToken]['content']; - } - - // Some systems are always available. - if (isset($this->_ignore[strtolower($className)]) === true) { - return; - } - - $includedClasses = array(); - - $fileName = strtolower($phpcsFile->getFilename()); - $matches = array(); - if (preg_match('|/systems/([^/]+)/([^/]+)?actions.inc$|', $fileName, $matches) !== 0) { - // This is an actions file, which means we don't - // have to include the system in which it exists - // We know the system from the path. - $includedClasses[$matches[1]] = true; - } - - // Go searching for includeSystem, includeAsset or require/include - // calls outside our scope. - for ($i = 0; $i < $stackPtr; $i++) { - // Skip classes and functions as will we never get - // into their scopes when including this file, although - // we have a chance of getting into IF's, WHILE's etc. - if (($tokens[$i]['code'] === T_CLASS - || $tokens[$i]['code'] === T_INTERFACE - || $tokens[$i]['code'] === T_FUNCTION) - && isset($tokens[$i]['scope_closer']) === true - ) { - $i = $tokens[$i]['scope_closer']; - continue; - } - - $name = $this->getIncludedClassFromToken($phpcsFile, $tokens, $i); - if ($name !== false) { - $includedClasses[$name] = true; - // Special case for Widgets cause they are, well, special. - } else if (strtolower($tokens[$i]['content']) === 'includewidget') { - $typeName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, ($i + 1)); - $typeName = trim($tokens[$typeName]['content'], " '"); - $includedClasses[strtolower($typeName).'widgettype'] = true; - } - }//end for - - if (isset($includedClasses[strtolower($className)]) === false) { - if ($tokens[$stackPtr]['code'] === T_EXTENDS) { - $error = 'Class extends non-included class or system "%s"; include system with Channels::includeSystem() or include class with require_once'; - $data = array($className); - $phpcsFile->addError($error, $stackPtr, 'NotIncludedExtends', $data); - } else { - $error = 'Static method called on non-included class or system "%s"; include system with Channels::includeSystem() or include class with require_once'; - $data = array($className); - $phpcsFile->addError($error, $stackPtr, 'NotIncludedCall', $data); - } - } - - }//end processTokenOutsideScope() - - - /** - * Determines the included class name from given token. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param array $tokens The array of file tokens. - * @param int $stackPtr The position in the tokens array of the - * potentially included class. - * - * @return string - */ - protected function getIncludedClassFromToken( - PHP_CodeSniffer_File $phpcsFile, - array $tokens, - $stackPtr - ) { - if (strtolower($tokens[$stackPtr]['content']) === 'includesystem') { - $systemName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, ($stackPtr + 1)); - $systemName = trim($tokens[$systemName]['content'], " '"); - return strtolower($systemName); - } else if (strtolower($tokens[$stackPtr]['content']) === 'includeasset') { - $typeName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, ($stackPtr + 1)); - $typeName = trim($tokens[$typeName]['content'], " '"); - return strtolower($typeName).'assettype'; - } else if (isset(PHP_CodeSniffer_Tokens::$includeTokens[$tokens[$stackPtr]['code']]) === true) { - $filePath = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, ($stackPtr + 1)); - $filePath = $tokens[$filePath]['content']; - $filePath = trim($filePath, " '"); - $filePath = basename($filePath, '.inc'); - return strtolower($filePath); - } - - return false; - - }//end getIncludedClassFromToken() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Channels/UnusedSystemSniff.php b/phpcs/CodeSniffer/Standards/MySource/Sniffs/Channels/UnusedSystemSniff.php deleted file mode 100644 index 3a66509..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Channels/UnusedSystemSniff.php +++ /dev/null @@ -1,152 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Ensures that systems and asset types are used if they are included. - * - * @category PHP - * @package PHP_CodeSniffer_MySource - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class MySource_Sniffs_Channels_UnusedSystemSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_DOUBLE_COLON); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Check if this is a call to includeSystem, includeAsset or includeWidget. - $methodName = strtolower($tokens[($stackPtr + 1)]['content']); - if ($methodName === 'includesystem' - || $methodName === 'includeasset' - || $methodName === 'includewidget' - ) { - $systemName = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 3), null, true); - if ($systemName === false || $tokens[$systemName]['code'] !== T_CONSTANT_ENCAPSED_STRING) { - // Must be using a variable instead of a specific system name. - // We can't accurately check that. - return; - } - - $systemName = trim($tokens[$systemName]['content'], " '"); - } else { - return; - } - - if ($methodName === 'includeasset') { - $systemName .= 'assettype'; - } else if ($methodName === 'includewidget') { - $systemName .= 'widgettype'; - } - - $systemName = strtolower($systemName); - - // Now check if this system is used anywhere in this scope. - $level = $tokens[$stackPtr]['level']; - for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) { - if ($tokens[$i]['level'] < $level) { - // We have gone out of scope. - // If the original include was inside an IF statement that - // is checking if the system exists, check the outer scope - // as well. - if ($tokens[$stackPtr]['level'] === $level) { - // We are still in the base level, so this is the first - // time we have got here. - $conditions = array_keys($tokens[$stackPtr]['conditions']); - if (empty($conditions) === false) { - $cond = array_pop($conditions); - if ($tokens[$cond]['code'] === T_IF) { - $i = $tokens[$cond]['scope_closer']; - $level--; - continue; - } - } - } - - break; - }//end if - - if ($tokens[$i]['code'] !== T_DOUBLE_COLON - && $tokens[$i]['code'] !== T_EXTENDS - && $tokens[$i]['code'] !== T_IMPLEMENTS - ) { - continue; - } - - switch ($tokens[$i]['code']) { - case T_DOUBLE_COLON: - $usedName = strtolower($tokens[($i - 1)]['content']); - if ($usedName === $systemName) { - // The included system was used, so it is fine. - return; - } - break; - case T_EXTENDS: - $classNameToken = $phpcsFile->findNext(T_STRING, ($i + 1)); - $className = strtolower($tokens[$classNameToken]['content']); - if ($className === $systemName) { - // The included system was used, so it is fine. - return; - } - break; - case T_IMPLEMENTS: - $endImplements = $phpcsFile->findNext(array(T_EXTENDS, T_OPEN_CURLY_BRACKET), ($i + 1)); - for ($x = ($i + 1); $x < $endImplements; $x++) { - if ($tokens[$x]['code'] === T_STRING) { - $className = strtolower($tokens[$x]['content']); - if ($className === $systemName) { - // The included system was used, so it is fine. - return; - } - } - } - break; - }//end switch - }//end for - - // If we get to here, the system was not use. - $error = 'Included system "%s" is never used'; - $data = array($systemName); - $phpcsFile->addError($error, $stackPtr, 'Found', $data); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Commenting/FunctionCommentSniff.php b/phpcs/CodeSniffer/Standards/MySource/Sniffs/Commenting/FunctionCommentSniff.php deleted file mode 100644 index 50773d2..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Commenting/FunctionCommentSniff.php +++ /dev/null @@ -1,100 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('Squiz_Sniffs_Commenting_FunctionCommentSniff', true) === false) { - $error = 'Class Squiz_Sniffs_Commenting_FunctionCommentSniff not found'; - throw new PHP_CodeSniffer_Exception($error); -} - -/** - * Parses and verifies the doc comments for functions. - * - * Same as the Squiz standard, but adds support for API tags. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class MySource_Sniffs_Commenting_FunctionCommentSniff extends Squiz_Sniffs_Commenting_FunctionCommentSniff -{ - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - parent::process($phpcsFile, $stackPtr); - - $tokens = $phpcsFile->getTokens(); - $find = PHP_CodeSniffer_Tokens::$methodPrefixes; - $find[] = T_WHITESPACE; - - $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); - if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG) { - return; - } - - $commentStart = $tokens[$commentEnd]['comment_opener']; - $hasApiTag = false; - foreach ($tokens[$commentStart]['comment_tags'] as $tag) { - if ($tokens[$tag]['content'] === '@api') { - if ($hasApiTag === true) { - // We've come across an API tag already, which means - // we were not the first tag in the API list. - $error = 'The @api tag must come first in the @api tag list in a function comment'; - $phpcsFile->addError($error, $tag, 'ApiNotFirst'); - } - - $hasApiTag = true; - - // There needs to be a blank line before the @api tag. - $prev = $phpcsFile->findPrevious(array(T_DOC_COMMENT_STRING, T_DOC_COMMENT_TAG), ($tag - 1)); - if ($tokens[$prev]['line'] !== ($tokens[$tag]['line'] - 2)) { - $error = 'There must be one blank line before the @api tag in a function comment'; - $phpcsFile->addError($error, $tag, 'ApiSpacing'); - } - } else if (substr($tokens[$tag]['content'], 0, 5) === '@api-') { - $hasApiTag = true; - - $prev = $phpcsFile->findPrevious(array(T_DOC_COMMENT_STRING, T_DOC_COMMENT_TAG), ($tag - 1)); - if ($tokens[$prev]['line'] !== ($tokens[$tag]['line'] - 1)) { - $error = 'There must be no blank line before the @%s tag in a function comment'; - $data = array($tokens[$tag]['content']); - $phpcsFile->addError($error, $tag, 'ApiTagSpacing', $data); - } - }//end if - }//end foreach - - if ($hasApiTag === true && substr($tokens[$tag]['content'], 0, 4) !== '@api') { - // API tags must be the last tags in a function comment. - $error = 'The @api tags must be the last tags in a function comment'; - $phpcsFile->addError($error, $commentEnd, 'ApiNotLast'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Debug/DebugCodeSniff.php b/phpcs/CodeSniffer/Standards/MySource/Sniffs/Debug/DebugCodeSniff.php deleted file mode 100644 index 9b34ddc..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Debug/DebugCodeSniff.php +++ /dev/null @@ -1,66 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Warns about the use of debug code. - * - * @category PHP - * @package PHP_CodeSniffer_MySource - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class MySource_Sniffs_Debug_DebugCodeSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_DOUBLE_COLON); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $className = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if (strtolower($tokens[$className]['content']) === 'debug') { - $method = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - $error = 'Call to debug function Debug::%s() must be removed'; - $data = array($tokens[$method]['content']); - $phpcsFile->addError($error, $stackPtr, 'Found', $data); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Debug/FirebugConsoleSniff.php b/phpcs/CodeSniffer/Standards/MySource/Sniffs/Debug/FirebugConsoleSniff.php deleted file mode 100644 index b948b46..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Debug/FirebugConsoleSniff.php +++ /dev/null @@ -1,75 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Ensures that console is not used for function or var names. - * - * @category PHP - * @package PHP_CodeSniffer_MySource - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class MySource_Sniffs_Debug_FirebugConsoleSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('JS'); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_STRING, - T_PROPERTY, - T_LABEL, - T_OBJECT, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (strtolower($tokens[$stackPtr]['content']) === 'console') { - $error = 'Variables, functions and labels must not be named "console"; name may conflict with Firebug internal variable'; - $phpcsFile->addError($error, $stackPtr, 'ConflictFound'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Objects/AssignThisSniff.php b/phpcs/CodeSniffer/Standards/MySource/Sniffs/Objects/AssignThisSniff.php deleted file mode 100644 index afef9a2..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Objects/AssignThisSniff.php +++ /dev/null @@ -1,92 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Ensures this is not assigned to any other var but self. - * - * @category PHP - * @package PHP_CodeSniffer_MySource - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class MySource_Sniffs_Objects_AssignThisSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('JS'); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_THIS); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Ignore this.something and other uses of "this" that are not - // direct assignments. - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($tokens[$next]['code'] !== T_SEMICOLON) { - if ($tokens[$next]['line'] === $tokens[$stackPtr]['line']) { - return; - } - } - - // Something must be assigned to "this". - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if ($tokens[$prev]['code'] !== T_EQUAL) { - return; - } - - // A variable needs to be assigned to "this". - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($prev - 1), null, true); - if ($tokens[$prev]['code'] !== T_STRING) { - return; - } - - // We can only assign "this" to a var called "self". - if ($tokens[$prev]['content'] !== 'self' && $tokens[$prev]['content'] !== '_self') { - $error = 'Keyword "this" can only be assigned to a variable called "self" or "_self"'; - $phpcsFile->addError($error, $prev, 'NotSelf'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Objects/CreateWidgetTypeCallbackSniff.php b/phpcs/CodeSniffer/Standards/MySource/Sniffs/Objects/CreateWidgetTypeCallbackSniff.php deleted file mode 100644 index 7147e5c..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Objects/CreateWidgetTypeCallbackSniff.php +++ /dev/null @@ -1,227 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Ensures the create() method of widget types properly uses callbacks. - * - * @category PHP - * @package PHP_CodeSniffer_MySource - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class MySource_Sniffs_Objects_CreateWidgetTypeCallbackSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('JS'); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OBJECT); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $className = $phpcsFile->findPrevious(T_STRING, ($stackPtr - 1)); - if (substr(strtolower($tokens[$className]['content']), -10) !== 'widgettype') { - return; - } - - // Search for a create method. - $create = $phpcsFile->findNext(T_PROPERTY, $stackPtr, $tokens[$stackPtr]['bracket_closer'], null, 'create'); - if ($create === false) { - return; - } - - $function = $phpcsFile->findNext(array(T_WHITESPACE, T_COLON), ($create + 1), null, true); - if ($tokens[$function]['code'] !== T_FUNCTION - && $tokens[$function]['code'] !== T_CLOSURE - ) { - return; - } - - $start = ($tokens[$function]['scope_opener'] + 1); - $end = ($tokens[$function]['scope_closer'] - 1); - - // Check that the first argument is called "callback". - $arg = $phpcsFile->findNext(T_WHITESPACE, ($tokens[$function]['parenthesis_opener'] + 1), null, true); - if ($tokens[$arg]['content'] !== 'callback') { - $error = 'The first argument of the create() method of a widget type must be called "callback"'; - $phpcsFile->addError($error, $arg, 'FirstArgNotCallback'); - } - - /* - Look for return statements within the function. They cannot return - anything and must be preceded by the callback.call() line. The - callback itself must contain "self" or "this" as the first argument - and there needs to be a call to the callback function somewhere - in the create method. All calls to the callback function must be - followed by a return statement or the end of the method. - */ - - $foundCallback = false; - $passedCallback = false; - $nestedFunction = null; - for ($i = $start; $i <= $end; $i++) { - // Keep track of nested functions. - if ($nestedFunction !== null) { - if ($i === $nestedFunction) { - $nestedFunction = null; - continue; - } - } else if (($tokens[$i]['code'] === T_FUNCTION - || $tokens[$i]['code'] === T_CLOSURE) - && isset($tokens[$i]['scope_closer']) === true - ) { - $nestedFunction = $tokens[$i]['scope_closer']; - continue; - } - - if ($nestedFunction === null && $tokens[$i]['code'] === T_RETURN) { - // Make sure return statements are not returning anything. - if ($tokens[($i + 1)]['code'] !== T_SEMICOLON) { - $error = 'The create() method of a widget type must not return a value'; - $phpcsFile->addError($error, $i, 'ReturnValue'); - } - - continue; - } else if ($tokens[$i]['code'] !== T_STRING - || $tokens[$i]['content'] !== 'callback' - ) { - continue; - } - - // If this is the form "callback.call(" then it is a call - // to the callback function. - if ($tokens[($i + 1)]['code'] !== T_OBJECT_OPERATOR - || $tokens[($i + 2)]['content'] !== 'call' - || $tokens[($i + 3)]['code'] !== T_OPEN_PARENTHESIS - ) { - // One last chance; this might be the callback function - // being passed to another function, like this - // "this.init(something, callback, something)". - if (isset($tokens[$i]['nested_parenthesis']) === false) { - continue; - } - - // Just make sure those brackets dont belong to anyone, - // like an IF or FOR statement. - foreach ($tokens[$i]['nested_parenthesis'] as $bracket) { - if (isset($tokens[$bracket]['parenthesis_owner']) === true) { - continue(2); - } - } - - // Note that we use this endBracket down further when checking - // for a RETURN statement. - $endBracket = end($tokens[$i]['nested_parenthesis']); - $bracket = key($tokens[$i]['nested_parenthesis']); - - $prev = $phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, - ($bracket - 1), - null, - true - ); - - if ($tokens[$prev]['code'] !== T_STRING) { - // This is not a function passing the callback. - continue; - } - - $passedCallback = true; - }//end if - - $foundCallback = true; - - if ($passedCallback === false) { - // The first argument must be "this" or "self". - $arg = $phpcsFile->findNext(T_WHITESPACE, ($i + 4), null, true); - if ($tokens[$arg]['content'] !== 'this' - && $tokens[$arg]['content'] !== 'self' - ) { - $error = 'The first argument passed to the callback function must be "this" or "self"'; - $phpcsFile->addError($error, $arg, 'FirstArgNotSelf'); - } - } - - // Now it must be followed by a return statement or the end of the function. - if ($passedCallback === false) { - $endBracket = $tokens[($i + 3)]['parenthesis_closer']; - } - - for ($next = $endBracket; $next <= $end; $next++) { - // Skip whitespace so we find the next content after the call. - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$next]['code']]) === true) { - continue; - } - - // Skip closing braces like END IF because it is not executable code. - if ($tokens[$next]['code'] === T_CLOSE_CURLY_BRACKET) { - continue; - } - - // We don't care about anything on the current line, like a - // semicolon. It doesn't matter if there are other statements on the - // line because another sniff will check for those. - if ($tokens[$next]['line'] === $tokens[$endBracket]['line']) { - continue; - } - - break; - } - - if ($next !== $tokens[$function]['scope_closer'] - && $tokens[$next]['code'] !== T_RETURN - ) { - $error = 'The call to the callback function must be followed by a return statement if it is not the last statement in the create() method'; - $phpcsFile->addError($error, $i, 'NoReturn'); - } - }//end for - - if ($foundCallback === false) { - $error = 'The create() method of a widget type must call the callback function'; - $phpcsFile->addError($error, $create, 'CallbackNotCalled'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Objects/DisallowNewWidgetSniff.php b/phpcs/CodeSniffer/Standards/MySource/Sniffs/Objects/DisallowNewWidgetSniff.php deleted file mode 100644 index c149954..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Objects/DisallowNewWidgetSniff.php +++ /dev/null @@ -1,70 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Ensures that widgets are not manually created. - * - * @category PHP - * @package PHP_CodeSniffer_MySource - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class MySource_Sniffs_Objects_DisallowNewWidgetSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_NEW); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $className = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($tokens[$className]['code'] !== T_STRING) { - return; - } - - if (substr(strtolower($tokens[$className]['content']), -10) === 'widgettype') { - $widgetType = substr($tokens[$className]['content'], 0, -10); - $error = 'Manual creation of widget objects is banned; use Widget::getWidget(\'%s\'); instead'; - $data = array($widgetType); - $phpcsFile->addError($error, $stackPtr, 'Found', $data); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/Sniffs/PHP/AjaxNullComparisonSniff.php b/phpcs/CodeSniffer/Standards/MySource/Sniffs/PHP/AjaxNullComparisonSniff.php deleted file mode 100644 index 405dfa2..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/Sniffs/PHP/AjaxNullComparisonSniff.php +++ /dev/null @@ -1,109 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Ensures that values submitted via JS are not compared to NULL. - * - * With jQuery 1.8, the behaviour of ajax requests changed so that null values are - * submitted as null= instead of null=null. - * - * @category PHP - * @package PHP_CodeSniffer_MySource - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class MySource_Sniffs_PHP_AjaxNullComparisonSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_FUNCTION); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Make sure it is an API function. We know this by the doc comment. - $commentEnd = $phpcsFile->findPrevious(T_DOC_COMMENT_CLOSE_TAG, $stackPtr); - $commentStart = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, ($commentEnd - 1)); - $comment = $phpcsFile->getTokensAsString($commentStart, ($commentEnd - $commentStart)); - if (strpos($comment, '* @api') === false) { - return; - } - - // Find all the vars passed in as we are only interested in comparisons - // to NULL for these specific variables. - $foundVars = array(); - $open = $tokens[$stackPtr]['parenthesis_opener']; - $close = $tokens[$stackPtr]['parenthesis_closer']; - for ($i = ($open + 1); $i < $close; $i++) { - if ($tokens[$i]['code'] === T_VARIABLE) { - $foundVars[$tokens[$i]['content']] = true; - } - } - - if (empty($foundVars) === true) { - return; - } - - $start = $tokens[$stackPtr]['scope_opener']; - $end = $tokens[$stackPtr]['scope_closer']; - for ($i = ($start + 1); $i < $end; $i++) { - if ($tokens[$i]['code'] !== T_VARIABLE - || isset($foundVars[$tokens[$i]['content']]) === false - ) { - continue; - } - - $operator = $phpcsFile->findNext(T_WHITESPACE, ($i + 1), null, true); - if ($tokens[$operator]['code'] !== T_IS_IDENTICAL - && $tokens[$operator]['code'] !== T_IS_NOT_IDENTICAL - ) { - continue; - } - - $nullValue = $phpcsFile->findNext(T_WHITESPACE, ($operator + 1), null, true); - if ($tokens[$nullValue]['code'] !== T_NULL) { - continue; - } - - $error = 'Values submitted via Ajax requests should not be compared directly to NULL; use empty() instead'; - $phpcsFile->addWarning($error, $nullValue, 'Found'); - }//end for - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/Sniffs/PHP/EvalObjectFactorySniff.php b/phpcs/CodeSniffer/Standards/MySource/Sniffs/PHP/EvalObjectFactorySniff.php deleted file mode 100644 index 945f571..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/Sniffs/PHP/EvalObjectFactorySniff.php +++ /dev/null @@ -1,124 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Ensures that eval() is not used to create objects. - * - * @category PHP - * @package PHP_CodeSniffer_MySource - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class MySource_Sniffs_PHP_EvalObjectFactorySniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_EVAL); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - /* - We need to find all strings that will be in the eval - to determine if the "new" keyword is being used. - */ - - $openBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($stackPtr + 1)); - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; - - $strings = array(); - $vars = array(); - - for ($i = ($openBracket + 1); $i < $closeBracket; $i++) { - if (isset(PHP_CodeSniffer_Tokens::$stringTokens[$tokens[$i]['code']]) === true) { - $strings[$i] = $tokens[$i]['content']; - } else if ($tokens[$i]['code'] === T_VARIABLE) { - $vars[$i] = $tokens[$i]['content']; - } - } - - /* - We now have some variables that we need to expand into - the strings that were assigned to them, if any. - */ - - foreach ($vars as $varPtr => $varName) { - while (($prev = $phpcsFile->findPrevious(T_VARIABLE, ($varPtr - 1))) !== false) { - // Make sure this is an assignment of the variable. That means - // it will be the first thing on the line. - $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, ($prev - 1), null, true); - if ($tokens[$prevContent]['line'] === $tokens[$prev]['line']) { - $varPtr = $prevContent; - continue; - } - - if ($tokens[$prev]['content'] !== $varName) { - // This variable has a different name. - $varPtr = $prevContent; - continue; - } - - // We found one. - break; - }//end while - - if ($prev !== false) { - // Find all strings on the line. - $lineEnd = $phpcsFile->findNext(T_SEMICOLON, ($prev + 1)); - for ($i = ($prev + 1); $i < $lineEnd; $i++) { - if (isset(PHP_CodeSniffer_Tokens::$stringTokens[$tokens[$i]['code']]) === true) { - $strings[$i] = $tokens[$i]['content']; - } - } - } - }//end foreach - - foreach ($strings as $string) { - // If the string has "new" in it, it is not allowed. - // We don't bother checking if the word "new" is echo'd - // because that is unlikely to happen. We assume the use - // of "new" is for object instantiation. - if (strstr($string, ' new ') !== false) { - $error = 'Do not use eval() to create objects dynamically; use reflection instead'; - $phpcsFile->addWarning($error, $stackPtr, 'Found'); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/Sniffs/PHP/GetRequestDataSniff.php b/phpcs/CodeSniffer/Standards/MySource/Sniffs/PHP/GetRequestDataSniff.php deleted file mode 100644 index 8ff8979..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/Sniffs/PHP/GetRequestDataSniff.php +++ /dev/null @@ -1,117 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Ensures that getRequestData() is used to access super globals. - * - * @category PHP - * @package PHP_CodeSniffer_MySource - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class MySource_Sniffs_PHP_GetRequestDataSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_VARIABLE); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $varName = $tokens[$stackPtr]['content']; - if ($varName !== '$_REQUEST' - && $varName !== '$_GET' - && $varName !== '$_POST' - && $varName !== '$_FILES' - ) { - return; - } - - // The only place these super globals can be accessed directly is - // in the getRequestData() method of the Security class. - $inClass = false; - foreach ($tokens[$stackPtr]['conditions'] as $i => $type) { - if ($tokens[$i]['code'] === T_CLASS) { - $className = $phpcsFile->findNext(T_STRING, $i); - $className = $tokens[$className]['content']; - if (strtolower($className) === 'security') { - $inClass = true; - } else { - // We don't have nested classes. - break; - } - } else if ($inClass === true && $tokens[$i]['code'] === T_FUNCTION) { - $funcName = $phpcsFile->findNext(T_STRING, $i); - $funcName = $tokens[$funcName]['content']; - if (strtolower($funcName) === 'getrequestdata') { - // This is valid. - return; - } else { - // We don't have nested functions. - break; - } - }//end if - }//end foreach - - // If we get to here, the super global was used incorrectly. - // First find out how it is being used. - $globalName = strtolower(substr($varName, 2)); - $usedVar = ''; - - $openBracket = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($tokens[$openBracket]['code'] === T_OPEN_SQUARE_BRACKET) { - $closeBracket = $tokens[$openBracket]['bracket_closer']; - $usedVar = $phpcsFile->getTokensAsString(($openBracket + 1), ($closeBracket - $openBracket - 1)); - } - - $type = 'SuperglobalAccessed'; - $error = 'The %s super global must not be accessed directly; use Security::getRequestData('; - $data = array($varName); - if ($usedVar !== '') { - $type .= 'WithVar'; - $error .= '%s, \'%s\''; - $data[] = $usedVar; - $data[] = $globalName; - } - - $error .= ') instead'; - $phpcsFile->addError($error, $stackPtr, $type, $data); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/Sniffs/PHP/ReturnFunctionValueSniff.php b/phpcs/CodeSniffer/Standards/MySource/Sniffs/PHP/ReturnFunctionValueSniff.php deleted file mode 100644 index 458150c..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/Sniffs/PHP/ReturnFunctionValueSniff.php +++ /dev/null @@ -1,74 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Warns when function values are returned directly. - * - * @category PHP - * @package PHP_CodeSniffer_MySource - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class MySource_Sniffs_PHP_ReturnFunctionValueSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_RETURN); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $functionName = $phpcsFile->findNext(T_STRING, ($stackPtr + 1), null, false, null, true); - - while ($functionName !== false) { - // Check if this is really a function. - $bracket = $phpcsFile->findNext(T_WHITESPACE, ($functionName + 1), null, true); - if ($tokens[$bracket]['code'] !== T_OPEN_PARENTHESIS) { - // Not a function call. - $functionName = $phpcsFile->findNext(T_STRING, ($functionName + 1), null, false, null, true); - continue; - } - - $error = 'The result of a function call should be assigned to a variable before being returned'; - $phpcsFile->addWarning($error, $stackPtr, 'NotAssigned'); - break; - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Strings/JoinStringsSniff.php b/phpcs/CodeSniffer/Standards/MySource/Sniffs/Strings/JoinStringsSniff.php deleted file mode 100644 index 377bfb4..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/Sniffs/Strings/JoinStringsSniff.php +++ /dev/null @@ -1,86 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Ensures that strings are not joined using array.join(). - * - * @category PHP - * @package PHP_CodeSniffer_MySource - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class MySource_Sniffs_Strings_JoinStringsSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('JS'); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_STRING); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param integer $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[$stackPtr]['content'] !== 'join') { - return; - } - - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); - if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR) { - return; - } - - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($prev - 1), null, true); - if ($tokens[$prev]['code'] === T_CLOSE_SQUARE_BRACKET) { - $opener = $tokens[$prev]['bracket_opener']; - if ($tokens[($opener - 1)]['code'] !== T_STRING) { - // This means the array is declared inline, like x = [a,b,c].join() - // and not elsewhere, like x = y[a].join() - // The first is not allowed while the second is. - $error = 'Joining strings using inline arrays is not allowed; use the + operator instead'; - $phpcsFile->addError($error, $stackPtr, 'ArrayNotAllowed'); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/MySource/ruleset.xml b/phpcs/CodeSniffer/Standards/MySource/ruleset.xml deleted file mode 100644 index fe7ae66..0000000 --- a/phpcs/CodeSniffer/Standards/MySource/ruleset.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - The MySource coding standard builds on the Squiz coding standard. Currently used for MySource Mini development. - - */Tests/* - */Oven/* - */data/* - */jquery.js - */jquery.*.js - */viper/* - DALConf.inc - - - - - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/Classes/ClassDeclarationStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/Classes/ClassDeclarationStandard.xml deleted file mode 100644 index b5d53fd..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/Classes/ClassDeclarationStandard.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - { -} - ]]> - - - { -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/Commenting/ClassCommentStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/Commenting/ClassCommentStandard.xml deleted file mode 100644 index fe81620..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/Commenting/ClassCommentStandard.xml +++ /dev/null @@ -1,177 +0,0 @@ - - - - - - - /** - * The Foo class. - */ -class Foo -{ -} - ]]> - - - - - - - - /** - * The Foo class. - */ -class Foo -{ -} - ]]> - - - - - - - - /** - * The Foo class. - */ -class Foo -{ -} - ]]> - - - /** - * The Foo class. - */ - -class Foo -{ -} - ]]> - - - - - The Foo class. - */ -class Foo -{ -} - ]]> - - - The Foo class. - */ -class Foo -{ -} - ]]> - - - - - - * A helper for the Bar class. - * - * @see Bar - */ -class Foo -{ -} - ]]> - - - - * - * A helper for the Bar class. - * - * - * @see Bar - */ -class Foo -{ -} - ]]> - - - - - - * @see Bar - */ -class Foo -{ -} - ]]> - - - - * - * @see Bar - */ -class Foo -{ -} - ]]> - - - - - Release: 1.0 - */ -class Foo -{ -} - ]]> - - - 1.0 - */ -class Foo -{ -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/Commenting/FileCommentStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/Commenting/FileCommentStandard.xml deleted file mode 100644 index eef0b4e..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/Commenting/FileCommentStandard.xml +++ /dev/null @@ -1,286 +0,0 @@ - - - - - - - /** - * Short description here. - * - * PHP version 5 - * - * @category Foo - * @package Foo_Helpers - * @author Marty McFly - * @copyright 2013-2014 Foo Inc. - * @license MIT License - * @link http://example.com - */ - ]]> - - - - ]]> - - - - - Short description here. - * - * PHP version 5 - * - * @category Foo - * @package Foo_Helpers - * @author Marty McFly - * @copyright 2013-2014 Foo Inc. - * @license MIT License - * @link http://example.com - */ - ]]> - - - - * Short description here. - * - * PHP version 5 - * - * @category Foo - * @package Foo_Helpers - * @author Marty McFly - * @copyright 2013-2014 Foo Inc. - * @license MIT License - * @link http://example.com - */ - ]]> - - - - - - * PHP version 5 - * - * @category Foo - * @package Foo_Helpers - * @author Marty McFly - * @copyright 2013-2014 Foo Inc. - * @license MIT License - * @link http://example.com - */ - ]]> - - - - * - * PHP version 5 - * - * - * @category Foo - * @package Foo_Helpers - * @author Marty McFly - * @copyright 2013-2014 Foo Inc. - * @license MIT License - * @link http://example.com - */ - ]]> - - - - - - * @category Foo - * @package Foo_Helpers - * @author Marty McFly - * @copyright 2013-2014 Foo Inc. - * @license MIT License - * @link http://example.com - */ - ]]> - - - - * - * @category Foo - * @package Foo_Helpers - * @author Marty McFly - * @copyright 2013-2014 Foo Inc. - * @license MIT License - * @link http://example.com - */ - ]]> - - - - - @category Foo - * @package Foo_Helpers - * @author Marty McFly - * @copyright 2013-2014 Foo Inc. - * @license MIT License - * @link http://example.com - */ - ]]> - - - - - - - - @category Foo - * @package Foo_Helpers - * @author Marty McFly - * @copyright 2013-2014 Foo Inc. - * @license MIT License - * @link http://example.com - */ - ]]> - - - @category Foo - * @category Bar - * @package Foo_Helpers - * @author Marty McFly - * @copyright 2013-2014 Foo Inc. - * @license MIT License - * @link http://example.com - */ - ]]> - - - - - PHP version 5 - * - * @category Foo - * @package Foo_Helpers - * @author Marty McFly - * @copyright 2013-2014 Foo Inc. - * @license MIT License - * @link http://example.com - */ - ]]> - - - @package Foo_Helpers - * @category Foo - * @author Marty McFly - * @copyright 2013-2014 Foo Inc. - * @license MIT License - * @link http://example.com - */ - ]]> - - - - - - * @copyright 2013-2014 Foo Inc. - * @license MIT License - * @link http://example.com - */ - ]]> - - - - * @copyright 2013-2014 Foo Inc. - * @license MIT License - * @link http://example.com - */ - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/Commenting/FunctionCommentStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/Commenting/FunctionCommentStandard.xml deleted file mode 100644 index 621649f..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/Commenting/FunctionCommentStandard.xml +++ /dev/null @@ -1,230 +0,0 @@ - - - - - - - /** - * Short description here. - * - * @return void - */ - function foo() - { - } - ]]> - - - - - - - - Short description here. - * - * @return void - */ - function foo() - { - } - ]]> - - - - * Short description here. - * - * @return void - */ - function foo() - { - } - ]]> - - - - - - * Long description here. - * - * @return void - */ - function foo() - { - } - ]]> - - - - * - * Long description here. - * - * - * @return void - */ - function foo() - { - } - ]]> - - - - - - * @return void - */ - function foo() - { - } - ]]> - - - - * - * @return void - */ - function foo() - { - } - ]]> - - - - - FooException - */ - function foo() - { - } - ]]> - - - @throws - */ - function foo() - { - } - ]]> - - - - - @return void - */ - function foo() - { - } - ]]> - - - - - - - - $foo Foo parameter - * @param string $bar Bar parameter - * @return void - */ - function foo($foo, $bar) - { - } - ]]> - - - $qux Bar parameter - * @return void - */ - function foo($foo, $bar) - { - } - ]]> - - - - - $foo Foo parameter - * @param string $bar Bar parameter - * @return void - */ - function foo($foo, $bar) - { - } - ]]> - - - $bar Bar parameter - * @param string $foo Foo parameter - * @return void - */ - function foo($foo, $bar) - { - } - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/Commenting/InlineCommentStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/Commenting/InlineCommentStandard.xml deleted file mode 100644 index 53056e2..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/Commenting/InlineCommentStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - // A comment. - ]]> - - - # A comment. - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/ControlStructures/ControlSignatureStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/ControlStructures/ControlSignatureStandard.xml deleted file mode 100644 index ce430fb..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/ControlStructures/ControlSignatureStandard.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - ($foo) { -} - ]]> - - - ($foo){ -} - ]]> - - - - - { -} - ]]> - - - { -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/ControlStructures/MultiLineConditionStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/ControlStructures/MultiLineConditionStandard.xml deleted file mode 100644 index 96d451d..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/ControlStructures/MultiLineConditionStandard.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - && $bar -) { -} - ]]> - - - && $bar -) { -} - ]]> - - - - - && $bar -) { -} - ]]> - - - && - $bar -) { -} - ]]> - - - - - ) { -} - ]]> - - - ) { -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/Files/IncludingFileStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/Files/IncludingFileStandard.xml deleted file mode 100644 index 6d115be..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/Files/IncludingFileStandard.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - require_once. Anywhere you are conditionally including a class file (for example, factory methods), use include_once. Either of these will ensure that class files are included only once. They share the same file list, so you don't need to worry about mixing them - a file included with require_once will not be included again by include_once. - ]]> - - - include_once and require_once are statements, not functions. Parentheses should not surround the subject filename. - ]]> - - - - - - - ('PHP/CodeSniffer.php'); - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/Files/LineLengthStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/Files/LineLengthStandard.xml deleted file mode 100644 index e4911ef..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/Files/LineLengthStandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/Formatting/MultiLineAssignmentStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/Formatting/MultiLineAssignmentStandard.xml deleted file mode 100644 index e825c55..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/Formatting/MultiLineAssignmentStandard.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - = $bar; - ]]> - - - = - $bar; - ]]> - - - - - = $bar; - ]]> - - - = $bar; - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/Functions/FunctionCallSignatureStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/Functions/FunctionCallSignatureStandard.xml deleted file mode 100644 index f874227..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/Functions/FunctionCallSignatureStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - ( $bar, $baz, $quux ) ; - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/Functions/FunctionDeclarationStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/Functions/FunctionDeclarationStandard.xml deleted file mode 100644 index ced9ae2..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/Functions/FunctionDeclarationStandard.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - () use ($bar) { -}; - ]]> - - - ()use($bar){ -}; - ]]> - - - - - $bar, - $baz -) { -}; - ]]> - - - $bar, -$baz) -{ -}; - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/Functions/ValidDefaultValueStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/Functions/ValidDefaultValueStandard.xml deleted file mode 100644 index 56196cb..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/Functions/ValidDefaultValueStandard.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - $persistent = false) -{ - ... -} - ]]> - - - $persistent = false, $dsn) -{ - ... -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/NamingConventions/ValidClassNameStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/NamingConventions/ValidClassNameStandard.xml deleted file mode 100644 index d160879..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/NamingConventions/ValidClassNameStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/NamingConventions/ValidFunctionNameStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/NamingConventions/ValidFunctionNameStandard.xml deleted file mode 100644 index 60841dd..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/NamingConventions/ValidFunctionNameStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/NamingConventions/ValidVariableNameStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/NamingConventions/ValidVariableNameStandard.xml deleted file mode 100644 index 4c707bd..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/NamingConventions/ValidVariableNameStandard.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - publicVar; - protected $protectedVar; - private $_privateVar; -} - ]]> - - - _publicVar; - protected $_protectedVar; - private $privateVar; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/WhiteSpace/ObjectOperatorIndentStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/WhiteSpace/ObjectOperatorIndentStandard.xml deleted file mode 100644 index 9dee905..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/WhiteSpace/ObjectOperatorIndentStandard.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - ->bar() - ->baz(); - ]]> - - - -> - bar()-> - baz(); - ]]> - - - - - ->bar() - ->baz(); - ]]> - - - ->bar() -->baz(); - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/WhiteSpace/ScopeClosingBraceStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/WhiteSpace/ScopeClosingBraceStandard.xml deleted file mode 100644 index c8d6e27..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/WhiteSpace/ScopeClosingBraceStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - } - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Docs/WhiteSpace/ScopeIndentStandard.xml b/phpcs/CodeSniffer/Standards/PEAR/Docs/WhiteSpace/ScopeIndentStandard.xml deleted file mode 100644 index fafa07a..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Docs/WhiteSpace/ScopeIndentStandard.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - if ($test) { - $var = 1; - } -} - ]]> - - - if ($test) { -$var = 1; -} -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Classes/ClassDeclarationSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Classes/ClassDeclarationSniff.php deleted file mode 100644 index cf39c26..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Classes/ClassDeclarationSniff.php +++ /dev/null @@ -1,164 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Class Declaration Test. - * - * Checks the declaration of the class is correct. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_Classes_ClassDeclarationSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * The number of spaces code should be indented. - * - * @var int - */ - public $indent = 4; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_CLASS, - T_INTERFACE, - T_TRAIT, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param integer $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $errorData = array(strtolower($tokens[$stackPtr]['content'])); - - if (isset($tokens[$stackPtr]['scope_opener']) === false) { - $error = 'Possible parse error: %s missing opening or closing brace'; - $phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $errorData); - return; - } - - $curlyBrace = $tokens[$stackPtr]['scope_opener']; - $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($curlyBrace - 1), $stackPtr, true); - $classLine = $tokens[$lastContent]['line']; - $braceLine = $tokens[$curlyBrace]['line']; - if ($braceLine === $classLine) { - $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'same line'); - $error = 'Opening brace of a %s must be on the line after the definition'; - $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceNewLine', $errorData); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - if ($tokens[($curlyBrace - 1)]['code'] === T_WHITESPACE) { - $phpcsFile->fixer->replaceToken(($curlyBrace - 1), ''); - } - - $phpcsFile->fixer->addNewlineBefore($curlyBrace); - $phpcsFile->fixer->endChangeset(); - } - - return; - } else { - $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'new line'); - - if ($braceLine > ($classLine + 1)) { - $error = 'Opening brace of a %s must be on the line following the %s declaration; found %s line(s)'; - $data = array( - $tokens[$stackPtr]['content'], - $tokens[$stackPtr]['content'], - ($braceLine - $classLine - 1), - ); - $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceWrongLine', $data); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($curlyBrace - 1); $i > $lastContent; $i--) { - if ($tokens[$i]['line'] === ($tokens[$curlyBrace]['line'] + 1)) { - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - - return; - }//end if - }//end if - - if ($tokens[($curlyBrace + 1)]['content'] !== $phpcsFile->eolChar) { - $error = 'Opening %s brace must be on a line by itself'; - $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceNotAlone', $errorData); - if ($fix === true) { - $phpcsFile->fixer->addNewline($curlyBrace); - } - } - - if ($tokens[($curlyBrace - 1)]['code'] === T_WHITESPACE) { - $prevContent = $tokens[($curlyBrace - 1)]['content']; - if ($prevContent === $phpcsFile->eolChar) { - $spaces = 0; - } else { - $blankSpace = substr($prevContent, strpos($prevContent, $phpcsFile->eolChar)); - $spaces = strlen($blankSpace); - } - - $expected = ($tokens[$stackPtr]['level'] * $this->indent); - if ($spaces !== $expected) { - $error = 'Expected %s spaces before opening brace; %s found'; - $data = array( - $expected, - $spaces, - ); - - $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'SpaceBeforeBrace', $data); - if ($fix === true) { - $indent = str_repeat(' ', $expected); - if ($spaces === 0) { - $phpcsFile->fixer->addContentBefore($curlyBrace, $indent); - } else { - $phpcsFile->fixer->replaceToken(($curlyBrace - 1), $indent); - } - } - } - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Commenting/ClassCommentSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Commenting/ClassCommentSniff.php deleted file mode 100644 index 2157d1a..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Commenting/ClassCommentSniff.php +++ /dev/null @@ -1,117 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Parses and verifies the doc comments for classes. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_Commenting_ClassCommentSniff extends PEAR_Sniffs_Commenting_FileCommentSniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_CLASS, - T_INTERFACE, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $this->currentFile = $phpcsFile; - - $tokens = $phpcsFile->getTokens(); - $type = strtolower($tokens[$stackPtr]['content']); - $errorData = array($type); - - $find = PHP_CodeSniffer_Tokens::$methodPrefixes; - $find[] = T_WHITESPACE; - - $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); - if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG - && $tokens[$commentEnd]['code'] !== T_COMMENT - ) { - $phpcsFile->addError('Missing class doc comment', $stackPtr, 'Missing'); - $phpcsFile->recordMetric($stackPtr, 'Class has doc comment', 'no'); - return; - } - - $phpcsFile->recordMetric($stackPtr, 'Class has doc comment', 'yes'); - - if ($tokens[$commentEnd]['code'] === T_COMMENT) { - $phpcsFile->addError('You must use "/**" style comments for a class comment', $stackPtr, 'WrongStyle'); - return; - } - - // Check each tag. - $this->processTags($phpcsFile, $stackPtr, $tokens[$commentEnd]['comment_opener']); - - }//end process() - - - /** - * Process the version tag. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tags The tokens for these tags. - * - * @return void - */ - protected function processVersion(PHP_CodeSniffer_File $phpcsFile, array $tags) - { - $tokens = $phpcsFile->getTokens(); - foreach ($tags as $tag) { - if ($tokens[($tag + 2)]['code'] !== T_DOC_COMMENT_STRING) { - // No content. - continue; - } - - $content = $tokens[($tag + 2)]['content']; - if ((strstr($content, 'Release:') === false)) { - $error = 'Invalid version "%s" in doc comment; consider "Release: " instead'; - $data = array($content); - $phpcsFile->addWarning($error, $tag, 'InvalidVersion', $data); - } - } - - }//end processVersion() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php deleted file mode 100644 index 502e432..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php +++ /dev/null @@ -1,582 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Parses and verifies the doc comments for files. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -class PEAR_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * Tags in correct order and related info. - * - * @var array - */ - protected $tags = array( - '@category' => array( - 'required' => true, - 'allow_multiple' => false, - ), - '@package' => array( - 'required' => true, - 'allow_multiple' => false, - ), - '@subpackage' => array( - 'required' => false, - 'allow_multiple' => false, - ), - '@author' => array( - 'required' => true, - 'allow_multiple' => true, - ), - '@copyright' => array( - 'required' => false, - 'allow_multiple' => true, - ), - '@license' => array( - 'required' => true, - 'allow_multiple' => false, - ), - '@version' => array( - 'required' => false, - 'allow_multiple' => false, - ), - '@link' => array( - 'required' => true, - 'allow_multiple' => true, - ), - '@see' => array( - 'required' => false, - 'allow_multiple' => true, - ), - '@since' => array( - 'required' => false, - 'allow_multiple' => false, - ), - '@deprecated' => array( - 'required' => false, - 'allow_multiple' => false, - ), - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return int - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Find the next non whitespace token. - $commentStart = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - - // Allow declare() statements at the top of the file. - if ($tokens[$commentStart]['code'] === T_DECLARE) { - $semicolon = $phpcsFile->findNext(T_SEMICOLON, ($commentStart + 1)); - $commentStart = $phpcsFile->findNext(T_WHITESPACE, ($semicolon + 1), null, true); - } - - // Ignore vim header. - if ($tokens[$commentStart]['code'] === T_COMMENT) { - if (strstr($tokens[$commentStart]['content'], 'vim:') !== false) { - $commentStart = $phpcsFile->findNext( - T_WHITESPACE, - ($commentStart + 1), - null, - true - ); - } - } - - $errorToken = ($stackPtr + 1); - if (isset($tokens[$errorToken]) === false) { - $errorToken--; - } - - if ($tokens[$commentStart]['code'] === T_CLOSE_TAG) { - // We are only interested if this is the first open tag. - return ($phpcsFile->numTokens + 1); - } else if ($tokens[$commentStart]['code'] === T_COMMENT) { - $error = 'You must use "/**" style comments for a file comment'; - $phpcsFile->addError($error, $errorToken, 'WrongStyle'); - $phpcsFile->recordMetric($stackPtr, 'File has doc comment', 'yes'); - return ($phpcsFile->numTokens + 1); - } else if ($commentStart === false - || $tokens[$commentStart]['code'] !== T_DOC_COMMENT_OPEN_TAG - ) { - $phpcsFile->addError('Missing file doc comment', $errorToken, 'Missing'); - $phpcsFile->recordMetric($stackPtr, 'File has doc comment', 'no'); - return ($phpcsFile->numTokens + 1); - } - - $commentEnd = $tokens[$commentStart]['comment_closer']; - - $nextToken = $phpcsFile->findNext( - T_WHITESPACE, - ($commentEnd + 1), - null, - true - ); - - $ignore = array( - T_CLASS, - T_INTERFACE, - T_TRAIT, - T_FUNCTION, - T_CLOSURE, - T_PUBLIC, - T_PRIVATE, - T_PROTECTED, - T_FINAL, - T_STATIC, - T_ABSTRACT, - T_CONST, - T_PROPERTY, - ); - - if (in_array($tokens[$nextToken]['code'], $ignore) === true) { - $phpcsFile->addError('Missing file doc comment', $stackPtr, 'Missing'); - $phpcsFile->recordMetric($stackPtr, 'File has doc comment', 'no'); - return ($phpcsFile->numTokens + 1); - } - - $phpcsFile->recordMetric($stackPtr, 'File has doc comment', 'yes'); - - // Check the PHP Version, which should be in some text before the first tag. - $found = false; - for ($i = ($commentStart + 1); $i < $commentEnd; $i++) { - if ($tokens[$i]['code'] === T_DOC_COMMENT_TAG) { - break; - } else if ($tokens[$i]['code'] === T_DOC_COMMENT_STRING - && strstr(strtolower($tokens[$i]['content']), 'php version') !== false - ) { - $found = true; - break; - } - } - - if ($found === false) { - $error = 'PHP version not specified'; - $phpcsFile->addWarning($error, $commentEnd, 'MissingVersion'); - } - - // Check each tag. - $this->processTags($phpcsFile, $stackPtr, $commentStart); - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - - /** - * Processes each required or optional tag. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $commentStart Position in the stack where the comment started. - * - * @return void - */ - protected function processTags(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) - { - $tokens = $phpcsFile->getTokens(); - - if (get_class($this) === 'PEAR_Sniffs_Commenting_FileCommentSniff') { - $docBlock = 'file'; - } else { - $docBlock = 'class'; - } - - $commentEnd = $tokens[$commentStart]['comment_closer']; - - $foundTags = array(); - $tagTokens = array(); - foreach ($tokens[$commentStart]['comment_tags'] as $tag) { - $name = $tokens[$tag]['content']; - if (isset($this->tags[$name]) === false) { - continue; - } - - if ($this->tags[$name]['allow_multiple'] === false && isset($tagTokens[$name]) === true) { - $error = 'Only one %s tag is allowed in a %s comment'; - $data = array( - $name, - $docBlock, - ); - $phpcsFile->addError($error, $tag, 'Duplicate'.ucfirst(substr($name, 1)).'Tag', $data); - } - - $foundTags[] = $name; - $tagTokens[$name][] = $tag; - - $string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $tag, $commentEnd); - if ($string === false || $tokens[$string]['line'] !== $tokens[$tag]['line']) { - $error = 'Content missing for %s tag in %s comment'; - $data = array( - $name, - $docBlock, - ); - $phpcsFile->addError($error, $tag, 'Empty'.ucfirst(substr($name, 1)).'Tag', $data); - continue; - } - }//end foreach - - // Check if the tags are in the correct position. - $pos = 0; - foreach ($this->tags as $tag => $tagData) { - if (isset($tagTokens[$tag]) === false) { - if ($tagData['required'] === true) { - $error = 'Missing %s tag in %s comment'; - $data = array( - $tag, - $docBlock, - ); - $phpcsFile->addError($error, $commentEnd, 'Missing'.ucfirst(substr($tag, 1)).'Tag', $data); - } - - continue; - } else { - $method = 'process'.substr($tag, 1); - if (method_exists($this, $method) === true) { - // Process each tag if a method is defined. - call_user_func(array($this, $method), $phpcsFile, $tagTokens[$tag]); - } - } - - if (isset($foundTags[$pos]) === false) { - break; - } - - if ($foundTags[$pos] !== $tag) { - $error = 'The tag in position %s should be the %s tag'; - $data = array( - ($pos + 1), - $tag, - ); - $phpcsFile->addError($error, $tokens[$commentStart]['comment_tags'][$pos], ucfirst(substr($tag, 1)).'TagOrder', $data); - } - - // Account for multiple tags. - $pos++; - while (isset($foundTags[$pos]) === true && $foundTags[$pos] === $tag) { - $pos++; - } - }//end foreach - - }//end processTags() - - - /** - * Process the category tag. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tags The tokens for these tags. - * - * @return void - */ - protected function processCategory(PHP_CodeSniffer_File $phpcsFile, array $tags) - { - $tokens = $phpcsFile->getTokens(); - foreach ($tags as $tag) { - if ($tokens[($tag + 2)]['code'] !== T_DOC_COMMENT_STRING) { - // No content. - continue; - } - - $content = $tokens[($tag + 2)]['content']; - if (PHP_CodeSniffer::isUnderscoreName($content) !== true) { - $newContent = str_replace(' ', '_', $content); - $nameBits = explode('_', $newContent); - $firstBit = array_shift($nameBits); - $newName = ucfirst($firstBit).'_'; - foreach ($nameBits as $bit) { - if ($bit !== '') { - $newName .= ucfirst($bit).'_'; - } - } - - $error = 'Category name "%s" is not valid; consider "%s" instead'; - $validName = trim($newName, '_'); - $data = array( - $content, - $validName, - ); - $phpcsFile->addError($error, $tag, 'InvalidCategory', $data); - } - }//end foreach - - }//end processCategory() - - - /** - * Process the package tag. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tags The tokens for these tags. - * - * @return void - */ - protected function processPackage(PHP_CodeSniffer_File $phpcsFile, array $tags) - { - $tokens = $phpcsFile->getTokens(); - foreach ($tags as $tag) { - if ($tokens[($tag + 2)]['code'] !== T_DOC_COMMENT_STRING) { - // No content. - continue; - } - - $content = $tokens[($tag + 2)]['content']; - if (PHP_CodeSniffer::isUnderscoreName($content) === true) { - continue; - } - - $newContent = str_replace(' ', '_', $content); - $newContent = trim($newContent, '_'); - $newContent = preg_replace('/[^A-Za-z_]/', '', $newContent); - - if ($newContent === '') { - $error = 'Package name "%s" is not valid'; - $data = array($content); - $phpcsFile->addError($error, $tag, 'InvalidPackageValue', $data); - } else { - $nameBits = explode('_', $newContent); - $firstBit = array_shift($nameBits); - $newName = strtoupper($firstBit{0}).substr($firstBit, 1).'_'; - foreach ($nameBits as $bit) { - if ($bit !== '') { - $newName .= strtoupper($bit{0}).substr($bit, 1).'_'; - } - } - - $error = 'Package name "%s" is not valid; consider "%s" instead'; - $validName = trim($newName, '_'); - $data = array( - $content, - $validName, - ); - $phpcsFile->addError($error, $tag, 'InvalidPackage', $data); - }//end if - }//end foreach - - }//end processPackage() - - - /** - * Process the subpackage tag. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tags The tokens for these tags. - * - * @return void - */ - protected function processSubpackage(PHP_CodeSniffer_File $phpcsFile, array $tags) - { - $tokens = $phpcsFile->getTokens(); - foreach ($tags as $tag) { - if ($tokens[($tag + 2)]['code'] !== T_DOC_COMMENT_STRING) { - // No content. - continue; - } - - $content = $tokens[($tag + 2)]['content']; - if (PHP_CodeSniffer::isUnderscoreName($content) === true) { - continue; - } - - $newContent = str_replace(' ', '_', $content); - $nameBits = explode('_', $newContent); - $firstBit = array_shift($nameBits); - $newName = strtoupper($firstBit{0}).substr($firstBit, 1).'_'; - foreach ($nameBits as $bit) { - if ($bit !== '') { - $newName .= strtoupper($bit{0}).substr($bit, 1).'_'; - } - } - - $error = 'Subpackage name "%s" is not valid; consider "%s" instead'; - $validName = trim($newName, '_'); - $data = array( - $content, - $validName, - ); - $phpcsFile->addError($error, $tag, 'InvalidSubpackage', $data); - }//end foreach - - }//end processSubpackage() - - - /** - * Process the author tag(s) that this header comment has. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tags The tokens for these tags. - * - * @return void - */ - protected function processAuthor(PHP_CodeSniffer_File $phpcsFile, array $tags) - { - $tokens = $phpcsFile->getTokens(); - foreach ($tags as $tag) { - if ($tokens[($tag + 2)]['code'] !== T_DOC_COMMENT_STRING) { - // No content. - continue; - } - - $content = $tokens[($tag + 2)]['content']; - $local = '\da-zA-Z-_+'; - // Dot character cannot be the first or last character in the local-part. - $localMiddle = $local.'.\w'; - if (preg_match('/^([^<]*)\s+<(['.$local.'](['.$localMiddle.']*['.$local.'])*@[\da-zA-Z][-.\w]*[\da-zA-Z]\.[a-zA-Z]{2,7})>$/', $content) === 0) { - $error = 'Content of the @author tag must be in the form "Display Name "'; - $phpcsFile->addError($error, $tag, 'InvalidAuthors'); - } - } - - }//end processAuthor() - - - /** - * Process the copyright tags. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tags The tokens for these tags. - * - * @return void - */ - protected function processCopyright(PHP_CodeSniffer_File $phpcsFile, array $tags) - { - $tokens = $phpcsFile->getTokens(); - foreach ($tags as $tag) { - if ($tokens[($tag + 2)]['code'] !== T_DOC_COMMENT_STRING) { - // No content. - continue; - } - - $content = $tokens[($tag + 2)]['content']; - $matches = array(); - if (preg_match('/^([0-9]{4})((.{1})([0-9]{4}))? (.+)$/', $content, $matches) !== 0) { - // Check earliest-latest year order. - if ($matches[3] !== '' && $matches[3] !== null) { - if ($matches[3] !== '-') { - $error = 'A hyphen must be used between the earliest and latest year'; - $phpcsFile->addError($error, $tag, 'CopyrightHyphen'); - } - - if ($matches[4] !== '' && $matches[4] !== null && $matches[4] < $matches[1]) { - $error = "Invalid year span \"$matches[1]$matches[3]$matches[4]\" found; consider \"$matches[4]-$matches[1]\" instead"; - $phpcsFile->addWarning($error, $tag, 'InvalidCopyright'); - } - } - } else { - $error = '@copyright tag must contain a year and the name of the copyright holder'; - $phpcsFile->addError($error, $tag, 'IncompleteCopyright'); - } - }//end foreach - - }//end processCopyright() - - - /** - * Process the license tag. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tags The tokens for these tags. - * - * @return void - */ - protected function processLicense(PHP_CodeSniffer_File $phpcsFile, array $tags) - { - $tokens = $phpcsFile->getTokens(); - foreach ($tags as $tag) { - if ($tokens[($tag + 2)]['code'] !== T_DOC_COMMENT_STRING) { - // No content. - continue; - } - - $content = $tokens[($tag + 2)]['content']; - $matches = array(); - preg_match('/^([^\s]+)\s+(.*)/', $content, $matches); - if (count($matches) !== 3) { - $error = '@license tag must contain a URL and a license name'; - $phpcsFile->addError($error, $tag, 'IncompleteLicense'); - } - } - - }//end processLicense() - - - /** - * Process the version tag. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tags The tokens for these tags. - * - * @return void - */ - protected function processVersion(PHP_CodeSniffer_File $phpcsFile, array $tags) - { - $tokens = $phpcsFile->getTokens(); - foreach ($tags as $tag) { - if ($tokens[($tag + 2)]['code'] !== T_DOC_COMMENT_STRING) { - // No content. - continue; - } - - $content = $tokens[($tag + 2)]['content']; - if (strstr($content, 'CVS:') === false - && strstr($content, 'SVN:') === false - && strstr($content, 'GIT:') === false - && strstr($content, 'HG:') === false - ) { - $error = 'Invalid version "%s" in file comment; consider "CVS: " or "SVN: " or "GIT: " or "HG: " instead'; - $data = array($content); - $phpcsFile->addWarning($error, $tag, 'InvalidVersion', $data); - } - } - - }//end processVersion() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php deleted file mode 100644 index bcd4e64..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php +++ /dev/null @@ -1,438 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Parses and verifies the doc comments for functions. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_FUNCTION); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $find = PHP_CodeSniffer_Tokens::$methodPrefixes; - $find[] = T_WHITESPACE; - - $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); - if ($tokens[$commentEnd]['code'] === T_COMMENT) { - // Inline comments might just be closing comments for - // control structures or functions instead of function comments - // using the wrong comment type. If there is other code on the line, - // assume they relate to that code. - $prev = $phpcsFile->findPrevious($find, ($commentEnd - 1), null, true); - if ($prev !== false && $tokens[$prev]['line'] === $tokens[$commentEnd]['line']) { - $commentEnd = $prev; - } - } - - if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG - && $tokens[$commentEnd]['code'] !== T_COMMENT - ) { - $phpcsFile->addError('Missing function doc comment', $stackPtr, 'Missing'); - $phpcsFile->recordMetric($stackPtr, 'Function has doc comment', 'no'); - return; - } else { - $phpcsFile->recordMetric($stackPtr, 'Function has doc comment', 'yes'); - } - - if ($tokens[$commentEnd]['code'] === T_COMMENT) { - $phpcsFile->addError('You must use "/**" style comments for a function comment', $stackPtr, 'WrongStyle'); - return; - } - - if ($tokens[$commentEnd]['line'] !== ($tokens[$stackPtr]['line'] - 1)) { - $error = 'There must be no blank lines after the function comment'; - $phpcsFile->addError($error, $commentEnd, 'SpacingAfter'); - } - - $commentStart = $tokens[$commentEnd]['comment_opener']; - foreach ($tokens[$commentStart]['comment_tags'] as $tag) { - if ($tokens[$tag]['content'] === '@see') { - // Make sure the tag isn't empty. - $string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $tag, $commentEnd); - if ($string === false || $tokens[$string]['line'] !== $tokens[$tag]['line']) { - $error = 'Content missing for @see tag in function comment'; - $phpcsFile->addError($error, $tag, 'EmptySees'); - } - } - } - - $this->processReturn($phpcsFile, $stackPtr, $commentStart); - $this->processThrows($phpcsFile, $stackPtr, $commentStart); - $this->processParams($phpcsFile, $stackPtr, $commentStart); - - }//end process() - - - /** - * Process the return comment of this function comment. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $commentStart The position in the stack where the comment started. - * - * @return void - */ - protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) - { - $tokens = $phpcsFile->getTokens(); - - // Skip constructor and destructor. - $methodName = $phpcsFile->getDeclarationName($stackPtr); - $isSpecialMethod = ($methodName === '__construct' || $methodName === '__destruct'); - - $return = null; - foreach ($tokens[$commentStart]['comment_tags'] as $tag) { - if ($tokens[$tag]['content'] === '@return') { - if ($return !== null) { - $error = 'Only 1 @return tag is allowed in a function comment'; - $phpcsFile->addError($error, $tag, 'DuplicateReturn'); - return; - } - - $return = $tag; - } - } - - if ($isSpecialMethod === true) { - return; - } - - if ($return !== null) { - $content = $tokens[($return + 2)]['content']; - if (empty($content) === true || $tokens[($return + 2)]['code'] !== T_DOC_COMMENT_STRING) { - $error = 'Return type missing for @return tag in function comment'; - $phpcsFile->addError($error, $return, 'MissingReturnType'); - } - } else { - $error = 'Missing @return tag in function comment'; - $phpcsFile->addError($error, $tokens[$commentStart]['comment_closer'], 'MissingReturn'); - }//end if - - }//end processReturn() - - - /** - * Process any throw tags that this function comment has. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $commentStart The position in the stack where the comment started. - * - * @return void - */ - protected function processThrows(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) - { - $tokens = $phpcsFile->getTokens(); - - $throws = array(); - foreach ($tokens[$commentStart]['comment_tags'] as $tag) { - if ($tokens[$tag]['content'] !== '@throws') { - continue; - } - - $exception = null; - $comment = null; - if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING) { - $matches = array(); - preg_match('/([^\s]+)(?:\s+(.*))?/', $tokens[($tag + 2)]['content'], $matches); - $exception = $matches[1]; - if (isset($matches[2]) === true) { - $comment = $matches[2]; - } - } - - if ($exception === null) { - $error = 'Exception type missing for @throws tag in function comment'; - $phpcsFile->addError($error, $tag, 'InvalidThrows'); - } - }//end foreach - - }//end processThrows() - - - /** - * Process the function parameter comments. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $commentStart The position in the stack where the comment started. - * - * @return void - */ - protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) - { - $tokens = $phpcsFile->getTokens(); - - $params = array(); - $maxType = 0; - $maxVar = 0; - foreach ($tokens[$commentStart]['comment_tags'] as $pos => $tag) { - if ($tokens[$tag]['content'] !== '@param') { - continue; - } - - $type = ''; - $typeSpace = 0; - $var = ''; - $varSpace = 0; - $comment = ''; - $commentEnd = 0; - if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING) { - $matches = array(); - preg_match('/([^$&.]+)(?:((?:\.\.\.)?(?:\$|&)[^\s]+)(?:(\s+)(.*))?)?/', $tokens[($tag + 2)]['content'], $matches); - - if (empty($matches) === false) { - $typeLen = strlen($matches[1]); - $type = trim($matches[1]); - $typeSpace = ($typeLen - strlen($type)); - $typeLen = strlen($type); - if ($typeLen > $maxType) { - $maxType = $typeLen; - } - } - - if (isset($matches[2]) === true) { - $var = $matches[2]; - $varLen = strlen($var); - if ($varLen > $maxVar) { - $maxVar = $varLen; - } - - if (isset($matches[4]) === true) { - $varSpace = strlen($matches[3]); - $comment = $matches[4]; - - // Any strings until the next tag belong to this comment. - if (isset($tokens[$commentStart]['comment_tags'][($pos + 1)]) === true) { - $end = $tokens[$commentStart]['comment_tags'][($pos + 1)]; - } else { - $end = $tokens[$commentStart]['comment_closer']; - } - - for ($i = ($tag + 3); $i < $end; $i++) { - if ($tokens[$i]['code'] === T_DOC_COMMENT_STRING) { - $comment .= ' '.$tokens[$i]['content']; - $commentEnd = $i; - } - } - } else { - $error = 'Missing parameter comment'; - $phpcsFile->addError($error, $tag, 'MissingParamComment'); - }//end if - } else { - $error = 'Missing parameter name'; - $phpcsFile->addError($error, $tag, 'MissingParamName'); - }//end if - } else { - $error = 'Missing parameter type'; - $phpcsFile->addError($error, $tag, 'MissingParamType'); - }//end if - - $params[] = array( - 'tag' => $tag, - 'type' => $type, - 'var' => $var, - 'comment' => $comment, - 'comment_end' => $commentEnd, - 'type_space' => $typeSpace, - 'var_space' => $varSpace, - ); - }//end foreach - - $realParams = $phpcsFile->getMethodParameters($stackPtr); - $foundParams = array(); - - // We want to use ... for all variable length arguments, so added - // this prefix to the variable name so comparisons are easier. - foreach ($realParams as $pos => $param) { - if ($param['variable_length'] === true) { - $realParams[$pos]['name'] = '...'.$realParams[$pos]['name']; - } - } - - foreach ($params as $pos => $param) { - if ($param['var'] === '') { - continue; - } - - $foundParams[] = $param['var']; - - // Check number of spaces after the type. - $spaces = ($maxType - strlen($param['type']) + 1); - if ($param['type_space'] !== $spaces) { - $error = 'Expected %s spaces after parameter type; %s found'; - $data = array( - $spaces, - $param['type_space'], - ); - - $fix = $phpcsFile->addFixableError($error, $param['tag'], 'SpacingAfterParamType', $data); - if ($fix === true) { - $commentToken = ($param['tag'] + 2); - - $content = $param['type']; - $content .= str_repeat(' ', $spaces); - $content .= $param['var']; - $content .= str_repeat(' ', $param['var_space']); - - $wrapLength = ($tokens[$commentToken]['length'] - $param['type_space'] - $param['var_space'] - strlen($param['type']) - strlen($param['var']) - ); - - $star = $phpcsFile->findPrevious(T_DOC_COMMENT_STAR, $param['tag']); - $spaceLength = (strlen($content) + $tokens[($commentToken - 1)]['length'] + $tokens[($commentToken - 2)]['length'] - ); - - $padding = str_repeat(' ', ($tokens[$star]['column'] - 1)); - $padding .= '* '; - $padding .= str_repeat(' ', $spaceLength); - - $content .= wordwrap( - $param['comment'], - $wrapLength, - $phpcsFile->eolChar.$padding - ); - - $phpcsFile->fixer->replaceToken($commentToken, $content); - for ($i = ($commentToken + 1); $i <= $param['comment_end']; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - }//end if - }//end if - - // Make sure the param name is correct. - if (isset($realParams[$pos]) === true) { - $realName = $realParams[$pos]['name']; - if ($realName !== $param['var']) { - $code = 'ParamNameNoMatch'; - $data = array( - $param['var'], - $realName, - ); - - $error = 'Doc comment for parameter %s does not match '; - if (strtolower($param['var']) === strtolower($realName)) { - $error .= 'case of '; - $code = 'ParamNameNoCaseMatch'; - } - - $error .= 'actual variable name %s'; - - $phpcsFile->addError($error, $param['tag'], $code, $data); - } - } else if (substr($param['var'], -4) !== ',...') { - // We must have an extra parameter comment. - $error = 'Superfluous parameter comment'; - $phpcsFile->addError($error, $param['tag'], 'ExtraParamComment'); - }//end if - - if ($param['comment'] === '') { - continue; - } - - // Check number of spaces after the var name. - $spaces = ($maxVar - strlen($param['var']) + 1); - if ($param['var_space'] !== $spaces) { - $error = 'Expected %s spaces after parameter name; %s found'; - $data = array( - $spaces, - $param['var_space'], - ); - - $fix = $phpcsFile->addFixableError($error, $param['tag'], 'SpacingAfterParamName', $data); - if ($fix === true) { - $commentToken = ($param['tag'] + 2); - - $content = $param['type']; - $content .= str_repeat(' ', $param['type_space']); - $content .= $param['var']; - $content .= str_repeat(' ', $spaces); - - $wrapLength = ($tokens[$commentToken]['length'] - $param['type_space'] - $param['var_space'] - strlen($param['type']) - strlen($param['var']) - ); - - $star = $phpcsFile->findPrevious(T_DOC_COMMENT_STAR, $param['tag']); - $spaceLength = (strlen($content) + $tokens[($commentToken - 1)]['length'] + $tokens[($commentToken - 2)]['length'] - ); - - $padding = str_repeat(' ', ($tokens[$star]['column'] - 1)); - $padding .= '* '; - $padding .= str_repeat(' ', $spaceLength); - - $content .= wordwrap( - $param['comment'], - $wrapLength, - $phpcsFile->eolChar.$padding - ); - - $phpcsFile->fixer->replaceToken($commentToken, $content); - for ($i = ($commentToken + 1); $i <= $param['comment_end']; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - }//end if - }//end if - }//end foreach - - $realNames = array(); - foreach ($realParams as $realParam) { - $realNames[] = $realParam['name']; - } - - // Report missing comments. - $diff = array_diff($realNames, $foundParams); - foreach ($diff as $neededParam) { - $error = 'Doc comment for parameter "%s" missing'; - $data = array($neededParam); - $phpcsFile->addError($error, $commentStart, 'MissingParamTag', $data); - } - - }//end processParams() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Commenting/InlineCommentSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Commenting/InlineCommentSniff.php deleted file mode 100644 index fcc1d7a..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Commenting/InlineCommentSniff.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PHP_CodeSniffer_Sniffs_PEAR_Commenting_InlineCommentSniff. - * - * Checks that no perl-style comments are used. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_Commenting_InlineCommentSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_COMMENT); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[$stackPtr]['content']{0} === '#') { - $phpcsFile->recordMetric($stackPtr, 'Inline comment style', '# ...'); - - $error = 'Perl-style comments are not allowed. Use "// Comment."'; - $error .= ' or "/* comment */" instead.'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'WrongStyle'); - if ($fix === true) { - $newComment = ltrim($tokens[$stackPtr]['content'], '# '); - $newComment = '// '.$newComment; - $phpcsFile->fixer->replaceToken($stackPtr, $newComment); - } - } else if ($tokens[$stackPtr]['content']{0} === '/' - && $tokens[$stackPtr]['content']{1} === '/' - ) { - $phpcsFile->recordMetric($stackPtr, 'Inline comment style', '// ...'); - } else if ($tokens[$stackPtr]['content']{0} === '/' - && $tokens[$stackPtr]['content']{1} === '*' - ) { - $phpcsFile->recordMetric($stackPtr, 'Inline comment style', '/* ... */'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/ControlSignatureSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/ControlSignatureSniff.php deleted file mode 100644 index 453bc80..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/ControlSignatureSniff.php +++ /dev/null @@ -1,65 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractPatternSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractPatternSniff not found'); -} - -/** - * Verifies that control statements conform to their coding standards. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_ControlStructures_ControlSignatureSniff extends PHP_CodeSniffer_Standards_AbstractPatternSniff -{ - - /** - * If true, comments will be ignored if they are found in the code. - * - * @var boolean - */ - public $ignoreComments = true; - - - /** - * Returns the patterns that this test wishes to verify. - * - * @return string[] - */ - protected function getPatterns() - { - return array( - 'do {EOL...} while (...);EOL', - 'while (...) {EOL', - 'for (...) {EOL', - 'if (...) {EOL', - 'foreach (...) {EOL', - '} else if (...) {EOL', - '} elseif (...) {EOL', - '} else {EOL', - 'do {EOL', - ); - - }//end getPatterns() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/MultiLineConditionSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/MultiLineConditionSniff.php deleted file mode 100644 index 1d0f88d..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/MultiLineConditionSniff.php +++ /dev/null @@ -1,279 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PEAR_Sniffs_ControlStructures_MultiLineConditionSniff. - * - * Ensure multi-line IF conditions are defined correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_ControlStructures_MultiLineConditionSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - /** - * The number of spaces code should be indented. - * - * @var int - */ - public $indent = 4; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_IF, - T_ELSEIF, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (isset($tokens[$stackPtr]['parenthesis_opener']) === false) { - return; - } - - $openBracket = $tokens[$stackPtr]['parenthesis_opener']; - $closeBracket = $tokens[$stackPtr]['parenthesis_closer']; - $spaceAfterOpen = 0; - if ($tokens[($openBracket + 1)]['code'] === T_WHITESPACE) { - if (strpos($tokens[($openBracket + 1)]['content'], $phpcsFile->eolChar) !== false) { - $spaceAfterOpen = 'newline'; - } else { - $spaceAfterOpen = strlen($tokens[($openBracket + 1)]['content']); - } - } - - if ($spaceAfterOpen !== 0) { - $error = 'First condition of a multi-line IF statement must directly follow the opening parenthesis'; - $fix = $phpcsFile->addFixableError($error, ($openBracket + 1), 'SpacingAfterOpenBrace'); - if ($fix === true) { - if ($spaceAfterOpen === 'newline') { - $phpcsFile->fixer->replaceToken(($openBracket + 1), ''); - } else { - $phpcsFile->fixer->replaceToken(($openBracket + 1), ''); - } - } - } - - // We need to work out how far indented the if statement - // itself is, so we can work out how far to indent conditions. - $statementIndent = 0; - for ($i = ($stackPtr - 1); $i >= 0; $i--) { - if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) { - $i++; - break; - } - } - - if ($i >= 0 && $tokens[$i]['code'] === T_WHITESPACE) { - $statementIndent = strlen($tokens[$i]['content']); - } - - // Each line between the parenthesis should be indented 4 spaces - // and start with an operator, unless the line is inside a - // function call, in which case it is ignored. - $prevLine = $tokens[$openBracket]['line']; - for ($i = ($openBracket + 1); $i <= $closeBracket; $i++) { - if ($i === $closeBracket && $tokens[$openBracket]['line'] !== $tokens[$i]['line']) { - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($i - 1), null, true); - if ($tokens[$prev]['line'] === $tokens[$i]['line']) { - // Closing bracket is on the same line as a condition. - $error = 'Closing parenthesis of a multi-line IF statement must be on a new line'; - $fix = $phpcsFile->addFixableError($error, $closeBracket, 'CloseBracketNewLine'); - if ($fix === true) { - // Account for a comment at the end of the line. - $next = $phpcsFile->findNext(T_WHITESPACE, ($closeBracket + 1), null, true); - if ($tokens[$next]['code'] !== T_COMMENT) { - $phpcsFile->fixer->addNewlineBefore($closeBracket); - } else { - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true); - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->replaceToken($closeBracket, ''); - $phpcsFile->fixer->addContentBefore($next, ')'); - $phpcsFile->fixer->endChangeset(); - } - } - } - }//end if - - if ($tokens[$i]['line'] !== $prevLine) { - if ($tokens[$i]['line'] === $tokens[$closeBracket]['line']) { - $next = $phpcsFile->findNext(T_WHITESPACE, $i, null, true); - if ($next !== $closeBracket) { - $expectedIndent = ($statementIndent + $this->indent); - } else { - // Closing brace needs to be indented to the same level - // as the statement. - $expectedIndent = $statementIndent; - }//end if - } else { - $expectedIndent = ($statementIndent + $this->indent); - }//end if - - if ($tokens[$i]['code'] === T_COMMENT) { - $prevLine = $tokens[$i]['line']; - continue; - } - - // We changed lines, so this should be a whitespace indent token. - if ($tokens[$i]['code'] !== T_WHITESPACE) { - $foundIndent = 0; - } else { - $foundIndent = strlen($tokens[$i]['content']); - } - - if ($expectedIndent !== $foundIndent) { - $error = 'Multi-line IF statement not indented correctly; expected %s spaces but found %s'; - $data = array( - $expectedIndent, - $foundIndent, - ); - - $fix = $phpcsFile->addFixableError($error, $i, 'Alignment', $data); - if ($fix === true) { - $spaces = str_repeat(' ', $expectedIndent); - if ($foundIndent === 0) { - $phpcsFile->fixer->addContentBefore($i, $spaces); - } else { - $phpcsFile->fixer->replaceToken($i, $spaces); - } - } - } - - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $i, null, true); - if ($next !== $closeBracket) { - if (isset(PHP_CodeSniffer_Tokens::$booleanOperators[$tokens[$next]['code']]) === false) { - $error = 'Each line in a multi-line IF statement must begin with a boolean operator'; - $fix = $phpcsFile->addFixableError($error, $i, 'StartWithBoolean'); - if ($fix === true) { - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($i - 1), $openBracket, true); - if (isset(PHP_CodeSniffer_Tokens::$booleanOperators[$tokens[$prev]['code']]) === true) { - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->replaceToken($prev, ''); - $phpcsFile->fixer->addContentBefore($next, $tokens[$prev]['content'].' '); - $phpcsFile->fixer->endChangeset(); - } else { - for ($x = ($prev + 1); $x < $next; $x++) { - $phpcsFile->fixer->replaceToken($x, ''); - } - } - } - } - }//end if - - $prevLine = $tokens[$i]['line']; - }//end if - - if ($tokens[$i]['code'] === T_STRING) { - $next = $phpcsFile->findNext(T_WHITESPACE, ($i + 1), null, true); - if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) { - // This is a function call, so skip to the end as they - // have their own indentation rules. - $i = $tokens[$next]['parenthesis_closer']; - $prevLine = $tokens[$i]['line']; - continue; - } - } - }//end for - - // From here on, we are checking the spacing of the opening and closing - // braces. If this IF statement does not use braces, we end here. - if (isset($tokens[$stackPtr]['scope_opener']) === false) { - return; - } - - // The opening brace needs to be one space away from the closing parenthesis. - $openBrace = $tokens[$stackPtr]['scope_opener']; - $next = $phpcsFile->findNext(T_WHITESPACE, ($closeBracket + 1), $openBrace, true); - if ($next !== false) { - // Probably comments in between tokens, so don't check. - return; - } - - if ($tokens[$openBrace]['line'] > $tokens[$closeBracket]['line']) { - $length = -1; - } else if ($openBrace === ($closeBracket + 1)) { - $length = 0; - } else if ($openBrace === ($closeBracket + 2) - && $tokens[($closeBracket + 1)]['code'] === T_WHITESPACE - ) { - $length = strlen($tokens[($closeBracket + 1)]['content']); - } else { - // Confused, so don't check. - $length = 1; - } - - if ($length === 1) { - return; - } - - $data = array($length); - $code = 'SpaceBeforeOpenBrace'; - - $error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement; found '; - if ($length === -1) { - $error .= 'newline'; - $code = 'NewlineBeforeOpenBrace'; - } else { - $error .= '%s spaces'; - } - - $fix = $phpcsFile->addFixableError($error, ($closeBracket + 1), $code, $data); - if ($fix === true) { - if ($length === 0) { - $phpcsFile->fixer->addContent($closeBracket, ' '); - } else { - $phpcsFile->fixer->replaceToken(($closeBracket + 1), ' '); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Files/IncludingFileSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Files/IncludingFileSniff.php deleted file mode 100644 index 941ae67..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Files/IncludingFileSniff.php +++ /dev/null @@ -1,150 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PEAR_Sniffs_Files_IncludingFileSniff. - * - * Checks that the include_once is used in conditional situations, and - * require_once is used elsewhere. Also checks that brackets do not surround - * the file being included. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_Files_IncludingFileSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_INCLUDE_ONCE, - T_REQUIRE_ONCE, - T_REQUIRE, - T_INCLUDE, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true); - if ($tokens[$nextToken]['code'] === T_OPEN_PARENTHESIS) { - $error = '"%s" is a statement not a function; no parentheses are required'; - $data = array($tokens[$stackPtr]['content']); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'BracketsNotRequired', $data); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->replaceToken($tokens[$nextToken]['parenthesis_closer'], ''); - if ($tokens[($nextToken - 1)]['code'] !== T_WHITESPACE) { - $phpcsFile->fixer->replaceToken($nextToken, ' '); - } else { - $phpcsFile->fixer->replaceToken($nextToken, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - } - - if (count($tokens[$stackPtr]['conditions']) !== 0) { - $inCondition = true; - } else { - $inCondition = false; - } - - // Check to see if this including statement is within the parenthesis - // of a condition. If that's the case then we need to process it as being - // within a condition, as they are checking the return value. - if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) { - foreach ($tokens[$stackPtr]['nested_parenthesis'] as $left => $right) { - if (isset($tokens[$left]['parenthesis_owner']) === true) { - $inCondition = true; - } - } - } - - // Check to see if they are assigning the return value of this - // including call. If they are then they are probably checking it, so - // it's conditional. - $previous = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); - if (isset(PHP_CodeSniffer_Tokens::$assignmentTokens[$tokens[$previous]['code']]) === true) { - // The have assigned the return value to it, so its conditional. - $inCondition = true; - } - - $tokenCode = $tokens[$stackPtr]['code']; - if ($inCondition === true) { - // We are inside a conditional statement. We need an include_once. - if ($tokenCode === T_REQUIRE_ONCE) { - $error = 'File is being conditionally included; '; - $error .= 'use "include_once" instead'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'UseIncludeOnce'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, 'include_once'); - } - } else if ($tokenCode === T_REQUIRE) { - $error = 'File is being conditionally included; '; - $error .= 'use "include" instead'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'UseInclude'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, 'include'); - } - } - } else { - // We are unconditionally including, we need a require_once. - if ($tokenCode === T_INCLUDE_ONCE) { - $error = 'File is being unconditionally included; '; - $error .= 'use "require_once" instead'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'UseRequireOnce'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, 'require_once'); - } - } else if ($tokenCode === T_INCLUDE) { - $error = 'File is being unconditionally included; '; - $error .= 'use "require" instead'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'UseRequire'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, 'require'); - } - } - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Formatting/MultiLineAssignmentSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Formatting/MultiLineAssignmentSniff.php deleted file mode 100644 index fcb14b9..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Formatting/MultiLineAssignmentSniff.php +++ /dev/null @@ -1,119 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PEAR_Sniffs_Formatting_MultiLineAssignmentSniff. - * - * If an assignment goes over two lines, ensure the equal sign is indented. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_Formatting_MultiLineAssignmentSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * The number of spaces code should be indented. - * - * @var int - */ - public $indent = 4; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_EQUAL); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Equal sign can't be the last thing on the line. - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($next === false) { - // Bad assignment. - return; - } - - if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) { - $error = 'Multi-line assignments must have the equal sign on the second line'; - $phpcsFile->addError($error, $stackPtr, 'EqualSignLine'); - return; - } - - // Make sure it is the first thing on the line, otherwise we ignore it. - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), false, true); - if ($prev === false) { - // Bad assignment. - return; - } - - if ($tokens[$prev]['line'] === $tokens[$stackPtr]['line']) { - return; - } - - // Find the required indent based on the ident of the previous line. - $assignmentIndent = 0; - $prevLine = $tokens[$prev]['line']; - for ($i = ($prev - 1); $i >= 0; $i--) { - if ($tokens[$i]['line'] !== $prevLine) { - $i++; - break; - } - } - - if ($tokens[$i]['code'] === T_WHITESPACE) { - $assignmentIndent = strlen($tokens[$i]['content']); - } - - // Find the actual indent. - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1)); - - $expectedIndent = ($assignmentIndent + $this->indent); - $foundIndent = strlen($tokens[$prev]['content']); - if ($foundIndent !== $expectedIndent) { - $error = 'Multi-line assignment not indented correctly; expected %s spaces but found %s'; - $data = array( - $expectedIndent, - $foundIndent, - ); - $phpcsFile->addError($error, $stackPtr, 'Indent', $data); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php deleted file mode 100644 index 97e181a..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php +++ /dev/null @@ -1,560 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PEAR_Sniffs_Functions_FunctionCallSignatureSniff. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_Functions_FunctionCallSignatureSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - /** - * The number of spaces code should be indented. - * - * @var int - */ - public $indent = 4; - - /** - * If TRUE, multiple arguments can be defined per line in a multi-line call. - * - * @var bool - */ - public $allowMultipleArguments = true; - - /** - * How many spaces should follow the opening bracket. - * - * @var int - */ - public $requiredSpacesAfterOpen = 0; - - /** - * How many spaces should precede the closing bracket. - * - * @var int - */ - public $requiredSpacesBeforeClose = 0; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return PHP_CodeSniffer_Tokens::$functionNameTokens; - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $this->requiredSpacesAfterOpen = (int) $this->requiredSpacesAfterOpen; - $this->requiredSpacesBeforeClose = (int) $this->requiredSpacesBeforeClose; - $tokens = $phpcsFile->getTokens(); - - // Find the next non-empty token. - $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true); - - if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) { - // Not a function call. - return; - } - - if (isset($tokens[$openBracket]['parenthesis_closer']) === false) { - // Not a function call. - return; - } - - // Find the previous non-empty token. - $search = PHP_CodeSniffer_Tokens::$emptyTokens; - $search[] = T_BITWISE_AND; - $previous = $phpcsFile->findPrevious($search, ($stackPtr - 1), null, true); - if ($tokens[$previous]['code'] === T_FUNCTION) { - // It's a function definition, not a function call. - return; - } - - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; - - if (($stackPtr + 1) !== $openBracket) { - // Checking this: $value = my_function[*](...). - $error = 'Space before opening parenthesis of function call prohibited'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceBeforeOpenBracket'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($stackPtr + 1); $i < $openBracket; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - // Modify the bracket as well to ensure a conflict if the bracket - // has been changed in some way by another sniff. - $phpcsFile->fixer->replaceToken($openBracket, '('); - $phpcsFile->fixer->endChangeset(); - } - } - - $next = $phpcsFile->findNext(T_WHITESPACE, ($closeBracket + 1), null, true); - if ($tokens[$next]['code'] === T_SEMICOLON) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[($closeBracket + 1)]['code']]) === true) { - $error = 'Space after closing parenthesis of function call prohibited'; - $fix = $phpcsFile->addFixableError($error, $closeBracket, 'SpaceAfterCloseBracket'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($closeBracket + 1); $i < $next; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - // Modify the bracket as well to ensure a conflict if the bracket - // has been changed in some way by another sniff. - $phpcsFile->fixer->replaceToken($closeBracket, ')'); - $phpcsFile->fixer->endChangeset(); - } - } - } - - // Check if this is a single line or multi-line function call. - if ($this->isMultiLineCall($phpcsFile, $stackPtr, $openBracket, $tokens) === true) { - $this->processMultiLineCall($phpcsFile, $stackPtr, $openBracket, $tokens); - } else { - $this->processSingleLineCall($phpcsFile, $stackPtr, $openBracket, $tokens); - } - - }//end process() - - - /** - * Determine if this is a multi-line function call. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $openBracket The position of the opening bracket - * in the stack passed in $tokens. - * @param array $tokens The stack of tokens that make up - * the file. - * - * @return void - */ - public function isMultiLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens) - { - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; - if ($tokens[$openBracket]['line'] !== $tokens[$closeBracket]['line']) { - return true; - } - - return false; - - }//end isMultiLineCall() - - - /** - * Processes single-line calls. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $openBracket The position of the opening bracket - * in the stack passed in $tokens. - * @param array $tokens The stack of tokens that make up - * the file. - * - * @return void - */ - public function processSingleLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens) - { - $closer = $tokens[$openBracket]['parenthesis_closer']; - if ($openBracket === ($closer - 1)) { - return; - } - - if ($this->requiredSpacesAfterOpen === 0 && $tokens[($openBracket + 1)]['code'] === T_WHITESPACE) { - // Checking this: $value = my_function([*]...). - $error = 'Space after opening parenthesis of function call prohibited'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterOpenBracket'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($openBracket + 1), ''); - } - } else if ($this->requiredSpacesAfterOpen > 0) { - $spaceAfterOpen = 0; - if ($tokens[($openBracket + 1)]['code'] === T_WHITESPACE) { - $spaceAfterOpen = strlen($tokens[($openBracket + 1)]['content']); - } - - if ($spaceAfterOpen !== $this->requiredSpacesAfterOpen) { - $error = 'Expected %s spaces after opening bracket; %s found'; - $data = array( - $this->requiredSpacesAfterOpen, - $spaceAfterOpen, - ); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterOpenBracket', $data); - if ($fix === true) { - $padding = str_repeat(' ', $this->requiredSpacesAfterOpen); - if ($spaceAfterOpen === 0) { - $phpcsFile->fixer->addContent($openBracket, $padding); - } else { - $phpcsFile->fixer->replaceToken(($openBracket + 1), $padding); - } - } - } - }//end if - - // Checking this: $value = my_function(...[*]). - $spaceBeforeClose = 0; - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($closer - 1), $openBracket, true); - if ($tokens[$prev]['code'] === T_END_HEREDOC || $tokens[$prev]['code'] === T_END_NOWDOC) { - // Need a newline after these tokens, so ignore this rule. - return; - } - - if ($tokens[$prev]['line'] !== $tokens[$closer]['line']) { - $spaceBeforeClose = 'newline'; - } else if ($tokens[($closer - 1)]['code'] === T_WHITESPACE) { - $spaceBeforeClose = strlen($tokens[($closer - 1)]['content']); - } - - if ($spaceBeforeClose !== $this->requiredSpacesBeforeClose) { - $error = 'Expected %s spaces before closing bracket; %s found'; - $data = array( - $this->requiredSpacesBeforeClose, - $spaceBeforeClose, - ); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceBeforeCloseBracket', $data); - if ($fix === true) { - $padding = str_repeat(' ', $this->requiredSpacesBeforeClose); - - if ($spaceBeforeClose === 0) { - $phpcsFile->fixer->addContentBefore($closer, $padding); - } else if ($spaceBeforeClose === 'newline') { - $phpcsFile->fixer->beginChangeset(); - - $closingContent = ')'; - - $next = $phpcsFile->findNext(T_WHITESPACE, ($closer + 1), null, true); - if ($tokens[$next]['code'] === T_SEMICOLON) { - $closingContent .= ';'; - for ($i = ($closer + 1); $i <= $next; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - } - - // We want to jump over any whitespace or inline comment and - // move the closing parenthesis after any other token. - $prev = ($closer - 1); - while (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$prev]['code']]) === true) { - if (($tokens[$prev]['code'] === T_COMMENT) - && (strpos($tokens[$prev]['content'], '*/') !== false) - ) { - break; - } - - $prev--; - } - - $phpcsFile->fixer->addContent($prev, $padding.$closingContent); - - $prevNonWhitespace = $phpcsFile->findPrevious(T_WHITESPACE, ($closer - 1), null, true); - for ($i = ($prevNonWhitespace + 1); $i <= $closer; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } else { - $phpcsFile->fixer->replaceToken(($closer - 1), $padding); - }//end if - }//end if - }//end if - - }//end processSingleLineCall() - - - /** - * Processes multi-line calls. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $openBracket The position of the opening bracket - * in the stack passed in $tokens. - * @param array $tokens The stack of tokens that make up - * the file. - * - * @return void - */ - public function processMultiLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens) - { - // We need to work out how far indented the function - // call itself is, so we can work out how far to - // indent the arguments. - $start = $phpcsFile->findStartOfStatement($stackPtr); - foreach (array('stackPtr', 'start') as $checkToken) { - $x = $$checkToken; - for ($i = ($x - 1); $i >= 0; $i--) { - if ($tokens[$i]['line'] !== $tokens[$x]['line']) { - $i++; - break; - } - } - - if ($i <= 0) { - $functionIndent = 0; - } else if ($tokens[$i]['code'] === T_WHITESPACE) { - $functionIndent = strlen($tokens[$i]['content']); - } else if ($tokens[$i]['code'] === T_CONSTANT_ENCAPSED_STRING) { - $functionIndent = 0; - } else { - $trimmed = ltrim($tokens[$i]['content']); - if ($trimmed === '') { - if ($tokens[$i]['code'] === T_INLINE_HTML) { - $functionIndent = strlen($tokens[$i]['content']); - } else { - $functionIndent = ($tokens[$i]['column'] - 1); - } - } else { - $functionIndent = (strlen($tokens[$i]['content']) - strlen($trimmed)); - } - } - - $varName = $checkToken.'Indent'; - $$varName = $functionIndent; - }//end foreach - - $functionIndent = max($startIndent, $stackPtrIndent); - - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($openBracket + 1), null, true); - if ($tokens[$next]['line'] === $tokens[$openBracket]['line']) { - $error = 'Opening parenthesis of a multi-line function call must be the last content on the line'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'ContentAfterOpenBracket'); - if ($fix === true) { - $phpcsFile->fixer->addContent( - $openBracket, - $phpcsFile->eolChar.str_repeat(' ', ($functionIndent + $this->indent)) - ); - } - } - - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($closeBracket - 1), null, true); - if ($tokens[$prev]['line'] === $tokens[$closeBracket]['line']) { - $error = 'Closing parenthesis of a multi-line function call must be on a line by itself'; - $fix = $phpcsFile->addFixableError($error, $closeBracket, 'CloseBracketLine'); - if ($fix === true) { - $phpcsFile->fixer->addContentBefore( - $closeBracket, - $phpcsFile->eolChar.str_repeat(' ', ($functionIndent + $this->indent)) - ); - } - } - - // Each line between the parenthesis should be indented n spaces. - $lastLine = ($tokens[$openBracket]['line'] - 1); - $argStart = null; - $argEnd = null; - $inArg = false; - - // Start processing at the first argument. - $i = $phpcsFile->findNext(T_WHITESPACE, ($openBracket + 1), null, true); - if ($tokens[($i - 1)]['code'] === T_WHITESPACE - && $tokens[($i - 1)]['line'] === $tokens[$i]['line'] - ) { - // Make sure we check the indent. - $i--; - } - - for ($i; $i < $closeBracket; $i++) { - if ($i > $argStart && $i < $argEnd) { - $inArg = true; - } else { - $inArg = false; - } - - if ($tokens[$i]['line'] !== $lastLine) { - $lastLine = $tokens[$i]['line']; - - // Ignore heredoc indentation. - if (isset(PHP_CodeSniffer_Tokens::$heredocTokens[$tokens[$i]['code']]) === true) { - continue; - } - - // Ignore multi-line string indentation. - if (isset(PHP_CodeSniffer_Tokens::$stringTokens[$tokens[$i]['code']]) === true - && $tokens[$i]['code'] === $tokens[($i - 1)]['code'] - ) { - continue; - } - - // Ignore inline HTML. - if ($tokens[$i]['code'] === T_INLINE_HTML) { - continue; - } - - if ($tokens[$i]['line'] !== $tokens[$openBracket]['line']) { - // We changed lines, so this should be a whitespace indent token, but first make - // sure it isn't a blank line because we don't need to check indent unless there - // is actually some code to indent. - if ($tokens[$i]['code'] === T_WHITESPACE) { - $nextCode = $phpcsFile->findNext(T_WHITESPACE, ($i + 1), ($closeBracket + 1), true); - if ($tokens[$nextCode]['line'] !== $lastLine) { - if ($inArg === false) { - $error = 'Empty lines are not allowed in multi-line function calls'; - $fix = $phpcsFile->addFixableError($error, $i, 'EmptyLine'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($i, ''); - } - } - - continue; - } - } else { - $nextCode = $i; - } - - if ($tokens[$nextCode]['line'] === $tokens[$closeBracket]['line']) { - // Closing brace needs to be indented to the same level - // as the function call. - $inArg = false; - $expectedIndent = $functionIndent; - } else { - $expectedIndent = ($functionIndent + $this->indent); - } - - if ($tokens[$i]['code'] !== T_WHITESPACE - && $tokens[$i]['code'] !== T_DOC_COMMENT_WHITESPACE - ) { - // Just check if it is a multi-line block comment. If so, we can - // calculate the indent from the whitespace before the content. - if ($tokens[$i]['code'] === T_COMMENT - && $tokens[($i - 1)]['code'] === T_COMMENT - ) { - $trimmedLength = strlen(ltrim($tokens[$i]['content'])); - if ($trimmedLength === 0) { - // This is a blank comment line, so indenting it is - // pointless. - continue; - } - - $foundIndent = (strlen($tokens[$i]['content']) - $trimmedLength); - } else { - $foundIndent = 0; - } - } else { - $foundIndent = strlen($tokens[$i]['content']); - } - - if ($foundIndent < $expectedIndent - || ($inArg === false - && $expectedIndent !== $foundIndent) - ) { - $error = 'Multi-line function call not indented correctly; expected %s spaces but found %s'; - $data = array( - $expectedIndent, - $foundIndent, - ); - - $fix = $phpcsFile->addFixableError($error, $i, 'Indent', $data); - if ($fix === true) { - $padding = str_repeat(' ', $expectedIndent); - if ($foundIndent === 0) { - $phpcsFile->fixer->addContentBefore($i, $padding); - } else { - if ($tokens[$i]['code'] === T_COMMENT) { - $comment = $padding.ltrim($tokens[$i]['content']); - $phpcsFile->fixer->replaceToken($i, $comment); - } else { - $phpcsFile->fixer->replaceToken($i, $padding); - } - } - } - }//end if - } else { - $nextCode = $i; - }//end if - - if ($inArg === false) { - $argStart = $nextCode; - $argEnd = $phpcsFile->findEndOfStatement($nextCode); - } - }//end if - - // If we are within an argument we should be ignoring commas - // as these are not signaling the end of an argument. - if ($inArg === false && $tokens[$i]['code'] === T_COMMA) { - $next = $phpcsFile->findNext(array(T_WHITESPACE, T_COMMENT), ($i + 1), $closeBracket, true); - if ($next === false) { - continue; - } - - if ($this->allowMultipleArguments === false) { - // Comma has to be the last token on the line. - if ($tokens[$i]['line'] === $tokens[$next]['line']) { - $error = 'Only one argument is allowed per line in a multi-line function call'; - $fix = $phpcsFile->addFixableError($error, $next, 'MultipleArguments'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($x = ($next - 1); $x > $i; $x--) { - if ($tokens[$x]['code'] !== T_WHITESPACE) { - break; - } - - $phpcsFile->fixer->replaceToken($x, ''); - } - - $phpcsFile->fixer->addContentBefore( - $next, - $phpcsFile->eolChar.str_repeat(' ', ($functionIndent + $this->indent)) - ); - $phpcsFile->fixer->endChangeset(); - } - } - }//end if - - $argStart = $next; - $argEnd = $phpcsFile->findEndOfStatement($next); - }//end if - }//end for - - }//end processMultiLineCall() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php deleted file mode 100644 index c93dc80..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php +++ /dev/null @@ -1,438 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PEAR_Sniffs_Functions_FunctionDeclarationSniff. - * - * Ensure single and multi-line function declarations are defined correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_Functions_FunctionDeclarationSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * The number of spaces code should be indented. - * - * @var int - */ - public $indent = 4; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_FUNCTION, - T_CLOSURE, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (isset($tokens[$stackPtr]['parenthesis_opener']) === false - || isset($tokens[$stackPtr]['parenthesis_closer']) === false - || $tokens[$stackPtr]['parenthesis_opener'] === null - || $tokens[$stackPtr]['parenthesis_closer'] === null - ) { - return; - } - - $openBracket = $tokens[$stackPtr]['parenthesis_opener']; - $closeBracket = $tokens[$stackPtr]['parenthesis_closer']; - - // Must be one space after the FUNCTION keyword. - if ($tokens[($stackPtr + 1)]['content'] === $phpcsFile->eolChar) { - $spaces = 'newline'; - } else if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) { - $spaces = strlen($tokens[($stackPtr + 1)]['content']); - } else { - $spaces = 0; - } - - if ($spaces !== 1) { - $error = 'Expected 1 space after FUNCTION keyword; %s found'; - $data = array($spaces); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterFunction', $data); - if ($fix === true) { - if ($spaces === 0) { - $phpcsFile->fixer->addContent($stackPtr, ' '); - } else { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); - } - } - } - - // Must be one space before the opening parenthesis. For closures, this is - // enforced by the first check because there is no content between the keywords - // and the opening parenthesis. - if ($tokens[$stackPtr]['code'] === T_FUNCTION) { - if ($tokens[($openBracket - 1)]['content'] === $phpcsFile->eolChar) { - $spaces = 'newline'; - } else if ($tokens[($openBracket - 1)]['code'] === T_WHITESPACE) { - $spaces = strlen($tokens[($openBracket - 1)]['content']); - } else { - $spaces = 0; - } - - if ($spaces !== 0) { - $error = 'Expected 0 spaces before opening parenthesis; %s found'; - $data = array($spaces); - $fix = $phpcsFile->addFixableError($error, $openBracket, 'SpaceBeforeOpenParen', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($openBracket - 1), ''); - } - } - }//end if - - // Must be one space before and after USE keyword for closures. - if ($tokens[$stackPtr]['code'] === T_CLOSURE) { - $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']); - if ($use !== false) { - if ($tokens[($use + 1)]['code'] !== T_WHITESPACE) { - $length = 0; - } else if ($tokens[($use + 1)]['content'] === "\t") { - $length = '\t'; - } else { - $length = strlen($tokens[($use + 1)]['content']); - } - - if ($length !== 1) { - $error = 'Expected 1 space after USE keyword; found %s'; - $data = array($length); - $fix = $phpcsFile->addFixableError($error, $use, 'SpaceAfterUse', $data); - if ($fix === true) { - if ($length === 0) { - $phpcsFile->fixer->addContent($use, ' '); - } else { - $phpcsFile->fixer->replaceToken(($use + 1), ' '); - } - } - } - - if ($tokens[($use - 1)]['code'] !== T_WHITESPACE) { - $length = 0; - } else if ($tokens[($use - 1)]['content'] === "\t") { - $length = '\t'; - } else { - $length = strlen($tokens[($use - 1)]['content']); - } - - if ($length !== 1) { - $error = 'Expected 1 space before USE keyword; found %s'; - $data = array($length); - $fix = $phpcsFile->addFixableError($error, $use, 'SpaceBeforeUse', $data); - if ($fix === true) { - if ($length === 0) { - $phpcsFile->fixer->addContentBefore($use, ' '); - } else { - $phpcsFile->fixer->replaceToken(($use - 1), ' '); - } - } - } - }//end if - }//end if - - if ($this->isMultiLineDeclaration($phpcsFile, $stackPtr, $openBracket, $tokens) === true) { - $this->processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens); - } else { - $this->processSingleLineDeclaration($phpcsFile, $stackPtr, $tokens); - } - - }//end process() - - - /** - * Determine if this is a multi-line function declaration. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $openBracket The position of the opening bracket - * in the stack passed in $tokens. - * @param array $tokens The stack of tokens that make up - * the file. - * - * @return void - */ - public function isMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens) - { - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; - if ($tokens[$openBracket]['line'] !== $tokens[$closeBracket]['line']) { - return true; - } - - // Closures may use the USE keyword and so be multi-line in this way. - if ($tokens[$stackPtr]['code'] === T_CLOSURE) { - $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']); - if ($use !== false) { - // If the opening and closing parenthesis of the use statement - // are also on the same line, this is a single line declaration. - $open = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1)); - $close = $tokens[$open]['parenthesis_closer']; - if ($tokens[$open]['line'] !== $tokens[$close]['line']) { - return true; - } - } - } - - return false; - - }//end isMultiLineDeclaration() - - - /** - * Processes single-line declarations. - * - * Just uses the Generic BSD-Allman brace sniff. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param array $tokens The stack of tokens that make up - * the file. - * - * @return void - */ - public function processSingleLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens) - { - if ($tokens[$stackPtr]['code'] === T_CLOSURE) { - if (class_exists('Generic_Sniffs_Functions_OpeningFunctionBraceKernighanRitchieSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_Functions_OpeningFunctionBraceKernighanRitchieSniff not found'); - } - - $sniff = new Generic_Sniffs_Functions_OpeningFunctionBraceKernighanRitchieSniff(); - } else { - if (class_exists('Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff not found'); - } - - $sniff = new Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff(); - } - - $sniff->checkClosures = true; - $sniff->process($phpcsFile, $stackPtr); - - }//end processSingleLineDeclaration() - - - /** - * Processes multi-line declarations. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param array $tokens The stack of tokens that make up - * the file. - * - * @return void - */ - public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens) - { - // We need to work out how far indented the function - // declaration itself is, so we can work out how far to - // indent parameters. - $functionIndent = 0; - for ($i = ($stackPtr - 1); $i >= 0; $i--) { - if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) { - $i++; - break; - } - } - - if ($tokens[$i]['code'] === T_WHITESPACE) { - $functionIndent = strlen($tokens[$i]['content']); - } - - // The closing parenthesis must be on a new line, even - // when checking abstract function definitions. - $closeBracket = $tokens[$stackPtr]['parenthesis_closer']; - $prev = $phpcsFile->findPrevious( - T_WHITESPACE, - ($closeBracket - 1), - null, - true - ); - - if ($tokens[$closeBracket]['line'] !== $tokens[$tokens[$closeBracket]['parenthesis_opener']]['line']) { - if ($tokens[$prev]['line'] === $tokens[$closeBracket]['line']) { - $error = 'The closing parenthesis of a multi-line function declaration must be on a new line'; - $fix = $phpcsFile->addFixableError($error, $closeBracket, 'CloseBracketLine'); - if ($fix === true) { - $phpcsFile->fixer->addNewlineBefore($closeBracket); - } - } - } - - // If this is a closure and is using a USE statement, the closing - // parenthesis we need to look at from now on is the closing parenthesis - // of the USE statement. - if ($tokens[$stackPtr]['code'] === T_CLOSURE) { - $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']); - if ($use !== false) { - $open = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1)); - $closeBracket = $tokens[$open]['parenthesis_closer']; - - $prev = $phpcsFile->findPrevious( - T_WHITESPACE, - ($closeBracket - 1), - null, - true - ); - - if ($tokens[$closeBracket]['line'] !== $tokens[$tokens[$closeBracket]['parenthesis_opener']]['line']) { - if ($tokens[$prev]['line'] === $tokens[$closeBracket]['line']) { - $error = 'The closing parenthesis of a multi-line use declaration must be on a new line'; - $fix = $phpcsFile->addFixableError($error, $closeBracket, 'UseCloseBracketLine'); - if ($fix === true) { - $phpcsFile->fixer->addNewlineBefore($closeBracket); - } - } - } - }//end if - }//end if - - // Each line between the parenthesis should be indented 4 spaces. - $openBracket = $tokens[$stackPtr]['parenthesis_opener']; - $lastLine = $tokens[$openBracket]['line']; - for ($i = ($openBracket + 1); $i < $closeBracket; $i++) { - if ($tokens[$i]['line'] !== $lastLine) { - if ($i === $tokens[$stackPtr]['parenthesis_closer'] - || ($tokens[$i]['code'] === T_WHITESPACE - && (($i + 1) === $closeBracket - || ($i + 1) === $tokens[$stackPtr]['parenthesis_closer'])) - ) { - // Closing braces need to be indented to the same level - // as the function. - $expectedIndent = $functionIndent; - } else { - $expectedIndent = ($functionIndent + $this->indent); - } - - // We changed lines, so this should be a whitespace indent token. - if ($tokens[$i]['code'] !== T_WHITESPACE) { - $foundIndent = 0; - } else if ($tokens[$i]['line'] !== $tokens[($i + 1)]['line']) { - // This is an empty line, so don't check the indent. - $foundIndent = $expectedIndent; - - $error = 'Blank lines are not allowed in a multi-line function declaration'; - $fix = $phpcsFile->addFixableError($error, $i, 'EmptyLine'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($i, ''); - } - } else { - $foundIndent = strlen($tokens[$i]['content']); - } - - if ($expectedIndent !== $foundIndent) { - $error = 'Multi-line function declaration not indented correctly; expected %s spaces but found %s'; - $data = array( - $expectedIndent, - $foundIndent, - ); - - $fix = $phpcsFile->addFixableError($error, $i, 'Indent', $data); - if ($fix === true) { - $spaces = str_repeat(' ', $expectedIndent); - if ($foundIndent === 0) { - $phpcsFile->fixer->addContentBefore($i, $spaces); - } else { - $phpcsFile->fixer->replaceToken($i, $spaces); - } - } - } - - $lastLine = $tokens[$i]['line']; - }//end if - - if ($tokens[$i]['code'] === T_ARRAY || $tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) { - // Skip arrays as they have their own indentation rules. - if ($tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) { - $i = $tokens[$i]['bracket_closer']; - } else { - $i = $tokens[$i]['parenthesis_closer']; - } - - $lastLine = $tokens[$i]['line']; - continue; - } - }//end for - - if (isset($tokens[$stackPtr]['scope_opener']) === false) { - return; - } - - // The opening brace needs to be one space away from the closing parenthesis. - $opener = $tokens[$stackPtr]['scope_opener']; - if ($tokens[$opener]['line'] !== $tokens[$closeBracket]['line']) { - $error = 'The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line'; - $fix = $phpcsFile->addFixableError($error, $opener, 'NewlineBeforeOpenBrace'); - if ($fix === true) { - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($opener - 1), $closeBracket, true); - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->addContent($prev, ' {'); - $phpcsFile->fixer->replaceToken($opener, ''); - $phpcsFile->fixer->endChangeset(); - } - } else { - $prev = $tokens[($opener - 1)]; - if ($prev['code'] !== T_WHITESPACE) { - $length = 0; - } else { - $length = strlen($prev['content']); - } - - if ($length !== 1) { - $error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found %s spaces'; - $fix = $phpcsFile->addFixableError($error, ($opener - 1), 'SpaceBeforeOpenBrace', array($length)); - if ($fix === true) { - if ($length === 0) { - $phpcsFile->fixer->addContentBefore($opener, ' '); - } else { - $phpcsFile->fixer->replaceToken(($opener - 1), ' '); - } - } - - return; - }//end if - }//end if - - }//end processMultiLineDeclaration() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Functions/ValidDefaultValueSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Functions/ValidDefaultValueSniff.php deleted file mode 100644 index 76a81a0..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/Functions/ValidDefaultValueSniff.php +++ /dev/null @@ -1,98 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PEAR_Sniffs_Functions_ValidDefaultValueSniff. - * - * A Sniff to ensure that parameters defined for a function that have a default - * value come at the end of the function signature. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_Functions_ValidDefaultValueSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_FUNCTION, - T_CLOSURE, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $argStart = $tokens[$stackPtr]['parenthesis_opener']; - $argEnd = $tokens[$stackPtr]['parenthesis_closer']; - - // Flag for when we have found a default in our arg list. - // If there is a value without a default after this, it is an error. - $defaultFound = false; - - $params = $phpcsFile->getMethodParameters($stackPtr); - foreach ($params as $param) { - if ($param['variable_length'] === true) { - continue; - } - - if (array_key_exists('default', $param) === true) { - $defaultFound = true; - // Check if the arg is type hinted and using NULL for the default. - // This does not make the argument optional - it just allows NULL - // to be passed in. - if ($param['type_hint'] !== '' && strtolower($param['default']) === 'null') { - $defaultFound = false; - } - - continue; - } - - if ($defaultFound === true) { - $error = 'Arguments with default values must be at the end of the argument list'; - $phpcsFile->addError($error, $param['token'], 'NotAtEnd'); - return; - } - }//end foreach - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidClassNameSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidClassNameSniff.php deleted file mode 100644 index 7eb587d..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidClassNameSniff.php +++ /dev/null @@ -1,113 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PEAR_Sniffs_NamingConventions_ValidClassNameSniff. - * - * Ensures class and interface names start with a capital letter - * and use _ separators. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_NamingConventions_ValidClassNameSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_CLASS, - T_INTERFACE, - T_TRAIT, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $className = $phpcsFile->findNext(T_STRING, $stackPtr); - $name = trim($tokens[$className]['content']); - $errorData = array(ucfirst($tokens[$stackPtr]['content'])); - - // Make sure the first letter is a capital. - if (preg_match('|^[A-Z]|', $name) === 0) { - $error = '%s name must begin with a capital letter'; - $phpcsFile->addError($error, $stackPtr, 'StartWithCapital', $errorData); - } - - // Check that each new word starts with a capital as well, but don't - // check the first word, as it is checked above. - $validName = true; - $nameBits = explode('_', $name); - $firstBit = array_shift($nameBits); - foreach ($nameBits as $bit) { - if ($bit === '' || $bit{0} !== strtoupper($bit{0})) { - $validName = false; - break; - } - } - - if ($validName === false) { - // Strip underscores because they cause the suggested name - // to be incorrect. - $nameBits = explode('_', trim($name, '_')); - $firstBit = array_shift($nameBits); - if ($firstBit === '') { - $error = '%s name is not valid'; - $phpcsFile->addError($error, $stackPtr, 'Invalid', $errorData); - } else { - $newName = strtoupper($firstBit{0}).substr($firstBit, 1).'_'; - foreach ($nameBits as $bit) { - if ($bit !== '') { - $newName .= strtoupper($bit{0}).substr($bit, 1).'_'; - } - } - - $newName = rtrim($newName, '_'); - $error = '%s name is not valid; consider %s instead'; - $data = $errorData; - $data[] = $newName; - $phpcsFile->addError($error, $stackPtr, 'Invalid', $data); - } - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php deleted file mode 100644 index 410009c..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ /dev/null @@ -1,298 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found'); -} - -/** - * PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff. - * - * Ensures method names are correct depending on whether they are public - * or private, and that functions are named correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff -{ - - /** - * A list of all PHP magic methods. - * - * @var array - */ - protected $magicMethods = array( - 'construct' => true, - 'destruct' => true, - 'call' => true, - 'callstatic' => true, - 'get' => true, - 'set' => true, - 'isset' => true, - 'unset' => true, - 'sleep' => true, - 'wakeup' => true, - 'tostring' => true, - 'set_state' => true, - 'clone' => true, - 'invoke' => true, - 'debuginfo' => true, - ); - - /** - * A list of all PHP magic functions. - * - * @var array - */ - protected $magicFunctions = array('autoload' => true); - - - /** - * Constructs a PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff. - */ - public function __construct() - { - parent::__construct(array(T_CLASS, T_ANON_CLASS, T_INTERFACE, T_TRAIT), array(T_FUNCTION), true); - - }//end __construct() - - - /** - * Processes the tokens within the scope. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being processed. - * @param int $stackPtr The position where this token was - * found. - * @param int $currScope The position of the current scope. - * - * @return void - */ - protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) - { - $methodName = $phpcsFile->getDeclarationName($stackPtr); - if ($methodName === null) { - // Ignore closures. - return; - } - - $className = $phpcsFile->getDeclarationName($currScope); - $errorData = array($className.'::'.$methodName); - - // Is this a magic method. i.e., is prefixed with "__" ? - if (preg_match('|^__[^_]|', $methodName) !== 0) { - $magicPart = strtolower(substr($methodName, 2)); - if (isset($this->magicMethods[$magicPart]) === false) { - $error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore'; - $phpcsFile->addError($error, $stackPtr, 'MethodDoubleUnderscore', $errorData); - } - - return; - } - - // PHP4 constructors are allowed to break our rules. - if ($methodName === $className) { - return; - } - - // PHP4 destructors are allowed to break our rules. - if ($methodName === '_'.$className) { - return; - } - - $methodProps = $phpcsFile->getMethodProperties($stackPtr); - $scope = $methodProps['scope']; - $scopeSpecified = $methodProps['scope_specified']; - - if ($methodProps['scope'] === 'private') { - $isPublic = false; - } else { - $isPublic = true; - } - - // If it's a private method, it must have an underscore on the front. - if ($isPublic === false) { - if ($methodName{0} !== '_') { - $error = 'Private method name "%s" must be prefixed with an underscore'; - $phpcsFile->addError($error, $stackPtr, 'PrivateNoUnderscore', $errorData); - $phpcsFile->recordMetric($stackPtr, 'Private method prefixed with underscore', 'no'); - return; - } else { - $phpcsFile->recordMetric($stackPtr, 'Private method prefixed with underscore', 'yes'); - } - } - - // If it's not a private method, it must not have an underscore on the front. - if ($isPublic === true && $scopeSpecified === true && $methodName{0} === '_') { - $error = '%s method name "%s" must not be prefixed with an underscore'; - $data = array( - ucfirst($scope), - $errorData[0], - ); - $phpcsFile->addError($error, $stackPtr, 'PublicUnderscore', $data); - return; - } - - // If the scope was specified on the method, then the method must be - // camel caps and an underscore should be checked for. If it wasn't - // specified, treat it like a public method and remove the underscore - // prefix if there is one because we cant determine if it is private or - // public. - $testMethodName = $methodName; - if ($scopeSpecified === false && $methodName{0} === '_') { - $testMethodName = substr($methodName, 1); - } - - if (PHP_CodeSniffer::isCamelCaps($testMethodName, false, $isPublic, false) === false) { - if ($scopeSpecified === true) { - $error = '%s method name "%s" is not in camel caps format'; - $data = array( - ucfirst($scope), - $errorData[0], - ); - $phpcsFile->addError($error, $stackPtr, 'ScopeNotCamelCaps', $data); - } else { - $error = 'Method name "%s" is not in camel caps format'; - $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData); - } - - return; - } - - }//end processTokenWithinScope() - - - /** - * Processes the tokens outside the scope. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being processed. - * @param int $stackPtr The position where this token was - * found. - * - * @return void - */ - protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $functionName = $phpcsFile->getDeclarationName($stackPtr); - if ($functionName === null) { - // Ignore closures. - return; - } - - if (ltrim($functionName, '_') === '') { - // Ignore special functions. - return; - } - - $errorData = array($functionName); - - // Is this a magic function. i.e., it is prefixed with "__". - if (preg_match('|^__[^_]|', $functionName) !== 0) { - $magicPart = strtolower(substr($functionName, 2)); - if (isset($this->magicFunctions[$magicPart]) === false) { - $error = 'Function name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore'; - $phpcsFile->addError($error, $stackPtr, 'FunctionDoubleUnderscore', $errorData); - } - - return; - } - - // Function names can be in two parts; the package name and - // the function name. - $packagePart = ''; - $camelCapsPart = ''; - $underscorePos = strrpos($functionName, '_'); - if ($underscorePos === false) { - $camelCapsPart = $functionName; - } else { - $packagePart = substr($functionName, 0, $underscorePos); - $camelCapsPart = substr($functionName, ($underscorePos + 1)); - - // We don't care about _'s on the front. - $packagePart = ltrim($packagePart, '_'); - } - - // If it has a package part, make sure the first letter is a capital. - if ($packagePart !== '') { - if ($functionName{0} === '_') { - $error = 'Function name "%s" is invalid; only private methods should be prefixed with an underscore'; - $phpcsFile->addError($error, $stackPtr, 'FunctionUnderscore', $errorData); - return; - } - - if ($functionName{0} !== strtoupper($functionName{0})) { - $error = 'Function name "%s" is prefixed with a package name but does not begin with a capital letter'; - $phpcsFile->addError($error, $stackPtr, 'FunctionNoCapital', $errorData); - return; - } - } - - // If it doesn't have a camel caps part, it's not valid. - if (trim($camelCapsPart) === '') { - $error = 'Function name "%s" is not valid; name appears incomplete'; - $phpcsFile->addError($error, $stackPtr, 'FunctionInvalid', $errorData); - return; - } - - $validName = true; - $newPackagePart = $packagePart; - $newCamelCapsPart = $camelCapsPart; - - // Every function must have a camel caps part, so check that first. - if (PHP_CodeSniffer::isCamelCaps($camelCapsPart, false, true, false) === false) { - $validName = false; - $newCamelCapsPart = strtolower($camelCapsPart{0}).substr($camelCapsPart, 1); - } - - if ($packagePart !== '') { - // Check that each new word starts with a capital. - $nameBits = explode('_', $packagePart); - foreach ($nameBits as $bit) { - if ($bit{0} !== strtoupper($bit{0})) { - $newPackagePart = ''; - foreach ($nameBits as $bit) { - $newPackagePart .= strtoupper($bit{0}).substr($bit, 1).'_'; - } - - $validName = false; - break; - } - } - } - - if ($validName === false) { - $newName = rtrim($newPackagePart, '_').'_'.$newCamelCapsPart; - if ($newPackagePart === '') { - $newName = $newCamelCapsPart; - } else { - $newName = rtrim($newPackagePart, '_').'_'.$newCamelCapsPart; - } - - $error = 'Function name "%s" is invalid; consider "%s" instead'; - $data = $errorData; - $data[] = $newName; - $phpcsFile->addError($error, $stackPtr, 'FunctionNameInvalid', $data); - } - - }//end processTokenOutsideScope() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidVariableNameSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidVariableNameSniff.php deleted file mode 100644 index 2cc7bef..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ /dev/null @@ -1,121 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) { - $error = 'Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found'; - throw new PHP_CodeSniffer_Exception($error); -} - -/** - * PEAR_Sniffs_NamingConventions_ValidVariableNameSniff. - * - * Checks the naming of member variables. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_NamingConventions_ValidVariableNameSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff -{ - - - /** - * Processes class member variables. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $memberProps = $phpcsFile->getMemberProperties($stackPtr); - if (empty($memberProps) === true) { - return; - } - - $memberName = ltrim($tokens[$stackPtr]['content'], '$'); - $scope = $memberProps['scope']; - $scopeSpecified = $memberProps['scope_specified']; - - if ($memberProps['scope'] === 'private') { - $isPublic = false; - } else { - $isPublic = true; - } - - // If it's a private member, it must have an underscore on the front. - if ($isPublic === false && $memberName{0} !== '_') { - $error = 'Private member variable "%s" must be prefixed with an underscore'; - $data = array($memberName); - $phpcsFile->addError($error, $stackPtr, 'PrivateNoUnderscore', $data); - return; - } - - // If it's not a private member, it must not have an underscore on the front. - if ($isPublic === true && $scopeSpecified === true && $memberName{0} === '_') { - $error = '%s member variable "%s" must not be prefixed with an underscore'; - $data = array( - ucfirst($scope), - $memberName, - ); - $phpcsFile->addError($error, $stackPtr, 'PublicUnderscore', $data); - return; - } - - }//end processMemberVar() - - - /** - * Processes normal variables. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. - * - * @return void - */ - protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - /* - We don't care about normal variables. - */ - - }//end processVariable() - - - /** - * Processes variables in double quoted strings. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. - * - * @return void - */ - protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - /* - We don't care about normal variables. - */ - - }//end processVariableInString() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php deleted file mode 100644 index e82790d..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php +++ /dev/null @@ -1,193 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PEAR_Sniffs_WhiteSpace_ObjectOperatorIndentSniff. - * - * Checks that object operators are indented 4 spaces if they are the first - * thing on a line. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_WhiteSpace_ObjectOperatorIndentSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * The number of spaces code should be indented. - * - * @var int - */ - public $indent = 4; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OBJECT_OPERATOR); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Make sure this is the first object operator in a chain of them. - $varToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if ($varToken === false || $tokens[$varToken]['code'] !== T_VARIABLE) { - return; - } - - // Make sure this is a chained call. - $next = $phpcsFile->findNext( - T_OBJECT_OPERATOR, - ($stackPtr + 1), - null, - false, - null, - true - ); - - if ($next === false) { - // Not a chained call. - return; - } - - // Determine correct indent. - for ($i = ($varToken - 1); $i >= 0; $i--) { - if ($tokens[$i]['line'] !== $tokens[$varToken]['line']) { - $i++; - break; - } - } - - $requiredIndent = 0; - if ($i >= 0 && $tokens[$i]['code'] === T_WHITESPACE) { - $requiredIndent = strlen($tokens[$i]['content']); - } - - $requiredIndent += $this->indent; - - // Determine the scope of the original object operator. - $origBrackets = null; - if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) { - $origBrackets = $tokens[$stackPtr]['nested_parenthesis']; - } - - $origConditions = null; - if (isset($tokens[$stackPtr]['conditions']) === true) { - $origConditions = $tokens[$stackPtr]['conditions']; - } - - // Check indentation of each object operator in the chain. - // If the first object operator is on a different line than - // the variable, make sure we check its indentation too. - if ($tokens[$stackPtr]['line'] > $tokens[$varToken]['line']) { - $next = $stackPtr; - } - - while ($next !== false) { - // Make sure it is in the same scope, otherwise don't check indent. - $brackets = null; - if (isset($tokens[$next]['nested_parenthesis']) === true) { - $brackets = $tokens[$next]['nested_parenthesis']; - } - - $conditions = null; - if (isset($tokens[$next]['conditions']) === true) { - $conditions = $tokens[$next]['conditions']; - } - - if ($origBrackets === $brackets && $origConditions === $conditions) { - // Make sure it starts a line, otherwise dont check indent. - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($next - 1), $stackPtr, true); - $indent = $tokens[($next - 1)]; - if ($tokens[$prev]['line'] !== $tokens[$next]['line'] - && $indent['code'] === T_WHITESPACE - ) { - if ($indent['line'] === $tokens[$next]['line']) { - $foundIndent = strlen($indent['content']); - } else { - $foundIndent = 0; - } - - if ($foundIndent !== $requiredIndent) { - $error = 'Object operator not indented correctly; expected %s spaces but found %s'; - $data = array( - $requiredIndent, - $foundIndent, - ); - - $fix = $phpcsFile->addFixableError($error, $next, 'Incorrect', $data); - if ($fix === true) { - $spaces = str_repeat(' ', $requiredIndent); - if ($foundIndent === 0) { - $phpcsFile->fixer->addContentBefore($next, $spaces); - } else { - $phpcsFile->fixer->replaceToken(($next - 1), $spaces); - } - } - } - }//end if - - // It cant be the last thing on the line either. - $content = $phpcsFile->findNext(T_WHITESPACE, ($next + 1), null, true); - if ($tokens[$content]['line'] !== $tokens[$next]['line']) { - $error = 'Object operator must be at the start of the line, not the end'; - $fix = $phpcsFile->addFixableError($error, $next, 'StartOfLine'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($x = ($next + 1); $x < $content; $x++) { - $phpcsFile->fixer->replaceToken($x, ''); - } - - $phpcsFile->fixer->addNewlineBefore($next); - $phpcsFile->fixer->endChangeset(); - } - } - }//end if - - $next = $phpcsFile->findNext( - T_OBJECT_OPERATOR, - ($next + 1), - null, - false, - null, - true - ); - }//end while - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php deleted file mode 100644 index 226b22a..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php +++ /dev/null @@ -1,193 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PEAR_Sniffs_Whitespace_ScopeClosingBraceSniff. - * - * Checks that the closing braces of scopes are aligned correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_WhiteSpace_ScopeClosingBraceSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * The number of spaces code should be indented. - * - * @var int - */ - public $indent = 4; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return PHP_CodeSniffer_Tokens::$scopeOpeners; - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // If this is an inline condition (ie. there is no scope opener), then - // return, as this is not a new scope. - if (isset($tokens[$stackPtr]['scope_closer']) === false) { - return; - } - - $scopeStart = $tokens[$stackPtr]['scope_opener']; - $scopeEnd = $tokens[$stackPtr]['scope_closer']; - - // If the scope closer doesn't think it belongs to this scope opener - // then the opener is sharing its closer with other tokens. We only - // want to process the closer once, so skip this one. - if (isset($tokens[$scopeEnd]['scope_condition']) === false - || $tokens[$scopeEnd]['scope_condition'] !== $stackPtr - ) { - return; - } - - // We need to actually find the first piece of content on this line, - // because if this is a method with tokens before it (public, static etc) - // or an if with an else before it, then we need to start the scope - // checking from there, rather than the current token. - $lineStart = ($stackPtr - 1); - for ($lineStart; $lineStart > 0; $lineStart--) { - if (strpos($tokens[$lineStart]['content'], $phpcsFile->eolChar) !== false) { - break; - } - } - - $lineStart++; - - $startColumn = 1; - if ($tokens[$lineStart]['code'] === T_WHITESPACE) { - $startColumn = $tokens[($lineStart + 1)]['column']; - } else if ($tokens[$lineStart]['code'] === T_INLINE_HTML) { - $trimmed = ltrim($tokens[$lineStart]['content']); - if ($trimmed === '') { - $startColumn = $tokens[($lineStart + 1)]['column']; - } else { - $startColumn = (strlen($tokens[$lineStart]['content']) - strlen($trimmed)); - } - } - - // Check that the closing brace is on it's own line. - $lastContent = $phpcsFile->findPrevious( - array( - T_WHITESPACE, - T_INLINE_HTML, - T_OPEN_TAG, - ), - ($scopeEnd - 1), - $scopeStart, - true - ); - - if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']) { - $error = 'Closing brace must be on a line by itself'; - $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'Line'); - if ($fix === true) { - $phpcsFile->fixer->addNewlineBefore($scopeEnd); - } - - return; - } - - // Check now that the closing brace is lined up correctly. - $lineStart = ($scopeEnd - 1); - for ($lineStart; $lineStart > 0; $lineStart--) { - if (strpos($tokens[$lineStart]['content'], $phpcsFile->eolChar) !== false) { - break; - } - } - - $lineStart++; - - $braceIndent = 0; - if ($tokens[$lineStart]['code'] === T_WHITESPACE) { - $braceIndent = ($tokens[($lineStart + 1)]['column'] - 1); - } else if ($tokens[$lineStart]['code'] === T_INLINE_HTML) { - $trimmed = ltrim($tokens[$lineStart]['content']); - if ($trimmed === '') { - $braceIndent = ($tokens[($lineStart + 1)]['column'] - 1); - } else { - $braceIndent = (strlen($tokens[$lineStart]['content']) - strlen($trimmed) - 1); - } - } - - $fix = false; - if ($tokens[$stackPtr]['code'] === T_CASE - || $tokens[$stackPtr]['code'] === T_DEFAULT - ) { - // BREAK statements should be indented n spaces from the - // CASE or DEFAULT statement. - $expectedIndent = ($startColumn + $this->indent - 1); - if ($braceIndent !== $expectedIndent) { - $error = 'Case breaking statement indented incorrectly; expected %s spaces, found %s'; - $data = array( - $expectedIndent, - $braceIndent, - ); - $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'BreakIndent', $data); - } - } else { - $expectedIndent = ($startColumn - 1); - if ($braceIndent !== $expectedIndent) { - $error = 'Closing brace indented incorrectly; expected %s spaces, found %s'; - $data = array( - $expectedIndent, - $braceIndent, - ); - $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'Indent', $data); - } - }//end if - - if ($fix === true) { - $spaces = str_repeat(' ', $expectedIndent); - if ($braceIndent === 0) { - $phpcsFile->fixer->addContentBefore($lineStart, $spaces); - } else { - $phpcsFile->fixer->replaceToken($lineStart, ltrim($tokens[$lineStart]['content'])); - $phpcsFile->fixer->addContentBefore($lineStart, $spaces); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ScopeIndentSniff.php b/phpcs/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ScopeIndentSniff.php deleted file mode 100644 index a5f524d..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ScopeIndentSniff.php +++ /dev/null @@ -1,46 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('Generic_Sniffs_WhiteSpace_ScopeIndentSniff', true) === false) { - $error = 'Class Generic_Sniffs_WhiteSpace_ScopeIndentSniff not found'; - throw new PHP_CodeSniffer_Exception($error); -} - -/** - * PEAR_Sniffs_Whitespace_ScopeIndentSniff. - * - * Checks that control structures are structured correctly, and their content - * is indented correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PEAR_Sniffs_WhiteSpace_ScopeIndentSniff extends Generic_Sniffs_WhiteSpace_ScopeIndentSniff -{ - - /** - * Any scope openers that should not cause an indent. - * - * @var array(int) - */ - protected $nonIndentingScopes = array(T_SWITCH); - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PEAR/ruleset.xml b/phpcs/CodeSniffer/Standards/PEAR/ruleset.xml deleted file mode 100644 index f358b98..0000000 --- a/phpcs/CodeSniffer/Standards/PEAR/ruleset.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - The PEAR coding standard. - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - - - - - - - - diff --git a/phpcs/CodeSniffer/Standards/PHPCS/ruleset.xml b/phpcs/CodeSniffer/Standards/PHPCS/ruleset.xml deleted file mode 100644 index c9abdf9..0000000 --- a/phpcs/CodeSniffer/Standards/PHPCS/ruleset.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - The coding standard for PHP_CodeSniffer itself. - */Tests/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/phpcs/CodeSniffer/Standards/PSR1/Docs/Classes/ClassDeclarationStandard.xml b/phpcs/CodeSniffer/Standards/PSR1/Docs/Classes/ClassDeclarationStandard.xml deleted file mode 100644 index eaae99b..0000000 --- a/phpcs/CodeSniffer/Standards/PSR1/Docs/Classes/ClassDeclarationStandard.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - class Bar { -} - ]]> - - - class Bar { -} - -class Baz { -} - ]]> - - - - - namespace Foo; - -class Bar { -} - ]]> - - - - - - diff --git a/phpcs/CodeSniffer/Standards/PSR1/Docs/Files/SideEffectsStandard.xml b/phpcs/CodeSniffer/Standards/PSR1/Docs/Files/SideEffectsStandard.xml deleted file mode 100644 index 0ed04a0..0000000 --- a/phpcs/CodeSniffer/Standards/PSR1/Docs/Files/SideEffectsStandard.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - echo "Class Foo loaded." - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PSR1/Sniffs/Classes/ClassDeclarationSniff.php b/phpcs/CodeSniffer/Standards/PSR1/Sniffs/Classes/ClassDeclarationSniff.php deleted file mode 100644 index 18ca5f1..0000000 --- a/phpcs/CodeSniffer/Standards/PSR1/Sniffs/Classes/ClassDeclarationSniff.php +++ /dev/null @@ -1,102 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Class Declaration Test. - * - * Checks the declaration of the class is correct. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PSR1_Sniffs_Classes_ClassDeclarationSniff implements PHP_CodeSniffer_Sniff -{ - /** - * The current PHP version. - * - * @var integer - */ - private $_phpVersion = null; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_CLASS, - T_INTERFACE, - T_TRAIT, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param integer $stackPtr The position of the current token in - * the token stack. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - if ($this->_phpVersion === null) { - $this->_phpVersion = PHP_CodeSniffer::getConfigData('php_version'); - if ($this->_phpVersion === null) { - $this->_phpVersion = PHP_VERSION_ID; - } - } - - $tokens = $phpcsFile->getTokens(); - if (isset($tokens[$stackPtr]['scope_closer']) === false) { - return; - } - - $errorData = array(strtolower($tokens[$stackPtr]['content'])); - - $nextClass = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE, T_TRAIT), ($tokens[$stackPtr]['scope_closer'] + 1)); - if ($nextClass !== false) { - $error = 'Each %s must be in a file by itself'; - $phpcsFile->addError($error, $nextClass, 'MultipleClasses', $errorData); - $phpcsFile->recordMetric($stackPtr, 'One class per file', 'no'); - } else { - $phpcsFile->recordMetric($stackPtr, 'One class per file', 'yes'); - } - - if ($this->_phpVersion >= 50300) { - $namespace = $phpcsFile->findNext(array(T_NAMESPACE, T_CLASS, T_INTERFACE, T_TRAIT), 0); - if ($tokens[$namespace]['code'] !== T_NAMESPACE) { - $error = 'Each %s must be in a namespace of at least one level (a top-level vendor name)'; - $phpcsFile->addError($error, $stackPtr, 'MissingNamespace', $errorData); - $phpcsFile->recordMetric($stackPtr, 'Class defined in namespace', 'no'); - } else { - $phpcsFile->recordMetric($stackPtr, 'Class defined in namespace', 'yes'); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php b/phpcs/CodeSniffer/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php deleted file mode 100644 index a41051f..0000000 --- a/phpcs/CodeSniffer/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php +++ /dev/null @@ -1,238 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PSR1_Sniffs_Files_SideEffectsSniff. - * - * Ensures a file declare new symbols and causes no other side effects, or executes - * logic with side effects, but not both. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PSR1_Sniffs_Files_SideEffectsSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the token stack. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $result = $this->_searchForConflict($phpcsFile, 0, ($phpcsFile->numTokens - 1), $tokens); - - if ($result['symbol'] !== null && $result['effect'] !== null) { - $error = 'A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line %s and the first side effect is on line %s.'; - $data = array( - $tokens[$result['symbol']]['line'], - $tokens[$result['effect']]['line'], - ); - $phpcsFile->addWarning($error, 0, 'FoundWithSymbols', $data); - $phpcsFile->recordMetric($stackPtr, 'Declarations and side effects mixed', 'yes'); - } else { - $phpcsFile->recordMetric($stackPtr, 'Declarations and side effects mixed', 'no'); - } - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - - /** - * Searches for symbol declarations and side effects. - * - * Returns the positions of both the first symbol declared and the first - * side effect in the file. A NULL value for either indicates nothing was - * found. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $start The token to start searching from. - * @param int $end The token to search to. - * @param array $tokens The stack of tokens that make up - * the file. - * - * @return array - */ - private function _searchForConflict(PHP_CodeSniffer_File $phpcsFile, $start, $end, $tokens) - { - $symbols = array( - T_CLASS => T_CLASS, - T_INTERFACE => T_INTERFACE, - T_TRAIT => T_TRAIT, - T_FUNCTION => T_FUNCTION, - ); - - $conditions = array( - T_IF => T_IF, - T_ELSE => T_ELSE, - T_ELSEIF => T_ELSEIF, - ); - - $firstSymbol = null; - $firstEffect = null; - for ($i = $start; $i <= $end; $i++) { - // Ignore whitespace and comments. - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$i]['code']]) === true) { - continue; - } - - // Ignore PHP tags. - if ($tokens[$i]['code'] === T_OPEN_TAG - || $tokens[$i]['code'] === T_CLOSE_TAG - ) { - continue; - } - - // Ignore shebang. - if (substr($tokens[$i]['content'], 0, 2) === '#!') { - continue; - } - - // Ignore entire namespace, declare, const and use statements. - if ($tokens[$i]['code'] === T_NAMESPACE - || $tokens[$i]['code'] === T_USE - || $tokens[$i]['code'] === T_DECLARE - || $tokens[$i]['code'] === T_CONST - ) { - if (isset($tokens[$i]['scope_opener']) === true) { - $i = $tokens[$i]['scope_closer']; - } else { - $semicolon = $phpcsFile->findNext(T_SEMICOLON, ($i + 1)); - if ($semicolon !== false) { - $i = $semicolon; - } - } - - continue; - } - - // Ignore function/class prefixes. - if (isset(PHP_CodeSniffer_Tokens::$methodPrefixes[$tokens[$i]['code']]) === true) { - continue; - } - - // Ignore anon classes. - if ($tokens[$i]['code'] === T_ANON_CLASS) { - $i = $tokens[$i]['scope_closer']; - continue; - } - - // Detect and skip over symbols. - if (isset($symbols[$tokens[$i]['code']]) === true - && isset($tokens[$i]['scope_closer']) === true - ) { - if ($firstSymbol === null) { - $firstSymbol = $i; - } - - $i = $tokens[$i]['scope_closer']; - continue; - } else if ($tokens[$i]['code'] === T_STRING - && strtolower($tokens[$i]['content']) === 'define' - ) { - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($i - 1), null, true); - if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR) { - if ($firstSymbol === null) { - $firstSymbol = $i; - } - - $semicolon = $phpcsFile->findNext(T_SEMICOLON, ($i + 1)); - if ($semicolon !== false) { - $i = $semicolon; - } - - continue; - } - }//end if - - // Conditional statements are allowed in symbol files as long as the - // contents is only a symbol definition. So don't count these as effects - // in this case. - if (isset($conditions[$tokens[$i]['code']]) === true) { - if (isset($tokens[$i]['scope_opener']) === false) { - // Probably an "else if", so just ignore. - continue; - } - - $result = $this->_searchForConflict( - $phpcsFile, - ($tokens[$i]['scope_opener'] + 1), - ($tokens[$i]['scope_closer'] - 1), - $tokens - ); - - if ($result['symbol'] !== null) { - if ($firstSymbol === null) { - $firstSymbol = $result['symbol']; - } - - if ($result['effect'] !== null) { - // Found a conflict. - $firstEffect = $result['effect']; - break; - } - } - - if ($firstEffect === null) { - $firstEffect = $result['effect']; - } - - $i = $tokens[$i]['scope_closer']; - continue; - }//end if - - if ($firstEffect === null) { - $firstEffect = $i; - } - - if ($firstSymbol !== null) { - // We have a conflict we have to report, so no point continuing. - break; - } - }//end for - - return array( - 'symbol' => $firstSymbol, - 'effect' => $firstEffect, - ); - - }//end _searchForConflict() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PSR1/Sniffs/Methods/CamelCapsMethodNameSniff.php b/phpcs/CodeSniffer/Standards/PSR1/Sniffs/Methods/CamelCapsMethodNameSniff.php deleted file mode 100644 index f8a8b8a..0000000 --- a/phpcs/CodeSniffer/Standards/PSR1/Sniffs/Methods/CamelCapsMethodNameSniff.php +++ /dev/null @@ -1,93 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff not found'); -} - -/** - * PSR1_Sniffs_Methods_CamelCapsMethodNameSniff. - * - * Ensures method names are defined using camel case. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PSR1_Sniffs_Methods_CamelCapsMethodNameSniff extends Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff -{ - - - /** - * Processes the tokens within the scope. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being processed. - * @param int $stackPtr The position where this token was - * found. - * @param int $currScope The position of the current scope. - * - * @return void - */ - protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) - { - $methodName = $phpcsFile->getDeclarationName($stackPtr); - if ($methodName === null) { - // Ignore closures. - return; - } - - // Ignore magic methods. - if (preg_match('|^__[^_]|', $methodName) !== 0) { - $magicPart = strtolower(substr($methodName, 2)); - if (isset($this->magicMethods[$magicPart]) === true - || isset($this->methodsDoubleUnderscore[$magicPart]) === true - ) { - return; - } - } - - $testName = ltrim($methodName, '_'); - if ($testName !== '' && PHP_CodeSniffer::isCamelCaps($testName, false, true, false) === false) { - $error = 'Method name "%s" is not in camel caps format'; - $className = $phpcsFile->getDeclarationName($currScope); - $errorData = array($className.'::'.$methodName); - $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData); - $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no'); - } else { - $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes'); - } - - }//end processTokenWithinScope() - - - /** - * Processes the tokens outside the scope. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being processed. - * @param int $stackPtr The position where this token was - * found. - * - * @return void - */ - protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - - }//end processTokenOutsideScope() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PSR1/ruleset.xml b/phpcs/CodeSniffer/Standards/PSR1/ruleset.xml deleted file mode 100644 index 9b0096b..0000000 --- a/phpcs/CodeSniffer/Standards/PSR1/ruleset.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - The PSR1 coding standard. - - - - - - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/phpcs/CodeSniffer/Standards/PSR2/Docs/Classes/ClassDeclarationStandard.xml b/phpcs/CodeSniffer/Standards/PSR2/Docs/Classes/ClassDeclarationStandard.xml deleted file mode 100644 index 4e56bc0..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Docs/Classes/ClassDeclarationStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - class Foo -{ -} - ]]> - - - class Foo -{ -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PSR2/Docs/Classes/PropertyDeclarationStandard.xml b/phpcs/CodeSniffer/Standards/PSR2/Docs/Classes/PropertyDeclarationStandard.xml deleted file mode 100644 index ab60a3b..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Docs/Classes/PropertyDeclarationStandard.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - bar; -} - ]]> - - - _bar; -} - ]]> - - - - - private $bar; -} - ]]> - - - var $bar; -} - ]]> - - - - - - - - $bar, $baz; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PSR2/Docs/ControlStructures/ControlStructureSpacingStandard.xml b/phpcs/CodeSniffer/Standards/PSR2/Docs/ControlStructures/ControlStructureSpacingStandard.xml deleted file mode 100644 index dcbe98f..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Docs/ControlStructures/ControlStructureSpacingStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - $foo) { - $var = 1; -} - ]]> - - - $foo ) { - $var = 1; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PSR2/Docs/ControlStructures/ElseIfDeclarationStandard.xml b/phpcs/CodeSniffer/Standards/PSR2/Docs/ControlStructures/ElseIfDeclarationStandard.xml deleted file mode 100644 index a22dd17..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Docs/ControlStructures/ElseIfDeclarationStandard.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - elseif ($bar) { - $var = 2; -} - ]]> - - - else if ($bar) { - $var = 2; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PSR2/Docs/ControlStructures/SwitchDeclarationStandard.xml b/phpcs/CodeSniffer/Standards/PSR2/Docs/ControlStructures/SwitchDeclarationStandard.xml deleted file mode 100644 index 1d6d053..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Docs/ControlStructures/SwitchDeclarationStandard.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - - case 'bar': - break; -} - ]]> - - - case 'bar': - break; -} - ]]> - - - - - 'bar': - break; -} - ]]> - - - 'bar': - break; -} - ]]> - - - - - : - break; - default: - break; -} - ]]> - - - : - break; - default : - break; -} - ]]> - - - - - break; -} - ]]> - - - break; -} - ]]> - - - - - // no break - default: - break; -} - ]]> - - - : - break; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PSR2/Docs/Files/EndFileNewlineStandard.xml b/phpcs/CodeSniffer/Standards/PSR2/Docs/Files/EndFileNewlineStandard.xml deleted file mode 100644 index d6d3aad..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Docs/Files/EndFileNewlineStandard.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/phpcs/CodeSniffer/Standards/PSR2/Docs/Methods/MethodDeclarationStandard.xml b/phpcs/CodeSniffer/Standards/PSR2/Docs/Methods/MethodDeclarationStandard.xml deleted file mode 100644 index e45469e..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Docs/Methods/MethodDeclarationStandard.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - bar() - { - } -} - ]]> - - - _bar() - { - } -} - ]]> - - - - - final public static function bar() - { - } -} - ]]> - - - static public final function bar() - { - } -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/PSR2/Docs/Namespaces/NamespaceDeclarationStandard.xml b/phpcs/CodeSniffer/Standards/PSR2/Docs/Namespaces/NamespaceDeclarationStandard.xml deleted file mode 100644 index 1f4d389..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Docs/Namespaces/NamespaceDeclarationStandard.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - -use \Baz; - ]]> - - - - - - diff --git a/phpcs/CodeSniffer/Standards/PSR2/Docs/Namespaces/UseDeclarationStandard.xml b/phpcs/CodeSniffer/Standards/PSR2/Docs/Namespaces/UseDeclarationStandard.xml deleted file mode 100644 index 4082603..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Docs/Namespaces/UseDeclarationStandard.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - \Foo, \Bar; - ]]> - - - - - - - - - - - - - -class Baz -{ -} - ]]> - - - - - - diff --git a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php b/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php deleted file mode 100644 index c219ba5..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php +++ /dev/null @@ -1,455 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PEAR_Sniffs_Classes_ClassDeclarationSniff', true) === false) { - $error = 'Class PEAR_Sniffs_Classes_ClassDeclarationSniff not found'; - throw new PHP_CodeSniffer_Exception($error); -} - -/** - * Class Declaration Test. - * - * Checks the declaration of the class and its inheritance is correct. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PSR2_Sniffs_Classes_ClassDeclarationSniff extends PEAR_Sniffs_Classes_ClassDeclarationSniff -{ - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - // We want all the errors from the PEAR standard, plus some of our own. - parent::process($phpcsFile, $stackPtr); - - // Just in case. - $tokens = $phpcsFile->getTokens(); - if (isset($tokens[$stackPtr]['scope_opener']) === false) { - return; - } - - $this->processOpen($phpcsFile, $stackPtr); - $this->processClose($phpcsFile, $stackPtr); - - }//end process() - - - /** - * Processes the opening section of a class declaration. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function processOpen(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $stackPtrType = strtolower($tokens[$stackPtr]['content']); - - // Check alignment of the keyword and braces. - if ($tokens[($stackPtr - 1)]['code'] === T_WHITESPACE) { - $prevContent = $tokens[($stackPtr - 1)]['content']; - if ($prevContent !== $phpcsFile->eolChar) { - $blankSpace = substr($prevContent, strpos($prevContent, $phpcsFile->eolChar)); - $spaces = strlen($blankSpace); - - if (in_array($tokens[($stackPtr - 2)]['code'], array(T_ABSTRACT, T_FINAL)) === true - && $spaces !== 1 - ) { - $prevContent = strtolower($tokens[($stackPtr - 2)]['content']); - $error = 'Expected 1 space between %s and %s keywords; %s found'; - $data = array( - $prevContent, - $stackPtrType, - $spaces, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceBeforeKeyword', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr - 1), ' '); - } - } - } else if ($tokens[($stackPtr - 2)]['code'] === T_ABSTRACT - || $tokens[($stackPtr - 2)]['code'] === T_FINAL - ) { - $prevContent = strtolower($tokens[($stackPtr - 2)]['content']); - $error = 'Expected 1 space between %s and %s keywords; newline found'; - $data = array( - $prevContent, - $stackPtrType, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NewlineBeforeKeyword', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr - 1), ' '); - } - }//end if - }//end if - - // We'll need the indent of the class/interface declaration for later. - $classIndent = 0; - for ($i = ($stackPtr - 1); $i > 0; $i--) { - if ($tokens[$i]['line'] === $tokens[$stackPtr]['line']) { - continue; - } - - // We changed lines. - if ($tokens[($i + 1)]['code'] === T_WHITESPACE) { - $classIndent = strlen($tokens[($i + 1)]['content']); - } - - break; - } - - $className = $phpcsFile->findNext(T_STRING, $stackPtr); - - // Spacing of the keyword. - $gap = $tokens[($stackPtr + 1)]['content']; - if (strlen($gap) !== 1) { - $found = strlen($gap); - $error = 'Expected 1 space between %s keyword and %s name; %s found'; - $data = array( - $stackPtrType, - $stackPtrType, - $found, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterKeyword', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); - } - } - - // Check after the class/interface name. - if ($tokens[($className + 2)]['line'] === $tokens[$className]['line']) { - $gap = $tokens[($className + 1)]['content']; - if (strlen($gap) !== 1) { - $found = strlen($gap); - $error = 'Expected 1 space after %s name; %s found'; - $data = array( - $stackPtrType, - $found, - ); - - $fix = $phpcsFile->addFixableError($error, $className, 'SpaceAfterName', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($className + 1), ' '); - } - } - } - - $openingBrace = $tokens[$stackPtr]['scope_opener']; - - // Check positions of the extends and implements keywords. - foreach (array('extends', 'implements') as $keywordType) { - $keyword = $phpcsFile->findNext(constant('T_'.strtoupper($keywordType)), ($stackPtr + 1), $openingBrace); - if ($keyword !== false) { - if ($tokens[$keyword]['line'] !== $tokens[$stackPtr]['line']) { - $error = 'The '.$keywordType.' keyword must be on the same line as the %s name'; - $data = array($stackPtrType); - $fix = $phpcsFile->addFixableError($error, $keyword, ucfirst($keywordType).'Line', $data); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($stackPtr + 1); $i < $keyword; $i++) { - if ($tokens[$i]['line'] !== $tokens[($i + 1)]['line']) { - $phpcsFile->fixer->substrToken($i, 0, (strlen($phpcsFile->eolChar) * -1)); - } - } - - $phpcsFile->fixer->addContentBefore($keyword, ' '); - $phpcsFile->fixer->endChangeset(); - } - } else { - // Check the whitespace before. Whitespace after is checked - // later by looking at the whitespace before the first class name - // in the list. - $gap = strlen($tokens[($keyword - 1)]['content']); - if ($gap !== 1) { - $error = 'Expected 1 space before '.$keywordType.' keyword; %s found'; - $data = array($gap); - $fix = $phpcsFile->addFixableError($error, $keyword, 'SpaceBefore'.ucfirst($keywordType), $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($keyword - 1), ' '); - } - } - }//end if - }//end if - }//end foreach - - // Check each of the extends/implements class names. If the extends/implements - // keyword is the last content on the line, it means we need to check for - // the multi-line format, so we do not include the class names - // from the extends/implements list in the following check. - // Note that classes can only extend one other class, so they can't use a - // multi-line extends format, whereas an interface can extend multiple - // other interfaces, and so uses a multi-line extends format. - if ($tokens[$stackPtr]['code'] === T_INTERFACE) { - $keywordTokenType = T_EXTENDS; - } else { - $keywordTokenType = T_IMPLEMENTS; - } - - $implements = $phpcsFile->findNext($keywordTokenType, ($stackPtr + 1), $openingBrace); - $multiLineImplements = false; - if ($implements !== false) { - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($openingBrace - 1), $implements, true); - if ($tokens[$prev]['line'] !== $tokens[$implements]['line']) { - $multiLineImplements = true; - } - } - - $find = array( - T_STRING, - $keywordTokenType, - ); - - $classNames = array(); - $nextClass = $phpcsFile->findNext($find, ($className + 2), ($openingBrace - 1)); - while ($nextClass !== false) { - $classNames[] = $nextClass; - $nextClass = $phpcsFile->findNext($find, ($nextClass + 1), ($openingBrace - 1)); - } - - $classCount = count($classNames); - $checkingImplements = false; - $implementsToken = null; - foreach ($classNames as $i => $className) { - if ($tokens[$className]['code'] === $keywordTokenType) { - $checkingImplements = true; - $implementsToken = $className; - continue; - } - - if ($checkingImplements === true - && $multiLineImplements === true - && ($tokens[($className - 1)]['code'] !== T_NS_SEPARATOR - || $tokens[($className - 2)]['code'] !== T_STRING) - ) { - $prev = $phpcsFile->findPrevious( - array( - T_NS_SEPARATOR, - T_WHITESPACE, - ), - ($className - 1), - $implements, - true - ); - - if ($prev === $implementsToken && $tokens[$className]['line'] !== ($tokens[$prev]['line'] + 1)) { - if ($keywordTokenType === T_EXTENDS) { - $error = 'The first item in a multi-line extends list must be on the line following the extends keyword'; - $fix = $phpcsFile->addFixableError($error, $className, 'FirstExtendsInterfaceSameLine'); - } else { - $error = 'The first item in a multi-line implements list must be on the line following the implements keyword'; - $fix = $phpcsFile->addFixableError($error, $className, 'FirstInterfaceSameLine'); - } - - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($prev + 1); $i < $className; $i++) { - if ($tokens[$i]['code'] !== T_WHITESPACE) { - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->addNewline($prev); - $phpcsFile->fixer->endChangeset(); - } - } else if ($tokens[$prev]['line'] !== ($tokens[$className]['line'] - 1)) { - if ($keywordTokenType === T_EXTENDS) { - $error = 'Only one interface may be specified per line in a multi-line extends declaration'; - $fix = $phpcsFile->addFixableError($error, $className, 'ExtendsInterfaceSameLine'); - } else { - $error = 'Only one interface may be specified per line in a multi-line implements declaration'; - $fix = $phpcsFile->addFixableError($error, $className, 'InterfaceSameLine'); - } - - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($prev + 1); $i < $className; $i++) { - if ($tokens[$i]['code'] !== T_WHITESPACE) { - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->addNewline($prev); - $phpcsFile->fixer->endChangeset(); - } - } else { - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($className - 1), $implements); - if ($tokens[$prev]['line'] !== $tokens[$className]['line']) { - $found = 0; - } else { - $found = strlen($tokens[$prev]['content']); - } - - $expected = ($classIndent + $this->indent); - if ($found !== $expected) { - $error = 'Expected %s spaces before interface name; %s found'; - $data = array( - $expected, - $found, - ); - $fix = $phpcsFile->addFixableError($error, $className, 'InterfaceWrongIndent', $data); - if ($fix === true) { - $padding = str_repeat(' ', $expected); - if ($found === 0) { - $phpcsFile->fixer->addContent($prev, $padding); - } else { - $phpcsFile->fixer->replaceToken($prev, $padding); - } - } - } - }//end if - } else if ($tokens[($className - 1)]['code'] !== T_NS_SEPARATOR - || $tokens[($className - 2)]['code'] !== T_STRING - ) { - // Not part of a longer fully qualified class name. - if ($tokens[($className - 1)]['code'] === T_COMMA - || ($tokens[($className - 1)]['code'] === T_NS_SEPARATOR - && $tokens[($className - 2)]['code'] === T_COMMA) - ) { - $error = 'Expected 1 space before "%s"; 0 found'; - $data = array($tokens[$className]['content']); - $fix = $phpcsFile->addFixableError($error, ($nextComma + 1), 'NoSpaceBeforeName', $data); - if ($fix === true) { - $phpcsFile->fixer->addContentBefore(($nextComma + 1), ' '); - } - } else { - if ($tokens[($className - 1)]['code'] === T_NS_SEPARATOR) { - $prev = ($className - 2); - } else { - $prev = ($className - 1); - } - - $spaceBefore = strlen($tokens[$prev]['content']); - if ($spaceBefore !== 1) { - $error = 'Expected 1 space before "%s"; %s found'; - $data = array( - $tokens[$className]['content'], - $spaceBefore, - ); - - $fix = $phpcsFile->addFixableError($error, $className, 'SpaceBeforeName', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($prev, ' '); - } - } - }//end if - }//end if - - if ($checkingImplements === true - && $tokens[($className + 1)]['code'] !== T_NS_SEPARATOR - && $tokens[($className + 1)]['code'] !== T_COMMA - ) { - if ($i !== ($classCount - 1)) { - // This is not the last class name, and the comma - // is not where we expect it to be. - if ($tokens[($className + 2)]['code'] !== $keywordTokenType) { - $error = 'Expected 0 spaces between "%s" and comma; %s found'; - $data = array( - $tokens[$className]['content'], - strlen($tokens[($className + 1)]['content']), - ); - - $fix = $phpcsFile->addFixableError($error, $className, 'SpaceBeforeComma', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($className + 1), ''); - } - } - } - - $nextComma = $phpcsFile->findNext(T_COMMA, $className); - } else { - $nextComma = ($className + 1); - }//end if - }//end foreach - - }//end processOpen() - - - /** - * Processes the closing section of a class declaration. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function processClose(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Check that the closing brace comes right after the code body. - $closeBrace = $tokens[$stackPtr]['scope_closer']; - $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, ($closeBrace - 1), null, true); - if ($prevContent !== $tokens[$stackPtr]['scope_opener'] - && $tokens[$prevContent]['line'] !== ($tokens[$closeBrace]['line'] - 1) - ) { - $error = 'The closing brace for the %s must go on the next line after the body'; - $data = array($tokens[$stackPtr]['content']); - $fix = $phpcsFile->addFixableError($error, $closeBrace, 'CloseBraceAfterBody', $data); - - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($prevContent + 1); $i < $closeBrace; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - if (strpos($tokens[$prevContent]['content'], $phpcsFile->eolChar) === false) { - $phpcsFile->fixer->replaceToken($closeBrace, $phpcsFile->eolChar.$tokens[$closeBrace]['content']); - } - - $phpcsFile->fixer->endChangeset(); - } - }//end if - - // Check the closing brace is on it's own line, but allow - // for comments like "//end class". - $nextContent = $phpcsFile->findNext(array(T_WHITESPACE, T_COMMENT), ($closeBrace + 1), null, true); - if ($tokens[$nextContent]['content'] !== $phpcsFile->eolChar - && $tokens[$nextContent]['line'] === $tokens[$closeBrace]['line'] - ) { - $type = strtolower($tokens[$stackPtr]['content']); - $error = 'Closing %s brace must be on a line by itself'; - $data = array($type); - $phpcsFile->addError($error, $closeBrace, 'CloseBraceSameLine', $data); - } - - }//end processClose() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Classes/PropertyDeclarationSniff.php b/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Classes/PropertyDeclarationSniff.php deleted file mode 100644 index 408813f..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Classes/PropertyDeclarationSniff.php +++ /dev/null @@ -1,117 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found'); -} - -/** - * Verifies that properties are declared correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PSR2_Sniffs_Classes_PropertyDeclarationSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff -{ - - - /** - * Processes the function tokens within the class. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. - * - * @return void - */ - protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[$stackPtr]['content'][1] === '_') { - $error = 'Property name "%s" should not be prefixed with an underscore to indicate visibility'; - $data = array($tokens[$stackPtr]['content']); - $phpcsFile->addWarning($error, $stackPtr, 'Underscore', $data); - } - - // Detect multiple properties defined at the same time. Throw an error - // for this, but also only process the first property in the list so we don't - // repeat errors. - $find = PHP_CodeSniffer_Tokens::$scopeModifiers; - $find = array_merge($find, array(T_VARIABLE, T_VAR, T_SEMICOLON)); - $prev = $phpcsFile->findPrevious($find, ($stackPtr - 1)); - if ($tokens[$prev]['code'] === T_VARIABLE) { - return; - } - - if ($tokens[$prev]['code'] === T_VAR) { - $error = 'The var keyword must not be used to declare a property'; - $phpcsFile->addError($error, $stackPtr, 'VarUsed'); - } - - $next = $phpcsFile->findNext(array(T_VARIABLE, T_SEMICOLON), ($stackPtr + 1)); - if ($tokens[$next]['code'] === T_VARIABLE) { - $error = 'There must not be more than one property declared per statement'; - $phpcsFile->addError($error, $stackPtr, 'Multiple'); - } - - $modifier = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$scopeModifiers, $stackPtr); - if (($modifier === false) || ($tokens[$modifier]['line'] !== $tokens[$stackPtr]['line'])) { - $error = 'Visibility must be declared on property "%s"'; - $data = array($tokens[$stackPtr]['content']); - $phpcsFile->addError($error, $stackPtr, 'ScopeMissing', $data); - } - - }//end processMemberVar() - - - /** - * Processes normal variables. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. - * - * @return void - */ - protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - /* - We don't care about normal variables. - */ - - }//end processVariable() - - - /** - * Processes variables in double quoted strings. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. - * - * @return void - */ - protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - /* - We don't care about normal variables. - */ - - }//end processVariableInString() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/ControlStructureSpacingSniff.php b/phpcs/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/ControlStructureSpacingSniff.php deleted file mode 100644 index b215b06..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/ControlStructureSpacingSniff.php +++ /dev/null @@ -1,152 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PSR2_Sniffs_WhiteSpace_ControlStructureSpacingSniff. - * - * Checks that control structures have the correct spacing around brackets. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PSR2_Sniffs_ControlStructures_ControlStructureSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * How many spaces should follow the opening bracket. - * - * @var int - */ - public $requiredSpacesAfterOpen = 0; - - /** - * How many spaces should precede the closing bracket. - * - * @var int - */ - public $requiredSpacesBeforeClose = 0; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_IF, - T_WHILE, - T_FOREACH, - T_FOR, - T_SWITCH, - T_DO, - T_ELSE, - T_ELSEIF, - T_TRY, - T_CATCH, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $this->requiredSpacesAfterOpen = (int) $this->requiredSpacesAfterOpen; - $this->requiredSpacesBeforeClose = (int) $this->requiredSpacesBeforeClose; - $tokens = $phpcsFile->getTokens(); - - if (isset($tokens[$stackPtr]['parenthesis_opener']) === false - || isset($tokens[$stackPtr]['parenthesis_closer']) === false - ) { - return; - } - - $parenOpener = $tokens[$stackPtr]['parenthesis_opener']; - $parenCloser = $tokens[$stackPtr]['parenthesis_closer']; - $spaceAfterOpen = 0; - if ($tokens[($parenOpener + 1)]['code'] === T_WHITESPACE) { - if (strpos($tokens[($parenOpener + 1)]['content'], $phpcsFile->eolChar) !== false) { - $spaceAfterOpen = 'newline'; - } else { - $spaceAfterOpen = strlen($tokens[($parenOpener + 1)]['content']); - } - } - - $phpcsFile->recordMetric($stackPtr, 'Spaces after control structure open parenthesis', $spaceAfterOpen); - - if ($spaceAfterOpen !== $this->requiredSpacesAfterOpen) { - $error = 'Expected %s spaces after opening bracket; %s found'; - $data = array( - $this->requiredSpacesAfterOpen, - $spaceAfterOpen, - ); - $fix = $phpcsFile->addFixableError($error, ($parenOpener + 1), 'SpacingAfterOpenBrace', $data); - if ($fix === true) { - $padding = str_repeat(' ', $this->requiredSpacesAfterOpen); - if ($spaceAfterOpen === 0) { - $phpcsFile->fixer->addContent($parenOpener, $padding); - } else if ($spaceAfterOpen === 'newline') { - $phpcsFile->fixer->replaceToken(($parenOpener + 1), ''); - } else { - $phpcsFile->fixer->replaceToken(($parenOpener + 1), $padding); - } - } - } - - if ($tokens[$parenOpener]['line'] === $tokens[$parenCloser]['line']) { - $spaceBeforeClose = 0; - if ($tokens[($parenCloser - 1)]['code'] === T_WHITESPACE) { - $spaceBeforeClose = strlen(ltrim($tokens[($parenCloser - 1)]['content'], $phpcsFile->eolChar)); - } - - $phpcsFile->recordMetric($stackPtr, 'Spaces before control structure close parenthesis', $spaceBeforeClose); - - if ($spaceBeforeClose !== $this->requiredSpacesBeforeClose) { - $error = 'Expected %s spaces before closing bracket; %s found'; - $data = array( - $this->requiredSpacesBeforeClose, - $spaceBeforeClose, - ); - $fix = $phpcsFile->addFixableError($error, ($parenCloser - 1), 'SpaceBeforeCloseBrace', $data); - if ($fix === true) { - $padding = str_repeat(' ', $this->requiredSpacesBeforeClose); - if ($spaceBeforeClose === 0) { - $phpcsFile->fixer->addContentBefore($parenCloser, $padding); - } else { - $phpcsFile->fixer->replaceToken(($parenCloser - 1), $padding); - } - } - } - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/ElseIfDeclarationSniff.php b/phpcs/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/ElseIfDeclarationSniff.php deleted file mode 100644 index 549ffd0..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/ElseIfDeclarationSniff.php +++ /dev/null @@ -1,85 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PSR2_Sniffs_ControlStructures_ElseIfDeclarationSniff. - * - * Verifies that there are no else if statements. Elseif should be used instead. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PSR2_Sniffs_ControlStructures_ElseIfDeclarationSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_ELSE, - T_ELSEIF, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[$stackPtr]['code'] === T_ELSEIF) { - $phpcsFile->recordMetric($stackPtr, 'Use of ELSE IF or ELSEIF', 'elseif'); - return; - } - - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($tokens[$next]['code'] === T_IF) { - $phpcsFile->recordMetric($stackPtr, 'Use of ELSE IF or ELSEIF', 'else if'); - $error = 'Usage of ELSE IF is discouraged; use ELSEIF instead'; - $fix = $phpcsFile->addFixableWarning($error, $stackPtr, 'NotAllowed'); - - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->replaceToken($stackPtr, 'elseif'); - for ($i = ($stackPtr + 1); $i <= $next; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php b/phpcs/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php deleted file mode 100644 index c624271..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php +++ /dev/null @@ -1,248 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PSR2_Sniffs_ControlStructures_SwitchDeclarationSniff. - * - * Ensures all switch statements are defined correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PSR2_Sniffs_ControlStructures_SwitchDeclarationSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * The number of spaces code should be indented. - * - * @var int - */ - public $indent = 4; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_SWITCH); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // We can't process SWITCH statements unless we know where they start and end. - if (isset($tokens[$stackPtr]['scope_opener']) === false - || isset($tokens[$stackPtr]['scope_closer']) === false - ) { - return; - } - - $switch = $tokens[$stackPtr]; - $nextCase = $stackPtr; - $caseAlignment = ($switch['column'] + $this->indent); - $caseCount = 0; - $foundDefault = false; - - while (($nextCase = $this->_findNextCase($phpcsFile, ($nextCase + 1), $switch['scope_closer'])) !== false) { - if ($tokens[$nextCase]['code'] === T_DEFAULT) { - $type = 'default'; - $foundDefault = true; - } else { - $type = 'case'; - $caseCount++; - } - - if ($tokens[$nextCase]['content'] !== strtolower($tokens[$nextCase]['content'])) { - $expected = strtolower($tokens[$nextCase]['content']); - $error = strtoupper($type).' keyword must be lowercase; expected "%s" but found "%s"'; - $data = array( - $expected, - $tokens[$nextCase]['content'], - ); - - $fix = $phpcsFile->addFixableError($error, $nextCase, $type.'NotLower', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($nextCase, $expected); - } - } - - if ($type === 'case' - && ($tokens[($nextCase + 1)]['code'] !== T_WHITESPACE - || $tokens[($nextCase + 1)]['content'] !== ' ') - ) { - $error = 'CASE keyword must be followed by a single space'; - $fix = $phpcsFile->addFixableError($error, $nextCase, 'SpacingAfterCase'); - if ($fix === true) { - if ($tokens[($nextCase + 1)]['code'] !== T_WHITESPACE) { - $phpcsFile->fixer->addContent($nextCase, ' '); - } else { - $phpcsFile->fixer->replaceToken(($nextCase + 1), ' '); - } - } - } - - $opener = $tokens[$nextCase]['scope_opener']; - $nextCloser = $tokens[$nextCase]['scope_closer']; - if ($tokens[$opener]['code'] === T_COLON) { - if ($tokens[($opener - 1)]['code'] === T_WHITESPACE) { - $error = 'There must be no space before the colon in a '.strtoupper($type).' statement'; - $fix = $phpcsFile->addFixableError($error, $nextCase, 'SpaceBeforeColon'.strtoupper($type)); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($opener - 1), ''); - } - } - - $next = $phpcsFile->findNext(T_WHITESPACE, ($opener + 1), null, true); - if ($tokens[$next]['line'] === $tokens[$opener]['line'] - && $tokens[$next]['code'] === T_COMMENT - ) { - // Skip comments on the same line. - $next = $phpcsFile->findNext(T_WHITESPACE, ($next + 1), null, true); - } - - if ($tokens[$next]['line'] !== ($tokens[$opener]['line'] + 1)) { - $error = 'The '.strtoupper($type).' body must start on the line following the statement'; - $fix = $phpcsFile->addFixableError($error, $nextCase, 'BodyOnNextLine'.strtoupper($type)); - if ($fix === true) { - if ($tokens[$next]['line'] === $tokens[$opener]['line']) { - $padding = str_repeat(' ', ($caseAlignment + $this->indent - 1)); - $phpcsFile->fixer->addContentBefore($next, $phpcsFile->eolChar.$padding); - } else { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($opener + 1); $i < $next; $i++) { - if ($tokens[$i]['line'] === $tokens[$next]['line']) { - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->addNewLineBefore($i); - $phpcsFile->fixer->endChangeset(); - } - } - }//end if - - if ($tokens[$nextCloser]['scope_condition'] === $nextCase) { - // Only need to check some things once, even if the - // closer is shared between multiple case statements, or even - // the default case. - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($nextCloser - 1), $nextCase, true); - if ($tokens[$prev]['line'] === $tokens[$nextCloser]['line']) { - $error = 'Terminating statement must be on a line by itself'; - $fix = $phpcsFile->addFixableError($error, $nextCloser, 'BreakNotNewLine'); - if ($fix === true) { - $phpcsFile->fixer->addNewLine($prev); - $phpcsFile->fixer->replaceToken($nextCloser, trim($tokens[$nextCloser]['content'])); - } - } else { - $diff = ($caseAlignment + $this->indent - $tokens[$nextCloser]['column']); - if ($diff !== 0) { - $error = 'Terminating statement must be indented to the same level as the CASE body'; - $fix = $phpcsFile->addFixableError($error, $nextCloser, 'BreakIndent'); - if ($fix === true) { - if ($diff > 0) { - $phpcsFile->fixer->addContentBefore($nextCloser, str_repeat(' ', $diff)); - } else { - $phpcsFile->fixer->substrToken(($nextCloser - 1), 0, $diff); - } - } - } - }//end if - }//end if - } else { - $error = strtoupper($type).' statements must be defined using a colon'; - $phpcsFile->addError($error, $nextCase, 'WrongOpener'.$type); - }//end if - - // We only want cases from here on in. - if ($type !== 'case') { - continue; - } - - $nextCode = $phpcsFile->findNext( - T_WHITESPACE, - ($tokens[$nextCase]['scope_opener'] + 1), - $nextCloser, - true - ); - - if ($tokens[$nextCode]['code'] !== T_CASE && $tokens[$nextCode]['code'] !== T_DEFAULT) { - // This case statement has content. If the next case or default comes - // before the closer, it means we dont have a terminating statement - // and instead need a comment. - $nextCode = $this->_findNextCase($phpcsFile, ($tokens[$nextCase]['scope_opener'] + 1), $nextCloser); - if ($nextCode !== false) { - $prevCode = $phpcsFile->findPrevious(T_WHITESPACE, ($nextCode - 1), $nextCase, true); - if ($tokens[$prevCode]['code'] !== T_COMMENT) { - $error = 'There must be a comment when fall-through is intentional in a non-empty case body'; - $phpcsFile->addError($error, $nextCase, 'TerminatingComment'); - } - } - } - }//end while - - }//end process() - - - /** - * Find the next CASE or DEFAULT statement from a point in the file. - * - * Note that nested switches are ignored. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position to start looking at. - * @param int $end The position to stop looking at. - * - * @return int | bool - */ - private function _findNextCase(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $end) - { - $tokens = $phpcsFile->getTokens(); - while (($stackPtr = $phpcsFile->findNext(array(T_CASE, T_DEFAULT, T_SWITCH), $stackPtr, $end)) !== false) { - // Skip nested SWITCH statements; they are handled on their own. - if ($tokens[$stackPtr]['code'] === T_SWITCH) { - $stackPtr = $tokens[$stackPtr]['scope_closer']; - continue; - } - - break; - } - - return $stackPtr; - - }//end _findNextCase() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Files/ClosingTagSniff.php b/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Files/ClosingTagSniff.php deleted file mode 100644 index efcd4b6..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Files/ClosingTagSniff.php +++ /dev/null @@ -1,100 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PSR2_Sniffs_Files_LineEndingsSniff. - * - * Checks that the file does not end with a closing tag. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PSR2_Sniffs_Files_ClosingTagSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Make sure this file only contains PHP code. - for ($i = 0; $i < $phpcsFile->numTokens; $i++) { - if ($tokens[$i]['code'] === T_INLINE_HTML - && trim($tokens[$i]['content']) !== '' - ) { - return $phpcsFile->numTokens; - } - } - - // Find the last non-empty token. - for ($last = ($phpcsFile->numTokens - 1); $last > 0; $last--) { - if (trim($tokens[$last]['content']) !== '') { - break; - } - } - - if ($tokens[$last]['code'] === T_CLOSE_TAG) { - $error = 'A closing tag is not permitted at the end of a PHP file'; - $fix = $phpcsFile->addFixableError($error, $last, 'NotAllowed'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->replaceToken($last, $phpcsFile->eolChar); - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($last - 1), null, true); - if ($tokens[$prev]['code'] !== T_SEMICOLON - && $tokens[$prev]['code'] !== T_CLOSE_CURLY_BRACKET - ) { - $phpcsFile->fixer->addContent($prev, ';'); - } - - $phpcsFile->fixer->endChangeset(); - } - - $phpcsFile->recordMetric($stackPtr, 'PHP closing tag at end of PHP-only file', 'yes'); - } else { - $phpcsFile->recordMetric($stackPtr, 'PHP closing tag at end of PHP-only file', 'no'); - } - - // Ignore the rest of the file. - return $phpcsFile->numTokens; - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Files/EndFileNewlineSniff.php b/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Files/EndFileNewlineSniff.php deleted file mode 100644 index 9282b46..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Files/EndFileNewlineSniff.php +++ /dev/null @@ -1,117 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Generic_Sniffs_Files_EndFileNewlineSniff. - * - * Ensures the file ends with a newline character. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PSR2_Sniffs_Files_EndFileNewlineSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - if ($phpcsFile->findNext(T_INLINE_HTML, ($stackPtr + 1)) !== false) { - return ($phpcsFile->numTokens + 1); - } - - // Skip to the end of the file. - $tokens = $phpcsFile->getTokens(); - $lastToken = ($phpcsFile->numTokens - 1); - - if ($tokens[$lastToken]['content'] === '') { - $lastToken--; - } - - // Hard-coding the expected \n in this sniff as it is PSR-2 specific and - // PSR-2 enforces the use of unix style newlines. - if (substr($tokens[$lastToken]['content'], -1) !== "\n") { - $error = 'Expected 1 newline at end of file; 0 found'; - $fix = $phpcsFile->addFixableError($error, $lastToken, 'NoneFound'); - if ($fix === true) { - $phpcsFile->fixer->addNewline($lastToken); - } - - $phpcsFile->recordMetric($stackPtr, 'Number of newlines at EOF', '0'); - return ($phpcsFile->numTokens + 1); - } - - // Go looking for the last non-empty line. - $lastLine = $tokens[$lastToken]['line']; - if ($tokens[$lastToken]['code'] === T_WHITESPACE - || $tokens[$lastToken]['code'] === T_DOC_COMMENT_WHITESPACE - ) { - $lastCode = $phpcsFile->findPrevious(array(T_WHITESPACE, T_DOC_COMMENT_WHITESPACE), ($lastToken - 1), null, true); - } else { - $lastCode = $lastToken; - } - - $lastCodeLine = $tokens[$lastCode]['line']; - $blankLines = ($lastLine - $lastCodeLine + 1); - $phpcsFile->recordMetric($stackPtr, 'Number of newlines at EOF', $blankLines); - - if ($blankLines > 1) { - $error = 'Expected 1 blank line at end of file; %s found'; - $data = array($blankLines); - $fix = $phpcsFile->addFixableError($error, $lastCode, 'TooMany', $data); - - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->replaceToken($lastCode, rtrim($tokens[$lastCode]['content'])); - for ($i = ($lastCode + 1); $i < $lastToken; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->replaceToken($lastToken, $phpcsFile->eolChar); - $phpcsFile->fixer->endChangeset(); - } - } - - // Skip the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Methods/FunctionCallSignatureSniff.php b/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Methods/FunctionCallSignatureSniff.php deleted file mode 100644 index 7b2367b..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Methods/FunctionCallSignatureSniff.php +++ /dev/null @@ -1,89 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PSR2_Sniffs_Methods_FunctionCallSignatureSniff. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PSR2_Sniffs_Methods_FunctionCallSignatureSniff extends PEAR_Sniffs_Functions_FunctionCallSignatureSniff -{ - - /** - * If TRUE, multiple arguments can be defined per line in a multi-line call. - * - * @var bool - */ - public $allowMultipleArguments = false; - - - /** - * Processes single-line calls. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $openBracket The position of the opening bracket - * in the stack passed in $tokens. - * @param array $tokens The stack of tokens that make up - * the file. - * - * @return void - */ - public function isMultiLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens) - { - // If the first argument is on a new line, this is a multi-line - // function call, even if there is only one argument. - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($openBracket + 1), null, true); - if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) { - return true; - } - - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; - - $end = $phpcsFile->findEndOfStatement($openBracket + 1); - while ($tokens[$end]['code'] === T_COMMA) { - // If the next bit of code is not on the same line, this is a - // multi-line function call. - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($end + 1), $closeBracket, true); - if ($next === false) { - return false; - } - - if ($tokens[$next]['line'] !== $tokens[$end]['line']) { - return true; - } - - $end = $phpcsFile->findEndOfStatement($next); - } - - // We've reached the last argument, so see if the next content - // (should be the close bracket) is also on the same line. - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($end + 1), $closeBracket, true); - if ($next !== false && $tokens[$next]['line'] !== $tokens[$end]['line']) { - return true; - } - - return false; - - }//end isMultiLineCall() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Methods/FunctionClosingBraceSniff.php b/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Methods/FunctionClosingBraceSniff.php deleted file mode 100644 index 8a4c188..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Methods/FunctionClosingBraceSniff.php +++ /dev/null @@ -1,104 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PSR2_Sniffs_Methods_FunctionClosingBraceSniff. - * - * Checks that the closing brace of a function goes directly after the body. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PSR2_Sniffs_Methods_FunctionClosingBraceSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_FUNCTION, - T_CLOSURE, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (isset($tokens[$stackPtr]['scope_closer']) === false) { - // Probably an interface method. - return; - } - - $closeBrace = $tokens[$stackPtr]['scope_closer']; - $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, ($closeBrace - 1), null, true); - $found = ($tokens[$closeBrace]['line'] - $tokens[$prevContent]['line'] - 1); - - if ($found < 0) { - // Brace isn't on a new line, so not handled by us. - return; - } - - if ($found === 0) { - // All is good. - return; - } - - $error = 'Function closing brace must go on the next line following the body; found %s blank lines before brace'; - $data = array($found); - $fix = $phpcsFile->addFixableError($error, $closeBrace, 'SpacingBeforeClose', $data); - - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($prevContent + 1); $i < $closeBrace; $i++) { - if ($tokens[$i]['line'] === $tokens[$prevContent]['line']) { - continue; - } - - // Don't remove any identation before the brace. - if ($tokens[$i]['line'] === $tokens[$closeBrace]['line']) { - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Methods/MethodDeclarationSniff.php b/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Methods/MethodDeclarationSniff.php deleted file mode 100644 index 71900da..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Methods/MethodDeclarationSniff.php +++ /dev/null @@ -1,155 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found'); -} - -/** - * PSR2_Sniffs_Methods_MethodDeclarationSniff. - * - * Checks that the method declaration is correct. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PSR2_Sniffs_Methods_MethodDeclarationSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff -{ - - - /** - * Constructs a Squiz_Sniffs_Scope_MethodScopeSniff. - */ - public function __construct() - { - parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION)); - - }//end __construct() - - - /** - * Processes the function tokens within the class. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. - * @param int $currScope The current scope opener token. - * - * @return void - */ - protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) - { - $tokens = $phpcsFile->getTokens(); - - $methodName = $phpcsFile->getDeclarationName($stackPtr); - if ($methodName === null) { - // Ignore closures. - return; - } - - if ($methodName[0] === '_' && isset($methodName[1]) === true && $methodName[1] !== '_') { - $error = 'Method name "%s" should not be prefixed with an underscore to indicate visibility'; - $data = array($methodName); - $phpcsFile->addWarning($error, $stackPtr, 'Underscore', $data); - } - - $visibility = 0; - $static = 0; - $abstract = 0; - $final = 0; - - $find = PHP_CodeSniffer_Tokens::$methodPrefixes; - $find[] = T_WHITESPACE; - $prev = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); - - $prefix = $stackPtr; - while (($prefix = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$methodPrefixes, ($prefix - 1), $prev)) !== false) { - switch ($tokens[$prefix]['code']) { - case T_STATIC: - $static = $prefix; - break; - case T_ABSTRACT: - $abstract = $prefix; - break; - case T_FINAL: - $final = $prefix; - break; - default: - $visibility = $prefix; - break; - } - } - - $fixes = array(); - - if ($visibility !== 0 && $final > $visibility) { - $error = 'The final declaration must precede the visibility declaration'; - $fix = $phpcsFile->addFixableError($error, $final, 'FinalAfterVisibility'); - if ($fix === true) { - $fixes[$final] = ''; - $fixes[($final + 1)] = ''; - if (isset($fixes[$visibility]) === true) { - $fixes[$visibility] = 'final '.$fixes[$visibility]; - } else { - $fixes[$visibility] = 'final '.$tokens[$visibility]['content']; - } - } - } - - if ($visibility !== 0 && $abstract > $visibility) { - $error = 'The abstract declaration must precede the visibility declaration'; - $fix = $phpcsFile->addFixableError($error, $abstract, 'AbstractAfterVisibility'); - if ($fix === true) { - $fixes[$abstract] = ''; - $fixes[($abstract + 1)] = ''; - if (isset($fixes[$visibility]) === true) { - $fixes[$visibility] = 'abstract '.$fixes[$visibility]; - } else { - $fixes[$visibility] = 'abstract '.$tokens[$visibility]['content']; - } - } - } - - if ($static !== 0 && $static < $visibility) { - $error = 'The static declaration must come after the visibility declaration'; - $fix = $phpcsFile->addFixableError($error, $static, 'StaticBeforeVisibility'); - if ($fix === true) { - $fixes[$static] = ''; - $fixes[($static + 1)] = ''; - if (isset($fixes[$visibility]) === true) { - $fixes[$visibility] = $fixes[$visibility].' static'; - } else { - $fixes[$visibility] = $tokens[$visibility]['content'].' static'; - } - } - } - - // Batch all the fixes together to reduce the possibility of conflicts. - if (empty($fixes) === false) { - $phpcsFile->fixer->beginChangeset(); - foreach ($fixes as $stackPtr => $content) { - $phpcsFile->fixer->replaceToken($stackPtr, $content); - } - - $phpcsFile->fixer->endChangeset(); - } - - }//end processTokenWithinScope() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Namespaces/NamespaceDeclarationSniff.php b/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Namespaces/NamespaceDeclarationSniff.php deleted file mode 100644 index aba41b8..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Namespaces/NamespaceDeclarationSniff.php +++ /dev/null @@ -1,105 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PSR2_Sniffs_Namespaces_NamespaceDeclarationSniff. - * - * Ensures namespaces are declared correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PSR2_Sniffs_Namespaces_NamespaceDeclarationSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_NAMESPACE); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - for ($i = ($stackPtr + 1); $i < ($phpcsFile->numTokens - 1); $i++) { - if ($tokens[$i]['line'] === $tokens[$stackPtr]['line']) { - continue; - } - - break; - } - - // The $i var now points to the first token on the line after the - // namespace declaration, which must be a blank line. - $next = $phpcsFile->findNext(T_WHITESPACE, $i, $phpcsFile->numTokens, true); - if ($next === false) { - return; - } - - $diff = ($tokens[$next]['line'] - $tokens[$i]['line']); - if ($diff === 1) { - return; - } - - if ($diff < 0) { - $diff = 0; - } - - $error = 'There must be one blank line after the namespace declaration'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'BlankLineAfter'); - - if ($fix === true) { - if ($diff === 0) { - $phpcsFile->fixer->addNewlineBefore($i); - } else { - $phpcsFile->fixer->beginChangeset(); - for ($x = $i; $x < $next; $x++) { - if ($tokens[$x]['line'] === $tokens[$next]['line']) { - break; - } - - $phpcsFile->fixer->replaceToken($x, ''); - } - - $phpcsFile->fixer->addNewline($i); - $phpcsFile->fixer->endChangeset(); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Namespaces/UseDeclarationSniff.php b/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Namespaces/UseDeclarationSniff.php deleted file mode 100644 index ea2330b..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/Sniffs/Namespaces/UseDeclarationSniff.php +++ /dev/null @@ -1,216 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * PSR2_Sniffs_Namespaces_UseDeclarationSniff. - * - * Ensures USE blocks are declared correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PSR2_Sniffs_Namespaces_UseDeclarationSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_USE); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - if ($this->_shouldIgnoreUse($phpcsFile, $stackPtr) === true) { - return; - } - - $tokens = $phpcsFile->getTokens(); - - // One space after the use keyword. - if ($tokens[($stackPtr + 1)]['content'] !== ' ') { - $error = 'There must be a single space after the USE keyword'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterUse'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); - } - } - - // Only one USE declaration allowed per statement. - $next = $phpcsFile->findNext(array(T_COMMA, T_SEMICOLON, T_OPEN_USE_GROUP), ($stackPtr + 1)); - if ($tokens[$next]['code'] !== T_SEMICOLON) { - $error = 'There must be one USE keyword per declaration'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'MultipleDeclarations'); - if ($fix === true) { - if ($tokens[$next]['code'] === T_COMMA) { - $phpcsFile->fixer->replaceToken($next, ';'.$phpcsFile->eolChar.'use '); - } else { - $baseUse = rtrim($phpcsFile->getTokensAsString($stackPtr, ($next - $stackPtr))); - $closingCurly = $phpcsFile->findNext(T_CLOSE_USE_GROUP, ($next + 1)); - - $phpcsFile->fixer->beginChangeset(); - - // Remove base use statement. - for ($i = $stackPtr; $i <= $next; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - // Convert grouped use statements into full use statements. - do { - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), $closingCurly, true); - - $whitespace = $phpcsFile->findPrevious(T_WHITESPACE, ($next - 1), null, true); - for ($i = ($whitespace + 1); $i < $next; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - if ($tokens[$next]['code'] === T_CONST || $tokens[$next]['code'] === T_FUNCTION) { - $phpcsFile->fixer->addContentBefore($next, 'use '); - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), $closingCurly, true); - $phpcsFile->fixer->addContentBefore($next, str_replace('use ', '', $baseUse)); - } else { - $phpcsFile->fixer->addContentBefore($next, $baseUse); - } - - $next = $phpcsFile->findNext(T_COMMA, ($next + 1), $closingCurly); - if ($next !== false) { - $phpcsFile->fixer->replaceToken($next, ';'.$phpcsFile->eolChar); - } - } while ($next !== false); - - $phpcsFile->fixer->replaceToken($closingCurly, ''); - - // Remove any trailing whitespace. - $next = $phpcsFile->findNext(T_SEMICOLON, $closingCurly); - $whitespace = $phpcsFile->findPrevious(T_WHITESPACE, ($closingCurly - 1), null, true); - for ($i = ($whitespace + 1); $i < $next; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - }//end if - }//end if - }//end if - - // Make sure this USE comes after the first namespace declaration. - $prev = $phpcsFile->findPrevious(T_NAMESPACE, ($stackPtr - 1)); - if ($prev !== false) { - $first = $phpcsFile->findNext(T_NAMESPACE, 1); - if ($prev !== $first) { - $error = 'USE declarations must go after the first namespace declaration'; - $phpcsFile->addError($error, $stackPtr, 'UseAfterNamespace'); - } - } - - // Only interested in the last USE statement from here onwards. - $nextUse = $phpcsFile->findNext(T_USE, ($stackPtr + 1)); - while ($this->_shouldIgnoreUse($phpcsFile, $nextUse) === true) { - $nextUse = $phpcsFile->findNext(T_USE, ($nextUse + 1)); - if ($nextUse === false) { - break; - } - } - - if ($nextUse !== false) { - return; - } - - $end = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1)); - $next = $phpcsFile->findNext(T_WHITESPACE, ($end + 1), null, true); - - if ($tokens[$next]['code'] === T_CLOSE_TAG) { - return; - } - - $diff = ($tokens[$next]['line'] - $tokens[$end]['line'] - 1); - if ($diff !== 1) { - if ($diff < 0) { - $diff = 0; - } - - $error = 'There must be one blank line after the last USE statement; %s found;'; - $data = array($diff); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterLastUse', $data); - if ($fix === true) { - if ($diff === 0) { - $phpcsFile->fixer->addNewline($end); - } else { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($end + 1); $i < $next; $i++) { - if ($tokens[$i]['line'] === $tokens[$next]['line']) { - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->addNewline($end); - $phpcsFile->fixer->endChangeset(); - } - } - }//end if - - }//end process() - - - /** - * Check if this use statement is part of the namespace block. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - private function _shouldIgnoreUse(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Ignore USE keywords inside closures. - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) { - return true; - } - - // Ignore USE keywords for traits. - if ($phpcsFile->hasCondition($stackPtr, array(T_CLASS, T_TRAIT)) === true) { - return true; - } - - return false; - - }//end _shouldIgnoreUse() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/PSR2/ruleset.xml b/phpcs/CodeSniffer/Standards/PSR2/ruleset.xml deleted file mode 100644 index 1bd543a..0000000 --- a/phpcs/CodeSniffer/Standards/PSR2/ruleset.xml +++ /dev/null @@ -1,206 +0,0 @@ - - - The PSR-2 coding standard. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - - - - - - - - - - - - - - - - - 0 - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/Arrays/ArrayBracketSpacingStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/Arrays/ArrayBracketSpacingStandard.xml deleted file mode 100644 index fc6ccbd..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/Arrays/ArrayBracketSpacingStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - ['bar']; -]]> - - - [ 'bar' ]; -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/Arrays/ArrayDeclarationStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/Arrays/ArrayDeclarationStandard.xml deleted file mode 100644 index 4cdfa2b..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/Arrays/ArrayDeclarationStandard.xml +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - array keyword must be lowercase. - ]]> - - - - array('val1', 'val2'); - ]]> - - - Array('val1', 'val2'); - ]]> - - - - array keyword. - ]]> - - - - 'key1' => 'value1', - 'key2' => 'value2', - ); - ]]> - - - 'key1' => 'value1', - 'key2' => 'value2', - ); - ]]> - - - - array keyword. The closing parenthesis must be aligned with the start of the array keyword. - ]]> - - - - 'key1' => 'value1', - 'key2' => 'value2', - ); - ]]> - - - 'key1' => 'value1', - 'key2' => 'value2', -); - ]]> - - - - - - - - => 'ValueTen', - 'keyTwenty' => 'ValueTwenty', - ); - ]]> - - - => 'ValueTen', - 'keyTwenty' => 'ValueTwenty', - ); - ]]> - - - - - - - - 'value1', - 'key2' => 'value2', - 'key3' => 'value3', - ); - ]]> - - - 'value1', - 'key2' => 'value2', - 'key3' => 'value3' - ); - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/Classes/LowercaseClassKeywordsStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/Classes/LowercaseClassKeywordsStandard.xml deleted file mode 100644 index 89fcb5d..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/Classes/LowercaseClassKeywordsStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - final class Foo extends Bar -{ -} -]]> - - - Final Class Foo Extends Bar -{ -} -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/Classes/SelfMemberReferenceStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/Classes/SelfMemberReferenceStandard.xml deleted file mode 100644 index 59d193f..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/Classes/SelfMemberReferenceStandard.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - self::foo(); -]]> - - - SELF::foo(); -]]> - - - - - ::foo(); -]]> - - - :: foo(); -]]> - - - - - self::bar(); - } -} -]]> - - - Foo -{ - public static function bar() - { - } - - public static function baz() - { - Foo::bar(); - } -} -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/Commenting/DocCommentAlignmentStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/Commenting/DocCommentAlignmentStandard.xml deleted file mode 100644 index 414b89a..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/Commenting/DocCommentAlignmentStandard.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - * @see foo() - */ -]]> - - - * @see foo() -*/ -]]> - - - - - @see foo() - */ -]]> - - - @see foo() - */ -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/Commenting/FunctionCommentThrowTagStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/Commenting/FunctionCommentThrowTagStandard.xml deleted file mode 100644 index 81df2e3..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/Commenting/FunctionCommentThrowTagStandard.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - @throws Exception all the time - * @return void - */ -function foo() -{ - throw new Exception('Danger!'); -} -]]> - - - - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/ControlStructures/ForEachLoopDeclarationStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/ControlStructures/ForEachLoopDeclarationStandard.xml deleted file mode 100644 index 87c6181..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/ControlStructures/ForEachLoopDeclarationStandard.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - $foo as $bar => $baz) { - echo $baz; -} -]]> - - - $foo as $bar=>$baz ) { - echo $baz; -} -]]> - - - - - as $bar => $baz) { - echo $baz; -} -]]> - - - AS $bar => $baz) { - echo $baz; -} -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/ControlStructures/ForLoopDeclarationStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/ControlStructures/ForLoopDeclarationStandard.xml deleted file mode 100644 index bbc4392..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/ControlStructures/ForLoopDeclarationStandard.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - $i = 0; $i < 10; $i++) { - echo $i; -} -]]> - - - $i = 0; $i < 10; $i++ ) { - echo $i; -} -]]> - - - - - ; $i < 10; $i++) { - echo $i; -} -]]> - - - ; $i < 10 ; $i++) { - echo $i; -} -]]> - - - - - $i < 10; $i++) { - echo $i; -} -]]> - - - $i < 10;$i++) { - echo $i; -} -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/ControlStructures/LowercaseDeclarationStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/ControlStructures/LowercaseDeclarationStandard.xml deleted file mode 100644 index 699f1f0..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/ControlStructures/LowercaseDeclarationStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - if ($foo) { - $bar = true; -} -]]> - - - IF ($foo) { - $bar = true; -} -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/Functions/FunctionDuplicateArgumentStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/Functions/FunctionDuplicateArgumentStandard.xml deleted file mode 100644 index a890aba..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/Functions/FunctionDuplicateArgumentStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - isset($foo)) { - echo $foo; -} -]]> - - - isSet($foo)) { - echo $foo; -} -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/Functions/LowercaseFunctionKeywordsStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/Functions/LowercaseFunctionKeywordsStandard.xml deleted file mode 100644 index 46e8a8f..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/Functions/LowercaseFunctionKeywordsStandard.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - function foo() -{ - return true; -} -]]> - - - FUNCTION foo() -{ - return true; -} -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/Scope/StaticThisUsageStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/Scope/StaticThisUsageStandard.xml deleted file mode 100644 index 3c97f54..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/Scope/StaticThisUsageStandard.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - static function bar() - { - return self::$staticMember; - } -} -]]> - - - static function bar() - { - return $this->$staticMember; - } -} -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/Strings/EchoedStringsStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/Strings/EchoedStringsStandard.xml deleted file mode 100644 index 030f2a6..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/Strings/EchoedStringsStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - "Hello"; -]]> - - - ("Hello"); -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/CastSpacingStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/CastSpacingStandard.xml deleted file mode 100644 index 0fb195c..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/CastSpacingStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - int)'42'; -]]> - - - int )'42'; -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/FunctionOpeningBraceStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/FunctionOpeningBraceStandard.xml deleted file mode 100644 index d2bc264..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/FunctionOpeningBraceStandard.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - { -} -]]> - - - { -} -]]> - - - - - return 42; -} -]]> - - - - return 42; -} -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/LanguageConstructSpacingStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/LanguageConstructSpacingStandard.xml deleted file mode 100644 index 608bed0..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/LanguageConstructSpacingStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - "hi"; -]]> - - - "hi"; -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/ObjectOperatorSpacingStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/ObjectOperatorSpacingStandard.xml deleted file mode 100644 index c6194d7..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/ObjectOperatorSpacingStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - ) should not have any space around it. - ]]> - - - - ->bar(); -]]> - - - -> bar(); -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/ScopeKeywordSpacingStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/ScopeKeywordSpacingStandard.xml deleted file mode 100644 index 8cadf66..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/ScopeKeywordSpacingStandard.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - static function foo() -{ -} -]]> - - - static function foo() -{ -} -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/SemicolonSpacingStandard.xml b/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/SemicolonSpacingStandard.xml deleted file mode 100644 index 7b22795..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Docs/WhiteSpace/SemicolonSpacingStandard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - ; -]]> - - - ; -]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Arrays/ArrayBracketSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Arrays/ArrayBracketSpacingSniff.php deleted file mode 100644 index 0a4b55f..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Arrays/ArrayBracketSpacingSniff.php +++ /dev/null @@ -1,119 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Arrays_ArrayBracketSpacingSniff. - * - * Ensure that there are no spaces around square brackets. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Arrays_ArrayBracketSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_OPEN_SQUARE_BRACKET, - T_CLOSE_SQUARE_BRACKET, - ); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The current file being checked. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // PHP 5.4 introduced a shorthand array declaration syntax, so we need - // to ignore the these type of array declarations because this sniff is - // only dealing with array usage. - if ($tokens[$stackPtr]['code'] === T_OPEN_SQUARE_BRACKET) { - $openBracket = $stackPtr; - } else { - if (isset($tokens[$stackPtr]['bracket_opener']) === false) { - return; - } - - $openBracket = $tokens[$stackPtr]['bracket_opener']; - } - - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($openBracket - 1), null, true); - if ($tokens[$prev]['code'] === T_EQUAL) { - return; - } - - // Square brackets can not have a space before them. - $prevType = $tokens[($stackPtr - 1)]['code']; - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$prevType]) === true) { - $nonSpace = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 2), null, true); - $expected = $tokens[$nonSpace]['content'].$tokens[$stackPtr]['content']; - $found = $phpcsFile->getTokensAsString($nonSpace, ($stackPtr - $nonSpace)).$tokens[$stackPtr]['content']; - $error = 'Space found before square bracket; expected "%s" but found "%s"'; - $data = array( - $expected, - $found, - ); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceBeforeBracket', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr - 1), ''); - } - } - - // Open square brackets can't ever have spaces after them. - if ($tokens[$stackPtr]['code'] === T_OPEN_SQUARE_BRACKET) { - $nextType = $tokens[($stackPtr + 1)]['code']; - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$nextType]) === true) { - $nonSpace = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 2), null, true); - $expected = $tokens[$stackPtr]['content'].$tokens[$nonSpace]['content']; - $found = $phpcsFile->getTokensAsString($stackPtr, ($nonSpace - $stackPtr + 1)); - $error = 'Space found after square bracket; expected "%s" but found "%s"'; - $data = array( - $expected, - $found, - ); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterBracket', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ''); - } - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php deleted file mode 100644 index ff5a286..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php +++ /dev/null @@ -1,863 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * A test to ensure that arrays conform to the array coding standard. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Arrays_ArrayDeclarationSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_ARRAY, - T_OPEN_SHORT_ARRAY, - ); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The current file being checked. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[$stackPtr]['code'] === T_ARRAY) { - $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'no'); - - // Array keyword should be lower case. - if ($tokens[$stackPtr]['content'] !== strtolower($tokens[$stackPtr]['content'])) { - if ($tokens[$stackPtr]['content'] === strtoupper($tokens[$stackPtr]['content'])) { - $phpcsFile->recordMetric($stackPtr, 'Array keyword case', 'upper'); - } else { - $phpcsFile->recordMetric($stackPtr, 'Array keyword case', 'mixed'); - } - - $error = 'Array keyword should be lower case; expected "array" but found "%s"'; - $data = array($tokens[$stackPtr]['content']); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotLowerCase', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, 'array'); - } - } else { - $phpcsFile->recordMetric($stackPtr, 'Array keyword case', 'lower'); - } - - $arrayStart = $tokens[$stackPtr]['parenthesis_opener']; - if (isset($tokens[$arrayStart]['parenthesis_closer']) === false) { - return; - } - - $arrayEnd = $tokens[$arrayStart]['parenthesis_closer']; - - if ($arrayStart !== ($stackPtr + 1)) { - $error = 'There must be no space between the "array" keyword and the opening parenthesis'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterKeyword'); - - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($stackPtr + 1); $i < $arrayStart; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - } - } else { - $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'yes'); - $arrayStart = $stackPtr; - $arrayEnd = $tokens[$stackPtr]['bracket_closer']; - }//end if - - // Check for empty arrays. - $content = $phpcsFile->findNext(T_WHITESPACE, ($arrayStart + 1), ($arrayEnd + 1), true); - if ($content === $arrayEnd) { - // Empty array, but if the brackets aren't together, there's a problem. - if (($arrayEnd - $arrayStart) !== 1) { - $error = 'Empty array declaration must have no space between the parentheses'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceInEmptyArray'); - - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($arrayStart + 1); $i < $arrayEnd; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - } - - // We can return here because there is nothing else to check. All code - // below can assume that the array is not empty. - return; - } - - if ($tokens[$arrayStart]['line'] === $tokens[$arrayEnd]['line']) { - $this->processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd); - } else { - $this->processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd); - } - - }//end process() - - - /** - * Processes a single-line array definition. - * - * @param PHP_CodeSniffer_File $phpcsFile The current file being checked. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $arrayStart The token that starts the array definition. - * @param int $arrayEnd The token that ends the array definition. - * - * @return void - */ - public function processSingleLineArray(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $arrayStart, $arrayEnd) - { - $tokens = $phpcsFile->getTokens(); - - // Check if there are multiple values. If so, then it has to be multiple lines - // unless it is contained inside a function call or condition. - $valueCount = 0; - $commas = array(); - for ($i = ($arrayStart + 1); $i < $arrayEnd; $i++) { - // Skip bracketed statements, like function calls. - if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS) { - $i = $tokens[$i]['parenthesis_closer']; - continue; - } - - if ($tokens[$i]['code'] === T_COMMA) { - // Before counting this comma, make sure we are not - // at the end of the array. - $next = $phpcsFile->findNext(T_WHITESPACE, ($i + 1), $arrayEnd, true); - if ($next !== false) { - $valueCount++; - $commas[] = $i; - } else { - // There is a comma at the end of a single line array. - $error = 'Comma not allowed after last value in single-line array declaration'; - $fix = $phpcsFile->addFixableError($error, $i, 'CommaAfterLast'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($i, ''); - } - } - } - }//end for - - // Now check each of the double arrows (if any). - $nextArrow = $arrayStart; - while (($nextArrow = $phpcsFile->findNext(T_DOUBLE_ARROW, ($nextArrow + 1), $arrayEnd)) !== false) { - if ($tokens[($nextArrow - 1)]['code'] !== T_WHITESPACE) { - $content = $tokens[($nextArrow - 1)]['content']; - $error = 'Expected 1 space between "%s" and double arrow; 0 found'; - $data = array($content); - $fix = $phpcsFile->addFixableError($error, $nextArrow, 'NoSpaceBeforeDoubleArrow', $data); - if ($fix === true) { - $phpcsFile->fixer->addContentBefore($nextArrow, ' '); - } - } else { - $spaceLength = $tokens[($nextArrow - 1)]['length']; - if ($spaceLength !== 1) { - $content = $tokens[($nextArrow - 2)]['content']; - $error = 'Expected 1 space between "%s" and double arrow; %s found'; - $data = array( - $content, - $spaceLength, - ); - - $fix = $phpcsFile->addFixableError($error, $nextArrow, 'SpaceBeforeDoubleArrow', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($nextArrow - 1), ' '); - } - } - }//end if - - if ($tokens[($nextArrow + 1)]['code'] !== T_WHITESPACE) { - $content = $tokens[($nextArrow + 1)]['content']; - $error = 'Expected 1 space between double arrow and "%s"; 0 found'; - $data = array($content); - $fix = $phpcsFile->addFixableError($error, $nextArrow, 'NoSpaceAfterDoubleArrow', $data); - if ($fix === true) { - $phpcsFile->fixer->addContent($nextArrow, ' '); - } - } else { - $spaceLength = $tokens[($nextArrow + 1)]['length']; - if ($spaceLength !== 1) { - $content = $tokens[($nextArrow + 2)]['content']; - $error = 'Expected 1 space between double arrow and "%s"; %s found'; - $data = array( - $content, - $spaceLength, - ); - - $fix = $phpcsFile->addFixableError($error, $nextArrow, 'SpaceAfterDoubleArrow', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($nextArrow + 1), ' '); - } - } - }//end if - }//end while - - if ($valueCount > 0) { - $conditionCheck = $phpcsFile->findPrevious(array(T_OPEN_PARENTHESIS, T_SEMICOLON), ($stackPtr - 1), null, false); - - if ($conditionCheck === false - || $tokens[$conditionCheck]['line'] !== $tokens[$stackPtr]['line'] - ) { - $error = 'Array with multiple values cannot be declared on a single line'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SingleLineNotAllowed'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->addNewline($arrayStart); - $phpcsFile->fixer->addNewlineBefore($arrayEnd); - $phpcsFile->fixer->endChangeset(); - } - - return; - } - - // We have a multiple value array that is inside a condition or - // function. Check its spacing is correct. - foreach ($commas as $comma) { - if ($tokens[($comma + 1)]['code'] !== T_WHITESPACE) { - $content = $tokens[($comma + 1)]['content']; - $error = 'Expected 1 space between comma and "%s"; 0 found'; - $data = array($content); - $fix = $phpcsFile->addFixableError($error, $comma, 'NoSpaceAfterComma', $data); - if ($fix === true) { - $phpcsFile->fixer->addContent($comma, ' '); - } - } else { - $spaceLength = $tokens[($comma + 1)]['length']; - if ($spaceLength !== 1) { - $content = $tokens[($comma + 2)]['content']; - $error = 'Expected 1 space between comma and "%s"; %s found'; - $data = array( - $content, - $spaceLength, - ); - - $fix = $phpcsFile->addFixableError($error, $comma, 'SpaceAfterComma', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($comma + 1), ' '); - } - } - }//end if - - if ($tokens[($comma - 1)]['code'] === T_WHITESPACE) { - $content = $tokens[($comma - 2)]['content']; - $spaceLength = $tokens[($comma - 1)]['length']; - $error = 'Expected 0 spaces between "%s" and comma; %s found'; - $data = array( - $content, - $spaceLength, - ); - - $fix = $phpcsFile->addFixableError($error, $comma, 'SpaceBeforeComma', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($comma - 1), ''); - } - } - }//end foreach - }//end if - - }//end processSingleLineArray() - - - /** - * Processes a multi-line array definition. - * - * @param PHP_CodeSniffer_File $phpcsFile The current file being checked. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $arrayStart The token that starts the array definition. - * @param int $arrayEnd The token that ends the array definition. - * - * @return void - */ - public function processMultiLineArray(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $arrayStart, $arrayEnd) - { - $tokens = $phpcsFile->getTokens(); - $keywordStart = $tokens[$stackPtr]['column']; - - // Check the closing bracket is on a new line. - $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($arrayEnd - 1), $arrayStart, true); - if ($tokens[$lastContent]['line'] === $tokens[$arrayEnd]['line']) { - $error = 'Closing parenthesis of array declaration must be on a new line'; - $fix = $phpcsFile->addFixableError($error, $arrayEnd, 'CloseBraceNewLine'); - if ($fix === true) { - $phpcsFile->fixer->addNewlineBefore($arrayEnd); - } - } else if ($tokens[$arrayEnd]['column'] !== $keywordStart) { - // Check the closing bracket is lined up under the "a" in array. - $expected = ($keywordStart - 1); - $found = ($tokens[$arrayEnd]['column'] - 1); - $error = 'Closing parenthesis not aligned correctly; expected %s space(s) but found %s'; - $data = array( - $expected, - $found, - ); - - $fix = $phpcsFile->addFixableError($error, $arrayEnd, 'CloseBraceNotAligned', $data); - if ($fix === true) { - if ($found === 0) { - $phpcsFile->fixer->addContent(($arrayEnd - 1), str_repeat(' ', $expected)); - } else { - $phpcsFile->fixer->replaceToken(($arrayEnd - 1), str_repeat(' ', $expected)); - } - } - }//end if - - $keyUsed = false; - $singleUsed = false; - $indices = array(); - $maxLength = 0; - - if ($tokens[$stackPtr]['code'] === T_ARRAY) { - $lastToken = $tokens[$stackPtr]['parenthesis_opener']; - } else { - $lastToken = $stackPtr; - } - - // Find all the double arrows that reside in this scope. - for ($nextToken = ($stackPtr + 1); $nextToken < $arrayEnd; $nextToken++) { - // Skip bracketed statements, like function calls. - if ($tokens[$nextToken]['code'] === T_OPEN_PARENTHESIS - && (isset($tokens[$nextToken]['parenthesis_owner']) === false - || $tokens[$nextToken]['parenthesis_owner'] !== $stackPtr) - ) { - $nextToken = $tokens[$nextToken]['parenthesis_closer']; - continue; - } - - if ($tokens[$nextToken]['code'] === T_ARRAY - || $tokens[$nextToken]['code'] === T_OPEN_SHORT_ARRAY - || $tokens[$nextToken]['code'] === T_CLOSURE - ) { - // Let subsequent calls of this test handle nested arrays. - if ($tokens[$lastToken]['code'] !== T_DOUBLE_ARROW) { - $indices[] = array('value' => $nextToken); - $lastToken = $nextToken; - } - - if ($tokens[$nextToken]['code'] === T_ARRAY) { - $nextToken = $tokens[$tokens[$nextToken]['parenthesis_opener']]['parenthesis_closer']; - } else if ($tokens[$nextToken]['code'] === T_OPEN_SHORT_ARRAY) { - $nextToken = $tokens[$nextToken]['bracket_closer']; - } else { - // T_CLOSURE. - $nextToken = $tokens[$nextToken]['scope_closer']; - } - - $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($nextToken + 1), null, true); - if ($tokens[$nextToken]['code'] !== T_COMMA) { - $nextToken--; - } else { - $lastToken = $nextToken; - } - - continue; - }//end if - - if ($tokens[$nextToken]['code'] !== T_DOUBLE_ARROW - && $tokens[$nextToken]['code'] !== T_COMMA - ) { - continue; - } - - $currentEntry = array(); - - if ($tokens[$nextToken]['code'] === T_COMMA) { - $stackPtrCount = 0; - if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) { - $stackPtrCount = count($tokens[$stackPtr]['nested_parenthesis']); - } - - $commaCount = 0; - if (isset($tokens[$nextToken]['nested_parenthesis']) === true) { - $commaCount = count($tokens[$nextToken]['nested_parenthesis']); - if ($tokens[$stackPtr]['code'] === T_ARRAY) { - // Remove parenthesis that are used to define the array. - $commaCount--; - } - } - - if ($commaCount > $stackPtrCount) { - // This comma is inside more parenthesis than the ARRAY keyword, - // then there it is actually a comma used to separate arguments - // in a function call. - continue; - } - - if ($keyUsed === true && $tokens[$lastToken]['code'] === T_COMMA) { - $error = 'No key specified for array entry; first entry specifies key'; - $phpcsFile->addError($error, $nextToken, 'NoKeySpecified'); - return; - } - - if ($keyUsed === false) { - if ($tokens[($nextToken - 1)]['code'] === T_WHITESPACE) { - $content = $tokens[($nextToken - 2)]['content']; - if ($tokens[($nextToken - 1)]['content'] === $phpcsFile->eolChar) { - $spaceLength = 'newline'; - } else { - $spaceLength = $tokens[($nextToken - 1)]['length']; - } - - $error = 'Expected 0 spaces between "%s" and comma; %s found'; - $data = array( - $content, - $spaceLength, - ); - - $fix = $phpcsFile->addFixableError($error, $nextToken, 'SpaceBeforeComma', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($nextToken - 1), ''); - } - } - - $valueContent = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, - ($lastToken + 1), - $nextToken, - true - ); - - $indices[] = array('value' => $valueContent); - $singleUsed = true; - }//end if - - $lastToken = $nextToken; - continue; - }//end if - - if ($tokens[$nextToken]['code'] === T_DOUBLE_ARROW) { - if ($singleUsed === true) { - $error = 'Key specified for array entry; first entry has no key'; - $phpcsFile->addError($error, $nextToken, 'KeySpecified'); - return; - } - - $currentEntry['arrow'] = $nextToken; - $keyUsed = true; - - // Find the start of index that uses this double arrow. - $indexEnd = $phpcsFile->findPrevious(T_WHITESPACE, ($nextToken - 1), $arrayStart, true); - $indexStart = $phpcsFile->findStartOfStatement($indexEnd); - - if ($indexStart === $indexEnd) { - $currentEntry['index'] = $indexEnd; - $currentEntry['index_content'] = $tokens[$indexEnd]['content']; - } else { - $currentEntry['index'] = $indexStart; - $currentEntry['index_content'] = $phpcsFile->getTokensAsString($indexStart, ($indexEnd - $indexStart + 1)); - } - - $indexLength = strlen($currentEntry['index_content']); - if ($maxLength < $indexLength) { - $maxLength = $indexLength; - } - - // Find the value of this index. - $nextContent = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, - ($nextToken + 1), - $arrayEnd, - true - ); - - $currentEntry['value'] = $nextContent; - $indices[] = $currentEntry; - $lastToken = $nextToken; - }//end if - }//end for - - // Check for mutli-line arrays that should be single-line. - $singleValue = false; - - if (empty($indices) === true) { - $singleValue = true; - } else if (count($indices) === 1 && $tokens[$lastToken]['code'] === T_COMMA) { - // There may be another array value without a comma. - $exclude = PHP_CodeSniffer_Tokens::$emptyTokens; - $exclude[] = T_COMMA; - $nextContent = $phpcsFile->findNext($exclude, ($indices[0]['value'] + 1), $arrayEnd, true); - if ($nextContent === false) { - $singleValue = true; - } - } - - if ($singleValue === true) { - // Array cannot be empty, so this is a multi-line array with - // a single value. It should be defined on single line. - $error = 'Multi-line array contains a single value; use single-line array instead'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'MultiLineNotAllowed'); - - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($arrayStart + 1); $i < $arrayEnd; $i++) { - if ($tokens[$i]['code'] !== T_WHITESPACE) { - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - for ($i = ($arrayEnd - 1); $i > $arrayStart; $i--) { - if ($tokens[$i]['code'] !== T_WHITESPACE) { - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - - return; - }//end if - - /* - This section checks for arrays that don't specify keys. - - Arrays such as: - array( - 'aaa', - 'bbb', - 'd', - ); - */ - - if ($keyUsed === false && empty($indices) === false) { - $count = count($indices); - $lastIndex = $indices[($count - 1)]['value']; - - $trailingContent = $phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, - ($arrayEnd - 1), - $lastIndex, - true - ); - - if ($tokens[$trailingContent]['code'] !== T_COMMA) { - $phpcsFile->recordMetric($stackPtr, 'Array end comma', 'no'); - $error = 'Comma required after last value in array declaration'; - $fix = $phpcsFile->addFixableError($error, $trailingContent, 'NoCommaAfterLast'); - if ($fix === true) { - $phpcsFile->fixer->addContent($trailingContent, ','); - } - } else { - $phpcsFile->recordMetric($stackPtr, 'Array end comma', 'yes'); - } - - $lastValueLine = false; - foreach ($indices as $value) { - if (empty($value['value']) === true) { - // Array was malformed and we couldn't figure out - // the array value correctly, so we have to ignore it. - // Other parts of this sniff will correct the error. - continue; - } - - if ($lastValueLine !== false && $tokens[$value['value']]['line'] === $lastValueLine) { - $error = 'Each value in a multi-line array must be on a new line'; - $fix = $phpcsFile->addFixableError($error, $value['value'], 'ValueNoNewline'); - if ($fix === true) { - if ($tokens[($value['value'] - 1)]['code'] === T_WHITESPACE) { - $phpcsFile->fixer->replaceToken(($value['value'] - 1), ''); - } - - $phpcsFile->fixer->addNewlineBefore($value['value']); - } - } else if ($tokens[($value['value'] - 1)]['code'] === T_WHITESPACE) { - $expected = $keywordStart; - - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $value['value'], true); - $found = ($tokens[$first]['column'] - 1); - if ($found !== $expected) { - $error = 'Array value not aligned correctly; expected %s spaces but found %s'; - $data = array( - $expected, - $found, - ); - - $fix = $phpcsFile->addFixableError($error, $value['value'], 'ValueNotAligned', $data); - if ($fix === true) { - if ($found === 0) { - $phpcsFile->fixer->addContent(($value['value'] - 1), str_repeat(' ', $expected)); - } else { - $phpcsFile->fixer->replaceToken(($value['value'] - 1), str_repeat(' ', $expected)); - } - } - } - }//end if - - $lastValueLine = $tokens[$value['value']]['line']; - }//end foreach - }//end if - - /* - Below the actual indentation of the array is checked. - Errors will be thrown when a key is not aligned, when - a double arrow is not aligned, and when a value is not - aligned correctly. - If an error is found in one of the above areas, then errors - are not reported for the rest of the line to avoid reporting - spaces and columns incorrectly. Often fixing the first - problem will fix the other 2 anyway. - - For example: - - $a = array( - 'index' => '2', - ); - - or - - $a = [ - 'index' => '2', - ]; - - In this array, the double arrow is indented too far, but this - will also cause an error in the value's alignment. If the arrow were - to be moved back one space however, then both errors would be fixed. - */ - - $numValues = count($indices); - - $indicesStart = ($keywordStart + 1); - $arrowStart = ($indicesStart + $maxLength + 1); - $valueStart = ($arrowStart + 3); - $indexLine = $tokens[$stackPtr]['line']; - $lastIndexLine = null; - foreach ($indices as $index) { - if (isset($index['index']) === false) { - // Array value only. - if ($tokens[$index['value']]['line'] === $tokens[$stackPtr]['line'] && $numValues > 1) { - $error = 'The first value in a multi-value array must be on a new line'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'FirstValueNoNewline'); - if ($fix === true) { - $phpcsFile->fixer->addNewlineBefore($index['value']); - } - } - - continue; - } - - $lastIndexLine = $indexLine; - $indexLine = $tokens[$index['index']]['line']; - - if ($indexLine === $tokens[$stackPtr]['line']) { - $error = 'The first index in a multi-value array must be on a new line'; - $fix = $phpcsFile->addFixableError($error, $index['index'], 'FirstIndexNoNewline'); - if ($fix === true) { - $phpcsFile->fixer->addNewlineBefore($index['index']); - } - - continue; - } - - if ($indexLine === $lastIndexLine) { - $error = 'Each index in a multi-line array must be on a new line'; - $fix = $phpcsFile->addFixableError($error, $index['index'], 'IndexNoNewline'); - if ($fix === true) { - if ($tokens[($index['index'] - 1)]['code'] === T_WHITESPACE) { - $phpcsFile->fixer->replaceToken(($index['index'] - 1), ''); - } - - $phpcsFile->fixer->addNewlineBefore($index['index']); - } - - continue; - } - - if ($tokens[$index['index']]['column'] !== $indicesStart) { - $expected = ($indicesStart - 1); - $found = ($tokens[$index['index']]['column'] - 1); - $error = 'Array key not aligned correctly; expected %s spaces but found %s'; - $data = array( - $expected, - $found, - ); - - $fix = $phpcsFile->addFixableError($error, $index['index'], 'KeyNotAligned', $data); - if ($fix === true) { - if ($found === 0) { - $phpcsFile->fixer->addContent(($index['index'] - 1), str_repeat(' ', $expected)); - } else { - $phpcsFile->fixer->replaceToken(($index['index'] - 1), str_repeat(' ', $expected)); - } - } - - continue; - } - - if ($tokens[$index['arrow']]['column'] !== $arrowStart) { - $expected = ($arrowStart - (strlen($index['index_content']) + $tokens[$index['index']]['column'])); - $found = ($tokens[$index['arrow']]['column'] - (strlen($index['index_content']) + $tokens[$index['index']]['column'])); - $error = 'Array double arrow not aligned correctly; expected %s space(s) but found %s'; - $data = array( - $expected, - $found, - ); - - $fix = $phpcsFile->addFixableError($error, $index['arrow'], 'DoubleArrowNotAligned', $data); - if ($fix === true) { - if ($found === 0) { - $phpcsFile->fixer->addContent(($index['arrow'] - 1), str_repeat(' ', $expected)); - } else { - $phpcsFile->fixer->replaceToken(($index['arrow'] - 1), str_repeat(' ', $expected)); - } - } - - continue; - } - - if ($tokens[$index['value']]['column'] !== $valueStart) { - $expected = ($valueStart - ($tokens[$index['arrow']]['length'] + $tokens[$index['arrow']]['column'])); - $found = ($tokens[$index['value']]['column'] - ($tokens[$index['arrow']]['length'] + $tokens[$index['arrow']]['column'])); - if ($found < 0) { - $found = 'newline'; - } - - $error = 'Array value not aligned correctly; expected %s space(s) but found %s'; - $data = array( - $expected, - $found, - ); - - $fix = $phpcsFile->addFixableError($error, $index['arrow'], 'ValueNotAligned', $data); - if ($fix === true) { - if ($found === 'newline') { - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($index['value'] - 1), null, true); - $phpcsFile->fixer->beginChangeset(); - for ($i = ($prev + 1); $i < $index['value']; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->replaceToken(($index['value'] - 1), str_repeat(' ', $expected)); - $phpcsFile->fixer->endChangeset(); - } else if ($found === 0) { - $phpcsFile->fixer->addContent(($index['value'] - 1), str_repeat(' ', $expected)); - } else { - $phpcsFile->fixer->replaceToken(($index['value'] - 1), str_repeat(' ', $expected)); - } - } - }//end if - - // Check each line ends in a comma. - $valueLine = $tokens[$index['value']]['line']; - $nextComma = false; - for ($i = $index['value']; $i < $arrayEnd; $i++) { - // Skip bracketed statements, like function calls. - if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS) { - $i = $tokens[$i]['parenthesis_closer']; - $valueLine = $tokens[$i]['line']; - continue; - } - - if ($tokens[$i]['code'] === T_ARRAY) { - $i = $tokens[$tokens[$i]['parenthesis_opener']]['parenthesis_closer']; - $valueLine = $tokens[$i]['line']; - continue; - } - - // Skip to the end of multi-line strings. - if (isset(PHP_CodeSniffer_Tokens::$stringTokens[$tokens[$i]['code']]) === true) { - $i = $phpcsFile->findNext($tokens[$i]['code'], ($i + 1), null, true); - $i--; - $valueLine = $tokens[$i]['line']; - continue; - } - - if ($tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) { - $i = $tokens[$i]['bracket_closer']; - $valueLine = $tokens[$i]['line']; - continue; - } - - if ($tokens[$i]['code'] === T_CLOSURE) { - $i = $tokens[$i]['scope_closer']; - $valueLine = $tokens[$i]['line']; - continue; - } - - if ($tokens[$i]['code'] === T_COMMA) { - $nextComma = $i; - break; - } - }//end for - - if ($nextComma === false || ($tokens[$nextComma]['line'] !== $valueLine)) { - $error = 'Each line in an array declaration must end in a comma'; - $fix = $phpcsFile->addFixableError($error, $index['value'], 'NoComma'); - - if ($fix === true) { - // Find the end of the line and put a comma there. - for ($i = ($index['value'] + 1); $i < $arrayEnd; $i++) { - if ($tokens[$i]['line'] > $valueLine) { - break; - } - } - - $phpcsFile->fixer->addContentBefore(($i - 1), ','); - } - } - - // Check that there is no space before the comma. - if ($nextComma !== false && $tokens[($nextComma - 1)]['code'] === T_WHITESPACE) { - $content = $tokens[($nextComma - 2)]['content']; - $spaceLength = $tokens[($nextComma - 1)]['length']; - $error = 'Expected 0 spaces between "%s" and comma; %s found'; - $data = array( - $content, - $spaceLength, - ); - - $fix = $phpcsFile->addFixableError($error, $nextComma, 'SpaceBeforeComma', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($nextComma - 1), ''); - } - } - }//end foreach - - }//end processMultiLineArray() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ClassDefinitionClosingBraceSpaceSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ClassDefinitionClosingBraceSpaceSniff.php deleted file mode 100644 index f1b4e71..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ClassDefinitionClosingBraceSpaceSniff.php +++ /dev/null @@ -1,122 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_ClassDefinitionClosingBraceSpaceSniff. - * - * Ensure there is a single blank line after the closing brace of a class definition. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_ClassDefinitionClosingBraceSpaceSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_CLOSE_CURLY_BRACKET); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($next === false) { - return; - } - - if ($tokens[$next]['code'] !== T_CLOSE_TAG) { - $found = (($tokens[$next]['line'] - $tokens[$stackPtr]['line']) - 1); - if ($found !== 1) { - $error = 'Expected one blank line after closing brace of class definition; %s found'; - $data = array($found); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterClose', $data); - - if ($fix === true) { - if ($found === 0) { - $phpcsFile->fixer->addNewline($stackPtr); - } else { - $nextContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - $phpcsFile->fixer->beginChangeset(); - for ($i = ($stackPtr + 1); $i < ($nextContent - 1); $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->addNewline($i); - $phpcsFile->fixer->endChangeset(); - } - } - }//end if - }//end if - - // Ignore nested style definitions from here on. The spacing before the closing brace - // (a single blank line) will be enforced by the above check, which ensures there is a - // blank line after the last nested class. - $found = $phpcsFile->findPrevious( - T_CLOSE_CURLY_BRACKET, - ($stackPtr - 1), - $tokens[$stackPtr]['bracket_opener'] - ); - - if ($found !== false) { - return; - } - - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); - if ($prev === false) { - return; - } - - if ($tokens[$prev]['line'] === $tokens[$stackPtr]['line']) { - $error = 'Closing brace of class definition must be on new line'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'ContentBeforeClose'); - if ($fix === true) { - $phpcsFile->fixer->addNewlineBefore($stackPtr); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php deleted file mode 100644 index 02d6ae1..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php +++ /dev/null @@ -1,118 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_ClassDefinitionNameSpacingSniff. - * - * Ensure there are no blank lines between the names of classes/IDs. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_ClassDefinitionNameSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_OPEN_CURLY_BRACKET); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Do not check nested style definitions as, for example, in @media style rules. - $nested = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), $tokens[$stackPtr]['bracket_closer']); - if ($nested !== false) { - return; - } - - // Find the first blank line before this opening brace, unless we get - // to another style definition, comment or the start of the file. - $endTokens = array( - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, - T_OPEN_TAG => T_OPEN_TAG, - ); - $endTokens += PHP_CodeSniffer_Tokens::$commentTokens; - - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); - - $foundContent = false; - $currentLine = $tokens[$prev]['line']; - for ($i = ($stackPtr - 1); $i >= 0; $i--) { - if (isset($endTokens[$tokens[$i]['code']]) === true) { - break; - } - - if ($tokens[$i]['line'] === $currentLine) { - if ($tokens[$i]['code'] !== T_WHITESPACE) { - $foundContent = true; - } - - continue; - } - - // We changed lines. - if ($foundContent === false) { - // Before we throw an error, make sure we are not looking - // at a gap before the style definition. - $prev = $phpcsFile->findPrevious(T_WHITESPACE, $i, null, true); - if ($prev !== false - && isset($endTokens[$tokens[$prev]['code']]) === false - ) { - $error = 'Blank lines are not allowed between class names'; - $phpcsFile->addError($error, ($i + 1), 'BlankLinesFound'); - } - - break; - } - - $foundContent = false; - $currentLine = $tokens[$i]['line']; - }//end for - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ClassDefinitionOpeningBraceSpaceSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ClassDefinitionOpeningBraceSpaceSniff.php deleted file mode 100644 index ee889fd..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ClassDefinitionOpeningBraceSpaceSniff.php +++ /dev/null @@ -1,144 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_ClassDefinitionOpeningBraceSpaceSniff. - * - * Ensure there is a single space before the opening brace in a class definition - * and the content starts on the next line. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_ClassDefinitionOpeningBraceSpaceSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_OPEN_CURLY_BRACKET); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) { - $error = 'Expected 1 space before opening brace of class definition; 0 found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoneBefore'); - if ($fix === true) { - $phpcsFile->fixer->addContentBefore($stackPtr, ' '); - } - } else { - $content = $tokens[($stackPtr - 1)]['content']; - if ($content !== ' ') { - if ($tokens[($stackPtr - 1)]['line'] < $tokens[$stackPtr]['line']) { - $length = 'newline'; - } else { - $length = strlen($content); - if ($length === 1) { - $length = 'tab'; - } - } - - $error = 'Expected 1 space before opening brace of class definition; %s found'; - $data = array($length); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Before', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr - 1), ' '); - } - } - }//end if - - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true); - if ($next === false) { - return; - } - - // Check for nested class definitions. - $nested = false; - $found = $phpcsFile->findNext( - T_OPEN_CURLY_BRACKET, - ($stackPtr + 1), - $tokens[$stackPtr]['bracket_closer'] - ); - - if ($found !== false) { - $nested = true; - } - - if ($tokens[$next]['line'] === $tokens[$stackPtr]['line']) { - $error = 'Opening brace should be the last content on the line'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'ContentBefore'); - if ($fix === true) { - $phpcsFile->fixer->addNewline($stackPtr); - } - } else { - $foundLines = ($tokens[$next]['line'] - $tokens[$stackPtr]['line'] - 1); - if ($nested === true) { - if ($foundLines !== 1) { - $error = 'Expected 1 blank line after opening brace of nesting class definition; %s found'; - $data = array($foundLines); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'AfterNesting', $data); - - if ($fix === true) { - if ($foundLines === 0) { - $phpcsFile->fixer->addNewline($stackPtr); - } else { - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - $phpcsFile->fixer->beginChangeset(); - for ($i = ($stackPtr + 1); $i < ($next + 1); $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->addNewline($stackPtr); - $phpcsFile->fixer->endChangeset(); - } - } - }//end if - }//end if - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ColonSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ColonSpacingSniff.php deleted file mode 100644 index 47376ab..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ColonSpacingSniff.php +++ /dev/null @@ -1,118 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_ColonSpacingSniff. - * - * Ensure there is no space before a colon and one space after it. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_ColonSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_COLON); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); - if ($tokens[$prev]['code'] !== T_STYLE) { - // The colon is not part of a style definition. - return; - } - - if ($tokens[$prev]['content'] === 'progid') { - // Special case for IE filters. - return; - } - - if ($tokens[($stackPtr - 1)]['code'] === T_WHITESPACE) { - $error = 'There must be no space before a colon in a style definition'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Before'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr - 1), ''); - } - } - - if ($tokens[($stackPtr + 1)]['code'] === T_SEMICOLON) { - // Empty style definition, ignore it. - return; - } - - if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { - $error = 'Expected 1 space after colon in style definition; 0 found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoneAfter'); - if ($fix === true) { - $phpcsFile->fixer->addContent($stackPtr, ' '); - } - } else { - $content = $tokens[($stackPtr + 1)]['content']; - if (strpos($content, $phpcsFile->eolChar) === false) { - $length = strlen($content); - if ($length !== 1) { - $error = 'Expected 1 space after colon in style definition; %s found'; - $data = array($length); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'After', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); - } - } - } else { - $error = 'Expected 1 space after colon in style definition; newline found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'AfterNewline'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); - } - } - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ColourDefinitionSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ColourDefinitionSniff.php deleted file mode 100644 index 85849ca..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ColourDefinitionSniff.php +++ /dev/null @@ -1,101 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_ColourDefinitionSniff. - * - * Ensure colours are defined in upper-case and use shortcuts where possible. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_ColourDefinitionSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_COLOUR); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $colour = $tokens[$stackPtr]['content']; - - $expected = strtoupper($colour); - if ($colour !== $expected) { - $error = 'CSS colours must be defined in uppercase; expected %s but found %s'; - $data = array( - $expected, - $colour, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotUpper', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, $expected); - } - } - - // Now check if shorthand can be used. - if (strlen($colour) !== 7) { - return; - } - - if ($colour{1} === $colour{2} && $colour{3} === $colour{4} && $colour{5} === $colour{6}) { - $expected = '#'.$colour{1}.$colour{3}.$colour{5}; - $error = 'CSS colours must use shorthand if available; expected %s but found %s'; - $data = array( - $expected, - $colour, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Shorthand', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, $expected); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/DisallowMultipleStyleDefinitionsSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/DisallowMultipleStyleDefinitionsSniff.php deleted file mode 100644 index b3eebe6..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/DisallowMultipleStyleDefinitionsSniff.php +++ /dev/null @@ -1,84 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_DisallowMultipleStyleDefinitionsSniff. - * - * Ensure that each style definition is on a line by itself. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_DisallowMultipleStyleDefinitionsSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_STYLE); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $next = $phpcsFile->findNext(T_STYLE, ($stackPtr + 1)); - if ($next === false) { - return; - } - - if ($tokens[$next]['content'] === 'progid') { - // Special case for IE filters. - return; - } - - if ($tokens[$next]['line'] === $tokens[$stackPtr]['line']) { - $error = 'Each style definition must be on a line by itself'; - $fix = $phpcsFile->addFixableError($error, $next, 'Found'); - if ($fix === true) { - $phpcsFile->fixer->addNewlineBefore($next); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/DuplicateClassDefinitionSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/DuplicateClassDefinitionSniff.php deleted file mode 100644 index be1ac03..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/DuplicateClassDefinitionSniff.php +++ /dev/null @@ -1,128 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_DuplicateClassDefinitionSniff. - * - * Check for duplicate class definitions that can be merged into one. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_DuplicateClassDefinitionSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Find the content of each class definition name. - $classNames = array(); - $next = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1)); - if ($next === false) { - // No class definitions in the file. - return; - } - - // Save the class names in a "scope", - // to prevent false positives with @media blocks. - $scope = 'main'; - - $find = array( - T_CLOSE_CURLY_BRACKET, - T_OPEN_CURLY_BRACKET, - T_COMMENT, - T_OPEN_TAG, - ); - - while ($next !== false) { - $prev = $phpcsFile->findPrevious($find, ($next - 1)); - - // Check if an inner block was closed. - $beforePrev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($prev - 1), null, true); - if ($beforePrev !== false - && $tokens[$beforePrev]['code'] === T_CLOSE_CURLY_BRACKET - ) { - $scope = 'main'; - } - - // Create a sorted name for the class so we can compare classes - // even when the individual names are all over the place. - $name = ''; - for ($i = ($prev + 1); $i < $next; $i++) { - $name .= $tokens[$i]['content']; - } - - $name = trim($name); - $name = str_replace("\n", ' ', $name); - $name = preg_replace('|[\s]+|', ' ', $name); - $name = str_replace(', ', ',', $name); - - $names = explode(',', $name); - sort($names); - $name = implode(',', $names); - - if ($name{0} === '@') { - // Media block has its own "scope". - $scope = $name; - } else if (isset($classNames[$scope][$name]) === true) { - $first = $classNames[$scope][$name]; - $error = 'Duplicate class definition found; first defined on line %s'; - $data = array($tokens[$first]['line']); - $phpcsFile->addError($error, $next, 'Found', $data); - } else { - $classNames[$scope][$name] = $next; - } - - $next = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($next + 1)); - }//end while - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/DuplicateStyleDefinitionSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/DuplicateStyleDefinitionSniff.php deleted file mode 100644 index 4c04a80..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/DuplicateStyleDefinitionSniff.php +++ /dev/null @@ -1,96 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_DuplicateStyleDefinitionSniff. - * - * Check for duplicate style definitions in the same class. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_DuplicateStyleDefinitionSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_OPEN_CURLY_BRACKET); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Find the content of each style definition name. - $styleNames = array(); - - $next = $stackPtr; - $end = $tokens[$stackPtr]['bracket_closer']; - - do { - $next = $phpcsFile->findNext(array(T_STYLE, T_OPEN_CURLY_BRACKET), ($next + 1), $end); - if ($next === false) { - // Class definition is empty. - break; - } - - if ($tokens[$next]['code'] === T_OPEN_CURLY_BRACKET) { - $next = $tokens[$next]['bracket_closer']; - continue; - } - - $name = $tokens[$next]['content']; - if (isset($styleNames[$name]) === true) { - $first = $styleNames[$name]; - $error = 'Duplicate style definition found; first defined on line %s'; - $data = array($tokens[$first]['line']); - $phpcsFile->addError($error, $next, 'Found', $data); - } else { - $styleNames[$name] = $next; - } - } while ($next !== false); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/EmptyClassDefinitionSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/EmptyClassDefinitionSniff.php deleted file mode 100644 index cdb86e2..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/EmptyClassDefinitionSniff.php +++ /dev/null @@ -1,73 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_EmptyClassDefinitionSniff. - * - * Ensure that class definitions are not empty. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_EmptyClassDefinitionSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_OPEN_CURLY_BRACKET); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true); - - if ($next === false || $tokens[$next]['code'] === T_CLOSE_CURLY_BRACKET) { - $error = 'Class definition is empty'; - $phpcsFile->addError($error, $stackPtr, 'Found'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/EmptyStyleDefinitionSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/EmptyStyleDefinitionSniff.php deleted file mode 100644 index 708a9b4..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/EmptyStyleDefinitionSniff.php +++ /dev/null @@ -1,73 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_EmptyStyleDefinitionSniff. - * - * Ensure that style definitions are not empty. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_EmptyStyleDefinitionSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_STYLE); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $next = $phpcsFile->findNext(array(T_WHITESPACE, T_COLON), ($stackPtr + 1), null, true); - - if ($next === false || $tokens[$next]['code'] === T_SEMICOLON || $tokens[$next]['line'] !== $tokens[$stackPtr]['line']) { - $error = 'Style definition is empty'; - $phpcsFile->addError($error, $stackPtr, 'Found'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ForbiddenStylesSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ForbiddenStylesSniff.php deleted file mode 100644 index db3266d..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ForbiddenStylesSniff.php +++ /dev/null @@ -1,190 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_ForbiddenStylesSniff. - * - * Bans the use of some styles, such as deprecated or browser-specific styles. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_ForbiddenStylesSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - /** - * A list of forbidden styles with their alternatives. - * - * The value is NULL if no alternative exists. i.e., the - * function should just not be used. - * - * @var array(string => string|null) - */ - protected $forbiddenStyles = array( - '-moz-border-radius' => 'border-radius', - '-webkit-border-radius' => 'border-radius', - '-moz-border-radius-topleft' => 'border-top-left-radius', - '-moz-border-radius-topright' => 'border-top-right-radius', - '-moz-border-radius-bottomright' => 'border-bottom-right-radius', - '-moz-border-radius-bottomleft' => 'border-bottom-left-radius', - '-moz-box-shadow' => 'box-shadow', - '-webkit-box-shadow' => 'box-shadow', - ); - - /** - * A cache of forbidden style names, for faster lookups. - * - * @var array(string) - */ - protected $forbiddenStyleNames = array(); - - /** - * If true, forbidden styles will be considered regular expressions. - * - * @var bool - */ - protected $patternMatch = false; - - /** - * If true, an error will be thrown; otherwise a warning. - * - * @var bool - */ - public $error = true; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - $this->forbiddenStyleNames = array_keys($this->forbiddenStyles); - - if ($this->patternMatch === true) { - foreach ($this->forbiddenStyleNames as $i => $name) { - $this->forbiddenStyleNames[$i] = '/'.$name.'/i'; - } - } - - return array(T_STYLE); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $style = strtolower($tokens[$stackPtr]['content']); - $pattern = null; - - if ($this->patternMatch === true) { - $count = 0; - $pattern = preg_replace( - $this->forbiddenStyleNames, - $this->forbiddenStyleNames, - $style, - 1, - $count - ); - - if ($count === 0) { - return; - } - - // Remove the pattern delimiters and modifier. - $pattern = substr($pattern, 1, -2); - } else { - if (in_array($style, $this->forbiddenStyleNames) === false) { - return; - } - }//end if - - $this->addError($phpcsFile, $stackPtr, $style, $pattern); - - }//end process() - - - /** - * Generates the error or warning for this sniff. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the forbidden style - * in the token array. - * @param string $style The name of the forbidden style. - * @param string $pattern The pattern used for the match. - * - * @return void - */ - protected function addError($phpcsFile, $stackPtr, $style, $pattern=null) - { - $data = array($style); - $error = 'The use of style %s is '; - if ($this->error === true) { - $type = 'Found'; - $error .= 'forbidden'; - } else { - $type = 'Discouraged'; - $error .= 'discouraged'; - } - - if ($pattern === null) { - $pattern = $style; - } - - if ($this->forbiddenStyles[$pattern] !== null) { - $data[] = $this->forbiddenStyles[$pattern]; - if ($this->error === true) { - $fix = $phpcsFile->addFixableError($error.'; use %s instead', $stackPtr, $type.'WithAlternative', $data); - } else { - $fix = $phpcsFile->addFixableWarning($error.'; use %s instead', $stackPtr, $type.'WithAlternative', $data); - } - - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, $this->forbiddenStyles[$pattern]); - } - } else { - if ($this->error === true) { - $phpcsFile->addError($error, $stackPtr, $type, $data); - } else { - $phpcsFile->addWarning($error, $stackPtr, $type, $data); - } - } - - }//end addError() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/IndentationSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/IndentationSniff.php deleted file mode 100644 index 27e3a4c..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/IndentationSniff.php +++ /dev/null @@ -1,154 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_IndentationSniff. - * - * Ensures styles are indented 4 spaces. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_IndentationSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - /** - * The number of spaces code should be indented. - * - * @var int - */ - public $indent = 4; - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $numTokens = (count($tokens) - 2); - $indentLevel = 0; - $nestingLevel = 0; - for ($i = 1; $i < $numTokens; $i++) { - if ($tokens[$i]['code'] === T_COMMENT) { - // Don't check the indent of comments. - continue; - } - - if ($tokens[$i]['code'] === T_OPEN_CURLY_BRACKET) { - $indentLevel++; - - // Check for nested class definitions. - $found = $phpcsFile->findNext( - T_OPEN_CURLY_BRACKET, - ($i + 1), - $tokens[$i]['bracket_closer'] - ); - - if ($found !== false) { - $nestingLevel = $indentLevel; - } - } - - if (($tokens[$i]['code'] === T_CLOSE_CURLY_BRACKET - && $tokens[$i]['line'] !== $tokens[($i - 1)]['line']) - || ($tokens[($i + 1)]['code'] === T_CLOSE_CURLY_BRACKET - && $tokens[$i]['line'] === $tokens[($i + 1)]['line']) - ) { - $indentLevel--; - if ($indentLevel === 0) { - $nestingLevel = 0; - } - } - - if ($tokens[$i]['column'] !== 1 - || $tokens[$i]['code'] === T_OPEN_CURLY_BRACKET - || $tokens[$i]['code'] === T_CLOSE_CURLY_BRACKET - ) { - continue; - } - - // We started a new line, so check indent. - if ($tokens[$i]['code'] === T_WHITESPACE) { - $content = str_replace($phpcsFile->eolChar, '', $tokens[$i]['content']); - $foundIndent = strlen($content); - } else { - $foundIndent = 0; - } - - $expectedIndent = ($indentLevel * $this->indent); - if ($expectedIndent > 0 - && strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false - ) { - if ($nestingLevel !== $indentLevel) { - $error = 'Blank lines are not allowed in class definitions'; - $fix = $phpcsFile->addFixableError($error, $i, 'BlankLine'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($i, ''); - } - } - } else if ($foundIndent !== $expectedIndent) { - $error = 'Line indented incorrectly; expected %s spaces, found %s'; - $data = array( - $expectedIndent, - $foundIndent, - ); - - $fix = $phpcsFile->addFixableError($error, $i, 'Incorrect', $data); - if ($fix === true) { - $indent = str_repeat(' ', $expectedIndent); - if ($foundIndent === 0) { - $phpcsFile->fixer->addContentBefore($i, $indent); - } else { - $phpcsFile->fixer->replaceToken($i, $indent); - } - } - }//end if - }//end for - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/LowercaseStyleDefinitionSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/LowercaseStyleDefinitionSniff.php deleted file mode 100644 index 5155a40..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/LowercaseStyleDefinitionSniff.php +++ /dev/null @@ -1,110 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_LowercaseStyleDefinitionSniff. - * - * Ensure that all style definitions are in lowercase. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_LowercaseStyleDefinitionSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_OPEN_CURLY_BRACKET); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $start = ($stackPtr + 1); - $end = ($tokens[$stackPtr]['bracket_closer'] - 1); - $inStyle = null; - - for ($i = $start; $i <= $end; $i++) { - // Skip nested definitions as they are checked individually. - if ($tokens[$i]['code'] === T_OPEN_CURLY_BRACKET) { - $i = $tokens[$i]['bracket_closer']; - continue; - } - - if ($tokens[$i]['code'] === T_STYLE) { - $inStyle = $tokens[$i]['content']; - } - - if ($tokens[$i]['code'] === T_SEMICOLON) { - $inStyle = null; - } - - if ($inStyle === 'progid') { - // Special case for IE filters. - continue; - } - - if ($tokens[$i]['code'] === T_STYLE - || ($inStyle !== null - && $tokens[$i]['code'] === T_STRING) - ) { - $expected = strtolower($tokens[$i]['content']); - if ($expected !== $tokens[$i]['content']) { - $error = 'Style definitions must be lowercase; expected %s but found %s'; - $data = array( - $expected, - $tokens[$i]['content'], - ); - - $fix = $phpcsFile->addFixableError($error, $i, 'FoundUpper', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($i, $expected); - } - } - } - }//end for - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/MissingColonSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/MissingColonSniff.php deleted file mode 100644 index f9a1227..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/MissingColonSniff.php +++ /dev/null @@ -1,99 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_MissingColonSniff. - * - * Ensure that all style definitions have a colon. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_MissingColonSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_OPEN_CURLY_BRACKET); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $lastLine = $tokens[$stackPtr]['line']; - $end = $tokens[$stackPtr]['bracket_closer']; - $endLine = $tokens[$end]['line']; - - // Do not check nested style definitions as, for example, in @media style rules. - $nested = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), $end); - if ($nested !== false) { - return; - } - - $foundColon = false; - $foundString = false; - for ($i = ($stackPtr + 1); $i <= $end; $i++) { - if ($tokens[$i]['line'] !== $lastLine) { - // We changed lines. - if ($foundColon === false && $foundString !== false) { - // We didn't find a colon on the previous line. - $error = 'No style definition found on line; check for missing colon'; - $phpcsFile->addError($error, $foundString, 'Found'); - } - - $foundColon = false; - $foundString = false; - $lastLine = $tokens[$i]['line']; - } - - if ($tokens[$i]['code'] === T_STRING) { - $foundString = $i; - } else if ($tokens[$i]['code'] === T_COLON) { - $foundColon = $i; - } - }//end for - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/NamedColoursSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/NamedColoursSniff.php deleted file mode 100644 index 672123e..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/NamedColoursSniff.php +++ /dev/null @@ -1,107 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_NamedColoursSniff. - * - * Ensure colour names are not used. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_NamedColoursSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - - /** - * A list of named colours. - * - * This is the list of standard colours defined in the CSS spec. - * - * @var array - */ - protected $colourNames = array( - 'aqua' => 'aqua', - 'black' => 'black', - 'blue' => 'blue', - 'fuchsia' => 'fuchsia', - 'gray' => 'gray', - 'green' => 'green', - 'lime' => 'lime', - 'maroon' => 'maroon', - 'navy' => 'navy', - 'olive' => 'olive', - 'orange' => 'orange', - 'purple' => 'purple', - 'red' => 'red', - 'silver' => 'silver', - 'teal' => 'teal', - 'white' => 'white', - 'yellow' => 'yellow', - ); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_STRING); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[($stackPtr - 1)]['code'] === T_HASH - || $tokens[($stackPtr - 1)]['code'] === T_STRING_CONCAT - ) { - // Class name. - return; - } - - if (isset($this->colourNames[strtolower($tokens[$stackPtr]['content'])]) === true) { - $error = 'Named colours are forbidden; use hex, rgb, or rgba values instead'; - $phpcsFile->addError($error, $stackPtr, 'Forbidden'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/OpacitySniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/OpacitySniff.php deleted file mode 100644 index 4f2a32c..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/OpacitySniff.php +++ /dev/null @@ -1,110 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_OpacitySniff. - * - * Ensure that opacity values start with a 0 if it is not a whole number. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_OpacitySniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_STYLE); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[$stackPtr]['content'] !== 'opacity') { - return; - } - - $next = $phpcsFile->findNext(array(T_COLON, T_WHITESPACE), ($stackPtr + 1), null, true); - - if ($next === false - || ($tokens[$next]['code'] !== T_DNUMBER - && $tokens[$next]['code'] !== T_LNUMBER) - ) { - return; - } - - $value = $tokens[$next]['content']; - if ($tokens[$next]['code'] === T_LNUMBER) { - if ($value !== '0' && $value !== '1') { - $error = 'Opacity values must be between 0 and 1'; - $phpcsFile->addError($error, $next, 'Invalid'); - } - } else { - if (strlen($value) > 3) { - $error = 'Opacity values must have a single value after the decimal point'; - $phpcsFile->addError($error, $next, 'DecimalPrecision'); - } else if ($value === '0.0' || $value === '1.0') { - $error = 'Opacity value does not require decimal point; use %s instead'; - $data = array($value{0}); - $fix = $phpcsFile->addFixableError($error, $next, 'PointNotRequired', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($next, $value{0}); - } - } else if ($value{0} === '.') { - $error = 'Opacity values must not start with a decimal point; use 0%s instead'; - $data = array($value); - $fix = $phpcsFile->addFixableError($error, $next, 'StartWithPoint', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($next, '0'.$value); - } - } else if ($value{0} !== '0') { - $error = 'Opacity values must be between 0 and 1'; - $phpcsFile->addError($error, $next, 'Invalid'); - }//end if - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/SemicolonSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/SemicolonSpacingSniff.php deleted file mode 100644 index 5f945fe..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/SemicolonSpacingSniff.php +++ /dev/null @@ -1,84 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_SemicolonSpacingSniff. - * - * Ensure each style definition has a semi-colon and it is spaced correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_SemicolonSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_STYLE); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $semicolon = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1)); - if ($semicolon === false || $tokens[$semicolon]['line'] !== $tokens[$stackPtr]['line']) { - $error = 'Style definitions must end with a semicolon'; - $phpcsFile->addError($error, $stackPtr, 'NotAtEnd'); - return; - } - - if ($tokens[($semicolon - 1)]['code'] === T_WHITESPACE) { - $length = strlen($tokens[($semicolon - 1)]['content']); - $error = 'Expected 0 spaces before semicolon in style definition; %s found'; - $data = array($length); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceFound', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($semicolon - 1), ''); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ShorthandSizeSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ShorthandSizeSniff.php deleted file mode 100644 index 5c73ae5..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/CSS/ShorthandSizeSniff.php +++ /dev/null @@ -1,191 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_CSS_ShorthandSizeSniff. - * - * Ensure sizes are defined using shorthand notation where possible, except in the - * case where shorthand becomes 3 values. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_CSS_ShorthandSizeSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('CSS'); - - /** - * A list of styles that we shouldn't check. - * - * These have values that looks like sizes, but are not. - * - * @var array - */ - protected $excludeStyles = array( - 'background-position' => 'background-position', - 'box-shadow' => 'box-shadow', - 'transform-origin' => 'transform-origin', - '-webkit-transform-origin' => '-webkit-transform-origin', - '-ms-transform-origin' => '-ms-transform-origin', - ); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_STYLE); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Some styles look like shorthand but are not actually a set of 4 sizes. - $style = strtolower($tokens[$stackPtr]['content']); - if (isset($this->excludeStyles[$style]) === true) { - return; - } - - // Get the whole style content. - $end = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1)); - $origContent = $phpcsFile->getTokensAsString(($stackPtr + 1), ($end - $stackPtr - 1)); - $origContent = trim($origContent, ': '); - - // Account for a !important annotation. - $content = $origContent; - if (substr($content, -10) === '!important') { - $content = substr($content, 0, -10); - $content = trim($content); - } - - // Check if this style value is a set of numbers with optional prefixes. - $content = preg_replace('/\s+/', ' ', $content); - $values = array(); - $num = preg_match_all( - '/([0-9]+)([a-zA-Z]{2}\s+|%\s+|\s+)/', - $content.' ', - $values, - PREG_SET_ORDER - ); - - // Only interested in styles that have multiple sizes defined. - if ($num < 2) { - return; - } - - // Rebuild the content we matched to ensure we got everything. - $matched = ''; - foreach ($values as $value) { - $matched .= $value[0]; - } - - if ($content !== trim($matched)) { - return; - } - - if ($num === 3) { - $expected = trim($content.' '.$values[1][1].$values[1][2]); - $error = 'Shorthand syntax not allowed here; use %s instead'; - $data = array($expected); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotAllowed', $data); - - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - if (substr($origContent, -10) === '!important') { - $expected .= ' !important'; - } - - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 2), null, true); - $phpcsFile->fixer->replaceToken($next, $expected); - for ($next++; $next < $end; $next++) { - $phpcsFile->fixer->replaceToken($next, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - - return; - }//end if - - if ($num === 2) { - if ($values[0][0] !== $values[1][0]) { - // Both values are different, so it is already shorthand. - return; - } - } else if ($values[0][0] !== $values[2][0] || $values[1][0] !== $values[3][0]) { - // Can't shorthand this. - return; - } - - if ($values[0][0] === $values[1][0]) { - // All values are the same. - $expected = $values[0][0]; - } else { - $expected = $values[0][0].' '.$values[1][0]; - } - - $expected = preg_replace('/\s+/', ' ', trim($expected)); - - $error = 'Size definitions must use shorthand if available; expected "%s" but found "%s"'; - $data = array( - $expected, - $content, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotUsed', $data); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - if (substr($origContent, -10) === '!important') { - $expected .= ' !important'; - } - - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 2), null, true); - $phpcsFile->fixer->replaceToken($next, $expected); - for ($next++; $next < $end; $next++) { - $phpcsFile->fixer->replaceToken($next, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/ClassDeclarationSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/ClassDeclarationSniff.php deleted file mode 100644 index 4bf7855..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/ClassDeclarationSniff.php +++ /dev/null @@ -1,219 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PSR2_Sniffs_Classes_ClassDeclarationSniff', true) === false) { - $error = 'Class PSR2_Sniffs_Classes_ClassDeclarationSniff not found'; - throw new PHP_CodeSniffer_Exception($error); -} - -/** - * Class Declaration Test. - * - * Checks the declaration of the class and its inheritance is correct. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Classes_ClassDeclarationSniff extends PSR2_Sniffs_Classes_ClassDeclarationSniff -{ - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - // We want all the errors from the PSR2 standard, plus some of our own. - parent::process($phpcsFile, $stackPtr); - - $tokens = $phpcsFile->getTokens(); - - // Check that this is the only class or interface in the file. - $nextClass = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE), ($stackPtr + 1)); - if ($nextClass !== false) { - // We have another, so an error is thrown. - $error = 'Only one interface or class is allowed in a file'; - $phpcsFile->addError($error, $nextClass, 'MultipleClasses'); - } - - }//end process() - - - /** - * Processes the opening section of a class declaration. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function processOpen(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - parent::processOpen($phpcsFile, $stackPtr); - - $tokens = $phpcsFile->getTokens(); - - if ($tokens[($stackPtr - 1)]['code'] === T_WHITESPACE) { - $prevContent = $tokens[($stackPtr - 1)]['content']; - if ($prevContent !== $phpcsFile->eolChar) { - $blankSpace = substr($prevContent, strpos($prevContent, $phpcsFile->eolChar)); - $spaces = strlen($blankSpace); - - if ($tokens[($stackPtr - 2)]['code'] !== T_ABSTRACT - && $tokens[($stackPtr - 2)]['code'] !== T_FINAL - ) { - if ($spaces !== 0) { - $type = strtolower($tokens[$stackPtr]['content']); - $error = 'Expected 0 spaces before %s keyword; %s found'; - $data = array( - $type, - $spaces, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceBeforeKeyword', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr - 1), ''); - } - } - } - }//end if - }//end if - - }//end processOpen() - - - /** - * Processes the closing section of a class declaration. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function processClose(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - if (isset($tokens[$stackPtr]['scope_closer']) === false) { - return; - } - - $closeBrace = $tokens[$stackPtr]['scope_closer']; - - // Check that the closing brace has one blank line after it. - for ($nextContent = ($closeBrace + 1); $nextContent < $phpcsFile->numTokens; $nextContent++) { - // Ignore comments on the same lines as the brace. - if ($tokens[$nextContent]['line'] === $tokens[$closeBrace]['line'] - && ($tokens[$nextContent]['code'] === T_WHITESPACE - || $tokens[$nextContent]['code'] === T_COMMENT) - ) { - continue; - } - - if ($tokens[$nextContent]['code'] !== T_WHITESPACE) { - break; - } - } - - if ($nextContent === $phpcsFile->numTokens) { - // Ignore the line check as this is the very end of the file. - $difference = 1; - } else { - $difference = ($tokens[$nextContent]['line'] - $tokens[$closeBrace]['line'] - 1); - } - - $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($closeBrace - 1), $stackPtr, true); - - if ($difference === -1 - || $tokens[$lastContent]['line'] === $tokens[$closeBrace]['line'] - ) { - $error = 'Closing %s brace must be on a line by itself'; - $data = array($tokens[$stackPtr]['content']); - $fix = $phpcsFile->addFixableError($error, $closeBrace, 'CloseBraceSameLine', $data); - if ($fix === true) { - if ($difference === -1) { - $phpcsFile->fixer->addNewlineBefore($nextContent); - } - - if ($tokens[$lastContent]['line'] === $tokens[$closeBrace]['line']) { - $phpcsFile->fixer->addNewlineBefore($closeBrace); - } - } - } else if ($tokens[($closeBrace - 1)]['code'] === T_WHITESPACE) { - $prevContent = $tokens[($closeBrace - 1)]['content']; - if ($prevContent !== $phpcsFile->eolChar) { - $blankSpace = substr($prevContent, strpos($prevContent, $phpcsFile->eolChar)); - $spaces = strlen($blankSpace); - if ($spaces !== 0) { - if ($tokens[($closeBrace - 1)]['line'] !== $tokens[$closeBrace]['line']) { - $error = 'Expected 0 spaces before closing brace; newline found'; - $phpcsFile->addError($error, $closeBrace, 'NewLineBeforeCloseBrace'); - } else { - $error = 'Expected 0 spaces before closing brace; %s found'; - $data = array($spaces); - $fix = $phpcsFile->addFixableError($error, $closeBrace, 'SpaceBeforeCloseBrace', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($closeBrace - 1), ''); - } - } - } - } - }//end if - - if ($difference !== -1 && $difference !== 1) { - $error = 'Closing brace of a %s must be followed by a single blank line; found %s'; - $data = array( - $tokens[$stackPtr]['content'], - $difference, - ); - $fix = $phpcsFile->addFixableError($error, $closeBrace, 'NewlinesAfterCloseBrace', $data); - if ($fix === true) { - if ($difference === 0) { - $first = $phpcsFile->findFirstOnLine(array(), $nextContent, true); - $phpcsFile->fixer->addNewlineBefore($first); - } else { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($closeBrace + 1); $i < $nextContent; $i++) { - if ($tokens[$i]['line'] <= ($tokens[$closeBrace]['line'] + 1)) { - continue; - } else if ($tokens[$i]['line'] === $tokens[$nextContent]['line']) { - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - } - }//end if - - }//end processClose() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/ClassFileNameSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/ClassFileNameSniff.php deleted file mode 100644 index d3585b9..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/ClassFileNameSniff.php +++ /dev/null @@ -1,84 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Classes_ClassFileNameSniff. - * - * Tests that the file name and the name of the class contained within the file - * match. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Classes_ClassFileNameSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_CLASS, - T_INTERFACE, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $fullPath = basename($phpcsFile->getFilename()); - $fileName = substr($fullPath, 0, strrpos($fullPath, '.')); - if ($fileName === '') { - // No filename probably means STDIN, so we can't do this check. - return; - } - - $tokens = $phpcsFile->getTokens(); - $decName = $phpcsFile->findNext(T_STRING, $stackPtr); - - if ($tokens[$decName]['content'] !== $fileName) { - $error = '%s name doesn\'t match filename; expected "%s %s"'; - $data = array( - ucfirst($tokens[$stackPtr]['content']), - $tokens[$stackPtr]['content'], - $fileName, - ); - $phpcsFile->addError($error, $stackPtr, 'NoMatch', $data); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/DuplicatePropertySniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/DuplicatePropertySniff.php deleted file mode 100644 index 0a9624b..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/DuplicatePropertySniff.php +++ /dev/null @@ -1,95 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Classes_DuplicatePropertySniff. - * - * Ensures JS classes don't contain duplicate property names. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Classes_DuplicatePropertySniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('JS'); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OBJECT); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $properties = array(); - $wantedTokens = array( - T_PROPERTY, - T_OBJECT, - ); - - $next = $phpcsFile->findNext($wantedTokens, ($stackPtr + 1), $tokens[$stackPtr]['bracket_closer']); - while ($next !== false && $next < $tokens[$stackPtr]['bracket_closer']) { - if ($tokens[$next]['code'] === T_OBJECT) { - // Skip nested objects. - $next = $tokens[$next]['bracket_closer']; - } else { - $propName = $tokens[$next]['content']; - if (isset($properties[$propName]) === true) { - $error = 'Duplicate property definition found for "%s"; previously defined on line %s'; - $data = array( - $propName, - $tokens[$properties[$propName]]['line'], - ); - $phpcsFile->addError($error, $next, 'Found', $data); - } - - $properties[$propName] = $next; - }//end if - - $next = $phpcsFile->findNext($wantedTokens, ($next + 1), $tokens[$stackPtr]['bracket_closer']); - }//end while - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/LowercaseClassKeywordsSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/LowercaseClassKeywordsSniff.php deleted file mode 100644 index d7ff590..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/LowercaseClassKeywordsSniff.php +++ /dev/null @@ -1,87 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Classes_LowercaseClassKeywordsSniff. - * - * Ensures all class keywords are lowercase. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Classes_LowercaseClassKeywordsSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_CLASS, - T_INTERFACE, - T_TRAIT, - T_EXTENDS, - T_IMPLEMENTS, - T_ABSTRACT, - T_FINAL, - T_VAR, - T_CONST, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $content = $tokens[$stackPtr]['content']; - if ($content !== strtolower($content)) { - $error = '%s keyword must be lowercase; expected "%s" but found "%s"'; - $data = array( - strtoupper($content), - strtolower($content), - $content, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'FoundUppercase', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, strtolower($content)); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/SelfMemberReferenceSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/SelfMemberReferenceSniff.php deleted file mode 100644 index 3d67c66..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/SelfMemberReferenceSniff.php +++ /dev/null @@ -1,198 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) { - $error = 'Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found'; - throw new PHP_CodeSniffer_Exception($error); -} - -/** - * Tests self member references. - * - * Verifies that : - *
    - *
  • self:: is used instead of Self::
  • - *
  • self:: is used for local static member reference
  • - *
  • self:: is used instead of self ::
  • - *
- * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Classes_SelfMemberReferenceSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff -{ - - - /** - * Constructs a Squiz_Sniffs_Classes_SelfMemberReferenceSniff. - */ - public function __construct() - { - parent::__construct(array(T_CLASS), array(T_DOUBLE_COLON)); - - }//end __construct() - - - /** - * Processes the function tokens within the class. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. - * @param int $currScope The current scope opener token. - * - * @return void - */ - protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) - { - $tokens = $phpcsFile->getTokens(); - - $calledClassName = ($stackPtr - 1); - if ($tokens[$calledClassName]['code'] === T_SELF) { - if ($tokens[$calledClassName]['content'] !== 'self') { - $error = 'Must use "self::" for local static member reference; found "%s::"'; - $data = array($tokens[$calledClassName]['content']); - $fix = $phpcsFile->addFixableError($error, $calledClassName, 'IncorrectCase', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($calledClassName, 'self'); - } - - return; - } - } else if ($tokens[$calledClassName]['code'] === T_STRING) { - // If the class is called with a namespace prefix, build fully qualified - // namespace calls for both current scope class and requested class. - if ($tokens[($calledClassName - 1)]['code'] === T_NS_SEPARATOR) { - $declarationName = $this->getDeclarationNameWithNamespace($tokens, $calledClassName); - $declarationName = substr($declarationName, 1); - $fullQualifiedClassName = $this->getNamespaceOfScope($phpcsFile, $currScope); - if ($fullQualifiedClassName === '\\') { - $fullQualifiedClassName = ''; - } else { - $fullQualifiedClassName .= '\\'; - } - - $fullQualifiedClassName .= $phpcsFile->getDeclarationName($currScope); - } else { - $declarationName = $phpcsFile->getDeclarationName($currScope); - $fullQualifiedClassName = $tokens[$calledClassName]['content']; - } - - if ($declarationName === $fullQualifiedClassName) { - // Class name is the same as the current class, which is not allowed - // except if being used inside a closure. - if ($phpcsFile->hasCondition($stackPtr, T_CLOSURE) === false) { - $error = 'Must use "self::" for local static member reference'; - $fix = $phpcsFile->addFixableError($error, $calledClassName, 'NotUsed'); - - if ($fix === true) { - $prev = $phpcsFile->findPrevious(array(T_NS_SEPARATOR, T_STRING), ($stackPtr - 1), null, true); - $phpcsFile->fixer->beginChangeset(); - for ($i = ($prev + 1); $i < $stackPtr; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->replaceToken($stackPtr, 'self::'); - $phpcsFile->fixer->endChangeset(); - } - - return; - } - }//end if - }//end if - - if ($tokens[($stackPtr - 1)]['code'] === T_WHITESPACE) { - $found = strlen($tokens[($stackPtr - 1)]['content']); - $error = 'Expected 0 spaces before double colon; %s found'; - $data = array($found); - $fix = $phpcsFile->addFixableError($error, $calledClassName, 'SpaceBefore', $data); - - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr - 1), ''); - } - } - - if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) { - $found = strlen($tokens[($stackPtr + 1)]['content']); - $error = 'Expected 0 spaces after double colon; %s found'; - $data = array($found); - $fix = $phpcsFile->addFixableError($error, $calledClassName, 'SpaceAfter', $data); - - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ''); - } - } - - }//end processTokenWithinScope() - - - /** - * Returns the declaration names for classes/interfaces/functions with a namespace. - * - * @param array $tokens Token stack for this file - * @param int $stackPtr The position where the namespace building will start. - * - * @return string - */ - protected function getDeclarationNameWithNamespace(array $tokens, $stackPtr) - { - $nameParts = array(); - $currentPointer = $stackPtr; - while ($tokens[$currentPointer]['code'] === T_NS_SEPARATOR - || $tokens[$currentPointer]['code'] === T_STRING - ) { - $nameParts[] = $tokens[$currentPointer]['content']; - $currentPointer--; - } - - $nameParts = array_reverse($nameParts); - return implode('', $nameParts); - - }//end getDeclarationNameWithNamespace() - - - /** - * Returns the namespace declaration of a file. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the search for the - * namespace declaration will start. - * - * @return string - */ - protected function getNamespaceOfScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $namespace = '\\'; - $namespaceDeclaration = $phpcsFile->findPrevious(T_NAMESPACE, $stackPtr); - - if ($namespaceDeclaration !== false) { - $endOfNamespaceDeclaration = $phpcsFile->findNext(T_SEMICOLON, $namespaceDeclaration); - $namespace = $this->getDeclarationNameWithNamespace( - $phpcsFile->getTokens(), - ($endOfNamespaceDeclaration - 1) - ); - } - - return $namespace; - - }//end getNamespaceOfScope() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php deleted file mode 100644 index a223f02..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php +++ /dev/null @@ -1,100 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Classes_ValidClassNameSniff. - * - * Ensures classes are in camel caps, and the first letter is capitalised - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Classes_ValidClassNameSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_CLASS, - T_INTERFACE, - T_TRAIT, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (isset($tokens[$stackPtr]['scope_opener']) === false) { - $error = 'Possible parse error: %s missing opening or closing brace'; - $data = array($tokens[$stackPtr]['content']); - $phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $data); - return; - } - - // Determine the name of the class or interface. Note that we cannot - // simply look for the first T_STRING because a class name - // starting with the number will be multiple tokens. - $opener = $tokens[$stackPtr]['scope_opener']; - $nameStart = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), $opener, true); - $nameEnd = $phpcsFile->findNext(T_WHITESPACE, $nameStart, $opener); - if ($nameEnd === false) { - $name = $tokens[$nameStart]['content']; - } else { - $name = trim($phpcsFile->getTokensAsString($nameStart, ($nameEnd - $nameStart))); - } - - // Check for camel caps format. - $valid = PHP_CodeSniffer::isCamelCaps($name, true, true, false); - if ($valid === false) { - $type = ucfirst($tokens[$stackPtr]['content']); - $error = '%s name "%s" is not in camel caps format'; - $data = array( - $type, - $name, - ); - $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $data); - $phpcsFile->recordMetric($stackPtr, 'CamelCase class name', 'no'); - } else { - $phpcsFile->recordMetric($stackPtr, 'CamelCase class name', 'yes'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/BlockCommentSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/BlockCommentSniff.php deleted file mode 100644 index 60f31d0..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/BlockCommentSniff.php +++ /dev/null @@ -1,357 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Commenting_BlockCommentSniff. - * - * Verifies that block comments are used appropriately. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Commenting_BlockCommentSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * The --tab-width CLI value that is being used. - * - * @var int - */ - private $_tabWidth = null; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_COMMENT, - T_DOC_COMMENT_OPEN_TAG, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The current file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - if ($this->_tabWidth === null) { - $cliValues = $phpcsFile->phpcs->cli->getCommandLineValues(); - if (isset($cliValues['tabWidth']) === false || $cliValues['tabWidth'] === 0) { - // We have no idea how wide tabs are, so assume 4 spaces for fixing. - $this->_tabWidth = 4; - } else { - $this->_tabWidth = $cliValues['tabWidth']; - } - } - - $tokens = $phpcsFile->getTokens(); - - // If it's an inline comment, return. - if (substr($tokens[$stackPtr]['content'], 0, 2) !== '/*') { - return; - } - - // If this is a function/class/interface doc block comment, skip it. - // We are only interested in inline doc block comments. - if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) { - $nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true); - $ignore = array( - T_CLASS => true, - T_INTERFACE => true, - T_TRAIT => true, - T_FUNCTION => true, - T_PUBLIC => true, - T_PRIVATE => true, - T_FINAL => true, - T_PROTECTED => true, - T_STATIC => true, - T_ABSTRACT => true, - T_CONST => true, - T_VAR => true, - ); - if (isset($ignore[$tokens[$nextToken]['code']]) === true) { - return; - } - - $prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); - if ($tokens[$prevToken]['code'] === T_OPEN_TAG) { - return; - } - - $error = 'Block comments must be started with /*'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'WrongStart'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, '/*'); - } - - $end = $tokens[$stackPtr]['comment_closer']; - if ($tokens[$end]['content'] !== '*/') { - $error = 'Block comments must be ended with */'; - $fix = $phpcsFile->addFixableError($error, $end, 'WrongEnd'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($end, '*/'); - } - } - - return; - }//end if - - $commentLines = array($stackPtr); - $nextComment = $stackPtr; - $lastLine = $tokens[$stackPtr]['line']; - $commentString = $tokens[$stackPtr]['content']; - - // Construct the comment into an array. - while (($nextComment = $phpcsFile->findNext(T_WHITESPACE, ($nextComment + 1), null, true)) !== false) { - if ($tokens[$nextComment]['code'] !== $tokens[$stackPtr]['code']) { - // Found the next bit of code. - break; - } - - if (($tokens[$nextComment]['line'] - 1) !== $lastLine) { - // Not part of the block. - break; - } - - $lastLine = $tokens[$nextComment]['line']; - $commentLines[] = $nextComment; - $commentString .= $tokens[$nextComment]['content']; - if ($tokens[$nextComment]['code'] === T_DOC_COMMENT_CLOSE_TAG) { - break; - } - } - - $commentText = str_replace($phpcsFile->eolChar, '', $commentString); - $commentText = trim($commentText, '/* '); - if ($commentText === '') { - $error = 'Empty block comment not allowed'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Empty'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->replaceToken($stackPtr, ''); - $lastToken = array_pop($commentLines); - for ($i = ($stackPtr + 1); $i <= $lastToken; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - - return; - } - - if (count($commentLines) === 1) { - $error = 'Single line block comment not allowed; use inline ("// text") comment instead'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SingleLine'); - if ($fix === true) { - $comment = '// '.$commentText.$phpcsFile->eolChar; - $phpcsFile->fixer->replaceToken($stackPtr, $comment); - } - - return; - } - - $content = trim($tokens[$stackPtr]['content']); - if ($content !== '/*' && $content !== '/**') { - $error = 'Block comment text must start on a new line'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoNewLine'); - if ($fix === true) { - $indent = ''; - if ($tokens[($stackPtr - 1)]['code'] === T_WHITESPACE) { - if (isset($tokens[($stackPtr - 1)]['orig_content']) === true) { - $indent = $tokens[($stackPtr - 1)]['orig_content']; - } else { - $indent = $tokens[($stackPtr - 1)]['content']; - } - } - - $comment = preg_replace( - '/^(\s*\/\*\*?)/', - '$1'.$phpcsFile->eolChar.$indent, - $tokens[$stackPtr]['content'], - 1 - ); - $phpcsFile->fixer->replaceToken($stackPtr, $comment); - } - - return; - }//end if - - $starColumn = ($tokens[$stackPtr]['column'] + 3); - - // Make sure first line isn't blank. - if (trim($tokens[$commentLines[1]]['content']) === '') { - $error = 'Empty line not allowed at start of comment'; - $fix = $phpcsFile->addFixableError($error, $commentLines[1], 'HasEmptyLine'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($commentLines[1], ''); - } - } else { - // Check indentation of first line. - $content = $tokens[$commentLines[1]]['content']; - $commentText = ltrim($content); - $leadingSpace = (strlen($content) - strlen($commentText)); - if ($leadingSpace !== $starColumn) { - $expected = $starColumn.' space'; - if ($starColumn !== 1) { - $expected .= 's'; - } - - $data = array( - $expected, - $leadingSpace, - ); - - $error = 'First line of comment not aligned correctly; expected %s but found %s'; - $fix = $phpcsFile->addFixableError($error, $commentLines[1], 'FirstLineIndent', $data); - if ($fix === true) { - if (isset($tokens[$commentLines[1]]['orig_content']) === true - && $tokens[$commentLines[1]]['orig_content'][0] === "\t" - ) { - // Line is indented using tabs. - $padding = str_repeat("\t", floor($starColumn / $this->_tabWidth)); - } else { - $padding = str_repeat(' ', $starColumn); - } - - $phpcsFile->fixer->replaceToken($commentLines[1], $padding.ltrim($content)); - } - }//end if - - if (preg_match('/^\p{Ll}/u', $commentText) === 1) { - $error = 'Block comments must start with a capital letter'; - $phpcsFile->addError($error, $commentLines[1], 'NoCapital'); - } - }//end if - - // Check that each line of the comment is indented past the star. - foreach ($commentLines as $line) { - $leadingSpace = (strlen($tokens[$line]['content']) - strlen(ltrim($tokens[$line]['content']))); - // First and last lines (comment opener and closer) are handled separately. - if ($line === $commentLines[(count($commentLines) - 1)] || $line === $commentLines[0]) { - continue; - } - - // First comment line was handled above. - if ($line === $commentLines[1]) { - continue; - } - - // If it's empty, continue. - if (trim($tokens[$line]['content']) === '') { - continue; - } - - if ($leadingSpace < $starColumn) { - $expected = $starColumn.' space'; - if ($starColumn !== 1) { - $expected .= 's'; - } - - $data = array( - $expected, - $leadingSpace, - ); - - $error = 'Comment line indented incorrectly; expected at least %s but found %s'; - $fix = $phpcsFile->addFixableError($error, $line, 'LineIndent', $data); - if ($fix === true) { - if (isset($tokens[$line]['orig_content']) === true - && $tokens[$line]['orig_content'][0] === "\t" - ) { - // Line is indented using tabs. - $padding = str_repeat("\t", floor($starColumn / $this->_tabWidth)); - } else { - $padding = str_repeat(' ', $starColumn); - } - - $phpcsFile->fixer->replaceToken($line, $padding.ltrim($tokens[$line]['content'])); - } - }//end if - }//end foreach - - // Finally, test the last line is correct. - $lastIndex = (count($commentLines) - 1); - $content = trim($tokens[$commentLines[$lastIndex]]['content']); - if ($content !== '*/' && $content !== '**/') { - $error = 'Comment closer must be on a new line'; - $phpcsFile->addError($error, $commentLines[$lastIndex]); - } else { - $content = $tokens[$commentLines[$lastIndex]]['content']; - $commentText = ltrim($content); - $leadingSpace = (strlen($content) - strlen($commentText)); - if ($leadingSpace !== ($tokens[$stackPtr]['column'] - 1)) { - $expected = ($tokens[$stackPtr]['column'] - 1); - if ($expected === 1) { - $expected .= ' space'; - } else { - $expected .= ' spaces'; - } - - $data = array( - $expected, - $leadingSpace, - ); - - $error = 'Last line of comment aligned incorrectly; expected %s but found %s'; - $phpcsFile->addError($error, $commentLines[$lastIndex], 'LastLineIndent', $data); - } - }//end if - - // Check that the lines before and after this comment are blank. - $contentBefore = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if (isset($tokens[$contentBefore]['scope_closer']) === true - && $tokens[$contentBefore]['scope_opener'] === $contentBefore - ) { - if (($tokens[$stackPtr]['line'] - $tokens[$contentBefore]['line']) !== 1) { - $error = 'Empty line not required before block comment'; - $phpcsFile->addError($error, $stackPtr, 'HasEmptyLineBefore'); - } - } else { - if (($tokens[$stackPtr]['line'] - $tokens[$contentBefore]['line']) < 2) { - $error = 'Empty line required before block comment'; - $phpcsFile->addError($error, $stackPtr, 'NoEmptyLineBefore'); - } - } - - $commentCloser = $commentLines[$lastIndex]; - $contentAfter = $phpcsFile->findNext(T_WHITESPACE, ($commentCloser + 1), null, true); - if ($contentAfter !== false && ($tokens[$contentAfter]['line'] - $tokens[$commentCloser]['line']) < 2) { - $error = 'Empty line required after block comment'; - $phpcsFile->addError($error, $commentCloser, 'NoEmptyLineAfter'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/ClassCommentSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/ClassCommentSniff.php deleted file mode 100644 index 9b2e9bc..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/ClassCommentSniff.php +++ /dev/null @@ -1,97 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Parses and verifies the class doc comment. - * - * Verifies that : - *
    - *
  • A class doc comment exists.
  • - *
  • There is exactly one blank line before the class comment.
  • - *
  • There are no blank lines after the class comment.
  • - *
  • Short and long descriptions end with a full stop and start with capital letter.
  • - *
  • There is a blank line between descriptions.
  • - *
- * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Commenting_ClassCommentSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_CLASS); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $find = PHP_CodeSniffer_Tokens::$methodPrefixes; - $find[] = T_WHITESPACE; - - $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); - if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG - && $tokens[$commentEnd]['code'] !== T_COMMENT - ) { - $phpcsFile->addError('Missing class doc comment', $stackPtr, 'Missing'); - $phpcsFile->recordMetric($stackPtr, 'Class has doc comment', 'no'); - return; - } - - $phpcsFile->recordMetric($stackPtr, 'Class has doc comment', 'yes'); - - if ($tokens[$commentEnd]['code'] === T_COMMENT) { - $phpcsFile->addError('You must use "/**" style comments for a class comment', $stackPtr, 'WrongStyle'); - return; - } - - if ($tokens[$commentEnd]['line'] !== ($tokens[$stackPtr]['line'] - 1)) { - $error = 'There must be no blank lines after the class comment'; - $phpcsFile->addError($error, $commentEnd, 'SpacingAfter'); - } - - $commentStart = $tokens[$commentEnd]['comment_opener']; - foreach ($tokens[$commentStart]['comment_tags'] as $tag) { - $error = '%s tag is not allowed in class comment'; - $data = array($tokens[$tag]['content']); - $phpcsFile->addWarning($error, $tag, 'TagNotAllowed', $data); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/ClosingDeclarationCommentSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/ClosingDeclarationCommentSniff.php deleted file mode 100644 index aff6712..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/ClosingDeclarationCommentSniff.php +++ /dev/null @@ -1,149 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Commenting_ClosingDeclarationCommentSniff. - * - * Checks the //end ... comments on classes, interfaces and functions. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Commenting_ClosingDeclarationCommentSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_FUNCTION, - T_CLASS, - T_INTERFACE, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens.. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[$stackPtr]['code'] === T_FUNCTION) { - $methodProps = $phpcsFile->getMethodProperties($stackPtr); - - // Abstract methods do not require a closing comment. - if ($methodProps['is_abstract'] === true) { - return; - } - - // Closures do not require a closing comment. - if ($methodProps['is_closure'] === true) { - return; - } - - // If this function is in an interface then we don't require - // a closing comment. - if ($phpcsFile->hasCondition($stackPtr, T_INTERFACE) === true) { - return; - } - - if (isset($tokens[$stackPtr]['scope_closer']) === false) { - $error = 'Possible parse error: non-abstract method defined as abstract'; - $phpcsFile->addWarning($error, $stackPtr, 'Abstract'); - return; - } - - $decName = $phpcsFile->getDeclarationName($stackPtr); - $comment = '//end '.$decName.'()'; - } else if ($tokens[$stackPtr]['code'] === T_CLASS) { - $comment = '//end class'; - } else { - $comment = '//end interface'; - }//end if - - if (isset($tokens[$stackPtr]['scope_closer']) === false) { - $error = 'Possible parse error: %s missing opening or closing brace'; - $data = array($tokens[$stackPtr]['content']); - $phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $data); - return; - } - - $closingBracket = $tokens[$stackPtr]['scope_closer']; - - if ($closingBracket === null) { - // Possible inline structure. Other tests will handle it. - return; - } - - $error = 'Expected '.$comment; - if (isset($tokens[($closingBracket + 1)]) === false || $tokens[($closingBracket + 1)]['code'] !== T_COMMENT) { - $next = $phpcsFile->findNext(T_WHITESPACE, ($closingBracket + 1), null, true); - if (rtrim($tokens[$next]['content']) === $comment) { - // The comment isn't really missing; it is just in the wrong place. - $fix = $phpcsFile->addFixableError($error.' directly after closing brace', $closingBracket, 'Misplaced'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($closingBracket + 1); $i < $next; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - // Just in case, because indentation fixes can add indents onto - // these comments and cause us to be unable to fix them. - $phpcsFile->fixer->replaceToken($next, $comment.$phpcsFile->eolChar); - $phpcsFile->fixer->endChangeset(); - } - } else { - $fix = $phpcsFile->addFixableError($error, $closingBracket, 'Missing'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($closingBracket, '}'.$comment.$phpcsFile->eolChar); - } - } - - return; - }//end if - - if (rtrim($tokens[($closingBracket + 1)]['content']) !== $comment) { - $fix = $phpcsFile->addFixableError($error, $closingBracket, 'Incorrect'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($closingBracket + 1), $comment.$phpcsFile->eolChar); - } - - return; - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php deleted file mode 100644 index cab7847..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php +++ /dev/null @@ -1,167 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Commenting_DocCommentAlignmentSniff. - * - * Tests that the stars in a doc comment align correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Commenting_DocCommentAlignmentSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_DOC_COMMENT_OPEN_TAG); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // We are only interested in function/class/interface doc block comments. - $ignore = PHP_CodeSniffer_Tokens::$emptyTokens; - if ($phpcsFile->tokenizerType === 'JS') { - $ignore[] = T_EQUAL; - $ignore[] = T_STRING; - $ignore[] = T_OBJECT_OPERATOR; - } - - $nextToken = $phpcsFile->findNext($ignore, ($stackPtr + 1), null, true); - $ignore = array( - T_CLASS => true, - T_INTERFACE => true, - T_FUNCTION => true, - T_PUBLIC => true, - T_PRIVATE => true, - T_PROTECTED => true, - T_STATIC => true, - T_ABSTRACT => true, - T_PROPERTY => true, - T_OBJECT => true, - T_PROTOTYPE => true, - T_VAR => true, - ); - - if (isset($ignore[$tokens[$nextToken]['code']]) === false) { - // Could be a file comment. - $prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); - if ($tokens[$prevToken]['code'] !== T_OPEN_TAG) { - return; - } - } - - // There must be one space after each star (unless it is an empty comment line) - // and all the stars must be aligned correctly. - $requiredColumn = ($tokens[$stackPtr]['column'] + 1); - $endComment = $tokens[$stackPtr]['comment_closer']; - for ($i = ($stackPtr + 1); $i <= $endComment; $i++) { - if ($tokens[$i]['code'] !== T_DOC_COMMENT_STAR - && $tokens[$i]['code'] !== T_DOC_COMMENT_CLOSE_TAG - ) { - continue; - } - - if ($tokens[$i]['code'] === T_DOC_COMMENT_CLOSE_TAG) { - // Can't process the close tag if it is not the first thing on the line. - $prev = $phpcsFile->findPrevious(T_DOC_COMMENT_WHITESPACE, ($i - 1), $stackPtr, true); - if ($tokens[$prev]['line'] === $tokens[$i]['line']) { - continue; - } - } - - if ($tokens[$i]['column'] !== $requiredColumn) { - $error = 'Expected %s space(s) before asterisk; %s found'; - $data = array( - ($requiredColumn - 1), - ($tokens[$i]['column'] - 1), - ); - $fix = $phpcsFile->addFixableError($error, $i, 'SpaceBeforeStar', $data); - if ($fix === true) { - $padding = str_repeat(' ', ($requiredColumn - 1)); - if ($tokens[$i]['column'] === 1) { - $phpcsFile->fixer->addContentBefore($i, $padding); - } else { - $phpcsFile->fixer->replaceToken(($i - 1), $padding); - } - } - } - - if ($tokens[$i]['code'] !== T_DOC_COMMENT_STAR) { - continue; - } - - if ($tokens[($i + 2)]['line'] !== $tokens[$i]['line']) { - // Line is empty. - continue; - } - - if ($tokens[($i + 1)]['code'] !== T_DOC_COMMENT_WHITESPACE) { - $error = 'Expected 1 space after asterisk; 0 found'; - $fix = $phpcsFile->addFixableError($error, $i, 'NoSpaceAfterStar'); - if ($fix === true) { - $phpcsFile->fixer->addContent($i, ' '); - } - } else if ($tokens[($i + 2)]['code'] === T_DOC_COMMENT_TAG - && $tokens[($i + 1)]['content'] !== ' ' - ) { - $error = 'Expected 1 space after asterisk; %s found'; - $data = array(strlen($tokens[($i + 1)]['content'])); - $fix = $phpcsFile->addFixableError($error, $i, 'SpaceAfterStar', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($i + 1), ' '); - } - } - }//end for - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/EmptyCatchCommentSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/EmptyCatchCommentSniff.php deleted file mode 100644 index f6024a8..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/EmptyCatchCommentSniff.php +++ /dev/null @@ -1,70 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Commenting_EmptyCatchCommentSniff. - * - * Checks for empty Catch clause. Catch clause must at least have comment - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Commenting_EmptyCatchCommentSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_CATCH); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $scopeStart = $tokens[$stackPtr]['scope_opener']; - $firstContent = $phpcsFile->findNext(T_WHITESPACE, ($scopeStart + 1), $tokens[$stackPtr]['scope_closer'], true); - - if ($firstContent === false) { - $error = 'Empty CATCH statement must have a comment to explain why the exception is not handled'; - $phpcsFile->addError($error, $scopeStart, 'Missing'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php deleted file mode 100644 index d3c7f3d..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php +++ /dev/null @@ -1,222 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Parses and verifies the file doc comment. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -class Squiz_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return int - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $this->currentFile = $phpcsFile; - - $tokens = $phpcsFile->getTokens(); - $commentStart = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - - if ($tokens[$commentStart]['code'] === T_COMMENT) { - $phpcsFile->addError('You must use "/**" style comments for a file comment', $commentStart, 'WrongStyle'); - $phpcsFile->recordMetric($stackPtr, 'File has doc comment', 'yes'); - return ($phpcsFile->numTokens + 1); - } else if ($commentStart === false || $tokens[$commentStart]['code'] !== T_DOC_COMMENT_OPEN_TAG) { - $phpcsFile->addError('Missing file doc comment', $stackPtr, 'Missing'); - $phpcsFile->recordMetric($stackPtr, 'File has doc comment', 'no'); - return ($phpcsFile->numTokens + 1); - } - - $commentEnd = $tokens[$commentStart]['comment_closer']; - - $nextToken = $phpcsFile->findNext( - T_WHITESPACE, - ($commentEnd + 1), - null, - true - ); - - $ignore = array( - T_CLASS, - T_INTERFACE, - T_TRAIT, - T_FUNCTION, - T_CLOSURE, - T_PUBLIC, - T_PRIVATE, - T_PROTECTED, - T_FINAL, - T_STATIC, - T_ABSTRACT, - T_CONST, - T_PROPERTY, - T_INCLUDE, - T_INCLUDE_ONCE, - T_REQUIRE, - T_REQUIRE_ONCE, - ); - - if (in_array($tokens[$nextToken]['code'], $ignore) === true) { - $phpcsFile->addError('Missing file doc comment', $stackPtr, 'Missing'); - $phpcsFile->recordMetric($stackPtr, 'File has doc comment', 'no'); - return ($phpcsFile->numTokens + 1); - } - - $phpcsFile->recordMetric($stackPtr, 'File has doc comment', 'yes'); - - // No blank line between the open tag and the file comment. - if ($tokens[$commentStart]['line'] > ($tokens[$stackPtr]['line'] + 1)) { - $error = 'There must be no blank lines before the file comment'; - $phpcsFile->addError($error, $stackPtr, 'SpacingAfterOpen'); - } - - // Exactly one blank line after the file comment. - $next = $phpcsFile->findNext(T_WHITESPACE, ($commentEnd + 1), null, true); - if ($tokens[$next]['line'] !== ($tokens[$commentEnd]['line'] + 2)) { - $error = 'There must be exactly one blank line after the file comment'; - $phpcsFile->addError($error, $commentEnd, 'SpacingAfterComment'); - } - - // Required tags in correct order. - $required = array( - '@package' => true, - '@subpackage' => true, - '@author' => true, - '@copyright' => true, - ); - - $foundTags = array(); - foreach ($tokens[$commentStart]['comment_tags'] as $tag) { - $name = $tokens[$tag]['content']; - $isRequired = isset($required[$name]); - - if ($isRequired === true && in_array($name, $foundTags) === true) { - $error = 'Only one %s tag is allowed in a file comment'; - $data = array($name); - $phpcsFile->addError($error, $tag, 'Duplicate'.ucfirst(substr($name, 1)).'Tag', $data); - } - - $foundTags[] = $name; - - if ($isRequired === false) { - continue; - } - - $string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $tag, $commentEnd); - if ($string === false || $tokens[$string]['line'] !== $tokens[$tag]['line']) { - $error = 'Content missing for %s tag in file comment'; - $data = array($name); - $phpcsFile->addError($error, $tag, 'Empty'.ucfirst(substr($name, 1)).'Tag', $data); - continue; - } - - if ($name === '@author') { - if ($tokens[$string]['content'] !== 'Squiz Pty Ltd ') { - $error = 'Expected "Squiz Pty Ltd " for author tag'; - $fix = $phpcsFile->addFixableError($error, $tag, 'IncorrectAuthor'); - if ($fix === true) { - $expected = 'Squiz Pty Ltd '; - $phpcsFile->fixer->replaceToken($string, $expected); - } - } - } else if ($name === '@copyright') { - if (preg_match('/^([0-9]{4})(-[0-9]{4})? (Squiz Pty Ltd \(ABN 77 084 670 600\))$/', $tokens[$string]['content']) === 0) { - $error = 'Expected "xxxx-xxxx Squiz Pty Ltd (ABN 77 084 670 600)" for copyright declaration'; - $fix = $phpcsFile->addFixableError($error, $tag, 'IncorrectCopyright'); - if ($fix === true) { - $matches = array(); - preg_match('/^(([0-9]{4})(-[0-9]{4})?)?.*$/', $tokens[$string]['content'], $matches); - if (isset($matches[1]) === false) { - $matches[1] = date('Y'); - } - - $expected = $matches[1].' Squiz Pty Ltd (ABN 77 084 670 600)'; - $phpcsFile->fixer->replaceToken($string, $expected); - } - } - }//end if - }//end foreach - - // Check if the tags are in the correct position. - $pos = 0; - foreach ($required as $tag => $true) { - if (in_array($tag, $foundTags) === false) { - $error = 'Missing %s tag in file comment'; - $data = array($tag); - $phpcsFile->addError($error, $commentEnd, 'Missing'.ucfirst(substr($tag, 1)).'Tag', $data); - } - - if (isset($foundTags[$pos]) === false) { - break; - } - - if ($foundTags[$pos] !== $tag) { - $error = 'The tag in position %s should be the %s tag'; - $data = array( - ($pos + 1), - $tag, - ); - $phpcsFile->addError($error, $tokens[$commentStart]['comment_tags'][$pos], ucfirst(substr($tag, 1)).'TagOrder', $data); - } - - $pos++; - }//end foreach - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php deleted file mode 100644 index 0dd5ab4..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php +++ /dev/null @@ -1,674 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PEAR_Sniffs_Commenting_FunctionCommentSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PEAR_Sniffs_Commenting_FunctionCommentSniff not found'); -} - -/** - * Parses and verifies the doc comments for functions. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Commenting_FunctionCommentSniff extends PEAR_Sniffs_Commenting_FunctionCommentSniff -{ - - /** - * The current PHP version. - * - * @var integer - */ - private $_phpVersion = null; - - - /** - * Process the return comment of this function comment. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $commentStart The position in the stack where the comment started. - * - * @return void - */ - protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) - { - $tokens = $phpcsFile->getTokens(); - - // Skip constructor and destructor. - $methodName = $phpcsFile->getDeclarationName($stackPtr); - $isSpecialMethod = ($methodName === '__construct' || $methodName === '__destruct'); - - $return = null; - foreach ($tokens[$commentStart]['comment_tags'] as $tag) { - if ($tokens[$tag]['content'] === '@return') { - if ($return !== null) { - $error = 'Only 1 @return tag is allowed in a function comment'; - $phpcsFile->addError($error, $tag, 'DuplicateReturn'); - return; - } - - $return = $tag; - } - } - - if ($isSpecialMethod === true) { - return; - } - - if ($return !== null) { - $content = $tokens[($return + 2)]['content']; - if (empty($content) === true || $tokens[($return + 2)]['code'] !== T_DOC_COMMENT_STRING) { - $error = 'Return type missing for @return tag in function comment'; - $phpcsFile->addError($error, $return, 'MissingReturnType'); - } else { - // Support both a return type and a description. - $split = preg_match('`^((?:\|?(?:array\([^\)]*\)|[\\\\a-z0-9\[\]]+))*)( .*)?`i', $content, $returnParts); - if (isset($returnParts[1]) === false) { - return; - } - - $returnType = $returnParts[1]; - - // Check return type (can be multiple, separated by '|'). - $typeNames = explode('|', $returnType); - $suggestedNames = array(); - foreach ($typeNames as $i => $typeName) { - $suggestedName = PHP_CodeSniffer::suggestType($typeName); - if (in_array($suggestedName, $suggestedNames) === false) { - $suggestedNames[] = $suggestedName; - } - } - - $suggestedType = implode('|', $suggestedNames); - if ($returnType !== $suggestedType) { - $error = 'Expected "%s" but found "%s" for function return type'; - $data = array( - $suggestedType, - $returnType, - ); - $fix = $phpcsFile->addFixableError($error, $return, 'InvalidReturn', $data); - if ($fix === true) { - $replacement = $suggestedType; - if (empty($returnParts[2]) === false) { - $replacement .= $returnParts[2]; - } - - $phpcsFile->fixer->replaceToken(($return + 2), $replacement); - unset($replacement); - } - } - - // If the return type is void, make sure there is - // no return statement in the function. - if ($returnType === 'void') { - if (isset($tokens[$stackPtr]['scope_closer']) === true) { - $endToken = $tokens[$stackPtr]['scope_closer']; - for ($returnToken = $stackPtr; $returnToken < $endToken; $returnToken++) { - if ($tokens[$returnToken]['code'] === T_CLOSURE - || $tokens[$returnToken]['code'] === T_ANON_CLASS - ) { - $returnToken = $tokens[$returnToken]['scope_closer']; - continue; - } - - if ($tokens[$returnToken]['code'] === T_RETURN - || $tokens[$returnToken]['code'] === T_YIELD - ) { - break; - } - } - - if ($returnToken !== $endToken) { - // If the function is not returning anything, just - // exiting, then there is no problem. - $semicolon = $phpcsFile->findNext(T_WHITESPACE, ($returnToken + 1), null, true); - if ($tokens[$semicolon]['code'] !== T_SEMICOLON) { - $error = 'Function return type is void, but function contains return statement'; - $phpcsFile->addError($error, $return, 'InvalidReturnVoid'); - } - } - }//end if - } else if ($returnType !== 'mixed' && in_array('void', $typeNames, true) === false) { - // If return type is not void, there needs to be a return statement - // somewhere in the function that returns something. - if (isset($tokens[$stackPtr]['scope_closer']) === true) { - $endToken = $tokens[$stackPtr]['scope_closer']; - $returnToken = $phpcsFile->findNext(array(T_RETURN, T_YIELD), $stackPtr, $endToken); - if ($returnToken === false) { - $error = 'Function return type is not void, but function has no return statement'; - $phpcsFile->addError($error, $return, 'InvalidNoReturn'); - } else { - $semicolon = $phpcsFile->findNext(T_WHITESPACE, ($returnToken + 1), null, true); - if ($tokens[$semicolon]['code'] === T_SEMICOLON) { - $error = 'Function return type is not void, but function is returning void here'; - $phpcsFile->addError($error, $returnToken, 'InvalidReturnNotVoid'); - } - } - } - }//end if - }//end if - } else { - $error = 'Missing @return tag in function comment'; - $phpcsFile->addError($error, $tokens[$commentStart]['comment_closer'], 'MissingReturn'); - }//end if - - }//end processReturn() - - - /** - * Process any throw tags that this function comment has. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $commentStart The position in the stack where the comment started. - * - * @return void - */ - protected function processThrows(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) - { - $tokens = $phpcsFile->getTokens(); - - $throws = array(); - foreach ($tokens[$commentStart]['comment_tags'] as $pos => $tag) { - if ($tokens[$tag]['content'] !== '@throws') { - continue; - } - - $exception = null; - $comment = null; - if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING) { - $matches = array(); - preg_match('/([^\s]+)(?:\s+(.*))?/', $tokens[($tag + 2)]['content'], $matches); - $exception = $matches[1]; - if (isset($matches[2]) === true && trim($matches[2]) !== '') { - $comment = $matches[2]; - } - } - - if ($exception === null) { - $error = 'Exception type and comment missing for @throws tag in function comment'; - $phpcsFile->addError($error, $tag, 'InvalidThrows'); - } else if ($comment === null) { - $error = 'Comment missing for @throws tag in function comment'; - $phpcsFile->addError($error, $tag, 'EmptyThrows'); - } else { - // Any strings until the next tag belong to this comment. - if (isset($tokens[$commentStart]['comment_tags'][($pos + 1)]) === true) { - $end = $tokens[$commentStart]['comment_tags'][($pos + 1)]; - } else { - $end = $tokens[$commentStart]['comment_closer']; - } - - for ($i = ($tag + 3); $i < $end; $i++) { - if ($tokens[$i]['code'] === T_DOC_COMMENT_STRING) { - $comment .= ' '.$tokens[$i]['content']; - } - } - - // Starts with a capital letter and ends with a fullstop. - $firstChar = $comment{0}; - if (strtoupper($firstChar) !== $firstChar) { - $error = '@throws tag comment must start with a capital letter'; - $phpcsFile->addError($error, ($tag + 2), 'ThrowsNotCapital'); - } - - $lastChar = substr($comment, -1); - if ($lastChar !== '.') { - $error = '@throws tag comment must end with a full stop'; - $phpcsFile->addError($error, ($tag + 2), 'ThrowsNoFullStop'); - } - }//end if - }//end foreach - - }//end processThrows() - - - /** - * Process the function parameter comments. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $commentStart The position in the stack where the comment started. - * - * @return void - */ - protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) - { - if ($this->_phpVersion === null) { - $this->_phpVersion = PHP_CodeSniffer::getConfigData('php_version'); - if ($this->_phpVersion === null) { - $this->_phpVersion = PHP_VERSION_ID; - } - } - - $tokens = $phpcsFile->getTokens(); - - $params = array(); - $maxType = 0; - $maxVar = 0; - foreach ($tokens[$commentStart]['comment_tags'] as $pos => $tag) { - if ($tokens[$tag]['content'] !== '@param') { - continue; - } - - $type = ''; - $typeSpace = 0; - $var = ''; - $varSpace = 0; - $comment = ''; - $commentLines = array(); - if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING) { - $matches = array(); - preg_match('/([^$&.]+)(?:((?:\.\.\.)?(?:\$|&)[^\s]+)(?:(\s+)(.*))?)?/', $tokens[($tag + 2)]['content'], $matches); - - if (empty($matches) === false) { - $typeLen = strlen($matches[1]); - $type = trim($matches[1]); - $typeSpace = ($typeLen - strlen($type)); - $typeLen = strlen($type); - if ($typeLen > $maxType) { - $maxType = $typeLen; - } - } - - if (isset($matches[2]) === true) { - $var = $matches[2]; - $varLen = strlen($var); - if ($varLen > $maxVar) { - $maxVar = $varLen; - } - - if (isset($matches[4]) === true) { - $varSpace = strlen($matches[3]); - $comment = $matches[4]; - $commentLines[] = array( - 'comment' => $comment, - 'token' => ($tag + 2), - 'indent' => $varSpace, - ); - - // Any strings until the next tag belong to this comment. - if (isset($tokens[$commentStart]['comment_tags'][($pos + 1)]) === true) { - $end = $tokens[$commentStart]['comment_tags'][($pos + 1)]; - } else { - $end = $tokens[$commentStart]['comment_closer']; - } - - for ($i = ($tag + 3); $i < $end; $i++) { - if ($tokens[$i]['code'] === T_DOC_COMMENT_STRING) { - $indent = 0; - if ($tokens[($i - 1)]['code'] === T_DOC_COMMENT_WHITESPACE) { - $indent = strlen($tokens[($i - 1)]['content']); - } - - $comment .= ' '.$tokens[$i]['content']; - $commentLines[] = array( - 'comment' => $tokens[$i]['content'], - 'token' => $i, - 'indent' => $indent, - ); - } - } - } else { - $error = 'Missing parameter comment'; - $phpcsFile->addError($error, $tag, 'MissingParamComment'); - $commentLines[] = array('comment' => ''); - }//end if - } else { - $error = 'Missing parameter name'; - $phpcsFile->addError($error, $tag, 'MissingParamName'); - }//end if - } else { - $error = 'Missing parameter type'; - $phpcsFile->addError($error, $tag, 'MissingParamType'); - }//end if - - $params[] = array( - 'tag' => $tag, - 'type' => $type, - 'var' => $var, - 'comment' => $comment, - 'commentLines' => $commentLines, - 'type_space' => $typeSpace, - 'var_space' => $varSpace, - ); - }//end foreach - - $realParams = $phpcsFile->getMethodParameters($stackPtr); - $foundParams = array(); - - // We want to use ... for all variable length arguments, so added - // this prefix to the variable name so comparisons are easier. - foreach ($realParams as $pos => $param) { - if ($param['variable_length'] === true) { - $realParams[$pos]['name'] = '...'.$realParams[$pos]['name']; - } - } - - foreach ($params as $pos => $param) { - // If the type is empty, the whole line is empty. - if ($param['type'] === '') { - continue; - } - - // Check the param type value. - $typeNames = explode('|', $param['type']); - $suggestedTypeNames = array(); - - foreach ($typeNames as $typeName) { - $suggestedName = PHP_CodeSniffer::suggestType($typeName); - $suggestedTypeNames[] = $suggestedName; - - if (count($typeNames) > 1) { - continue; - } - - // Check type hint for array and custom type. - $suggestedTypeHint = ''; - if (strpos($suggestedName, 'array') !== false || substr($suggestedName, -2) === '[]') { - $suggestedTypeHint = 'array'; - } else if (strpos($suggestedName, 'callable') !== false) { - $suggestedTypeHint = 'callable'; - } else if (strpos($suggestedName, 'callback') !== false) { - $suggestedTypeHint = 'callable'; - } else if (in_array($typeName, PHP_CodeSniffer::$allowedTypes) === false) { - $suggestedTypeHint = $suggestedName; - } else if ($this->_phpVersion >= 70000) { - if ($typeName === 'string') { - $suggestedTypeHint = 'string'; - } else if ($typeName === 'int' || $typeName === 'integer') { - $suggestedTypeHint = 'int'; - } else if ($typeName === 'float') { - $suggestedTypeHint = 'float'; - } else if ($typeName === 'bool' || $typeName === 'boolean') { - $suggestedTypeHint = 'bool'; - } - } - - if ($suggestedTypeHint !== '' && isset($realParams[$pos]) === true) { - $typeHint = $realParams[$pos]['type_hint']; - if ($typeHint === '') { - $error = 'Type hint "%s" missing for %s'; - $data = array( - $suggestedTypeHint, - $param['var'], - ); - - $errorCode = 'TypeHintMissing'; - if ($suggestedTypeHint === 'string' - || $suggestedTypeHint === 'int' - || $suggestedTypeHint === 'float' - || $suggestedTypeHint === 'bool' - ) { - $errorCode = 'Scalar'.$errorCode; - } - - $phpcsFile->addError($error, $stackPtr, $errorCode, $data); - } else if ($typeHint !== substr($suggestedTypeHint, (strlen($typeHint) * -1))) { - $error = 'Expected type hint "%s"; found "%s" for %s'; - $data = array( - $suggestedTypeHint, - $typeHint, - $param['var'], - ); - $phpcsFile->addError($error, $stackPtr, 'IncorrectTypeHint', $data); - }//end if - } else if ($suggestedTypeHint === '' && isset($realParams[$pos]) === true) { - $typeHint = $realParams[$pos]['type_hint']; - if ($typeHint !== '') { - $error = 'Unknown type hint "%s" found for %s'; - $data = array( - $typeHint, - $param['var'], - ); - $phpcsFile->addError($error, $stackPtr, 'InvalidTypeHint', $data); - } - }//end if - }//end foreach - - $suggestedType = implode($suggestedTypeNames, '|'); - if ($param['type'] !== $suggestedType) { - $error = 'Expected "%s" but found "%s" for parameter type'; - $data = array( - $suggestedType, - $param['type'], - ); - - $fix = $phpcsFile->addFixableError($error, $param['tag'], 'IncorrectParamVarName', $data); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - - $content = $suggestedType; - $content .= str_repeat(' ', $param['type_space']); - $content .= $param['var']; - $content .= str_repeat(' ', $param['var_space']); - if (isset($param['commentLines'][0]) === true) { - $content .= $param['commentLines'][0]['comment']; - } - - $phpcsFile->fixer->replaceToken(($param['tag'] + 2), $content); - - // Fix up the indent of additional comment lines. - foreach ($param['commentLines'] as $lineNum => $line) { - if ($lineNum === 0 - || $param['commentLines'][$lineNum]['indent'] === 0 - ) { - continue; - } - - $diff = (strlen($param['type']) - strlen($suggestedType)); - $newIndent = ($param['commentLines'][$lineNum]['indent'] - $diff); - $phpcsFile->fixer->replaceToken( - ($param['commentLines'][$lineNum]['token'] - 1), - str_repeat(' ', $newIndent) - ); - } - - $phpcsFile->fixer->endChangeset(); - }//end if - }//end if - - if ($param['var'] === '') { - continue; - } - - $foundParams[] = $param['var']; - - // Check number of spaces after the type. - $this->checkSpacingAfterParamType($phpcsFile, $param, $maxType); - - // Make sure the param name is correct. - if (isset($realParams[$pos]) === true) { - $realName = $realParams[$pos]['name']; - if ($realName !== $param['var']) { - $code = 'ParamNameNoMatch'; - $data = array( - $param['var'], - $realName, - ); - - $error = 'Doc comment for parameter %s does not match '; - if (strtolower($param['var']) === strtolower($realName)) { - $error .= 'case of '; - $code = 'ParamNameNoCaseMatch'; - } - - $error .= 'actual variable name %s'; - - $phpcsFile->addError($error, $param['tag'], $code, $data); - } - } else if (substr($param['var'], -4) !== ',...') { - // We must have an extra parameter comment. - $error = 'Superfluous parameter comment'; - $phpcsFile->addError($error, $param['tag'], 'ExtraParamComment'); - }//end if - - if ($param['comment'] === '') { - continue; - } - - // Check number of spaces after the var name. - $this->checkSpacingAfterParamName($phpcsFile, $param, $maxVar); - - // Param comments must start with a capital letter and end with the full stop. - if (preg_match('/^(\p{Ll}|\P{L})/u', $param['comment']) === 1) { - $error = 'Parameter comment must start with a capital letter'; - $phpcsFile->addError($error, $param['tag'], 'ParamCommentNotCapital'); - } - - $lastChar = substr($param['comment'], -1); - if ($lastChar !== '.') { - $error = 'Parameter comment must end with a full stop'; - $phpcsFile->addError($error, $param['tag'], 'ParamCommentFullStop'); - } - }//end foreach - - $realNames = array(); - foreach ($realParams as $realParam) { - $realNames[] = $realParam['name']; - } - - // Report missing comments. - $diff = array_diff($realNames, $foundParams); - foreach ($diff as $neededParam) { - $error = 'Doc comment for parameter "%s" missing'; - $data = array($neededParam); - $phpcsFile->addError($error, $commentStart, 'MissingParamTag', $data); - } - - }//end processParams() - - - /** - * Check the spacing after the type of a parameter. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $param The parameter to be checked. - * @param int $maxType The maxlength of the longest parameter type. - * @param int $spacing The number of spaces to add after the type. - * - * @return void - */ - protected function checkSpacingAfterParamType(PHP_CodeSniffer_File $phpcsFile, $param, $maxType, $spacing = 1) - { - // Check number of spaces after the type. - $spaces = ($maxType - strlen($param['type']) + $spacing); - if ($param['type_space'] !== $spaces) { - $error = 'Expected %s spaces after parameter type; %s found'; - $data = array( - $spaces, - $param['type_space'], - ); - - $fix = $phpcsFile->addFixableError($error, $param['tag'], 'SpacingAfterParamType', $data); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - - $content = $param['type']; - $content .= str_repeat(' ', $spaces); - $content .= $param['var']; - $content .= str_repeat(' ', $param['var_space']); - $content .= $param['commentLines'][0]['comment']; - $phpcsFile->fixer->replaceToken(($param['tag'] + 2), $content); - - // Fix up the indent of additional comment lines. - foreach ($param['commentLines'] as $lineNum => $line) { - if ($lineNum === 0 - || $param['commentLines'][$lineNum]['indent'] === 0 - ) { - continue; - } - - $diff = ($param['type_space'] - $spaces); - $newIndent = ($param['commentLines'][$lineNum]['indent'] - $diff); - $phpcsFile->fixer->replaceToken( - ($param['commentLines'][$lineNum]['token'] - 1), - str_repeat(' ', $newIndent) - ); - } - - $phpcsFile->fixer->endChangeset(); - }//end if - }//end if - - }//end checkSpacingAfterParamType() - - - /** - * Check the spacing after the name of a parameter. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $param The parameter to be checked. - * @param int $maxVar The maxlength of the longest parameter name. - * @param int $spacing The number of spaces to add after the type. - * - * @return void - */ - protected function checkSpacingAfterParamName(PHP_CodeSniffer_File $phpcsFile, $param, $maxVar, $spacing = 1) - { - // Check number of spaces after the var name. - $spaces = ($maxVar - strlen($param['var']) + $spacing); - if ($param['var_space'] !== $spaces) { - $error = 'Expected %s spaces after parameter name; %s found'; - $data = array( - $spaces, - $param['var_space'], - ); - - $fix = $phpcsFile->addFixableError($error, $param['tag'], 'SpacingAfterParamName', $data); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - - $content = $param['type']; - $content .= str_repeat(' ', $param['type_space']); - $content .= $param['var']; - $content .= str_repeat(' ', $spaces); - $content .= $param['commentLines'][0]['comment']; - $phpcsFile->fixer->replaceToken(($param['tag'] + 2), $content); - - // Fix up the indent of additional comment lines. - foreach ($param['commentLines'] as $lineNum => $line) { - if ($lineNum === 0 - || $param['commentLines'][$lineNum]['indent'] === 0 - ) { - continue; - } - - $diff = ($param['var_space'] - $spaces); - $newIndent = ($param['commentLines'][$lineNum]['indent'] - $diff); - $phpcsFile->fixer->replaceToken( - ($param['commentLines'][$lineNum]['token'] - 1), - str_repeat(' ', $newIndent) - ); - } - - $phpcsFile->fixer->endChangeset(); - }//end if - }//end if - - }//end checkSpacingAfterParamName() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FunctionCommentThrowTagSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FunctionCommentThrowTagSniff.php deleted file mode 100644 index 98abfb8..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FunctionCommentThrowTagSniff.php +++ /dev/null @@ -1,203 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) { - $error = 'Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found'; - throw new PHP_CodeSniffer_Exception($error); -} - -/** - * Verifies that a @throws tag exists for a function that throws exceptions. - * Verifies the number of @throws tags and the number of throw tokens matches. - * Verifies the exception type. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Commenting_FunctionCommentThrowTagSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff -{ - - - /** - * Constructs a Squiz_Sniffs_Commenting_FunctionCommentThrowTagSniff. - */ - public function __construct() - { - parent::__construct(array(T_FUNCTION), array(T_THROW)); - - }//end __construct() - - - /** - * Processes the function tokens within the class. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. - * @param int $currScope The current scope opener token. - * - * @return void - */ - protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) - { - // Is this the first throw token within the current function scope? - // If so, we have to validate other throw tokens within the same scope. - $previousThrow = $phpcsFile->findPrevious(T_THROW, ($stackPtr - 1), $currScope); - if ($previousThrow !== false) { - return; - } - - $tokens = $phpcsFile->getTokens(); - - $find = PHP_CodeSniffer_Tokens::$methodPrefixes; - $find[] = T_WHITESPACE; - - $commentEnd = $phpcsFile->findPrevious($find, ($currScope - 1), null, true); - if ($tokens[$commentEnd]['code'] === T_COMMENT) { - // Function is using the wrong type of comment. - return; - } - - if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG - && $tokens[$commentEnd]['code'] !== T_COMMENT - ) { - // Function doesn't have a doc comment. - return; - } - - $currScopeEnd = $tokens[$currScope]['scope_closer']; - - // Find all the exception type token within the current scope. - $throwTokens = array(); - $currPos = $stackPtr; - $foundThrows = false; - while ($currPos < $currScopeEnd && $currPos !== false) { - if ($phpcsFile->hasCondition($currPos, T_CLOSURE) === false) { - $foundThrows = true; - - /* - If we can't find a NEW, we are probably throwing - a variable, so we ignore it, but they still need to - provide at least one @throws tag, even through we - don't know the exception class. - */ - - $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($currPos + 1), null, true); - if ($tokens[$nextToken]['code'] === T_NEW) { - $currException = $phpcsFile->findNext( - array( - T_NS_SEPARATOR, - T_STRING, - ), - $currPos, - $currScopeEnd, - false, - null, - true - ); - - if ($currException !== false) { - $endException = $phpcsFile->findNext( - array( - T_NS_SEPARATOR, - T_STRING, - ), - ($currException + 1), - $currScopeEnd, - true, - null, - true - ); - - if ($endException === false) { - $throwTokens[] = $tokens[$currException]['content']; - } else { - $throwTokens[] = $phpcsFile->getTokensAsString($currException, ($endException - $currException)); - } - }//end if - }//end if - }//end if - - $currPos = $phpcsFile->findNext(T_THROW, ($currPos + 1), $currScopeEnd); - }//end while - - if ($foundThrows === false) { - return; - } - - // Only need one @throws tag for each type of exception thrown. - $throwTokens = array_unique($throwTokens); - - $throwTags = array(); - $commentStart = $tokens[$commentEnd]['comment_opener']; - foreach ($tokens[$commentStart]['comment_tags'] as $tag) { - if ($tokens[$tag]['content'] !== '@throws') { - continue; - } - - if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING) { - $exception = $tokens[($tag + 2)]['content']; - $space = strpos($exception, ' '); - if ($space !== false) { - $exception = substr($exception, 0, $space); - } - - $throwTags[$exception] = true; - } - } - - if (empty($throwTags) === true) { - $error = 'Missing @throws tag in function comment'; - $phpcsFile->addError($error, $commentEnd, 'Missing'); - return; - } else if (empty($throwTokens) === true) { - // If token count is zero, it means that only variables are being - // thrown, so we need at least one @throws tag (checked above). - // Nothing more to do. - return; - } - - // Make sure @throws tag count matches throw token count. - $tokenCount = count($throwTokens); - $tagCount = count($throwTags); - if ($tokenCount !== $tagCount) { - $error = 'Expected %s @throws tag(s) in function comment; %s found'; - $data = array( - $tokenCount, - $tagCount, - ); - $phpcsFile->addError($error, $commentEnd, 'WrongNumber', $data); - return; - } - - foreach ($throwTokens as $throw) { - if (isset($throwTags[$throw]) === false) { - $error = 'Missing @throws tag for "%s" exception'; - $data = array($throw); - $phpcsFile->addError($error, $commentEnd, 'Missing', $data); - } - } - - }//end processTokenWithinScope() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/InlineCommentSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/InlineCommentSniff.php deleted file mode 100644 index fb5710f..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/InlineCommentSniff.php +++ /dev/null @@ -1,326 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Commenting_InlineCommentSniff. - * - * Checks that there is adequate spacing between comments. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Commenting_InlineCommentSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_COMMENT, - T_DOC_COMMENT_OPEN_TAG, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // If this is a function/class/interface doc block comment, skip it. - // We are only interested in inline doc block comments, which are - // not allowed. - if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) { - $nextToken = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, - ($stackPtr + 1), - null, - true - ); - - $ignore = array( - T_CLASS, - T_INTERFACE, - T_TRAIT, - T_FUNCTION, - T_CLOSURE, - T_PUBLIC, - T_PRIVATE, - T_PROTECTED, - T_FINAL, - T_STATIC, - T_ABSTRACT, - T_CONST, - T_PROPERTY, - T_INCLUDE, - T_INCLUDE_ONCE, - T_REQUIRE, - T_REQUIRE_ONCE, - ); - - if (in_array($tokens[$nextToken]['code'], $ignore) === true) { - return; - } - - if ($phpcsFile->tokenizerType === 'JS') { - // We allow block comments if a function or object - // is being assigned to a variable. - $ignore = PHP_CodeSniffer_Tokens::$emptyTokens; - $ignore[] = T_EQUAL; - $ignore[] = T_STRING; - $ignore[] = T_OBJECT_OPERATOR; - $nextToken = $phpcsFile->findNext($ignore, ($nextToken + 1), null, true); - if ($tokens[$nextToken]['code'] === T_FUNCTION - || $tokens[$nextToken]['code'] === T_CLOSURE - || $tokens[$nextToken]['code'] === T_OBJECT - || $tokens[$nextToken]['code'] === T_PROTOTYPE - ) { - return; - } - } - - $prevToken = $phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, - ($stackPtr - 1), - null, - true - ); - - if ($tokens[$prevToken]['code'] === T_OPEN_TAG) { - return; - } - - if ($tokens[$stackPtr]['content'] === '/**') { - $error = 'Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead'; - $phpcsFile->addError($error, $stackPtr, 'DocBlock'); - } - }//end if - - if ($tokens[$stackPtr]['content']{0} === '#') { - $error = 'Perl-style comments are not allowed; use "// Comment" instead'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'WrongStyle'); - if ($fix === true) { - $comment = ltrim($tokens[$stackPtr]['content'], "# \t"); - $phpcsFile->fixer->replaceToken($stackPtr, "// $comment"); - } - } - - // We don't want end of block comments. If the last comment is a closing - // curly brace. - $previousContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if ($tokens[$previousContent]['line'] === $tokens[$stackPtr]['line']) { - if ($tokens[$previousContent]['code'] === T_CLOSE_CURLY_BRACKET) { - return; - } - - // Special case for JS files. - if ($tokens[$previousContent]['code'] === T_COMMA - || $tokens[$previousContent]['code'] === T_SEMICOLON - ) { - $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($previousContent - 1), null, true); - if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) { - return; - } - } - } - - $comment = rtrim($tokens[$stackPtr]['content']); - - // Only want inline comments. - if (substr($comment, 0, 2) !== '//') { - return; - } - - if (trim(substr($comment, 2)) !== '') { - $spaceCount = 0; - $tabFound = false; - - $commentLength = strlen($comment); - for ($i = 2; $i < $commentLength; $i++) { - if ($comment[$i] === "\t") { - $tabFound = true; - break; - } - - if ($comment[$i] !== ' ') { - break; - } - - $spaceCount++; - } - - $fix = false; - if ($tabFound === true) { - $error = 'Tab found before comment text; expected "// %s" but found "%s"'; - $data = array( - ltrim(substr($comment, 2)), - $comment, - ); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'TabBefore', $data); - } else if ($spaceCount === 0) { - $error = 'No space found before comment text; expected "// %s" but found "%s"'; - $data = array( - substr($comment, 2), - $comment, - ); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceBefore', $data); - } else if ($spaceCount > 1) { - $error = 'Expected 1 space before comment text but found %s; use block comment if you need indentation'; - $data = array( - $spaceCount, - substr($comment, (2 + $spaceCount)), - $comment, - ); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBefore', $data); - }//end if - - if ($fix === true) { - $newComment = '// '.ltrim($tokens[$stackPtr]['content'], "/\t "); - $phpcsFile->fixer->replaceToken($stackPtr, $newComment); - } - }//end if - - // The below section determines if a comment block is correctly capitalised, - // and ends in a full-stop. It will find the last comment in a block, and - // work its way up. - $nextComment = $phpcsFile->findNext(array(T_COMMENT), ($stackPtr + 1), null, false); - if (($nextComment !== false) - && (($tokens[$nextComment]['line']) === ($tokens[$stackPtr]['line'] + 1)) - ) { - return; - } - - $topComment = $stackPtr; - $lastComment = $stackPtr; - while (($topComment = $phpcsFile->findPrevious(array(T_COMMENT), ($lastComment - 1), null, false)) !== false) { - if ($tokens[$topComment]['line'] !== ($tokens[$lastComment]['line'] - 1)) { - break; - } - - $lastComment = $topComment; - } - - $topComment = $lastComment; - $commentText = ''; - - for ($i = $topComment; $i <= $stackPtr; $i++) { - if ($tokens[$i]['code'] === T_COMMENT) { - $commentText .= trim(substr($tokens[$i]['content'], 2)); - } - } - - if ($commentText === '') { - $error = 'Blank comments are not allowed'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Empty'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, ''); - } - - return; - } - - if (preg_match('/^\p{Ll}/u', $commentText) === 1) { - $error = 'Inline comments must start with a capital letter'; - $phpcsFile->addError($error, $topComment, 'NotCapital'); - } - - // Only check the end of comment character if the start of the comment - // is a letter, indicating that the comment is just standard text. - if (preg_match('/^\p{L}/u', $commentText) === 1) { - $commentCloser = $commentText[(strlen($commentText) - 1)]; - $acceptedClosers = array( - 'full-stops' => '.', - 'exclamation marks' => '!', - 'or question marks' => '?', - ); - - if (in_array($commentCloser, $acceptedClosers) === false) { - $error = 'Inline comments must end in %s'; - $ender = ''; - foreach ($acceptedClosers as $closerName => $symbol) { - $ender .= ' '.$closerName.','; - } - - $ender = trim($ender, ' ,'); - $data = array($ender); - $phpcsFile->addError($error, $stackPtr, 'InvalidEndChar', $data); - } - } - - // Finally, the line below the last comment cannot be empty if this inline - // comment is on a line by itself. - if ($tokens[$previousContent]['line'] < $tokens[$stackPtr]['line']) { - $start = false; - for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) { - if ($tokens[$i]['line'] === ($tokens[$stackPtr]['line'] + 1)) { - if ($tokens[$i]['code'] !== T_WHITESPACE) { - return; - } - } else if ($tokens[$i]['line'] > ($tokens[$stackPtr]['line'] + 1)) { - break; - } - } - - $error = 'There must be no blank line following an inline comment'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfter'); - if ($fix === true) { - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - $phpcsFile->fixer->beginChangeset(); - for ($i = ($stackPtr + 1); $i < $next; $i++) { - if ($tokens[$i]['line'] === $tokens[$next]['line']) { - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/LongConditionClosingCommentSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/LongConditionClosingCommentSniff.php deleted file mode 100644 index cc72083..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/LongConditionClosingCommentSniff.php +++ /dev/null @@ -1,217 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_ControlStructures_LongConditionClosingCommentSniff. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Commenting_LongConditionClosingCommentSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - /** - * The openers that we are interested in. - * - * @var array(int) - */ - private static $_openers = array( - T_SWITCH, - T_IF, - T_FOR, - T_FOREACH, - T_WHILE, - T_TRY, - T_CASE, - ); - - /** - * The length that a code block must be before - * requiring a closing comment. - * - * @var int - */ - public $lineLimit = 20; - - /** - * The format the end comment should be in. - * - * The placeholder %s will be replaced with the type of condition opener. - * - * @var string - */ - public $commentFormat = '//end %s'; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_CLOSE_CURLY_BRACKET); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (isset($tokens[$stackPtr]['scope_condition']) === false) { - // No scope condition. It is a function closer. - return; - } - - $startCondition = $tokens[$tokens[$stackPtr]['scope_condition']]; - $startBrace = $tokens[$tokens[$stackPtr]['scope_opener']]; - $endBrace = $tokens[$stackPtr]; - - // We are only interested in some code blocks. - if (in_array($startCondition['code'], self::$_openers) === false) { - return; - } - - if ($startCondition['code'] === T_IF) { - // If this is actually an ELSE IF, skip it as the brace - // will be checked by the original IF. - $else = $phpcsFile->findPrevious(T_WHITESPACE, ($tokens[$stackPtr]['scope_condition'] - 1), null, true); - if ($tokens[$else]['code'] === T_ELSE) { - return; - } - - // IF statements that have an ELSE block need to use - // "end if" rather than "end else" or "end elseif". - do { - $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($tokens[$nextToken]['code'] === T_ELSE || $tokens[$nextToken]['code'] === T_ELSEIF) { - // Check for ELSE IF (2 tokens) as opposed to ELSEIF (1 token). - if ($tokens[$nextToken]['code'] === T_ELSE - && isset($tokens[$nextToken]['scope_closer']) === false - ) { - $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($nextToken + 1), null, true); - if ($tokens[$nextToken]['code'] !== T_IF - || isset($tokens[$nextToken]['scope_closer']) === false - ) { - // Not an ELSE IF or is an inline ELSE IF. - break; - } - } - - if (isset($tokens[$nextToken]['scope_closer']) === false) { - // There isn't going to be anywhere to print the "end if" comment - // because there is no closer. - return; - } - - // The end brace becomes the ELSE's end brace. - $stackPtr = $tokens[$nextToken]['scope_closer']; - $endBrace = $tokens[$stackPtr]; - } else { - break; - }//end if - } while (isset($tokens[$nextToken]['scope_closer']) === true); - }//end if - - if ($startCondition['code'] === T_TRY) { - // TRY statements need to check until the end of all CATCH statements. - do { - $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($tokens[$nextToken]['code'] === T_CATCH) { - // The end brace becomes the CATCH's end brace. - $stackPtr = $tokens[$nextToken]['scope_closer']; - $endBrace = $tokens[$stackPtr]; - } else { - break; - } - } while (isset($tokens[$nextToken]['scope_closer']) === true); - } - - $lineDifference = ($endBrace['line'] - $startBrace['line']); - - $expected = sprintf($this->commentFormat, $startCondition['content']); - $comment = $phpcsFile->findNext(array(T_COMMENT), $stackPtr, null, false); - - if (($comment === false) || ($tokens[$comment]['line'] !== $endBrace['line'])) { - if ($lineDifference >= $this->lineLimit) { - $error = 'End comment for long condition not found; expected "%s"'; - $data = array($expected); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Missing', $data); - - if ($fix === true) { - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($next !== false && $tokens[$next]['line'] === $tokens[$stackPtr]['line']) { - $expected .= $phpcsFile->eolChar; - } - - $phpcsFile->fixer->addContent($stackPtr, $expected); - } - } - - return; - } - - if (($comment - $stackPtr) !== 1) { - $error = 'Space found before closing comment; expected "%s"'; - $data = array($expected); - $phpcsFile->addError($error, $stackPtr, 'SpacingBefore', $data); - } - - if (trim($tokens[$comment]['content']) !== $expected) { - $found = trim($tokens[$comment]['content']); - $error = 'Incorrect closing comment; expected "%s" but found "%s"'; - $data = array( - $expected, - $found, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Invalid', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($comment, $expected.$phpcsFile->eolChar); - } - - return; - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/PostStatementCommentSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/PostStatementCommentSniff.php deleted file mode 100644 index dc582e0..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/PostStatementCommentSniff.php +++ /dev/null @@ -1,103 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Commenting_PostStatementCommentSniff. - * - * Checks to ensure that there are no comments after statements. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Commenting_PostStatementCommentSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_COMMENT); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//') { - return; - } - - $commentLine = $tokens[$stackPtr]['line']; - $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - - if ($tokens[$lastContent]['line'] !== $commentLine) { - return; - } - - if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) { - return; - } - - // Special case for JS files. - if ($tokens[$lastContent]['code'] === T_COMMA - || $tokens[$lastContent]['code'] === T_SEMICOLON - ) { - $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($lastContent - 1), null, true); - if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) { - return; - } - } - - $error = 'Comments may not appear after statements'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found'); - if ($fix === true) { - $phpcsFile->fixer->addNewlineBefore($stackPtr); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php deleted file mode 100644 index e41f191..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php +++ /dev/null @@ -1,170 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found'); -} - -/** - * Parses and verifies the variable doc comment. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -class Squiz_Sniffs_Commenting_VariableCommentSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff -{ - - - /** - * Called to process class member vars. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $ignore = array( - T_PUBLIC, - T_PRIVATE, - T_PROTECTED, - T_VAR, - T_STATIC, - T_WHITESPACE, - ); - - $commentEnd = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true); - if ($commentEnd === false - || ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG - && $tokens[$commentEnd]['code'] !== T_COMMENT) - ) { - $phpcsFile->addError('Missing member variable doc comment', $stackPtr, 'Missing'); - return; - } - - if ($tokens[$commentEnd]['code'] === T_COMMENT) { - $phpcsFile->addError('You must use "/**" style comments for a member variable comment', $stackPtr, 'WrongStyle'); - return; - } - - $commentStart = $tokens[$commentEnd]['comment_opener']; - - $foundVar = null; - foreach ($tokens[$commentStart]['comment_tags'] as $tag) { - if ($tokens[$tag]['content'] === '@var') { - if ($foundVar !== null) { - $error = 'Only one @var tag is allowed in a member variable comment'; - $phpcsFile->addError($error, $tag, 'DuplicateVar'); - } else { - $foundVar = $tag; - } - } else if ($tokens[$tag]['content'] === '@see') { - // Make sure the tag isn't empty. - $string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $tag, $commentEnd); - if ($string === false || $tokens[$string]['line'] !== $tokens[$tag]['line']) { - $error = 'Content missing for @see tag in member variable comment'; - $phpcsFile->addError($error, $tag, 'EmptySees'); - } - } else { - $error = '%s tag is not allowed in member variable comment'; - $data = array($tokens[$tag]['content']); - $phpcsFile->addWarning($error, $tag, 'TagNotAllowed', $data); - }//end if - }//end foreach - - // The @var tag is the only one we require. - if ($foundVar === null) { - $error = 'Missing @var tag in member variable comment'; - $phpcsFile->addError($error, $commentEnd, 'MissingVar'); - return; - } - - $firstTag = $tokens[$commentStart]['comment_tags'][0]; - if ($foundVar !== null && $tokens[$firstTag]['content'] !== '@var') { - $error = 'The @var tag must be the first tag in a member variable comment'; - $phpcsFile->addError($error, $foundVar, 'VarOrder'); - } - - // Make sure the tag isn't empty and has the correct padding. - $string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $foundVar, $commentEnd); - if ($string === false || $tokens[$string]['line'] !== $tokens[$foundVar]['line']) { - $error = 'Content missing for @var tag in member variable comment'; - $phpcsFile->addError($error, $foundVar, 'EmptyVar'); - return; - } - - $varType = $tokens[($foundVar + 2)]['content']; - $suggestedType = PHP_CodeSniffer::suggestType($varType); - if ($varType !== $suggestedType) { - $error = 'Expected "%s" but found "%s" for @var tag in member variable comment'; - $data = array( - $suggestedType, - $varType, - ); - - $fix = $phpcsFile->addFixableError($error, ($foundVar + 2), 'IncorrectVarType', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($foundVar + 2), $suggestedType); - } - } - - }//end processMemberVar() - - - /** - * Called to process a normal variable. - * - * Not required for this sniff. - * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this token was found. - * @param int $stackPtr The position where the double quoted - * string was found. - * - * @return void - */ - protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - - }//end processVariable() - - - /** - * Called to process variables found in double quoted strings. - * - * Not required for this sniff. - * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this token was found. - * @param int $stackPtr The position where the double quoted - * string was found. - * - * @return void - */ - protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - - }//end processVariableInString() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ControlSignatureSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ControlSignatureSniff.php deleted file mode 100644 index 5e426a2..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ControlSignatureSniff.php +++ /dev/null @@ -1,271 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Verifies that control statements conform to their coding standards. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_ControlStructures_ControlSignatureSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return int[] - */ - public function register() - { - return array( - T_TRY, - T_CATCH, - T_DO, - T_WHILE, - T_FOR, - T_IF, - T_FOREACH, - T_ELSE, - T_ELSEIF, - T_SWITCH, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (isset($tokens[($stackPtr + 1)]) === false) { - return; - } - - // Single space after the keyword. - $found = 1; - if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { - $found = 0; - } else if ($tokens[($stackPtr + 1)]['content'] !== ' ') { - if (strpos($tokens[($stackPtr + 1)]['content'], $phpcsFile->eolChar) !== false) { - $found = 'newline'; - } else { - $found = strlen($tokens[($stackPtr + 1)]['content']); - } - } - - if ($found !== 1) { - $error = 'Expected 1 space after %s keyword; %s found'; - $data = array( - strtoupper($tokens[$stackPtr]['content']), - $found, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterKeyword', $data); - if ($fix === true) { - if ($found === 0) { - $phpcsFile->fixer->addContent($stackPtr, ' '); - } else { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); - } - } - } - - // Single space after closing parenthesis. - if (isset($tokens[$stackPtr]['parenthesis_closer']) === true - && isset($tokens[$stackPtr]['scope_opener']) === true - ) { - $closer = $tokens[$stackPtr]['parenthesis_closer']; - $opener = $tokens[$stackPtr]['scope_opener']; - $content = $phpcsFile->getTokensAsString(($closer + 1), ($opener - $closer - 1)); - - if ($content !== ' ') { - $error = 'Expected 1 space after closing parenthesis; found %s'; - if (trim($content) === '') { - $found = strlen($content); - } else { - $found = '"'.str_replace($phpcsFile->eolChar, '\n', $content).'"'; - } - - $fix = $phpcsFile->addFixableError($error, $closer, 'SpaceAfterCloseParenthesis', array($found)); - if ($fix === true) { - if ($closer === ($opener - 1)) { - $phpcsFile->fixer->addContent($closer, ' '); - } else { - $phpcsFile->fixer->beginChangeset(); - if (trim($content) === '') { - $phpcsFile->fixer->addContent($closer, ' '); - if ($found !== 0) { - for ($i = ($closer + 1); $i < $opener; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - } - } else { - $phpcsFile->fixer->addContent($closer, ' '.$tokens[$opener]['content']); - $phpcsFile->fixer->replaceToken($opener, ''); - - if ($tokens[$opener]['line'] !== $tokens[$closer]['line']) { - $next = $phpcsFile->findNext(T_WHITESPACE, ($opener + 1), null, true); - if ($tokens[$next]['line'] !== $tokens[$opener]['line']) { - for ($i = ($opener + 1); $i < $next; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - } - } - } - - $phpcsFile->fixer->endChangeset(); - }//end if - }//end if - }//end if - }//end if - - // Single newline after opening brace. - if (isset($tokens[$stackPtr]['scope_opener']) === true) { - $opener = $tokens[$stackPtr]['scope_opener']; - for ($next = ($opener + 1); $next < $phpcsFile->numTokens; $next++) { - $code = $tokens[$next]['code']; - - if ($code === T_WHITESPACE - || ($code === T_INLINE_HTML - && trim($tokens[$next]['content']) === '') - ) { - continue; - } - - // Skip all empty tokens on the same line as the opener. - if ($tokens[$next]['line'] === $tokens[$opener]['line'] - && (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$code]) === true - || $code === T_CLOSE_TAG) - ) { - continue; - } - - // We found the first bit of a code, or a comment on the - // following line. - break; - }//end for - - if ($tokens[$next]['line'] === $tokens[$opener]['line']) { - $error = 'Newline required after opening brace'; - $fix = $phpcsFile->addFixableError($error, $opener, 'NewlineAfterOpenBrace'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($opener + 1); $i < $next; $i++) { - if (trim($tokens[$i]['content']) !== '') { - break; - } - - // Remove whitespace. - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->addContent($opener, $phpcsFile->eolChar); - $phpcsFile->fixer->endChangeset(); - } - }//end if - } else if ($tokens[$stackPtr]['code'] === T_WHILE) { - // Zero spaces after parenthesis closer. - $closer = $tokens[$stackPtr]['parenthesis_closer']; - $found = 0; - if ($tokens[($closer + 1)]['code'] === T_WHITESPACE) { - if (strpos($tokens[($closer + 1)]['content'], $phpcsFile->eolChar) !== false) { - $found = 'newline'; - } else { - $found = strlen($tokens[($closer + 1)]['content']); - } - } - - if ($found !== 0) { - $error = 'Expected 0 spaces before semicolon; %s found'; - $data = array($found); - $fix = $phpcsFile->addFixableError($error, $closer, 'SpaceBeforeSemicolon', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($closer + 1), ''); - } - } - }//end if - - // Only want to check multi-keyword structures from here on. - if ($tokens[$stackPtr]['code'] === T_DO) { - if (isset($tokens[$stackPtr]['scope_closer']) === false) { - return; - } - - $closer = $tokens[$stackPtr]['scope_closer']; - } else if ($tokens[$stackPtr]['code'] === T_ELSE - || $tokens[$stackPtr]['code'] === T_ELSEIF - || $tokens[$stackPtr]['code'] === T_CATCH - ) { - $closer = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); - if ($closer === false || $tokens[$closer]['code'] !== T_CLOSE_CURLY_BRACKET) { - return; - } - } else { - return; - } - - // Single space after closing brace. - $found = 1; - if ($tokens[($closer + 1)]['code'] !== T_WHITESPACE) { - $found = 0; - } else if ($tokens[($closer + 1)]['content'] !== ' ') { - if (strpos($tokens[($closer + 1)]['content'], $phpcsFile->eolChar) !== false) { - $found = 'newline'; - } else { - $found = strlen($tokens[($closer + 1)]['content']); - } - } - - if ($found !== 1) { - $error = 'Expected 1 space after closing brace; %s found'; - $data = array($found); - $fix = $phpcsFile->addFixableError($error, $closer, 'SpaceAfterCloseBrace', $data); - if ($fix === true) { - if ($found === 0) { - $phpcsFile->fixer->addContent($closer, ' '); - } else { - $phpcsFile->fixer->replaceToken(($closer + 1), ' '); - } - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ElseIfDeclarationSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ElseIfDeclarationSniff.php deleted file mode 100644 index c2b80b7..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ElseIfDeclarationSniff.php +++ /dev/null @@ -1,67 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_ControlStructures_ElseIfDeclarationSniff. - * - * Verifies that there are not elseif statements. The else and the if should - * be separated by a space. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_ControlStructures_ElseIfDeclarationSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_ELSEIF); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $error = 'Usage of ELSEIF not allowed; use ELSE IF instead'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotAllowed'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, 'else if'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ForEachLoopDeclarationSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ForEachLoopDeclarationSniff.php deleted file mode 100644 index c664def..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ForEachLoopDeclarationSniff.php +++ /dev/null @@ -1,252 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_ControlStructures_ForEachLoopDeclarationSniff. - * - * Verifies that there is a space between each condition of foreach loops. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_ControlStructures_ForEachLoopDeclarationSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * How many spaces should follow the opening bracket. - * - * @var int - */ - public $requiredSpacesAfterOpen = 0; - - /** - * How many spaces should precede the closing bracket. - * - * @var int - */ - public $requiredSpacesBeforeClose = 0; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_FOREACH); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $this->requiredSpacesAfterOpen = (int) $this->requiredSpacesAfterOpen; - $this->requiredSpacesBeforeClose = (int) $this->requiredSpacesBeforeClose; - $tokens = $phpcsFile->getTokens(); - - $openingBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr); - if ($openingBracket === false) { - $error = 'Possible parse error: FOREACH has no opening parenthesis'; - $phpcsFile->addWarning($error, $stackPtr, 'MissingOpenParenthesis'); - return; - } - - if (isset($tokens[$openingBracket]['parenthesis_closer']) === false) { - $error = 'Possible parse error: FOREACH has no closing parenthesis'; - $phpcsFile->addWarning($error, $stackPtr, 'MissingCloseParenthesis'); - return; - } - - $closingBracket = $tokens[$openingBracket]['parenthesis_closer']; - - if ($this->requiredSpacesAfterOpen === 0 && $tokens[($openingBracket + 1)]['code'] === T_WHITESPACE) { - $error = 'Space found after opening bracket of FOREACH loop'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterOpen'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($openingBracket + 1), ''); - } - } else if ($this->requiredSpacesAfterOpen > 0) { - $spaceAfterOpen = 0; - if ($tokens[($openingBracket + 1)]['code'] === T_WHITESPACE) { - $spaceAfterOpen = strlen($tokens[($openingBracket + 1)]['content']); - } - - if ($spaceAfterOpen !== $this->requiredSpacesAfterOpen) { - $error = 'Expected %s spaces after opening bracket; %s found'; - $data = array( - $this->requiredSpacesAfterOpen, - $spaceAfterOpen, - ); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterOpen', $data); - if ($fix === true) { - $padding = str_repeat(' ', $this->requiredSpacesAfterOpen); - if ($spaceAfterOpen === 0) { - $phpcsFile->fixer->addContent($openingBracket, $padding); - } else { - $phpcsFile->fixer->replaceToken(($openingBracket + 1), $padding); - } - } - } - }//end if - - if ($this->requiredSpacesBeforeClose === 0 && $tokens[($closingBracket - 1)]['code'] === T_WHITESPACE) { - $error = 'Space found before closing bracket of FOREACH loop'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceBeforeClose'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($closingBracket - 1), ''); - } - } else if ($this->requiredSpacesBeforeClose > 0) { - $spaceBeforeClose = 0; - if ($tokens[($closingBracket - 1)]['code'] === T_WHITESPACE) { - $spaceBeforeClose = strlen($tokens[($closingBracket - 1)]['content']); - } - - if ($spaceBeforeClose !== $this->requiredSpacesBeforeClose) { - $error = 'Expected %s spaces before closing bracket; %s found'; - $data = array( - $this->requiredSpacesBeforeClose, - $spaceBeforeClose, - ); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceBeforeClose', $data); - if ($fix === true) { - $padding = str_repeat(' ', $this->requiredSpacesBeforeClose); - if ($spaceBeforeClose === 0) { - $phpcsFile->fixer->addContentBefore($closingBracket, $padding); - } else { - $phpcsFile->fixer->replaceToken(($closingBracket - 1), $padding); - } - } - } - }//end if - - $asToken = $phpcsFile->findNext(T_AS, $openingBracket); - if ($asToken === false) { - $error = 'Possible parse error: FOREACH has no AS statement'; - $phpcsFile->addWarning($error, $stackPtr, 'MissingAs'); - return; - } - - $content = $tokens[$asToken]['content']; - if ($content !== strtolower($content)) { - $expected = strtolower($content); - $error = 'AS keyword must be lowercase; expected "%s" but found "%s"'; - $data = array( - $expected, - $content, - ); - - $fix = $phpcsFile->addFixableError($error, $asToken, 'AsNotLower', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($asToken, $expected); - } - } - - $doubleArrow = $phpcsFile->findNext(T_DOUBLE_ARROW, $asToken, $closingBracket); - - if ($doubleArrow !== false) { - if ($tokens[($doubleArrow - 1)]['code'] !== T_WHITESPACE) { - $error = 'Expected 1 space before "=>"; 0 found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceBeforeArrow'); - if ($fix === true) { - $phpcsFile->fixer->addContentBefore($doubleArrow, ' '); - } - } else { - if (strlen($tokens[($doubleArrow - 1)]['content']) !== 1) { - $spaces = strlen($tokens[($doubleArrow - 1)]['content']); - $error = 'Expected 1 space before "=>"; %s found'; - $data = array($spaces); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBeforeArrow', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($doubleArrow - 1), ' '); - } - } - } - - if ($tokens[($doubleArrow + 1)]['code'] !== T_WHITESPACE) { - $error = 'Expected 1 space after "=>"; 0 found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceAfterArrow'); - if ($fix === true) { - $phpcsFile->fixer->addContent($doubleArrow, ' '); - } - } else { - if (strlen($tokens[($doubleArrow + 1)]['content']) !== 1) { - $spaces = strlen($tokens[($doubleArrow + 1)]['content']); - $error = 'Expected 1 space after "=>"; %s found'; - $data = array($spaces); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterArrow', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($doubleArrow + 1), ' '); - } - } - } - }//end if - - if ($tokens[($asToken - 1)]['code'] !== T_WHITESPACE) { - $error = 'Expected 1 space before "as"; 0 found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceBeforeAs'); - if ($fix === true) { - $phpcsFile->fixer->addContentBefore($asToken, ' '); - } - } else { - if (strlen($tokens[($asToken - 1)]['content']) !== 1) { - $spaces = strlen($tokens[($asToken - 1)]['content']); - $error = 'Expected 1 space before "as"; %s found'; - $data = array($spaces); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBeforeAs', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($asToken - 1), ' '); - } - } - } - - if ($tokens[($asToken + 1)]['code'] !== T_WHITESPACE) { - $error = 'Expected 1 space after "as"; 0 found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceAfterAs'); - if ($fix === true) { - $phpcsFile->fixer->addContent($asToken, ' '); - } - } else { - if (strlen($tokens[($asToken + 1)]['content']) !== 1) { - $spaces = strlen($tokens[($asToken + 1)]['content']); - $error = 'Expected 1 space after "as"; %s found'; - $data = array($spaces); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterAs', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($asToken + 1), ' '); - } - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ForLoopDeclarationSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ForLoopDeclarationSniff.php deleted file mode 100644 index 12f7de7..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ForLoopDeclarationSniff.php +++ /dev/null @@ -1,232 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_ControlStructures_ForLoopDeclarationSniff. - * - * Verifies that there is a space between each condition of for loops. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_ControlStructures_ForLoopDeclarationSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * How many spaces should follow the opening bracket. - * - * @var int - */ - public $requiredSpacesAfterOpen = 0; - - /** - * How many spaces should precede the closing bracket. - * - * @var int - */ - public $requiredSpacesBeforeClose = 0; - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_FOR); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $this->requiredSpacesAfterOpen = (int) $this->requiredSpacesAfterOpen; - $this->requiredSpacesBeforeClose = (int) $this->requiredSpacesBeforeClose; - $tokens = $phpcsFile->getTokens(); - - $openingBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr); - if ($openingBracket === false) { - $error = 'Possible parse error: no opening parenthesis for FOR keyword'; - $phpcsFile->addWarning($error, $stackPtr, 'NoOpenBracket'); - return; - } - - $closingBracket = $tokens[$openingBracket]['parenthesis_closer']; - - if ($this->requiredSpacesAfterOpen === 0 && $tokens[($openingBracket + 1)]['code'] === T_WHITESPACE) { - $error = 'Space found after opening bracket of FOR loop'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterOpen'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($openingBracket + 1), ''); - } - } else if ($this->requiredSpacesAfterOpen > 0) { - $spaceAfterOpen = 0; - if ($tokens[($openingBracket + 1)]['code'] === T_WHITESPACE) { - $spaceAfterOpen = strlen($tokens[($openingBracket + 1)]['content']); - } - - if ($spaceAfterOpen !== $this->requiredSpacesAfterOpen) { - $error = 'Expected %s spaces after opening bracket; %s found'; - $data = array( - $this->requiredSpacesAfterOpen, - $spaceAfterOpen, - ); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterOpen', $data); - if ($fix === true) { - $padding = str_repeat(' ', $this->requiredSpacesAfterOpen); - if ($spaceAfterOpen === 0) { - $phpcsFile->fixer->addContent($openingBracket, $padding); - } else { - $phpcsFile->fixer->replaceToken(($openingBracket + 1), $padding); - } - } - } - }//end if - - if ($this->requiredSpacesBeforeClose === 0 && $tokens[($closingBracket - 1)]['code'] === T_WHITESPACE) { - $error = 'Space found before closing bracket of FOR loop'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBeforeClose'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($closingBracket - 1), ''); - } - } else if ($this->requiredSpacesBeforeClose > 0) { - $spaceBeforeClose = 0; - if ($tokens[($closingBracket - 1)]['code'] === T_WHITESPACE) { - $spaceBeforeClose = strlen($tokens[($closingBracket - 1)]['content']); - } - - if ($this->requiredSpacesBeforeClose !== $spaceBeforeClose) { - $error = 'Expected %s spaces before closing bracket; %s found'; - $data = array( - $this->requiredSpacesBeforeClose, - $spaceBeforeClose, - ); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBeforeClose', $data); - if ($fix === true) { - $padding = str_repeat(' ', $this->requiredSpacesBeforeClose); - if ($spaceBeforeClose === 0) { - $phpcsFile->fixer->addContentBefore($closingBracket, $padding); - } else { - $phpcsFile->fixer->replaceToken(($closingBracket - 1), $padding); - } - } - } - }//end if - - $firstSemicolon = $phpcsFile->findNext(T_SEMICOLON, $openingBracket, $closingBracket); - - // Check whitespace around each of the tokens. - if ($firstSemicolon !== false) { - if ($tokens[($firstSemicolon - 1)]['code'] === T_WHITESPACE) { - $error = 'Space found before first semicolon of FOR loop'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBeforeFirst'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($firstSemicolon - 1), ''); - } - } - - if ($tokens[($firstSemicolon + 1)]['code'] !== T_WHITESPACE - && $tokens[($firstSemicolon + 1)]['code'] !== T_SEMICOLON - ) { - $error = 'Expected 1 space after first semicolon of FOR loop; 0 found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceAfterFirst'); - if ($fix === true) { - $phpcsFile->fixer->addContent($firstSemicolon, ' '); - } - } else { - if (strlen($tokens[($firstSemicolon + 1)]['content']) !== 1) { - $spaces = strlen($tokens[($firstSemicolon + 1)]['content']); - $error = 'Expected 1 space after first semicolon of FOR loop; %s found'; - $data = array($spaces); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterFirst', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($firstSemicolon + 1), ' '); - } - } - } - - $secondSemicolon = $phpcsFile->findNext(T_SEMICOLON, ($firstSemicolon + 1)); - - if ($secondSemicolon !== false) { - if ($tokens[($secondSemicolon - 1)]['code'] === T_WHITESPACE - && $tokens[($firstSemicolon + 1)]['code'] !== T_SEMICOLON - ) { - $error = 'Space found before second semicolon of FOR loop'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBeforeSecond'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($secondSemicolon - 1), ''); - } - } - - if (($secondSemicolon + 1) !== $closingBracket - && $tokens[($secondSemicolon + 1)]['code'] !== T_WHITESPACE - ) { - $error = 'Expected 1 space after second semicolon of FOR loop; 0 found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceAfterSecond'); - if ($fix === true) { - $phpcsFile->fixer->addContent($secondSemicolon, ' '); - } - } else { - if (strlen($tokens[($secondSemicolon + 1)]['content']) !== 1) { - $spaces = strlen($tokens[($secondSemicolon + 1)]['content']); - $data = array($spaces); - if (($secondSemicolon + 2) === $closingBracket) { - $error = 'Expected no space after second semicolon of FOR loop; %s found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterSecondNoThird', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($secondSemicolon + 1), ''); - } - } else { - $error = 'Expected 1 space after second semicolon of FOR loop; %s found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterSecond', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($secondSemicolon + 1), ' '); - } - } - } - }//end if - }//end if - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/InlineIfDeclarationSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/InlineIfDeclarationSniff.php deleted file mode 100644 index 945a69c..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/InlineIfDeclarationSniff.php +++ /dev/null @@ -1,166 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_ControlStructures_InlineIfDeclarationSniff. - * - * Tests the spacing of shorthand IF statements. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_ControlStructures_InlineIfDeclarationSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_INLINE_THEN); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $openBracket = null; - $closeBracket = null; - if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) { - $parens = $tokens[$stackPtr]['nested_parenthesis']; - $openBracket = array_pop($parens); - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; - } - - // Find the beginning of the statement. If we don't find a - // semicolon (end of statement) or comma (end of array value) - // then assume the content before the closing parenthesis is the end. - $else = $phpcsFile->findNext(T_INLINE_ELSE, ($stackPtr + 1)); - $statementEnd = $phpcsFile->findNext(array(T_SEMICOLON, T_COMMA), ($else + 1), $closeBracket); - if ($statementEnd === false) { - $statementEnd = $phpcsFile->findPrevious(T_WHITESPACE, ($closeBracket - 1), null, true); - } - - // Make sure it's all on the same line. - if ($tokens[$statementEnd]['line'] !== $tokens[$stackPtr]['line']) { - $error = 'Inline shorthand IF statement must be declared on a single line'; - $phpcsFile->addError($error, $stackPtr, 'NotSingleLine'); - return; - } - - // Make sure there are spaces around the question mark. - $contentBefore = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - $contentAfter = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($tokens[$contentBefore]['code'] !== T_CLOSE_PARENTHESIS) { - $error = 'Inline shorthand IF statement requires brackets around comparison'; - $phpcsFile->addError($error, $stackPtr, 'NoBrackets'); - } - - $spaceBefore = ($tokens[$stackPtr]['column'] - ($tokens[$contentBefore]['column'] + $tokens[$contentBefore]['length'])); - if ($spaceBefore !== 1) { - $error = 'Inline shorthand IF statement requires 1 space before THEN; %s found'; - $data = array($spaceBefore); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBeforeThen', $data); - if ($fix === true) { - if ($spaceBefore === 0) { - $phpcsFile->fixer->addContentBefore($stackPtr, ' '); - } else { - $phpcsFile->fixer->replaceToken(($stackPtr - 1), ' '); - } - } - } - - // If there is no content between the ? and the : operators, then they are - // trying to replicate an elvis operator, even though PHP doesn't have one. - // In this case, we want no spaces between the two operators so ?: looks like - // an operator itself. - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($tokens[$next]['code'] === T_INLINE_ELSE) { - $inlineElse = $next; - if ($inlineElse !== ($stackPtr + 1)) { - $error = 'Inline shorthand IF statement without THEN statement requires 0 spaces between THEN and ELSE'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'ElvisSpacing'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ''); - } - } - } else { - $spaceAfter = (($tokens[$contentAfter]['column']) - ($tokens[$stackPtr]['column'] + 1)); - if ($spaceAfter !== 1) { - $error = 'Inline shorthand IF statement requires 1 space after THEN; %s found'; - $data = array($spaceAfter); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterThen', $data); - if ($spaceAfter === 0) { - $phpcsFile->fixer->addContent($stackPtr, ' '); - } else { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); - } - } - - // Make sure the ELSE has the correct spacing. - $inlineElse = $phpcsFile->findNext(T_INLINE_ELSE, ($stackPtr + 1), $statementEnd, false); - $contentBefore = $phpcsFile->findPrevious(T_WHITESPACE, ($inlineElse - 1), null, true); - $spaceBefore = ($tokens[$inlineElse]['column'] - ($tokens[$contentBefore]['column'] + $tokens[$contentBefore]['length'])); - if ($spaceBefore !== 1) { - $error = 'Inline shorthand IF statement requires 1 space before ELSE; %s found'; - $data = array($spaceBefore); - $fix = $phpcsFile->addFixableError($error, $inlineElse, 'SpacingBeforeElse', $data); - if ($fix === true) { - if ($spaceBefore === 0) { - $phpcsFile->fixer->addContentBefore($inlineElse, ' '); - } else { - $phpcsFile->fixer->replaceToken(($inlineElse - 1), ' '); - } - } - } - }//end if - - $contentAfter = $phpcsFile->findNext(T_WHITESPACE, ($inlineElse + 1), null, true); - $spaceAfter = (($tokens[$contentAfter]['column']) - ($tokens[$inlineElse]['column'] + 1)); - if ($spaceAfter !== 1) { - $error = 'Inline shorthand IF statement requires 1 space after ELSE; %s found'; - $data = array($spaceAfter); - $fix = $phpcsFile->addFixableError($error, $inlineElse, 'SpacingAfterElse', $data); - if ($spaceAfter === 0) { - $phpcsFile->fixer->addContent($inlineElse, ' '); - } else { - $phpcsFile->fixer->replaceToken(($inlineElse + 1), ' '); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/LowercaseDeclarationSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/LowercaseDeclarationSniff.php deleted file mode 100644 index 677d776..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/LowercaseDeclarationSniff.php +++ /dev/null @@ -1,88 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_ControlStructures_LowercaseDeclarationSniff. - * - * Ensures all control structure keywords are lowercase. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_ControlStructures_LowercaseDeclarationSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_IF, - T_ELSE, - T_ELSEIF, - T_FOREACH, - T_FOR, - T_DO, - T_SWITCH, - T_WHILE, - T_TRY, - T_CATCH, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $content = $tokens[$stackPtr]['content']; - if ($content !== strtolower($content)) { - $error = '%s keyword must be lowercase; expected "%s" but found "%s"'; - $data = array( - strtoupper($content), - strtolower($content), - $content, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'FoundUppercase', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, strtolower($content)); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php deleted file mode 100644 index acfbdf3..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php +++ /dev/null @@ -1,319 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_ControlStructures_SwitchDeclarationSniff. - * - * Ensures all the breaks and cases are aligned correctly according to their - * parent switch's alignment and enforces other switch formatting. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_ControlStructures_SwitchDeclarationSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - /** - * The number of spaces code should be indented. - * - * @var int - */ - public $indent = 4; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_SWITCH); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // We can't process SWITCH statements unless we know where they start and end. - if (isset($tokens[$stackPtr]['scope_opener']) === false - || isset($tokens[$stackPtr]['scope_closer']) === false - ) { - return; - } - - $switch = $tokens[$stackPtr]; - $nextCase = $stackPtr; - $caseAlignment = ($switch['column'] + $this->indent); - $caseCount = 0; - $foundDefault = false; - - while (($nextCase = $phpcsFile->findNext(array(T_CASE, T_DEFAULT, T_SWITCH), ($nextCase + 1), $switch['scope_closer'])) !== false) { - // Skip nested SWITCH statements; they are handled on their own. - if ($tokens[$nextCase]['code'] === T_SWITCH) { - $nextCase = $tokens[$nextCase]['scope_closer']; - continue; - } - - if ($tokens[$nextCase]['code'] === T_DEFAULT) { - $type = 'Default'; - $foundDefault = true; - } else { - $type = 'Case'; - $caseCount++; - } - - if ($tokens[$nextCase]['content'] !== strtolower($tokens[$nextCase]['content'])) { - $expected = strtolower($tokens[$nextCase]['content']); - $error = strtoupper($type).' keyword must be lowercase; expected "%s" but found "%s"'; - $data = array( - $expected, - $tokens[$nextCase]['content'], - ); - - $fix = $phpcsFile->addFixableError($error, $nextCase, $type.'NotLower', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($nextCase, $expected); - } - } - - if ($tokens[$nextCase]['column'] !== $caseAlignment) { - $error = strtoupper($type).' keyword must be indented '.$this->indent.' spaces from SWITCH keyword'; - $fix = $phpcsFile->addFixableError($error, $nextCase, $type.'Indent'); - - if ($fix === true) { - $padding = str_repeat(' ', ($caseAlignment - 1)); - if ($tokens[$nextCase]['column'] === 1 - || $tokens[($nextCase - 1)]['code'] !== T_WHITESPACE - ) { - $phpcsFile->fixer->addContentBefore($nextCase, $padding); - } else { - $phpcsFile->fixer->replaceToken(($nextCase - 1), $padding); - } - } - } - - if ($type === 'Case' - && ($tokens[($nextCase + 1)]['type'] !== 'T_WHITESPACE' - || $tokens[($nextCase + 1)]['content'] !== ' ') - ) { - $error = 'CASE keyword must be followed by a single space'; - $fix = $phpcsFile->addFixableError($error, $nextCase, 'SpacingAfterCase'); - if ($fix === true) { - if ($tokens[($nextCase + 1)]['type'] !== 'T_WHITESPACE') { - $phpcsFile->fixer->addContent($nextCase, ' '); - } else { - $phpcsFile->fixer->replaceToken(($nextCase + 1), ' '); - } - } - } - - if (isset($tokens[$nextCase]['scope_opener']) === false) { - $error = 'Possible parse error: CASE missing opening colon'; - $phpcsFile->addWarning($error, $nextCase, 'MissingColon'); - continue; - } - - $opener = $tokens[$nextCase]['scope_opener']; - if ($tokens[($opener - 1)]['type'] === 'T_WHITESPACE') { - $error = 'There must be no space before the colon in a '.strtoupper($type).' statement'; - $fix = $phpcsFile->addFixableError($error, $nextCase, 'SpaceBeforeColon'.$type); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($opener - 1), ''); - } - } - - $nextBreak = $tokens[$nextCase]['scope_closer']; - if ($tokens[$nextBreak]['code'] === T_BREAK - || $tokens[$nextBreak]['code'] === T_RETURN - || $tokens[$nextBreak]['code'] === T_CONTINUE - || $tokens[$nextBreak]['code'] === T_THROW - || $tokens[$nextBreak]['code'] === T_EXIT - ) { - if ($tokens[$nextBreak]['scope_condition'] === $nextCase) { - // Only need to check a couple of things once, even if the - // break is shared between multiple case statements, or even - // the default case. - if ($tokens[$nextBreak]['column'] !== $caseAlignment) { - $error = 'Case breaking statement must be indented '.$this->indent.' spaces from SWITCH keyword'; - $fix = $phpcsFile->addFixableError($error, $nextBreak, 'BreakIndent'); - - if ($fix === true) { - $padding = str_repeat(' ', ($caseAlignment - 1)); - if ($tokens[$nextBreak]['column'] === 1 - || $tokens[($nextBreak - 1)]['code'] !== T_WHITESPACE - ) { - $phpcsFile->fixer->addContentBefore($nextBreak, $padding); - } else { - $phpcsFile->fixer->replaceToken(($nextBreak - 1), $padding); - } - } - } - - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($nextBreak - 1), $stackPtr, true); - if ($tokens[$prev]['line'] !== ($tokens[$nextBreak]['line'] - 1)) { - $error = 'Blank lines are not allowed before case breaking statements'; - $phpcsFile->addError($error, $nextBreak, 'SpacingBeforeBreak'); - } - - $nextLine = $tokens[$tokens[$stackPtr]['scope_closer']]['line']; - $semicolon = $phpcsFile->findEndOfStatement($nextBreak); - for ($i = ($semicolon + 1); $i < $tokens[$stackPtr]['scope_closer']; $i++) { - if ($tokens[$i]['type'] !== 'T_WHITESPACE') { - $nextLine = $tokens[$i]['line']; - break; - } - } - - if ($type === 'Case') { - // Ensure the BREAK statement is followed by - // a single blank line, or the end switch brace. - if ($nextLine !== ($tokens[$semicolon]['line'] + 2) && $i !== $tokens[$stackPtr]['scope_closer']) { - $error = 'Case breaking statements must be followed by a single blank line'; - $fix = $phpcsFile->addFixableError($error, $nextBreak, 'SpacingAfterBreak'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($semicolon + 1); $i <= $tokens[$stackPtr]['scope_closer']; $i++) { - if ($tokens[$i]['line'] === $nextLine) { - $phpcsFile->fixer->addNewlineBefore($i); - break; - } - - if ($tokens[$i]['line'] === $tokens[$semicolon]['line']) { - continue; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - }//end if - } else { - // Ensure the BREAK statement is not followed by a blank line. - if ($nextLine !== ($tokens[$semicolon]['line'] + 1)) { - $error = 'Blank lines are not allowed after the DEFAULT case\'s breaking statement'; - $phpcsFile->addError($error, $nextBreak, 'SpacingAfterDefaultBreak'); - } - }//end if - - $caseLine = $tokens[$nextCase]['line']; - $nextLine = $tokens[$nextBreak]['line']; - for ($i = ($opener + 1); $i < $nextBreak; $i++) { - if ($tokens[$i]['type'] !== 'T_WHITESPACE') { - $nextLine = $tokens[$i]['line']; - break; - } - } - - if ($nextLine !== ($caseLine + 1)) { - $error = 'Blank lines are not allowed after '.strtoupper($type).' statements'; - $phpcsFile->addError($error, $nextCase, 'SpacingAfter'.$type); - } - }//end if - - if ($tokens[$nextBreak]['code'] === T_BREAK) { - if ($type === 'Case') { - // Ensure empty CASE statements are not allowed. - // They must have some code content in them. A comment is not enough. - // But count RETURN statements as valid content if they also - // happen to close the CASE statement. - $foundContent = false; - for ($i = ($tokens[$nextCase]['scope_opener'] + 1); $i < $nextBreak; $i++) { - if ($tokens[$i]['code'] === T_CASE) { - $i = $tokens[$i]['scope_opener']; - continue; - } - - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$i]['code']]) === false) { - $foundContent = true; - break; - } - } - - if ($foundContent === false) { - $error = 'Empty CASE statements are not allowed'; - $phpcsFile->addError($error, $nextCase, 'EmptyCase'); - } - } else { - // Ensure empty DEFAULT statements are not allowed. - // They must (at least) have a comment describing why - // the default case is being ignored. - $foundContent = false; - for ($i = ($tokens[$nextCase]['scope_opener'] + 1); $i < $nextBreak; $i++) { - if ($tokens[$i]['type'] !== 'T_WHITESPACE') { - $foundContent = true; - break; - } - } - - if ($foundContent === false) { - $error = 'Comment required for empty DEFAULT case'; - $phpcsFile->addError($error, $nextCase, 'EmptyDefault'); - } - }//end if - }//end if - } else if ($type === 'Default') { - $error = 'DEFAULT case must have a breaking statement'; - $phpcsFile->addError($error, $nextCase, 'DefaultNoBreak'); - }//end if - }//end while - - if ($foundDefault === false) { - $error = 'All SWITCH statements must contain a DEFAULT case'; - $phpcsFile->addError($error, $stackPtr, 'MissingDefault'); - } - - if ($tokens[$switch['scope_closer']]['column'] !== $switch['column']) { - $error = 'Closing brace of SWITCH statement must be aligned with SWITCH keyword'; - $phpcsFile->addError($error, $switch['scope_closer'], 'CloseBraceAlign'); - } - - if ($caseCount === 0) { - $error = 'SWITCH statements must contain at least one CASE statement'; - $phpcsFile->addError($error, $stackPtr, 'MissingCase'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Debug/JSLintSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Debug/JSLintSniff.php deleted file mode 100644 index 4e3e6d1..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Debug/JSLintSniff.php +++ /dev/null @@ -1,97 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Debug_JSLintSniff. - * - * Runs jslint.js on the file. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Debug_JSLintSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('JS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - * @throws PHP_CodeSniffer_Exception If jslint.js could not be run - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $fileName = $phpcsFile->getFilename(); - - $rhinoPath = PHP_CodeSniffer::getConfigData('rhino_path'); - $jslintPath = PHP_CodeSniffer::getConfigData('jslint_path'); - if ($rhinoPath === null || $jslintPath === null) { - return; - } - - $rhinoPath = escapeshellcmd($rhinoPath); - $jslintPath = escapeshellcmd($jslintPath); - - $cmd = "$rhinoPath \"$jslintPath\" ".escapeshellarg($fileName); - $msg = exec($cmd, $output, $retval); - - if (is_array($output) === true) { - foreach ($output as $finding) { - $matches = array(); - $numMatches = preg_match('/Lint at line ([0-9]+).*:(.*)$/', $finding, $matches); - if ($numMatches === 0) { - continue; - } - - $line = (int) $matches[1]; - $message = 'jslint says: '.trim($matches[2]); - $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool'); - } - } - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php deleted file mode 100644 index 7cd9925..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php +++ /dev/null @@ -1,98 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Debug_JavaScriptLintSniff. - * - * Runs JavaScript Lint on the file. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Debug_JavaScriptLintSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('JS'); - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $fileName = $phpcsFile->getFilename(); - - $jslPath = PHP_CodeSniffer::getConfigData('jsl_path'); - if (is_null($jslPath) === true) { - return; - } - - $cmd = '"'.escapeshellcmd($jslPath).'" -nologo -nofilelisting -nocontext -nosummary -output-format __LINE__:__ERROR__ -process '.escapeshellarg($fileName); - $msg = exec($cmd, $output, $retval); - - // Variable $exitCode is the last line of $output if no error occurs, on - // error it is numeric. Try to handle various error conditions and - // provide useful error reporting. - if ($retval === 2 || $retval === 4) { - if (is_array($output) === true) { - $msg = join('\n', $output); - } - - throw new PHP_CodeSniffer_Exception("Failed invoking JavaScript Lint, retval was [$retval], output was [$msg]"); - } - - if (is_array($output) === true) { - foreach ($output as $finding) { - $split = strpos($finding, ':'); - $line = substr($finding, 0, $split); - $message = substr($finding, ($split + 1)); - $phpcsFile->addWarningOnLine(trim($message), $line, 'ExternalTool'); - } - } - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Files/FileExtensionSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Files/FileExtensionSniff.php deleted file mode 100644 index b92d164..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Files/FileExtensionSniff.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Files_FileExtensionSniff. - * - * Tests that classes and interfaces are not declared in .php files - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Files_FileExtensionSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return int - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $fileName = $phpcsFile->getFileName(); - $extension = substr($fileName, strrpos($fileName, '.')); - $nextClass = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE, T_TRAIT), $stackPtr); - - if ($nextClass !== false) { - $phpcsFile->recordMetric($stackPtr, 'File extension for class files', $extension); - if ($extension === '.php') { - $error = '%s found in ".php" file; use ".inc" extension instead'; - $data = array(ucfirst($tokens[$nextClass]['content'])); - $phpcsFile->addError($error, $stackPtr, 'ClassFound', $data); - } - } else { - $phpcsFile->recordMetric($stackPtr, 'File extension for non-class files', $extension); - if ($extension === '.inc') { - $error = 'No interface or class found in ".inc" file; use ".php" extension instead'; - $phpcsFile->addError($error, $stackPtr, 'NoClass'); - } - } - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php deleted file mode 100644 index 6c92379..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php +++ /dev/null @@ -1,365 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Formatting_OperationBracketSniff. - * - * Tests that all arithmetic operations are bracketed. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Formatting_OperatorBracketSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return PHP_CodeSniffer_Tokens::$operators; - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($phpcsFile->tokenizerType === 'JS' && $tokens[$stackPtr]['code'] === T_PLUS) { - // JavaScript uses the plus operator for string concatenation as well - // so we cannot accurately determine if it is a string concat or addition. - // So just ignore it. - return; - } - - // If the & is a reference, then we don't want to check for brackets. - if ($tokens[$stackPtr]['code'] === T_BITWISE_AND && $phpcsFile->isReference($stackPtr) === true) { - return; - } - - // There is one instance where brackets aren't needed, which involves - // the minus sign being used to assign a negative number to a variable. - if ($tokens[$stackPtr]['code'] === T_MINUS) { - // Check to see if we are trying to return -n. - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); - if ($tokens[$prev]['code'] === T_RETURN) { - return; - } - - $number = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($tokens[$number]['code'] === T_LNUMBER || $tokens[$number]['code'] === T_DNUMBER) { - $previous = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if ($previous !== false) { - $isAssignment = in_array($tokens[$previous]['code'], PHP_CodeSniffer_Tokens::$assignmentTokens); - $isEquality = in_array($tokens[$previous]['code'], PHP_CodeSniffer_Tokens::$equalityTokens); - $isComparison = in_array($tokens[$previous]['code'], PHP_CodeSniffer_Tokens::$comparisonTokens); - if ($isAssignment === true || $isEquality === true || $isComparison === true) { - // This is a negative assignment or comparison. - // We need to check that the minus and the number are - // adjacent. - if (($number - $stackPtr) !== 1) { - $error = 'No space allowed between minus sign and number'; - $phpcsFile->addError($error, $stackPtr, 'SpacingAfterMinus'); - } - - return; - } - } - } - }//end if - - $previousToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true, null, true); - if ($previousToken !== false) { - // A list of tokens that indicate that the token is not - // part of an arithmetic operation. - $invalidTokens = array( - T_COMMA, - T_COLON, - T_OPEN_PARENTHESIS, - T_OPEN_SQUARE_BRACKET, - T_OPEN_SHORT_ARRAY, - T_CASE, - ); - - if (in_array($tokens[$previousToken]['code'], $invalidTokens) === true) { - return; - } - } - - // Tokens that are allowed inside a bracketed operation. - $allowed = array( - T_VARIABLE, - T_LNUMBER, - T_DNUMBER, - T_STRING, - T_WHITESPACE, - T_NS_SEPARATOR, - T_THIS, - T_SELF, - T_OBJECT_OPERATOR, - T_DOUBLE_COLON, - T_OPEN_SQUARE_BRACKET, - T_CLOSE_SQUARE_BRACKET, - T_MODULUS, - T_NONE, - ); - - $allowed += PHP_CodeSniffer_Tokens::$operators; - - $lastBracket = false; - if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) { - $parenthesis = array_reverse($tokens[$stackPtr]['nested_parenthesis'], true); - foreach ($parenthesis as $bracket => $endBracket) { - $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($bracket - 1), null, true); - $prevCode = $tokens[$prevToken]['code']; - - if ($prevCode === T_ISSET) { - // This operation is inside an isset() call, but has - // no bracket of it's own. - break; - } - - if ($prevCode === T_STRING || $prevCode === T_SWITCH) { - // We allow simple operations to not be bracketed. - // For example, ceil($one / $two). - for ($prev = ($stackPtr - 1); $prev > $bracket; $prev--) { - if (in_array($tokens[$prev]['code'], $allowed) === true) { - continue; - } - - if ($tokens[$prev]['code'] === T_CLOSE_PARENTHESIS) { - $prev = $tokens[$prev]['parenthesis_opener']; - } else { - break; - } - } - - if ($prev !== $bracket) { - break; - } - - for ($next = ($stackPtr + 1); $next < $endBracket; $next++) { - if (in_array($tokens[$next]['code'], $allowed) === true) { - continue; - } - - if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) { - $next = $tokens[$next]['parenthesis_closer']; - } else { - break; - } - } - - if ($next !== $endBracket) { - break; - } - }//end if - - if (in_array($prevCode, PHP_CodeSniffer_Tokens::$scopeOpeners) === true) { - // This operation is inside a control structure like FOREACH - // or IF, but has no bracket of it's own. - // The only control structure allowed to do this is SWITCH. - if ($prevCode !== T_SWITCH) { - break; - } - } - - if ($prevCode === T_OPEN_PARENTHESIS) { - // These are two open parenthesis in a row. If the current - // one doesn't enclose the operator, go to the previous one. - if ($endBracket < $stackPtr) { - continue; - } - } - - $lastBracket = $bracket; - break; - }//end foreach - }//end if - - if ($lastBracket === false) { - // It is not in a bracketed statement at all. - $this->addMissingBracketsError($phpcsFile, $stackPtr); - return; - } else if ($tokens[$lastBracket]['parenthesis_closer'] < $stackPtr) { - // There are a set of brackets in front of it that don't include it. - $this->addMissingBracketsError($phpcsFile, $stackPtr); - return; - } else { - // We are enclosed in a set of bracket, so the last thing to - // check is that we are not also enclosed in square brackets - // like this: ($array[$index + 1]), which is invalid. - $brackets = array( - T_OPEN_SQUARE_BRACKET, - T_CLOSE_SQUARE_BRACKET, - ); - - $squareBracket = $phpcsFile->findPrevious($brackets, ($stackPtr - 1), $lastBracket); - if ($squareBracket !== false && $tokens[$squareBracket]['code'] === T_OPEN_SQUARE_BRACKET) { - $closeSquareBracket = $phpcsFile->findNext($brackets, ($stackPtr + 1)); - if ($closeSquareBracket !== false && $tokens[$closeSquareBracket]['code'] === T_CLOSE_SQUARE_BRACKET) { - $this->addMissingBracketsError($phpcsFile, $stackPtr); - } - } - - return; - }//end if - - $lastAssignment = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$assignmentTokens, $stackPtr, null, false, null, true); - if ($lastAssignment !== false && $lastAssignment > $lastBracket) { - $this->addMissingBracketsError($phpcsFile, $stackPtr); - } - - }//end process() - - - /** - * Add and fix the missing brackets error. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function addMissingBracketsError(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $error = 'Arithmetic operation must be bracketed'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'MissingBrackets'); - - if ($fix === false) { - return; - } - - $tokens = $phpcsFile->getTokens(); - - $allowed = array( - T_VARIABLE => true, - T_LNUMBER => true, - T_DNUMBER => true, - T_STRING => true, - T_WHITESPACE => true, - T_THIS => true, - T_SELF => true, - T_OBJECT_OPERATOR => true, - T_DOUBLE_COLON => true, - T_MODULUS => true, - T_ISSET => true, - T_ARRAY => true, - T_NONE => true, - ); - - // Find the first token in the expression. - for ($before = ($stackPtr - 1); $before > 0; $before--) { - // Special case for plus operators because we can't tell if they are used - // for addition or string contact. So assume string concat to be safe. - if ($phpcsFile->tokenizerType === 'JS' && $tokens[$before]['code'] === T_PLUS) { - break; - } - - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$before]['code']]) === true - || isset(PHP_CodeSniffer_Tokens::$operators[$tokens[$before]['code']]) === true - || isset(PHP_CodeSniffer_Tokens::$castTokens[$tokens[$before]['code']]) === true - || isset($allowed[$tokens[$before]['code']]) === true - ) { - continue; - } - - if ($tokens[$before]['code'] === T_CLOSE_PARENTHESIS) { - $before = $tokens[$before]['parenthesis_opener']; - continue; - } - - if ($tokens[$before]['code'] === T_CLOSE_SQUARE_BRACKET) { - $before = $tokens[$before]['bracket_opener']; - continue; - } - - break; - }//end for - - $before = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($before + 1), null, true); - - // Find the last token in the expression. - for ($after = ($stackPtr + 1); $after < $phpcsFile->numTokens; $after++) { - // Special case for plus operators because we can't tell if they are used - // for addition or string contact. So assume string concat to be safe. - if ($phpcsFile->tokenizerType === 'JS' && $tokens[$after]['code'] === T_PLUS) { - break; - } - - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$after]['code']]) === true - || isset(PHP_CodeSniffer_Tokens::$operators[$tokens[$after]['code']]) === true - || isset(PHP_CodeSniffer_Tokens::$castTokens[$tokens[$after]['code']]) === true - || isset($allowed[$tokens[$after]['code']]) === true - ) { - continue; - } - - if ($tokens[$after]['code'] === T_OPEN_PARENTHESIS) { - $after = $tokens[$after]['parenthesis_closer']; - continue; - } - - if ($tokens[$after]['code'] === T_OPEN_SQUARE_BRACKET) { - $after = $tokens[$after]['bracket_closer']; - continue; - } - - break; - }//end for - - $after = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($after - 1), null, true); - - // Can only fix this error if both tokens are available for fixing. - // Adding one bracket without the other will create parse errors. - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->replaceToken($before, '('.$tokens[$before]['content']); - $phpcsFile->fixer->replaceToken($after, $tokens[$after]['content'].')'); - $phpcsFile->fixer->endChangeset(); - - }//end addMissingBracketsError() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php deleted file mode 100644 index fcbd996..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php +++ /dev/null @@ -1,417 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Functions_FunctionDeclarationArgumentSpacingSniff. - * - * Checks that arguments in function declarations are spaced correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Functions_FunctionDeclarationArgumentSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * How many spaces should surround the equals signs. - * - * @var int - */ - public $equalsSpacing = 0; - - /** - * How many spaces should follow the opening bracket. - * - * @var int - */ - public $requiredSpacesAfterOpen = 0; - - /** - * How many spaces should precede the closing bracket. - * - * @var int - */ - public $requiredSpacesBeforeClose = 0; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_FUNCTION, - T_CLOSURE, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (isset($tokens[$stackPtr]['parenthesis_opener']) === false - || isset($tokens[$stackPtr]['parenthesis_closer']) === false - || $tokens[$stackPtr]['parenthesis_opener'] === null - || $tokens[$stackPtr]['parenthesis_closer'] === null - ) { - return; - } - - $this->equalsSpacing = (int) $this->equalsSpacing; - $this->requiredSpacesAfterOpen = (int) $this->requiredSpacesAfterOpen; - $this->requiredSpacesBeforeClose = (int) $this->requiredSpacesBeforeClose; - - $openBracket = $tokens[$stackPtr]['parenthesis_opener']; - $this->processBracket($phpcsFile, $openBracket); - - if ($tokens[$stackPtr]['code'] === T_CLOSURE) { - $use = $phpcsFile->findNext(T_USE, ($tokens[$openBracket]['parenthesis_closer'] + 1), $tokens[$stackPtr]['scope_opener']); - if ($use !== false) { - $openBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1), null); - $this->processBracket($phpcsFile, $openBracket); - } - } - - }//end process() - - - /** - * Processes the contents of a single set of brackets. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $openBracket The position of the open bracket - * in the stack passed in $tokens. - * - * @return void - */ - public function processBracket(PHP_CodeSniffer_File $phpcsFile, $openBracket) - { - $tokens = $phpcsFile->getTokens(); - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; - $multiLine = ($tokens[$openBracket]['line'] !== $tokens[$closeBracket]['line']); - - $nextParam = $openBracket; - $params = array(); - while (($nextParam = $phpcsFile->findNext(T_VARIABLE, ($nextParam + 1), $closeBracket)) !== false) { - $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($nextParam + 1), ($closeBracket + 1), true); - if ($nextToken === false) { - break; - } - - $nextCode = $tokens[$nextToken]['code']; - - if ($nextCode === T_EQUAL) { - // Check parameter default spacing. - $spacesBefore = 0; - if (($nextToken - $nextParam) > 1) { - $spacesBefore = strlen($tokens[($nextParam + 1)]['content']); - } - - if ($spacesBefore !== $this->equalsSpacing) { - $error = 'Incorrect spacing between argument "%s" and equals sign; expected '.$this->equalsSpacing.' but found %s'; - $data = array( - $tokens[$nextParam]['content'], - $spacesBefore, - ); - - $fix = $phpcsFile->addFixableError($error, $nextToken, 'SpaceBeforeEquals', $data); - if ($fix === true) { - $padding = str_repeat(' ', $this->equalsSpacing); - if ($spacesBefore === 0) { - $phpcsFile->fixer->addContentBefore($nextToken, $padding); - } else { - $phpcsFile->fixer->replaceToken(($nextToken - 1), $padding); - } - } - }//end if - - $spacesAfter = 0; - if ($tokens[($nextToken + 1)]['code'] === T_WHITESPACE) { - $spacesAfter = strlen($tokens[($nextToken + 1)]['content']); - } - - if ($spacesAfter !== $this->equalsSpacing) { - $error = 'Incorrect spacing between default value and equals sign for argument "%s"; expected '.$this->equalsSpacing.' but found %s'; - $data = array( - $tokens[$nextParam]['content'], - $spacesAfter, - ); - - $fix = $phpcsFile->addFixableError($error, $nextToken, 'SpaceAfterDefault', $data); - if ($fix === true) { - $padding = str_repeat(' ', $this->equalsSpacing); - if ($spacesAfter === 0) { - $phpcsFile->fixer->addContent($nextToken, $padding); - } else { - $phpcsFile->fixer->replaceToken(($nextToken + 1), $padding); - } - } - }//end if - }//end if - - // Find and check the comma (if there is one). - $nextComma = $phpcsFile->findNext(T_COMMA, ($nextParam + 1), $closeBracket); - if ($nextComma !== false) { - // Comma found. - if ($tokens[($nextComma - 1)]['code'] === T_WHITESPACE) { - $error = 'Expected 0 spaces between argument "%s" and comma; %s found'; - $data = array( - $tokens[$nextParam]['content'], - strlen($tokens[($nextComma - 1)]['content']), - ); - - $fix = $phpcsFile->addFixableError($error, $nextToken, 'SpaceBeforeComma', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($nextComma - 1), ''); - } - } - } - - $checkToken = ($nextParam - 1); - $prev = $phpcsFile->findPrevious(T_WHITESPACE, $checkToken, null, true); - if ($tokens[$prev]['code'] === T_ELLIPSIS) { - $checkToken = ($prev - 1); - } - - // Take references into account when expecting the - // location of whitespace. - if ($phpcsFile->isReference($checkToken) === true) { - $whitespace = ($checkToken - 1); - } else { - $whitespace = $checkToken; - } - - if (empty($params) === false) { - // This is not the first argument in the function declaration. - $arg = $tokens[$nextParam]['content']; - - // Before we throw an error, make sure there is no type hint. - $comma = $phpcsFile->findPrevious(T_COMMA, ($nextParam - 1)); - $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($comma + 1), null, true); - if ($phpcsFile->isReference($nextToken) === true) { - $nextToken++; - } - - $gap = 0; - if ($tokens[$whitespace]['code'] === T_WHITESPACE) { - $gap = strlen($tokens[$whitespace]['content']); - } - - if ($nextToken !== $nextParam) { - // There was a type hint, so check the spacing between - // the hint and the variable as well. - $hint = $tokens[$nextToken]['content']; - - if ($gap !== 1) { - $error = 'Expected 1 space between type hint and argument "%s"; %s found'; - $data = array( - $arg, - $gap, - ); - $fix = $phpcsFile->addFixableError($error, $nextToken, 'SpacingAfterHint', $data); - if ($fix === true) { - if ($gap === 0) { - $phpcsFile->fixer->addContent($whitespace, ' '); - } else { - $phpcsFile->fixer->replaceToken($whitespace, ' '); - } - } - } - - if ($multiLine === false) { - if ($tokens[($comma + 1)]['code'] !== T_WHITESPACE) { - $error = 'Expected 1 space between comma and type hint "%s"; 0 found'; - $data = array($hint); - $fix = $phpcsFile->addFixableError($error, $nextToken, 'NoSpaceBeforeHint', $data); - if ($fix === true) { - $phpcsFile->fixer->addContent($comma, ' '); - } - } else { - $gap = strlen($tokens[($comma + 1)]['content']); - if ($gap !== 1) { - $error = 'Expected 1 space between comma and type hint "%s"; %s found'; - $data = array( - $hint, - $gap, - ); - $fix = $phpcsFile->addFixableError($error, $nextToken, 'SpacingBeforeHint', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($comma + 1), ' '); - } - } - }//end if - }//end if - } else { - // No type hint. - if ($gap === 0) { - $error = 'Expected 1 space between comma and argument "%s"; 0 found'; - $data = array($arg); - $fix = $phpcsFile->addFixableError($error, $nextToken, 'NoSpaceBeforeArg', $data); - if ($fix === true) { - $phpcsFile->fixer->addContent($whitespace, ' '); - } - } else if ($gap !== 1) { - // Just make sure this is not actually an indent. - if ($tokens[$whitespace]['line'] === $tokens[($whitespace - 1)]['line']) { - $error = 'Expected 1 space between comma and argument "%s"; %s found'; - $data = array( - $arg, - $gap, - ); - - $fix = $phpcsFile->addFixableError($error, $nextToken, 'SpacingBeforeArg', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($whitespace, ' '); - } - } - }//end if - }//end if - } else { - $gap = 0; - if ($tokens[$whitespace]['code'] === T_WHITESPACE) { - $gap = strlen($tokens[$whitespace]['content']); - } - - $arg = $tokens[$nextParam]['content']; - - // Before we throw an error, make sure there is no type hint. - $bracket = $phpcsFile->findPrevious(T_OPEN_PARENTHESIS, ($nextParam - 1)); - $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($bracket + 1), null, true); - if ($phpcsFile->isReference($nextToken) === true) { - $nextToken++; - } - - if ($tokens[$nextToken]['code'] !== T_ELLIPSIS && $nextToken !== $nextParam) { - // There was a type hint, so check the spacing between - // the hint and the variable as well. - $hint = $tokens[$nextToken]['content']; - - if ($gap !== 1) { - $error = 'Expected 1 space between type hint and argument "%s"; %s found'; - $data = array( - $arg, - $gap, - ); - $fix = $phpcsFile->addFixableError($error, $nextToken, 'SpacingAfterHint', $data); - if ($fix === true) { - if ($gap === 0) { - $phpcsFile->fixer->addContent($nextToken, ' '); - } else { - $phpcsFile->fixer->replaceToken(($nextToken + 1), ' '); - } - } - } - - $spaceAfterOpen = 0; - if ($tokens[($bracket + 1)]['code'] === T_WHITESPACE) { - $spaceAfterOpen = strlen($tokens[($bracket + 1)]['content']); - } - - if ($multiLine === false && $spaceAfterOpen !== $this->requiredSpacesAfterOpen) { - $error = 'Expected %s spaces between opening bracket and type hint "%s"; %s found'; - $data = array( - $this->requiredSpacesAfterOpen, - $hint, - $spaceAfterOpen, - ); - $fix = $phpcsFile->addFixableError($error, $nextToken, 'SpacingAfterOpenHint', $data); - if ($fix === true) { - $padding = str_repeat(' ', $this->requiredSpacesAfterOpen); - if ($spaceAfterOpen === 0) { - $phpcsFile->fixer->addContent($openBracket, $padding); - } else { - $phpcsFile->fixer->replaceToken(($openBracket + 1), $padding); - } - } - } - } else if ($multiLine === false && $gap !== $this->requiredSpacesAfterOpen) { - $error = 'Expected %s spaces between opening bracket and argument "%s"; %s found'; - $data = array( - $this->requiredSpacesAfterOpen, - $arg, - $gap, - ); - $fix = $phpcsFile->addFixableError($error, $nextToken, 'SpacingAfterOpen', $data); - if ($fix === true) { - $padding = str_repeat(' ', $this->requiredSpacesAfterOpen); - if ($gap === 0) { - $phpcsFile->fixer->addContent($openBracket, $padding); - } else { - $phpcsFile->fixer->replaceToken(($openBracket + 1), $padding); - } - } - }//end if - }//end if - - $params[] = $nextParam; - }//end while - - $gap = 0; - if ($tokens[($closeBracket - 1)]['code'] === T_WHITESPACE) { - $gap = strlen($tokens[($closeBracket - 1)]['content']); - } - - if (empty($params) === true) { - // There are no parameters for this function. - if (($closeBracket - $openBracket) !== 1) { - $error = 'Expected 0 spaces between brackets of function declaration; %s found'; - $data = array($gap); - $fix = $phpcsFile->addFixableError($error, $openBracket, 'SpacingBetween', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($openBracket + 1), ''); - } - } - } else if ($multiLine === false && $gap !== $this->requiredSpacesBeforeClose) { - $lastParam = array_pop($params); - $error = 'Expected %s spaces between argument "%s" and closing bracket; %s found'; - $data = array( - $this->requiredSpacesBeforeClose, - $tokens[$lastParam]['content'], - $gap, - ); - $fix = $phpcsFile->addFixableError($error, $closeBracket, 'SpacingBeforeClose', $data); - if ($fix === true) { - $padding = str_repeat(' ', $this->requiredSpacesBeforeClose); - if ($gap === 0) { - $phpcsFile->fixer->addContentBefore($closeBracket, $padding); - } else { - $phpcsFile->fixer->replaceToken(($closeBracket - 1), $padding); - } - } - }//end if - - }//end processBracket() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationSniff.php deleted file mode 100644 index 1270bbc..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationSniff.php +++ /dev/null @@ -1,54 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractPatternSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractPatternSniff not found'); -} - -/** - * Squiz_Sniffs_Functions_FunctionDeclarationSniff. - * - * Checks the function declaration is correct. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Functions_FunctionDeclarationSniff extends PHP_CodeSniffer_Standards_AbstractPatternSniff -{ - - - /** - * Returns an array of patterns to check are correct. - * - * @return array - */ - protected function getPatterns() - { - return array( - 'function abc(...);', - 'function abc(...)', - 'abstract function abc(...);', - ); - - }//end getPatterns() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDuplicateArgumentSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDuplicateArgumentSniff.php deleted file mode 100644 index b25d03f..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDuplicateArgumentSniff.php +++ /dev/null @@ -1,79 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Functions_FunctionDuplicateArgumentSpacingSniff. - * - * Checks that duplicate arguments are not used in function declarations. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Functions_FunctionDuplicateArgumentSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_FUNCTION); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $openBracket = $tokens[$stackPtr]['parenthesis_opener']; - $closeBracket = $tokens[$stackPtr]['parenthesis_closer']; - - $foundVariables = array(); - for ($i = ($openBracket + 1); $i < $closeBracket; $i++) { - if ($tokens[$i]['code'] === T_VARIABLE) { - $variable = $tokens[$i]['content']; - if (in_array($variable, $foundVariables) === true) { - $error = 'Variable "%s" appears more than once in function declaration'; - $data = array($variable); - $phpcsFile->addError($error, $i, 'Found', $data); - } else { - $foundVariables[] = $variable; - } - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/GlobalFunctionSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/GlobalFunctionSniff.php deleted file mode 100644 index 70923bd..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/GlobalFunctionSniff.php +++ /dev/null @@ -1,76 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Functions_GlobalFunctionSniff. - * - * Tests for functions outside of classes. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Functions_GlobalFunctionSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_FUNCTION); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (empty($tokens[$stackPtr]['conditions']) === true) { - $functionName = $phpcsFile->getDeclarationName($stackPtr); - if ($functionName === null) { - return; - } - - // Special exception for __autoload as it needs to be global. - if ($functionName !== '__autoload') { - $error = 'Consider putting global function "%s" in a static class'; - $data = array($functionName); - $phpcsFile->addWarning($error, $stackPtr, 'Found', $data); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/LowercaseFunctionKeywordsSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/LowercaseFunctionKeywordsSniff.php deleted file mode 100644 index 809888c..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/LowercaseFunctionKeywordsSniff.php +++ /dev/null @@ -1,79 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Functions_LowercaseFunctionKeywordsSniff. - * - * Ensures all function keywords are lowercase. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Functions_LowercaseFunctionKeywordsSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_FUNCTION, - T_PUBLIC, - T_PRIVATE, - T_PROTECTED, - T_STATIC, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $content = $tokens[$stackPtr]['content']; - if ($content !== strtolower($content)) { - $error = '%s keyword must be lowercase; expected "%s" but found "%s"'; - $data = array( - strtoupper($content), - strtolower($content), - $content, - ); - $phpcsFile->addError($error, $stackPtr, 'FoundUppercase', $data); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php deleted file mode 100644 index 749a1d9..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php +++ /dev/null @@ -1,220 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PEAR_Sniffs_Functions_FunctionDeclarationSniff', true) === false) { - $error = 'Class PEAR_Sniffs_Functions_FunctionDeclarationSniff not found'; - throw new PHP_CodeSniffer_Exception($error); -} - -/** - * Squiz_Sniffs_Functions_MultiLineFunctionDeclarationSniff. - * - * Ensure single and multi-line function declarations are defined correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Functions_MultiLineFunctionDeclarationSniff extends PEAR_Sniffs_Functions_FunctionDeclarationSniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Determine if this is a multi-line function declaration. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $openBracket The position of the opening bracket - * in the stack passed in $tokens. - * @param array $tokens The stack of tokens that make up - * the file. - * - * @return void - */ - public function isMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens) - { - $bracketsToCheck = array($stackPtr => $openBracket); - - // Closures may use the USE keyword and so be multi-line in this way. - if ($tokens[$stackPtr]['code'] === T_CLOSURE) { - $use = $phpcsFile->findNext(T_USE, ($tokens[$openBracket]['parenthesis_closer'] + 1), $tokens[$stackPtr]['scope_opener']); - if ($use !== false) { - $open = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1)); - if ($open !== false) { - $bracketsToCheck[$use] = $open; - } - } - } - - foreach ($bracketsToCheck as $stackPtr => $openBracket) { - // If the first argument is on a new line, this is a multi-line - // function declaration, even if there is only one argument. - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($openBracket + 1), null, true); - if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) { - return true; - } - - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; - - $end = $phpcsFile->findEndOfStatement($openBracket + 1); - while ($tokens[$end]['code'] === T_COMMA) { - // If the next bit of code is not on the same line, this is a - // multi-line function declaration. - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($end + 1), $closeBracket, true); - if ($next === false) { - continue(2); - } - - if ($tokens[$next]['line'] !== $tokens[$end]['line']) { - return true; - } - - $end = $phpcsFile->findEndOfStatement($next); - } - - // We've reached the last argument, so see if the next content - // (should be the close bracket) is also on the same line. - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($end + 1), $closeBracket, true); - if ($next !== false && $tokens[$next]['line'] !== $tokens[$end]['line']) { - return true; - } - }//end foreach - - return false; - - }//end isMultiLineDeclaration() - - - /** - * Processes multi-line declarations. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param array $tokens The stack of tokens that make up - * the file. - * - * @return void - */ - public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens) - { - // We do everything the parent sniff does, and a bit more. - parent::processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens); - - $openBracket = $tokens[$stackPtr]['parenthesis_opener']; - $this->processBracket($phpcsFile, $openBracket, $tokens, 'function'); - - if ($tokens[$stackPtr]['code'] !== T_CLOSURE) { - return; - } - - $use = $phpcsFile->findNext(T_USE, ($tokens[$stackPtr]['parenthesis_closer'] + 1), $tokens[$stackPtr]['scope_opener']); - if ($use === false) { - return; - } - - $openBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1), null); - $this->processBracket($phpcsFile, $openBracket, $tokens, 'use'); - - // Also check spacing. - if ($tokens[($use - 1)]['code'] === T_WHITESPACE) { - $gap = strlen($tokens[($use - 1)]['content']); - } else { - $gap = 0; - } - - }//end processMultiLineDeclaration() - - - /** - * Processes the contents of a single set of brackets. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $openBracket The position of the open bracket - * in the stack passed in $tokens. - * @param array $tokens The stack of tokens that make up - * the file. - * @param string $type The type of the token the brackets - * belong to (function or use). - * - * @return void - */ - public function processBracket(PHP_CodeSniffer_File $phpcsFile, $openBracket, $tokens, $type='function') - { - $errorPrefix = ''; - if ($type === 'use') { - $errorPrefix = 'Use'; - } - - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; - - // The open bracket should be the last thing on the line. - if ($tokens[$openBracket]['line'] !== $tokens[$closeBracket]['line']) { - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($openBracket + 1), null, true); - if ($tokens[$next]['line'] !== ($tokens[$openBracket]['line'] + 1)) { - $error = 'The first parameter of a multi-line '.$type.' declaration must be on the line after the opening bracket'; - $fix = $phpcsFile->addFixableError($error, $next, $errorPrefix.'FirstParamSpacing'); - if ($fix === true) { - $phpcsFile->fixer->addNewline($openBracket); - } - } - } - - // Each line between the brackets should contain a single parameter. - $lastComma = null; - for ($i = ($openBracket + 1); $i < $closeBracket; $i++) { - // Skip brackets, like arrays, as they can contain commas. - if (isset($tokens[$i]['bracket_opener']) === true) { - $i = $tokens[$i]['bracket_closer']; - continue; - } - - if (isset($tokens[$i]['parenthesis_opener']) === true) { - $i = $tokens[$i]['parenthesis_closer']; - continue; - } - - if ($tokens[$i]['code'] !== T_COMMA) { - continue; - } - - $next = $phpcsFile->findNext(T_WHITESPACE, ($i + 1), null, true); - if ($tokens[$next]['line'] === $tokens[$i]['line']) { - $error = 'Multi-line '.$type.' declarations must define one parameter per line'; - $fix = $phpcsFile->addFixableError($error, $next, $errorPrefix.'OneParamPerLine'); - if ($fix === true) { - $phpcsFile->fixer->addNewline($i); - } - } - }//end for - - }//end processBracket() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidFunctionNameSniff.php deleted file mode 100644 index 9aaef8b..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff not found'); -} - -/** - * Squiz_Sniffs_NamingConventions_ValidFunctionNameSniff. - * - * Ensures method names are correct depending on whether they are public - * or private, and that functions are named correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_NamingConventions_ValidFunctionNameSniff extends PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff -{ - - - /** - * Processes the tokens outside the scope. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being processed. - * @param int $stackPtr The position where this token was - * found. - * - * @return void - */ - protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $functionName = $phpcsFile->getDeclarationName($stackPtr); - if ($functionName === null) { - return; - } - - $errorData = array($functionName); - - // Does this function claim to be magical? - if (preg_match('|^__[^_]|', $functionName) !== 0) { - $error = 'Function name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore'; - $phpcsFile->addError($error, $stackPtr, 'DoubleUnderscore', $errorData); - return; - } - - if (PHP_CodeSniffer::isCamelCaps($functionName, false, true, false) === false) { - $error = 'Function name "%s" is not in camel caps format'; - $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData); - } - - }//end processTokenOutsideScope() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php deleted file mode 100644 index aa31ce3..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ /dev/null @@ -1,234 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found'); -} - -/** - * Squiz_Sniffs_NamingConventions_ValidVariableNameSniff. - * - * Checks the naming of variables and member variables. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_NamingConventions_ValidVariableNameSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff -{ - - /** - * Tokens to ignore so that we can find a DOUBLE_COLON. - * - * @var array - */ - private $_ignore = array( - T_WHITESPACE, - T_COMMENT, - ); - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $varName = ltrim($tokens[$stackPtr]['content'], '$'); - - $phpReservedVars = array( - '_SERVER', - '_GET', - '_POST', - '_REQUEST', - '_SESSION', - '_ENV', - '_COOKIE', - '_FILES', - 'GLOBALS', - 'http_response_header', - 'HTTP_RAW_POST_DATA', - 'php_errormsg', - ); - - // If it's a php reserved var, then its ok. - if (in_array($varName, $phpReservedVars) === true) { - return; - } - - $objOperator = $phpcsFile->findNext(array(T_WHITESPACE), ($stackPtr + 1), null, true); - if ($tokens[$objOperator]['code'] === T_OBJECT_OPERATOR) { - // Check to see if we are using a variable from an object. - $var = $phpcsFile->findNext(array(T_WHITESPACE), ($objOperator + 1), null, true); - if ($tokens[$var]['code'] === T_STRING) { - $bracket = $phpcsFile->findNext(array(T_WHITESPACE), ($var + 1), null, true); - if ($tokens[$bracket]['code'] !== T_OPEN_PARENTHESIS) { - $objVarName = $tokens[$var]['content']; - - // There is no way for us to know if the var is public or - // private, so we have to ignore a leading underscore if there is - // one and just check the main part of the variable name. - $originalVarName = $objVarName; - if (substr($objVarName, 0, 1) === '_') { - $objVarName = substr($objVarName, 1); - } - - if (PHP_CodeSniffer::isCamelCaps($objVarName, false, true, false) === false) { - $error = 'Variable "%s" is not in valid camel caps format'; - $data = array($originalVarName); - $phpcsFile->addError($error, $var, 'NotCamelCaps', $data); - } - }//end if - }//end if - }//end if - - // There is no way for us to know if the var is public or private, - // so we have to ignore a leading underscore if there is one and just - // check the main part of the variable name. - $originalVarName = $varName; - if (substr($varName, 0, 1) === '_') { - $objOperator = $phpcsFile->findPrevious(array(T_WHITESPACE), ($stackPtr - 1), null, true); - if ($tokens[$objOperator]['code'] === T_DOUBLE_COLON) { - // The variable lives within a class, and is referenced like - // this: MyClass::$_variable, so we don't know its scope. - $inClass = true; - } else { - $inClass = $phpcsFile->hasCondition($stackPtr, array(T_CLASS, T_INTERFACE, T_TRAIT)); - } - - if ($inClass === true) { - $varName = substr($varName, 1); - } - } - - if (PHP_CodeSniffer::isCamelCaps($varName, false, true, false) === false) { - $error = 'Variable "%s" is not in valid camel caps format'; - $data = array($originalVarName); - $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $data); - } - - }//end processVariable() - - - /** - * Processes class member variables. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $varName = ltrim($tokens[$stackPtr]['content'], '$'); - $memberProps = $phpcsFile->getMemberProperties($stackPtr); - if (empty($memberProps) === true) { - // Couldn't get any info about this variable, which - // generally means it is invalid or possibly has a parse - // error. Any errors will be reported by the core, so - // we can ignore it. - return; - } - - $public = ($memberProps['scope'] !== 'private'); - $errorData = array($varName); - - if ($public === true) { - if (substr($varName, 0, 1) === '_') { - $error = '%s member variable "%s" must not contain a leading underscore'; - $data = array( - ucfirst($memberProps['scope']), - $errorData[0], - ); - $phpcsFile->addError($error, $stackPtr, 'PublicHasUnderscore', $data); - return; - } - } else { - if (substr($varName, 0, 1) !== '_') { - $error = 'Private member variable "%s" must contain a leading underscore'; - $phpcsFile->addError($error, $stackPtr, 'PrivateNoUnderscore', $errorData); - return; - } - } - - if (PHP_CodeSniffer::isCamelCaps($varName, false, $public, false) === false) { - $error = 'Member variable "%s" is not in valid camel caps format'; - $phpcsFile->addError($error, $stackPtr, 'MemberNotCamelCaps', $errorData); - } - - }//end processMemberVar() - - - /** - * Processes the variable found within a double quoted string. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the double quoted - * string. - * - * @return void - */ - protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $phpReservedVars = array( - '_SERVER', - '_GET', - '_POST', - '_REQUEST', - '_SESSION', - '_ENV', - '_COOKIE', - '_FILES', - 'GLOBALS', - 'http_response_header', - 'HTTP_RAW_POST_DATA', - 'php_errormsg', - ); - - if (preg_match_all('|[^\\\]\${?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)|', $tokens[$stackPtr]['content'], $matches) !== 0) { - foreach ($matches[1] as $varName) { - // If it's a php reserved var, then its ok. - if (in_array($varName, $phpReservedVars) === true) { - continue; - } - - if (PHP_CodeSniffer::isCamelCaps($varName, false, true, false) === false) { - $error = 'Variable "%s" is not in valid camel caps format'; - $data = array($varName); - $phpcsFile->addError($error, $stackPtr, 'StringNotCamelCaps', $data); - } - } - } - - }//end processVariableInString() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Objects/DisallowObjectStringIndexSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Objects/DisallowObjectStringIndexSniff.php deleted file mode 100644 index 78ffc94..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Objects/DisallowObjectStringIndexSniff.php +++ /dev/null @@ -1,96 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Ensures that object indexes are written in dot notation. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Sertan Danis - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Objects_DisallowObjectStringIndexSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('JS'); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_SQUARE_BRACKET); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Check if the next non whitespace token is a string. - $index = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($tokens[$index]['code'] !== T_CONSTANT_ENCAPSED_STRING) { - return; - } - - // Make sure it is the only thing in the square brackets. - $next = $phpcsFile->findNext(T_WHITESPACE, ($index + 1), null, true); - if ($tokens[$next]['code'] !== T_CLOSE_SQUARE_BRACKET) { - return; - } - - // Allow indexes that have dots in them because we can't write - // them in dot notation. - $content = trim($tokens[$index]['content'], '"\' '); - if (strpos($content, '.') !== false) { - return; - } - - // Also ignore reserved words. - if ($content === 'super') { - return; - } - - // Token before the opening square bracket cannot be a var name. - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if ($tokens[$prev]['code'] === T_STRING) { - $error = 'Object indexes must be written in dot notation'; - $phpcsFile->addError($error, $prev, 'Found'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Objects/ObjectInstantiationSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Objects/ObjectInstantiationSniff.php deleted file mode 100644 index 0298a65..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Objects/ObjectInstantiationSniff.php +++ /dev/null @@ -1,81 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Objects_ObjectInstantiationSniff. - * - * Ensures objects are assigned to a variable when instantiated. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Objects_ObjectInstantiationSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Registers the token types that this sniff wishes to listen to. - * - * @return array - */ - public function register() - { - return array(T_NEW); - - }//end register() - - - /** - * Process the tokens that this sniff is listening for. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $allowedTokens = PHP_CodeSniffer_Tokens::$emptyTokens; - $allowedTokens[] = T_BITWISE_AND; - - $prev = $phpcsFile->findPrevious($allowedTokens, ($stackPtr - 1), null, true); - - $allowedTokens = array( - T_EQUAL => true, - T_DOUBLE_ARROW => true, - T_THROW => true, - T_RETURN => true, - T_INLINE_THEN => true, - T_INLINE_ELSE => true, - ); - - if (isset($allowedTokens[$tokens[$prev]['code']]) === false) { - $error = 'New objects must be assigned to a variable'; - $phpcsFile->addError($error, $stackPtr, 'NotAssigned'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Objects/ObjectMemberCommaSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Objects/ObjectMemberCommaSniff.php deleted file mode 100644 index 55f88de..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Objects/ObjectMemberCommaSniff.php +++ /dev/null @@ -1,76 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Objects_ObjectMemberCommaSniff. - * - * Ensures the last member of an object is not followed by a comma. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Objects_ObjectMemberCommaSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('JS'); - - - /** - * Registers the token types that this sniff wishes to listen to. - * - * @return array - */ - public function register() - { - return array(T_CLOSE_OBJECT); - - }//end register() - - - /** - * Process the tokens that this sniff is listening for. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); - if ($tokens[$prev]['code'] === T_COMMA) { - $error = 'Last member of object must not be followed by a comma'; - $fix = $phpcsFile->addFixableError($error, $prev, 'Missing'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($prev, ''); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Operators/ComparisonOperatorUsageSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Operators/ComparisonOperatorUsageSniff.php deleted file mode 100644 index bd96948..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Operators/ComparisonOperatorUsageSniff.php +++ /dev/null @@ -1,244 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * A Sniff to enforce the use of IDENTICAL type operators rather than EQUAL operators. - * - * The use of === true is enforced over implicit true statements, - * for example: - * - * - * if ($a) - * { - * ... - * } - * - * - * should be: - * - * - * if ($a === true) - * { - * ... - * } - * - * - * It also enforces the use of === false over ! operators. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Operators_ComparisonOperatorUsageSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - /** - * A list of valid comparison operators. - * - * @var array - */ - private static $_validOps = array( - T_IS_IDENTICAL, - T_IS_NOT_IDENTICAL, - T_LESS_THAN, - T_GREATER_THAN, - T_IS_GREATER_OR_EQUAL, - T_IS_SMALLER_OR_EQUAL, - T_INSTANCEOF, - ); - - /** - * A list of invalid operators with their alternatives. - * - * @var array(int => string) - */ - private static $_invalidOps = array( - 'PHP' => array( - T_IS_EQUAL => '===', - T_IS_NOT_EQUAL => '!==', - T_BOOLEAN_NOT => '=== FALSE', - ), - 'JS' => array( - T_IS_EQUAL => '===', - T_IS_NOT_EQUAL => '!==', - ), - ); - - - /** - * Registers the token types that this sniff wishes to listen to. - * - * @return array - */ - public function register() - { - return array( - T_IF, - T_ELSEIF, - T_INLINE_THEN, - T_WHILE, - T_FOR, - ); - - }//end register() - - - /** - * Process the tokens that this sniff is listening for. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where the token - * was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $tokenizer = $phpcsFile->tokenizerType; - - if ($tokens[$stackPtr]['code'] === T_INLINE_THEN) { - $end = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); - if ($tokens[$end]['code'] !== T_CLOSE_PARENTHESIS) { - // This inline IF statement does not have its condition - // bracketed, so we need to guess where it starts. - for ($i = ($end - 1); $i >= 0; $i--) { - if ($tokens[$i]['code'] === T_SEMICOLON) { - // Stop here as we assume it is the end - // of the previous statement. - break; - } else if ($tokens[$i]['code'] === T_OPEN_TAG) { - // Stop here as this is the start of the file. - break; - } else if ($tokens[$i]['code'] === T_CLOSE_CURLY_BRACKET) { - // Stop if this is the closing brace of - // a code block. - if (isset($tokens[$i]['scope_opener']) === true) { - break; - } - } else if ($tokens[$i]['code'] === T_OPEN_CURLY_BRACKET) { - // Stop if this is the opening brace of - // a code block. - if (isset($tokens[$i]['scope_closer']) === true) { - break; - } - } - }//end for - - $start = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($i + 1), null, true); - } else { - if (isset($tokens[$end]['parenthesis_opener']) === false) { - return; - } - - $start = $tokens[$end]['parenthesis_opener']; - }//end if - } else if ($tokens[$stackPtr]['code'] === T_FOR) { - if (isset($tokens[$stackPtr]['parenthesis_opener']) === false) { - return; - } - - $openingBracket = $tokens[$stackPtr]['parenthesis_opener']; - $closingBracket = $tokens[$stackPtr]['parenthesis_closer']; - - $start = $phpcsFile->findNext(T_SEMICOLON, $openingBracket, $closingBracket); - $end = $phpcsFile->findNext(T_SEMICOLON, ($start + 1), $closingBracket); - if ($start === false || $end === false) { - return; - } - } else { - if (isset($tokens[$stackPtr]['parenthesis_opener']) === false) { - return; - } - - $start = $tokens[$stackPtr]['parenthesis_opener']; - $end = $tokens[$stackPtr]['parenthesis_closer']; - }//end if - - $requiredOps = 0; - $foundOps = 0; - $foundBools = 0; - - for ($i = $start; $i <= $end; $i++) { - $type = $tokens[$i]['code']; - if (in_array($type, array_keys(self::$_invalidOps[$tokenizer])) === true) { - $error = 'Operator %s prohibited; use %s instead'; - $data = array( - $tokens[$i]['content'], - self::$_invalidOps[$tokenizer][$type], - ); - $phpcsFile->addError($error, $i, 'NotAllowed', $data); - $foundOps++; - } else if (in_array($type, self::$_validOps) === true) { - $foundOps++; - } - - if ($tokens[$i]['code'] === T_TRUE || $tokens[$i]['code'] === T_FALSE) { - $foundBools++; - } - - if ($phpcsFile->tokenizerType !== 'JS' - && ($tokens[$i]['code'] === T_BOOLEAN_AND - || $tokens[$i]['code'] === T_BOOLEAN_OR) - ) { - $requiredOps++; - - // When the instanceof operator is used with another operator - // like ===, you can get more ops than are required. - if ($foundOps > $requiredOps) { - $foundOps = $requiredOps; - } - - // If we get to here and we have not found the right number of - // comparison operators, then we must have had an implicit - // true operation i.e., if ($a) instead of the required - // if ($a === true), so let's add an error. - if ($requiredOps !== $foundOps) { - $error = 'Implicit true comparisons prohibited; use === TRUE instead'; - $phpcsFile->addError($error, $stackPtr, 'ImplicitTrue'); - $foundOps++; - } - } - }//end for - - $requiredOps++; - - if ($phpcsFile->tokenizerType !== 'JS' - && $foundOps < $requiredOps - && ($requiredOps !== $foundBools) - ) { - $error = 'Implicit true comparisons prohibited; use === TRUE instead'; - $phpcsFile->addError($error, $stackPtr, 'ImplicitTrue'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Operators/IncrementDecrementUsageSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Operators/IncrementDecrementUsageSniff.php deleted file mode 100644 index 761444c..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Operators/IncrementDecrementUsageSniff.php +++ /dev/null @@ -1,239 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Operators_IncrementDecrementUsageSniff. - * - * Tests that the ++ operators are used when possible and not - * used when it makes the code confusing. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Operators_IncrementDecrementUsageSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_EQUAL, - T_PLUS_EQUAL, - T_MINUS_EQUAL, - T_INC, - T_DEC, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[$stackPtr]['code'] === T_INC || $tokens[$stackPtr]['code'] === T_DEC) { - $this->processIncDec($phpcsFile, $stackPtr); - } else { - $this->processAssignment($phpcsFile, $stackPtr); - } - - }//end process() - - - /** - * Checks to ensure increment and decrement operators are not confusing. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - protected function processIncDec(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Work out where the variable is so we know where to - // start looking for other operators. - if ($tokens[($stackPtr - 1)]['code'] === T_VARIABLE - || ($tokens[($stackPtr - 1)]['code'] === T_STRING - && $tokens[($stackPtr - 2)]['code'] === T_OBJECT_OPERATOR) - ) { - $start = ($stackPtr + 1); - } else { - $start = ($stackPtr + 2); - } - - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $start, null, true); - if ($next === false) { - return; - } - - if (isset(PHP_CodeSniffer_Tokens::$arithmeticTokens[$tokens[$next]['code']]) === true) { - $error = 'Increment and decrement operators cannot be used in an arithmetic operation'; - $phpcsFile->addError($error, $stackPtr, 'NotAllowed'); - return; - } - - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($start - 3), null, true); - if ($prev === false) { - return; - } - - // Check if this is in a string concat. - if ($tokens[$next]['code'] === T_STRING_CONCAT || $tokens[$prev]['code'] === T_STRING_CONCAT) { - $error = 'Increment and decrement operators must be bracketed when used in string concatenation'; - $phpcsFile->addError($error, $stackPtr, 'NoBrackets'); - } - - }//end processIncDec() - - - /** - * Checks to ensure increment and decrement operators are used. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - protected function processAssignment(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $assignedVar = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - // Not an assignment, return. - if ($tokens[$assignedVar]['code'] !== T_VARIABLE) { - return; - } - - $statementEnd = $phpcsFile->findNext(array(T_SEMICOLON, T_CLOSE_PARENTHESIS, T_CLOSE_SQUARE_BRACKET, T_CLOSE_CURLY_BRACKET), $stackPtr); - - // If there is anything other than variables, numbers, spaces or operators we need to return. - $noiseTokens = $phpcsFile->findNext(array(T_LNUMBER, T_VARIABLE, T_WHITESPACE, T_PLUS, T_MINUS, T_OPEN_PARENTHESIS), ($stackPtr + 1), $statementEnd, true); - - if ($noiseTokens !== false) { - return; - } - - // If we are already using += or -=, we need to ignore - // the statement if a variable is being used. - if ($tokens[$stackPtr]['code'] !== T_EQUAL) { - $nextVar = $phpcsFile->findNext(T_VARIABLE, ($stackPtr + 1), $statementEnd); - if ($nextVar !== false) { - return; - } - } - - if ($tokens[$stackPtr]['code'] === T_EQUAL) { - $nextVar = ($stackPtr + 1); - $previousVariable = ($stackPtr + 1); - $variableCount = 0; - while (($nextVar = $phpcsFile->findNext(T_VARIABLE, ($nextVar + 1), $statementEnd)) !== false) { - $previousVariable = $nextVar; - $variableCount++; - } - - if ($variableCount !== 1) { - return; - } - - $nextVar = $previousVariable; - if ($tokens[$nextVar]['content'] !== $tokens[$assignedVar]['content']) { - return; - } - } - - // We have only one variable, and it's the same as what is being assigned, - // so we need to check what is being added or subtracted. - $nextNumber = ($stackPtr + 1); - $previousNumber = ($stackPtr + 1); - $numberCount = 0; - while (($nextNumber = $phpcsFile->findNext(array(T_LNUMBER), ($nextNumber + 1), $statementEnd, false)) !== false) { - $previousNumber = $nextNumber; - $numberCount++; - } - - if ($numberCount !== 1) { - return; - } - - $nextNumber = $previousNumber; - if ($tokens[$nextNumber]['content'] === '1') { - if ($tokens[$stackPtr]['code'] === T_EQUAL) { - $opToken = $phpcsFile->findNext(array(T_PLUS, T_MINUS), ($nextVar + 1), $statementEnd); - if ($opToken === false) { - // Operator was before the variable, like: - // $var = 1 + $var; - // So we ignore it. - return; - } - - $operator = $tokens[$opToken]['content']; - } else { - $operator = substr($tokens[$stackPtr]['content'], 0, 1); - } - - // If we are adding or subtracting negative value, the operator - // needs to be reversed. - if ($tokens[$stackPtr]['code'] !== T_EQUAL) { - $negative = $phpcsFile->findPrevious(T_MINUS, ($nextNumber - 1), $stackPtr); - if ($negative !== false) { - if ($operator === '+') { - $operator = '-'; - } else { - $operator = '+'; - } - } - } - - $expected = $tokens[$assignedVar]['content'].$operator.$operator; - $found = $phpcsFile->getTokensAsString($assignedVar, ($statementEnd - $assignedVar + 1)); - - if ($operator === '+') { - $error = 'Increment'; - } else { - $error = 'Decrement'; - } - - $error .= " operators should be used where possible; found \"$found\" but expected \"$expected\""; - $phpcsFile->addError($error, $stackPtr); - }//end if - - }//end processAssignment() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Operators/ValidLogicalOperatorsSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Operators/ValidLogicalOperatorsSniff.php deleted file mode 100644 index 5e2ccbf..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Operators/ValidLogicalOperatorsSniff.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Operators_ValidLogicalOperatorsSniff. - * - * Checks to ensure that the logical operators 'and' and 'or' are not used. - * Use the && and || operators instead. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Operators_ValidLogicalOperatorsSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_LOGICAL_AND, - T_LOGICAL_OR, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The current file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $replacements = array( - 'and' => '&&', - 'or' => '||', - ); - - $operator = strtolower($tokens[$stackPtr]['content']); - if (isset($replacements[$operator]) === false) { - return; - } - - $error = 'Logical operator "%s" is prohibited; use "%s" instead'; - $data = array( - $operator, - $replacements[$operator], - ); - $phpcsFile->addError($error, $stackPtr, 'NotAllowed', $data); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/CommentedOutCodeSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/CommentedOutCodeSniff.php deleted file mode 100644 index bfc5841..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/CommentedOutCodeSniff.php +++ /dev/null @@ -1,237 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_PHP_CommentedOutCodeSniff. - * - * Warn about commented out code. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_PHP_CommentedOutCodeSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'CSS', - ); - - /** - * If a comment is more than $maxPercentage% code, a warning will be shown. - * - * @var int - */ - public $maxPercentage = 35; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_COMMENT); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Process whole comment blocks at once, so skip all but the first token. - if ($stackPtr > 0 && $tokens[$stackPtr]['code'] === $tokens[($stackPtr - 1)]['code']) { - return; - } - - // Ignore comments at the end of code blocks. - if (substr($tokens[$stackPtr]['content'], 0, 6) === '//end ') { - return; - } - - $content = ''; - if ($phpcsFile->tokenizerType === 'PHP') { - $content = 'numTokens; $i++) { - if ($tokens[$stackPtr]['code'] !== $tokens[$i]['code']) { - break; - } - - /* - Trim as much off the comment as possible so we don't - have additional whitespace tokens or comment tokens - */ - - $tokenContent = trim($tokens[$i]['content']); - - if (substr($tokenContent, 0, 2) === '//') { - $tokenContent = substr($tokenContent, 2); - } - - if (substr($tokenContent, 0, 1) === '#') { - $tokenContent = substr($tokenContent, 1); - } - - if (substr($tokenContent, 0, 3) === '/**') { - $tokenContent = substr($tokenContent, 3); - } - - if (substr($tokenContent, 0, 2) === '/*') { - $tokenContent = substr($tokenContent, 2); - } - - if (substr($tokenContent, -2) === '*/') { - $tokenContent = substr($tokenContent, 0, -2); - } - - if (substr($tokenContent, 0, 1) === '*') { - $tokenContent = substr($tokenContent, 1); - } - - $content .= $tokenContent.$phpcsFile->eolChar; - }//end for - - $content = trim($content); - - if ($phpcsFile->tokenizerType === 'PHP') { - $content .= ' ?>'; - } - - // Quite a few comments use multiple dashes, equals signs etc - // to frame comments and licence headers. - $content = preg_replace('/[-=*]+/', '-', $content); - - // Because we are not really parsing code, the tokenizer can throw all sorts - // of errors that don't mean anything, so ignore them. - $oldErrors = ini_get('error_reporting'); - ini_set('error_reporting', 0); - try { - $stringTokens = PHP_CodeSniffer_File::tokenizeString($content, $phpcsFile->tokenizer, $phpcsFile->eolChar); - } catch (PHP_CodeSniffer_Exception $e) { - // We couldn't check the comment, so ignore it. - ini_set('error_reporting', $oldErrors); - return; - } - - ini_set('error_reporting', $oldErrors); - - $emptyTokens = array( - T_WHITESPACE => true, - T_STRING => true, - T_STRING_CONCAT => true, - T_ENCAPSED_AND_WHITESPACE => true, - T_NONE => true, - T_COMMENT => true, - ); - - $numTokens = count($stringTokens); - - /* - We know what the first two and last two tokens should be - (because we put them there) so ignore this comment if those - tokens were not parsed correctly. It obviously means this is not - valid code. - */ - - // First token is always the opening PHP tag. - if ($stringTokens[0]['code'] !== T_OPEN_TAG) { - return; - } - - // Last token is always the closing PHP tag, unless something went wrong. - if (isset($stringTokens[($numTokens - 1)]) === false - || $stringTokens[($numTokens - 1)]['code'] !== T_CLOSE_TAG - ) { - return; - } - - // Second last token is always whitespace or a comment, depending - // on the code inside the comment. - if ($phpcsFile->tokenizerType === 'PHP' - && isset(PHP_CodeSniffer_Tokens::$emptyTokens[$stringTokens[($numTokens - 2)]['code']]) === false - ) { - return; - } - - $numComment = 0; - $numPossible = 0; - $numCode = 0; - - for ($i = 0; $i < $numTokens; $i++) { - if (isset($emptyTokens[$stringTokens[$i]['code']]) === true) { - // Looks like comment. - $numComment++; - } else if (in_array($stringTokens[$i]['code'], PHP_CodeSniffer_Tokens::$comparisonTokens) === true - || in_array($stringTokens[$i]['code'], PHP_CodeSniffer_Tokens::$arithmeticTokens) === true - || $stringTokens[$i]['code'] === T_GOTO_LABEL - ) { - // Commented out HTML/XML and other docs contain a lot of these - // characters, so it is best to not use them directly. - $numPossible++; - } else { - // Looks like code. - $numCode++; - } - } - - // We subtract 3 from the token number so we ignore the start/end tokens - // and their surrounding whitespace. We take 2 off the number of code - // tokens so we ignore the start/end tokens. - if ($numTokens > 3) { - $numTokens -= 3; - } - - if ($numCode >= 2) { - $numCode -= 2; - } - - $percentCode = ceil((($numCode / $numTokens) * 100)); - if ($percentCode > $this->maxPercentage) { - // Just in case. - $percentCode = min(100, $percentCode); - - $error = 'This comment is %s%% valid code; is this commented out code?'; - $data = array($percentCode); - $phpcsFile->addWarning($error, $stackPtr, 'Found', $data); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowBooleanStatementSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowBooleanStatementSniff.php deleted file mode 100644 index 1f6dd34..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowBooleanStatementSniff.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_PHP_DisallowBooleanStatementSniff. - * - * Ensures that boolean operators are only used inside control structure conditions. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_PHP_DisallowBooleanStatementSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return PHP_CodeSniffer_Tokens::$booleanOperators; - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) { - $foundOwner = false; - foreach ($tokens[$stackPtr]['nested_parenthesis'] as $open => $close) { - if (isset($tokens[$open]['parenthesis_owner']) === true) { - // Any owner means we are not just a simple statement. - return; - } - } - } - - $error = 'Boolean operators are not allowed outside of control structure conditions'; - $phpcsFile->addError($error, $stackPtr, 'Found'); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowComparisonAssignmentSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowComparisonAssignmentSniff.php deleted file mode 100644 index e1d9d84..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowComparisonAssignmentSniff.php +++ /dev/null @@ -1,125 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_PHP_DisallowComparisonAssignmentSniff. - * - * Ensures that the value of a comparison is not assigned to a variable. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_PHP_DisallowComparisonAssignmentSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_EQUAL); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Ignore default value assignments in function definitions. - $function = $phpcsFile->findPrevious(T_FUNCTION, ($stackPtr - 1), null, false, null, true); - if ($function !== false) { - $opener = $tokens[$function]['parenthesis_opener']; - $closer = $tokens[$function]['parenthesis_closer']; - if ($opener < $stackPtr && $closer > $stackPtr) { - return; - } - } - - // Ignore values in array definitions. - $array = $phpcsFile->findNext( - T_ARRAY, - ($stackPtr + 1), - null, - false, - null, - true - ); - - if ($array !== false) { - return; - } - - // Ignore function calls. - $ignore = array( - T_STRING, - T_WHITESPACE, - T_OBJECT_OPERATOR, - ); - - $next = $phpcsFile->findNext($ignore, ($stackPtr + 1), null, true); - if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS - && $tokens[($next - 1)]['code'] === T_STRING - ) { - // Code will look like: $var = myFunction( - // and will be ignored. - return; - } - - $endStatement = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1)); - if ($tokens[$stackPtr]['conditions'] !== $tokens[$endStatement]['conditions']) { - // This statement doesn't end with a semicolon, which is the case for - // the last expression in a for loop. - return; - } - - for ($i = ($stackPtr + 1); $i < $endStatement; $i++) { - if (isset(PHP_CodeSniffer_Tokens::$comparisonTokens[$tokens[$i]['code']]) === true - || $tokens[$i]['code'] === T_INLINE_THEN - ) { - $error = 'The value of a comparison must not be assigned to a variable'; - $phpcsFile->addError($error, $stackPtr, 'AssignedComparison'); - break; - } - - if (isset(PHP_CodeSniffer_Tokens::$booleanOperators[$tokens[$i]['code']]) === true - || $tokens[$i]['code'] === T_BOOLEAN_NOT - ) { - $error = 'The value of a boolean operation must not be assigned to a variable'; - $phpcsFile->addError($error, $stackPtr, 'AssignedBool'); - break; - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowInlineIfSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowInlineIfSniff.php deleted file mode 100644 index 73fce7d..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowInlineIfSniff.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Formatting_DisallowInlineIfSniff. - * - * Stops inline IF statements from being used. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_PHP_DisallowInlineIfSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_INLINE_THEN); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $phpcsFile->addError('Inline IF statements are not allowed', $stackPtr, 'Found'); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowMultipleAssignmentsSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowMultipleAssignmentsSniff.php deleted file mode 100644 index f7de665..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowMultipleAssignmentsSniff.php +++ /dev/null @@ -1,183 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_PHP_DisallowMultipleAssignmentsSniff. - * - * Ensures that there is only one value assignment on a line, and that it is - * the first thing on the line. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_PHP_DisallowMultipleAssignmentsSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_EQUAL); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Ignore default value assignments in function definitions. - $function = $phpcsFile->findPrevious(array(T_FUNCTION, T_CLOSURE), ($stackPtr - 1), null, false, null, true); - if ($function !== false) { - $opener = $tokens[$function]['parenthesis_opener']; - $closer = $tokens[$function]['parenthesis_closer']; - if ($opener < $stackPtr && $closer > $stackPtr) { - return; - } - } - - /* - The general rule is: - Find an equal sign and go backwards along the line. If you hit an - end bracket, skip to the opening bracket. When you find a variable, - stop. That variable must be the first non-empty token on the line - or in the statement. If not, throw an error. - */ - - for ($varToken = ($stackPtr - 1); $varToken >= 0; $varToken--) { - // Skip brackets. - if (isset($tokens[$varToken]['parenthesis_opener']) === true && $tokens[$varToken]['parenthesis_opener'] < $varToken) { - $varToken = $tokens[$varToken]['parenthesis_opener']; - continue; - } - - if (isset($tokens[$varToken]['bracket_opener']) === true) { - $varToken = $tokens[$varToken]['bracket_opener']; - continue; - } - - if ($tokens[$varToken]['code'] === T_SEMICOLON) { - // We've reached the next statement, so we - // didn't find a variable. - return; - } - - if ($tokens[$varToken]['code'] === T_VARIABLE) { - // We found our variable. - break; - } - }//end for - - if ($varToken <= 0) { - // Didn't find a variable. - return; - } - - // Deal with this type of variable: self::$var by setting the var - // token to be "self" rather than "$var". - if ($tokens[($varToken - 1)]['code'] === T_DOUBLE_COLON) { - $varToken = ($varToken - 2); - } - - // Deal with this type of variable: $obj->$var by setting the var - // token to be "$obj" rather than "$var". - if ($tokens[($varToken - 1)]['code'] === T_OBJECT_OPERATOR) { - $varToken = ($varToken - 2); - } - - // Deal with this type of variable: $$var by setting the var - // token to be "$" rather than "$var". - if ($tokens[($varToken - 1)]['content'] === '$') { - $varToken--; - } - - // Ignore member var definitions. - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($varToken - 1), null, true); - if (isset(PHP_CodeSniffer_Tokens::$scopeModifiers[$tokens[$prev]['code']]) === true) { - return; - } - - if ($tokens[$prev]['code'] === T_STATIC) { - return; - } - - // Make sure this variable is the first thing in the statement. - $varLine = $tokens[$varToken]['line']; - $prevLine = 0; - for ($i = ($varToken - 1); $i >= 0; $i--) { - if ($tokens[$i]['code'] === T_SEMICOLON) { - // We reached the end of the statement. - return; - } - - if ($tokens[$i]['code'] === T_INLINE_THEN) { - // We reached the end of the inline THEN statement. - return; - } - - if ($tokens[$i]['code'] === T_INLINE_ELSE) { - // We reached the end of the inline ELSE statement. - return; - } - - if ($tokens[$i]['code'] === T_OPEN_TAG) { - // We reached the end of the code block. - return; - } - - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$i]['code']]) === false) { - $prevLine = $tokens[$i]['line']; - break; - } - }//end for - - // Ignore the first part of FOR loops as we are allowed to - // assign variables there even though the variable is not the - // first thing on the line. Also ignore WHILE loops. - if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS && isset($tokens[$i]['parenthesis_owner']) === true) { - $owner = $tokens[$i]['parenthesis_owner']; - if ($tokens[$owner]['code'] === T_FOR || $tokens[$owner]['code'] === T_WHILE) { - return; - } - } - - if ($prevLine === $varLine) { - $error = 'Assignments must be the first block of code on a line'; - $phpcsFile->addError($error, $stackPtr, 'Found'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowObEndFlushSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowObEndFlushSniff.php deleted file mode 100644 index d1a2018..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowObEndFlushSniff.php +++ /dev/null @@ -1,66 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Formatting_DisallowObEndFlushSniff. - * - * Checks the indenting used when an ob_start() call occurs. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_PHP_DisallowObEndFlushSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_STRING); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[$stackPtr]['content'] === 'ob_end_flush') { - $phpcsFile->addError('Use of ob_end_flush() is not allowed; use ob_get_contents() and ob_end_clean() instead', $stackPtr, 'Found'); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowSizeFunctionsInLoopsSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowSizeFunctionsInLoopsSniff.php deleted file mode 100644 index 5c146f4..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowSizeFunctionsInLoopsSniff.php +++ /dev/null @@ -1,127 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_PHP_DisallowSizeFunctionsInLoopsSniff. - * - * Bans the use of size-based functions in loop conditions. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_PHP_DisallowSizeFunctionsInLoopsSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - /** - * An array of functions we don't want in the condition of loops. - * - * @return array - */ - protected $forbiddenFunctions = array( - 'PHP' => array( - 'sizeof' => true, - 'strlen' => true, - 'count' => true, - ), - 'JS' => array('length' => true), - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_WHILE, - T_FOR, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $tokenizer = $phpcsFile->tokenizerType; - $openBracket = $tokens[$stackPtr]['parenthesis_opener']; - $closeBracket = $tokens[$stackPtr]['parenthesis_closer']; - - if ($tokens[$stackPtr]['code'] === T_FOR) { - // We only want to check the condition in FOR loops. - $start = $phpcsFile->findNext(T_SEMICOLON, ($openBracket + 1)); - $end = $phpcsFile->findPrevious(T_SEMICOLON, ($closeBracket - 1)); - } else { - $start = $openBracket; - $end = $closeBracket; - } - - for ($i = ($start + 1); $i < $end; $i++) { - if ($tokens[$i]['code'] === T_STRING - && isset($this->forbiddenFunctions[$tokenizer][$tokens[$i]['content']]) === true - ) { - $functionName = $tokens[$i]['content']; - if ($tokenizer === 'JS') { - // Needs to be in the form object.function to be valid. - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($i - 1), null, true); - if ($prev === false || $tokens[$prev]['code'] !== T_OBJECT_OPERATOR) { - continue; - } - - $functionName = 'object.'.$functionName; - } else { - // Make sure it isn't a member var. - if ($tokens[($i - 1)]['code'] === T_OBJECT_OPERATOR) { - continue; - } - - $functionName .= '()'; - } - - $error = 'The use of %s inside a loop condition is not allowed; assign the return value to a variable and use the variable in the loop condition instead'; - $data = array($functionName); - $phpcsFile->addError($error, $i, 'Found', $data); - }//end if - }//end for - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DiscouragedFunctionsSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DiscouragedFunctionsSniff.php deleted file mode 100644 index 1249b56..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/DiscouragedFunctionsSniff.php +++ /dev/null @@ -1,56 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('Generic_Sniffs_PHP_ForbiddenFunctionsSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_PHP_ForbiddenFunctionsSniff not found'); -} - -/** - * Squiz_Sniffs_PHP_DiscouragedFunctionsSniff. - * - * Discourages the use of debug functions. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_PHP_DiscouragedFunctionsSniff extends Generic_Sniffs_PHP_ForbiddenFunctionsSniff -{ - - /** - * A list of forbidden functions with their alternatives. - * - * The value is NULL if no alternative exists. IE, the - * function should just not be used. - * - * @var array(string => string|null) - */ - public $forbiddenFunctions = array( - 'error_log' => null, - 'print_r' => null, - 'var_dump' => null, - ); - - /** - * If true, an error will be thrown; otherwise a warning. - * - * @var bool - */ - public $error = false; - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/EmbeddedPhpSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/EmbeddedPhpSniff.php deleted file mode 100644 index 71bedc8..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/EmbeddedPhpSniff.php +++ /dev/null @@ -1,405 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_PHP_EmbeddedPhpSniff. - * - * Checks the indentation of embedded PHP code segments. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_PHP_EmbeddedPhpSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // If the close php tag is on the same line as the opening - // then we have an inline embedded PHP block. - $closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr); - if ($closeTag === false || $tokens[$stackPtr]['line'] !== $tokens[$closeTag]['line']) { - $this->_validateMultilineEmbeddedPhp($phpcsFile, $stackPtr); - } else { - $this->_validateInlineEmbeddedPhp($phpcsFile, $stackPtr); - } - - }//end process() - - - /** - * Validates embedded PHP that exists on multiple lines. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - private function _validateMultilineEmbeddedPhp(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $prevTag = $phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)); - if ($prevTag === false) { - // This is the first open tag. - return; - } - - $firstContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - $closingTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr); - if ($closingTag !== false) { - $nextContent = $phpcsFile->findNext(T_WHITESPACE, ($closingTag + 1), $phpcsFile->numTokens, true); - if ($nextContent === false) { - // Final closing tag. It will be handled elsewhere. - return; - } - - // We have an opening and a closing tag, that lie within other content. - if ($firstContent === $closingTag) { - $error = 'Empty embedded PHP tag found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Empty'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = $stackPtr; $i <= $closingTag; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - - return; - } - }//end if - - if ($tokens[$firstContent]['line'] === $tokens[$stackPtr]['line']) { - $error = 'Opening PHP tag must be on a line by itself'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'ContentAfterOpen'); - if ($fix === true) { - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true); - $padding = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content']))); - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->addNewline($stackPtr); - $phpcsFile->fixer->addContent($stackPtr, str_repeat(' ', $padding)); - $phpcsFile->fixer->endChangeset(); - } - } else { - // Check the indent of the first line, except if it is a scope closer. - if (isset($tokens[$firstContent]['scope_closer']) === false - || $tokens[$firstContent]['scope_closer'] !== $firstContent - ) { - // Check for a blank line at the top. - if ($tokens[$firstContent]['line'] > ($tokens[$stackPtr]['line'] + 1)) { - // Find a token on the blank line to throw the error on. - $i = $stackPtr; - do { - $i++; - } while ($tokens[$i]['line'] !== ($tokens[$stackPtr]['line'] + 1)); - - $error = 'Blank line found at start of embedded PHP content'; - $fix = $phpcsFile->addFixableError($error, $i, 'SpacingBefore'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($stackPtr + 1); $i < $firstContent; $i++) { - if ($tokens[$i]['line'] === $tokens[$firstContent]['line'] - || $tokens[$i]['line'] === $tokens[$stackPtr]['line'] - ) { - continue; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - }//end if - - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr); - if ($first === false) { - $first = $phpcsFile->findFirstOnLine(T_INLINE_HTML, $stackPtr); - $indent = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content']))); - } else { - $indent = ($tokens[($first + 1)]['column'] - 1); - } - - $contentColumn = ($tokens[$firstContent]['column'] - 1); - if ($contentColumn !== $indent) { - $error = 'First line of embedded PHP code must be indented %s spaces; %s found'; - $data = array( - $indent, - $contentColumn, - ); - $fix = $phpcsFile->addFixableError($error, $firstContent, 'Indent', $data); - if ($fix === true) { - $padding = str_repeat(' ', $indent); - if ($contentColumn === 0) { - $phpcsFile->fixer->addContentBefore($firstContent, $padding); - } else { - $phpcsFile->fixer->replaceToken(($firstContent - 1), $padding); - } - } - } - }//end if - }//end if - - $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if ($tokens[$lastContent]['line'] === $tokens[$stackPtr]['line'] - && trim($tokens[$lastContent]['content']) !== '' - ) { - $error = 'Opening PHP tag must be on a line by itself'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'ContentBeforeOpen'); - if ($fix === true) { - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr); - if ($first === false) { - $first = $phpcsFile->findFirstOnLine(T_INLINE_HTML, $stackPtr); - $padding = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content']))); - } else { - $padding = ($tokens[($first + 1)]['column'] - 1); - } - - $phpcsFile->fixer->addContentBefore($stackPtr, $phpcsFile->eolChar.str_repeat(' ', $padding)); - } - } else { - // Find the first token on the first non-empty line we find. - for ($first = ($stackPtr - 1); $first > 0; $first--) { - if ($tokens[$first]['line'] === $tokens[$stackPtr]['line']) { - continue; - } else if (trim($tokens[$first]['content']) !== '') { - $first = $phpcsFile->findFirstOnLine(array(), $first, true); - break; - } - } - - $expected = 0; - if ($tokens[$first]['code'] === T_INLINE_HTML - && trim($tokens[$first]['content']) !== '' - ) { - $expected = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content']))); - } else if ($tokens[$first]['code'] === T_WHITESPACE) { - $expected = ($tokens[($first + 1)]['column'] - 1); - } - - $expected += 4; - $found = ($tokens[$stackPtr]['column'] - 1); - if ($found > $expected) { - $error = 'Opening PHP tag indent incorrect; expected no more than %s spaces but found %s'; - $data = array( - $expected, - $found, - ); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'OpenTagIndent', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr - 1), str_repeat(' ', $expected)); - } - } - }//end if - - if ($closingTag === false) { - return; - } - - $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($closingTag - 1), ($stackPtr + 1), true); - $nextContent = $phpcsFile->findNext(T_WHITESPACE, ($closingTag + 1), null, true); - - if ($tokens[$lastContent]['line'] === $tokens[$closingTag]['line']) { - $error = 'Closing PHP tag must be on a line by itself'; - $fix = $phpcsFile->addFixableError($error, $closingTag, 'ContentBeforeEnd'); - if ($fix === true) { - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $closingTag, true); - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->addContentBefore($closingTag, str_repeat(' ', ($tokens[$first]['column'] - 1))); - $phpcsFile->fixer->addNewlineBefore($closingTag); - $phpcsFile->fixer->endChangeset(); - } - } else if ($tokens[$nextContent]['line'] === $tokens[$closingTag]['line']) { - $error = 'Closing PHP tag must be on a line by itself'; - $fix = $phpcsFile->addFixableError($error, $closingTag, 'ContentAfterEnd'); - if ($fix === true) { - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $closingTag, true); - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->addNewline($closingTag); - $phpcsFile->fixer->addContent($closingTag, str_repeat(' ', ($tokens[$first]['column'] - 1))); - $phpcsFile->fixer->endChangeset(); - } - }//end if - - $next = $phpcsFile->findNext(T_OPEN_TAG, ($closingTag + 1)); - if ($next === false) { - return; - } - - // Check for a blank line at the bottom. - if ((isset($tokens[$lastContent]['scope_closer']) === false - || $tokens[$lastContent]['scope_closer'] !== $lastContent) - && $tokens[$lastContent]['line'] < ($tokens[$closingTag]['line'] - 1) - ) { - // Find a token on the blank line to throw the error on. - $i = $closingTag; - do { - $i--; - } while ($tokens[$i]['line'] !== ($tokens[$closingTag]['line'] - 1)); - - $error = 'Blank line found at end of embedded PHP content'; - $fix = $phpcsFile->addFixableError($error, $i, 'SpacingAfter'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($lastContent + 1); $i < $closingTag; $i++) { - if ($tokens[$i]['line'] === $tokens[$lastContent]['line'] - || $tokens[$i]['line'] === $tokens[$closingTag]['line'] - ) { - continue; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - }//end if - - }//end _validateMultilineEmbeddedPhp() - - - /** - * Validates embedded PHP that exists on one line. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - private function _validateInlineEmbeddedPhp(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // We only want one line PHP sections, so return if the closing tag is - // on the next line. - $closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr, null, false); - if ($tokens[$stackPtr]['line'] !== $tokens[$closeTag]['line']) { - return; - } - - // Check that there is one, and only one space at the start of the statement. - $firstContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), ($closeTag - 1), true); - - if ($firstContent === false) { - $error = 'Empty embedded PHP tag found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Empty'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = $stackPtr; $i <= $closeTag; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - - return; - } - - // The open tag token always contains a single space after it. - $leadingSpace = 1; - if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) { - $leadingSpace = (strlen($tokens[($stackPtr + 1)]['content']) + 1); - } - - if ($leadingSpace !== 1) { - $error = 'Expected 1 space after opening PHP tag; %s found'; - $data = array($leadingSpace); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterOpen', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ''); - } - } - - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($closeTag - 1), $stackPtr, true); - if ((isset($tokens[$prev]['scope_opener']) === false - || $tokens[$prev]['scope_opener'] !== $prev) - && (isset($tokens[$prev]['scope_closer']) === false - || $tokens[$prev]['scope_closer'] !== $prev) - && $tokens[$prev]['code'] !== T_SEMICOLON - ) { - $error = 'Inline PHP statement must end with a semicolon'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSemicolon'); - if ($fix === true) { - $phpcsFile->fixer->addContent($prev, ';'); - } - } else if ($tokens[$prev]['code'] === T_SEMICOLON) { - $statementCount = 1; - for ($i = ($stackPtr + 1); $i < $prev; $i++) { - if ($tokens[$i]['code'] === T_SEMICOLON) { - $statementCount++; - } - } - - if ($statementCount > 1) { - $error = 'Inline PHP statement must contain a single statement; %s found'; - $data = array($statementCount); - $phpcsFile->addError($error, $stackPtr, 'MultipleStatements', $data); - } - } - - $trailingSpace = 0; - if ($tokens[($closeTag - 1)]['code'] === T_WHITESPACE) { - $trailingSpace = strlen($tokens[($closeTag - 1)]['content']); - } - - if ($trailingSpace !== 1) { - $error = 'Expected 1 space before closing PHP tag; %s found'; - $data = array($trailingSpace); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBeforeClose', $data); - if ($fix === true) { - if ($trailingSpace === 0) { - $phpcsFile->fixer->addContentBefore($closeTag, ' '); - } else { - $phpcsFile->fixer->replaceToken(($closeTag - 1), ' '); - } - } - } - - }//end _validateInlineEmbeddedPhp() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/EvalSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/EvalSniff.php deleted file mode 100644 index 89869ca..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/EvalSniff.php +++ /dev/null @@ -1,63 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_PHP_EvalSniff. - * - * The use of eval() is discouraged. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_PHP_EvalSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_EVAL); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $error = 'Use of eval() is discouraged'; - $phpcsFile->addWarning($error, $stackPtr, 'Discouraged'); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/ForbiddenFunctionsSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/ForbiddenFunctionsSniff.php deleted file mode 100644 index 2660c36..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/ForbiddenFunctionsSniff.php +++ /dev/null @@ -1,54 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('Generic_Sniffs_PHP_ForbiddenFunctionsSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_PHP_ForbiddenFunctionsSniff not found'); -} - -/** - * Squiz_Sniffs_PHP_ForbiddenFunctionsSniff. - * - * Discourages the use of alias functions that are kept in PHP for compatibility - * with older versions. Can be used to forbid the use of any function. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_PHP_ForbiddenFunctionsSniff extends Generic_Sniffs_PHP_ForbiddenFunctionsSniff -{ - - /** - * A list of forbidden functions with their alternatives. - * - * The value is NULL if no alternative exists. IE, the - * function should just not be used. - * - * @var array(string => string|null) - */ - public $forbiddenFunctions = array( - 'sizeof' => 'count', - 'delete' => 'unset', - 'print' => 'echo', - 'is_null' => null, - 'create_function' => null, - ); - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/GlobalKeywordSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/GlobalKeywordSniff.php deleted file mode 100644 index b8f7756..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/GlobalKeywordSniff.php +++ /dev/null @@ -1,68 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_PHP_GlobalKeywordSniff. - * - * Stops the usage of the "global" keyword. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_PHP_GlobalKeywordSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_GLOBAL); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $nextVar = $tokens[$phpcsFile->findNext(array(T_VARIABLE), $stackPtr)]; - $varName = str_replace('$', '', $nextVar['content']); - $error = 'Use of the "global" keyword is forbidden; use "$GLOBALS[\'%s\']" instead'; - $data = array($varName); - $phpcsFile->addError($error, $stackPtr, 'NotAllowed', $data); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/HeredocSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/HeredocSniff.php deleted file mode 100644 index b13e6e3..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/HeredocSniff.php +++ /dev/null @@ -1,66 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_PHP_HeredocSniff. - * - * Heredocs are prohibited. This test enforces that. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_PHP_HeredocSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_START_HEREDOC, - T_START_NOWDOC, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $error = 'Use of heredoc and nowdoc syntax ("<<<") is not allowed; use standard strings or inline HTML instead'; - $phpcsFile->addError($error, $stackPtr, 'NotAllowed'); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/InnerFunctionsSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/InnerFunctionsSniff.php deleted file mode 100644 index 7601a2c..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/InnerFunctionsSniff.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_PHP_InnerFunctionsSniff. - * - * Ensures that functions within functions are never used. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_PHP_InnerFunctionsSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_FUNCTION); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $function = $phpcsFile->getCondition($stackPtr, T_FUNCTION); - if ($function === false) { - // Not a nested function. - return; - } - - $class = $phpcsFile->getCondition($stackPtr, T_ANON_CLASS); - if ($class !== false && $class > $function) { - // Ignore methods in anon classes. - return; - } - - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if ($tokens[$prev]['code'] === T_EQUAL) { - // Ignore closures. - return; - } - - $error = 'The use of inner functions is forbidden'; - $phpcsFile->addError($error, $stackPtr, 'NotAllowed'); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/LowercasePHPFunctionsSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/LowercasePHPFunctionsSniff.php deleted file mode 100644 index ed9106d..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/LowercasePHPFunctionsSniff.php +++ /dev/null @@ -1,140 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_PHP_LowercasePHPFunctionsSniff. - * - * Ensures all calls to inbuilt PHP functions are lowercase. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_PHP_LowercasePHPFunctionsSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * String -> int hash map of all php built in function names - * - * @var array - */ - private $_builtInFunctions; - - - /** - * Construct the LowercasePHPFunctionSniff - */ - public function __construct() - { - - $allFunctions = get_defined_functions(); - $this->_builtInFunctions = array_flip($allFunctions['internal']); - - }//end __construct() - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_STRING); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Make sure this is a function call. - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($next === false) { - // Not a function call. - return; - } - - if ($tokens[$next]['code'] !== T_OPEN_PARENTHESIS) { - // Not a function call. - return; - } - - $prev = $phpcsFile->findPrevious(array(T_WHITESPACE, T_BITWISE_AND), ($stackPtr - 1), null, true); - if ($tokens[$prev]['code'] === T_FUNCTION) { - // Function declaration, not a function call. - return; - } - - if ($tokens[$prev]['code'] === T_NS_SEPARATOR) { - // Namespaced class/function, not an inbuilt function. - return; - } - - if ($tokens[$prev]['code'] === T_NEW) { - // Object creation, not an inbuilt function. - return; - } - - if ($tokens[$prev]['code'] === T_OBJECT_OPERATOR) { - // Not an inbuilt function. - return; - } - - if ($tokens[$prev]['code'] === T_DOUBLE_COLON) { - // Not an inbuilt function. - return; - } - - // Make sure it is an inbuilt PHP function. - // PHP_CodeSniffer can possibly include user defined functions - // through the use of vendor/autoload.php. - $content = $tokens[$stackPtr]['content']; - if (isset($this->_builtInFunctions[strtolower($content)]) === false) { - return; - } - - if ($content !== strtolower($content)) { - $error = 'Calls to inbuilt PHP functions must be lowercase; expected "%s" but found "%s"'; - $data = array( - strtolower($content), - $content, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'CallUppercase', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, strtolower($content)); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/NonExecutableCodeSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/NonExecutableCodeSniff.php deleted file mode 100644 index 8b44e48..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/PHP/NonExecutableCodeSniff.php +++ /dev/null @@ -1,270 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_PHP_NonExecutableCodeSniff. - * - * Warns about code that can never been executed. This happens when a function - * returns before the code, or a break ends execution of a statement etc. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_PHP_NonExecutableCodeSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_BREAK, - T_CONTINUE, - T_RETURN, - T_THROW, - T_EXIT, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // If this token is preceded with an "or", it only relates to one line - // and should be ignored. For example: fopen() or die(). - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); - if ($tokens[$prev]['code'] === T_LOGICAL_OR || $tokens[$prev]['code'] === T_BOOLEAN_OR) { - return; - } - - // Check if this token is actually part of a one-line IF or ELSE statement. - for ($i = ($stackPtr - 1); $i > 0; $i--) { - if ($tokens[$i]['code'] === T_CLOSE_PARENTHESIS) { - $i = $tokens[$i]['parenthesis_opener']; - continue; - } else if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$i]['code']]) === true) { - continue; - } - - break; - } - - if ($tokens[$i]['code'] === T_IF - || $tokens[$i]['code'] === T_ELSE - || $tokens[$i]['code'] === T_ELSEIF - ) { - return; - } - - if ($tokens[$stackPtr]['code'] === T_RETURN) { - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($tokens[$next]['code'] === T_SEMICOLON) { - $next = $phpcsFile->findNext(T_WHITESPACE, ($next + 1), null, true); - if ($tokens[$next]['code'] === T_CLOSE_CURLY_BRACKET) { - // If this is the closing brace of a function - // then this return statement doesn't return anything - // and is not required anyway. - $owner = $tokens[$next]['scope_condition']; - if ($tokens[$owner]['code'] === T_FUNCTION) { - $warning = 'Empty return statement not required here'; - $phpcsFile->addWarning($warning, $stackPtr, 'ReturnNotRequired'); - return; - } - } - } - } - - if (isset($tokens[$stackPtr]['scope_opener']) === true) { - $owner = $tokens[$stackPtr]['scope_condition']; - if ($tokens[$owner]['code'] === T_CASE || $tokens[$owner]['code'] === T_DEFAULT) { - // This token closes the scope of a CASE or DEFAULT statement - // so any code between this statement and the next CASE, DEFAULT or - // end of SWITCH token will not be executable. - $end = $phpcsFile->findEndOfStatement($stackPtr); - $next = $phpcsFile->findNext( - array( - T_CASE, - T_DEFAULT, - T_CLOSE_CURLY_BRACKET, - ), - ($end + 1) - ); - - if ($next !== false) { - $lastLine = $tokens[$end]['line']; - for ($i = ($stackPtr + 1); $i < $next; $i++) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$i]['code']]) === true) { - continue; - } - - $line = $tokens[$i]['line']; - if ($line > $lastLine) { - $type = substr($tokens[$stackPtr]['type'], 2); - $warning = 'Code after %s statement cannot be executed'; - $data = array($type); - $phpcsFile->addWarning($warning, $i, 'Unreachable', $data); - $lastLine = $line; - } - } - }//end if - - // That's all we have to check for these types of statements. - return; - }//end if - }//end if - - // This token may be part of an inline condition. - // If we find a closing parenthesis that belongs to a condition - // we should ignore this token. - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); - if (isset($tokens[$prev]['parenthesis_owner']) === true) { - $owner = $tokens[$prev]['parenthesis_owner']; - $ignore = array( - T_IF => true, - T_ELSE => true, - T_ELSEIF => true, - ); - if (isset($ignore[$tokens[$owner]['code']]) === true) { - return; - } - } - - $ourConditions = array_keys($tokens[$stackPtr]['conditions']); - - if (empty($ourConditions) === false) { - $condition = array_pop($ourConditions); - - if (isset($tokens[$condition]['scope_closer']) === false) { - return; - } - - // Special case for BREAK statements sitting directly inside SWITCH - // statements. If we get to this point, we know the BREAK is not being - // used to close a CASE statement, so it is most likely non-executable - // code itself (as is the case when you put return; break; at the end of - // a case). So we need to ignore this token. - if ($tokens[$condition]['code'] === T_SWITCH - && $tokens[$stackPtr]['code'] === T_BREAK - ) { - return; - } - - $closer = $tokens[$condition]['scope_closer']; - - // If the closer for our condition is shared with other openers, - // we will need to throw errors from this token to the next - // shared opener (if there is one), not to the scope closer. - $nextOpener = null; - for ($i = ($stackPtr + 1); $i < $closer; $i++) { - if (isset($tokens[$i]['scope_closer']) === true) { - if ($tokens[$i]['scope_closer'] === $closer) { - // We found an opener that shares the same - // closing token as us. - $nextOpener = $i; - break; - } - } - }//end for - - if ($nextOpener === null) { - $end = $closer; - } else { - $end = ($nextOpener - 1); - } - } else { - // This token is in the global scope. - if ($tokens[$stackPtr]['code'] === T_BREAK) { - return; - } - - // Throw an error for all lines until the end of the file. - $end = ($phpcsFile->numTokens - 1); - }//end if - - // Find the semicolon that ends this statement, skipping - // nested statements like FOR loops and closures. - for ($start = ($stackPtr + 1); $start < $phpcsFile->numTokens; $start++) { - if ($start === $end) { - break; - } - - if ($tokens[$start]['code'] === T_OPEN_PARENTHESIS) { - $start = $tokens[$start]['parenthesis_closer']; - continue; - } - - if ($tokens[$start]['code'] === T_OPEN_CURLY_BRACKET) { - $start = $tokens[$start]['bracket_closer']; - continue; - } - - if ($tokens[$start]['code'] === T_SEMICOLON) { - break; - } - }//end for - - $lastLine = $tokens[$start]['line']; - for ($i = ($start + 1); $i < $end; $i++) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$i]['code']]) === true - || isset(PHP_CodeSniffer_Tokens::$bracketTokens[$tokens[$i]['code']]) === true - ) { - continue; - } - - // Skip whole functions and classes/interfaces because they are not - // technically executed code, but rather declarations that may be used. - if ($tokens[$i]['code'] === T_FUNCTION - || $tokens[$i]['code'] === T_CLASS - || $tokens[$i]['code'] === T_INTERFACE - ) { - $i = $tokens[$i]['scope_closer']; - continue; - } - - $line = $tokens[$i]['line']; - if ($line > $lastLine) { - $type = substr($tokens[$stackPtr]['type'], 2); - $warning = 'Code after %s statement cannot be executed'; - $data = array($type); - $phpcsFile->addWarning($warning, $i, 'Unreachable', $data); - $lastLine = $line; - } - }//end for - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Scope/MemberVarScopeSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Scope/MemberVarScopeSniff.php deleted file mode 100644 index 25d31c8..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Scope/MemberVarScopeSniff.php +++ /dev/null @@ -1,101 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found'); -} - -/** - * Verifies that class members have scope modifiers. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Scope_MemberVarScopeSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff -{ - - - /** - * Processes the function tokens within the class. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. - * - * @return void - */ - protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $modifier = null; - for ($i = ($stackPtr - 1); $i > 0; $i--) { - if ($tokens[$i]['line'] < $tokens[$stackPtr]['line']) { - break; - } else if (isset(PHP_CodeSniffer_Tokens::$scopeModifiers[$tokens[$i]['code']]) === true) { - $modifier = $i; - break; - } - } - - if ($modifier === null) { - $error = 'Scope modifier not specified for member variable "%s"'; - $data = array($tokens[$stackPtr]['content']); - $phpcsFile->addError($error, $stackPtr, 'Missing', $data); - } - - }//end processMemberVar() - - - /** - * Processes normal variables. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. - * - * @return void - */ - protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - /* - We don't care about normal variables. - */ - - }//end processVariable() - - - /** - * Processes variables in double quoted strings. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. - * - * @return void - */ - protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - /* - We don't care about normal variables. - */ - - }//end processVariableInString() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Scope/MethodScopeSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Scope/MethodScopeSniff.php deleted file mode 100644 index d8d99d3..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Scope/MethodScopeSniff.php +++ /dev/null @@ -1,89 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found'); -} - -/** - * Verifies that class methods have scope modifiers. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Scope_MethodScopeSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff -{ - - - /** - * Constructs a Squiz_Sniffs_Scope_MethodScopeSniff. - */ - public function __construct() - { - parent::__construct(array(T_CLASS, T_INTERFACE, T_TRAIT), array(T_FUNCTION)); - - }//end __construct() - - - /** - * Processes the function tokens within the class. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. - * @param int $currScope The current scope opener token. - * - * @return void - */ - protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) - { - $tokens = $phpcsFile->getTokens(); - - $methodName = $phpcsFile->getDeclarationName($stackPtr); - if ($methodName === null) { - // Ignore closures. - return; - } - - if ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true) { - // Ignore nested functions. - return; - } - - $modifier = null; - for ($i = ($stackPtr - 1); $i > 0; $i--) { - if ($tokens[$i]['line'] < $tokens[$stackPtr]['line']) { - break; - } else if (isset(PHP_CodeSniffer_Tokens::$scopeModifiers[$tokens[$i]['code']]) === true) { - $modifier = $i; - break; - } - } - - if ($modifier === null) { - $error = 'Visibility must be declared on method "%s"'; - $data = array($methodName); - $phpcsFile->addError($error, $stackPtr, 'Missing', $data); - } - - }//end processTokenWithinScope() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Scope/StaticThisUsageSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Scope/StaticThisUsageSniff.php deleted file mode 100644 index cee2b5e..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Scope/StaticThisUsageSniff.php +++ /dev/null @@ -1,95 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found'); -} - -/** - * Squiz_Sniffs_Scope_StaticThisUsageSniff. - * - * Checks for usage of "$this" in static methods, which will cause - * runtime errors. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Scope_StaticThisUsageSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff -{ - - - /** - * Constructs the test with the tokens it wishes to listen for. - */ - public function __construct() - { - parent::__construct(array(T_CLASS), array(T_FUNCTION)); - - }//end __construct() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The current file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * @param int $currScope A pointer to the start of the scope. - * - * @return void - */ - public function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) - { - $tokens = $phpcsFile->getTokens(); - $function = $tokens[($stackPtr + 2)]; - - if ($function['code'] !== T_STRING) { - return; - } - - $functionName = $function['content']; - $classOpener = $tokens[$currScope]['scope_condition']; - $className = $tokens[($classOpener + 2)]['content']; - - $methodProps = $phpcsFile->getMethodProperties($stackPtr); - - if ($methodProps['is_static'] === true) { - if (isset($tokens[$stackPtr]['scope_closer']) === false) { - // There is no scope opener or closer, so the function - // must be abstract. - return; - } - - $thisUsage = $stackPtr; - while (($thisUsage = $phpcsFile->findNext(array(T_VARIABLE), ($thisUsage + 1), $tokens[$stackPtr]['scope_closer'], false, '$this')) !== false) { - if ($thisUsage === false) { - return; - } - - $error = 'Usage of "$this" in static methods will cause runtime errors'; - $phpcsFile->addError($error, $thisUsage, 'Found'); - } - }//end if - - }//end processTokenWithinScope() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Strings/ConcatenationSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Strings/ConcatenationSpacingSniff.php deleted file mode 100644 index 5408653..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Strings/ConcatenationSpacingSniff.php +++ /dev/null @@ -1,159 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Strings_ConcatenationSpacingSniff. - * - * Makes sure there are no spaces between the concatenation operator (.) and - * the strings being concatenated. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Strings_ConcatenationSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * The number of spaces before and after a string concat. - * - * @var int - */ - public $spacing = 0; - - /** - * Allow newlines instead of spaces. - * - * @var boolean - */ - public $ignoreNewlines = false; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_STRING_CONCAT); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $this->spacing = (int) $this->spacing; - - $tokens = $phpcsFile->getTokens(); - if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) { - $before = 0; - } else { - if ($tokens[($stackPtr - 2)]['line'] !== $tokens[$stackPtr]['line']) { - $before = 'newline'; - } else { - $before = $tokens[($stackPtr - 1)]['length']; - } - } - - if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { - $after = 0; - } else { - if ($tokens[($stackPtr + 2)]['line'] !== $tokens[$stackPtr]['line']) { - $after = 'newline'; - } else { - $after = $tokens[($stackPtr + 1)]['length']; - } - } - - $phpcsFile->recordMetric($stackPtr, 'Spacing before string concat', $before); - $phpcsFile->recordMetric($stackPtr, 'Spacing after string concat', $after); - - if (($before === $this->spacing || ($before === 'newline' && $this->ignoreNewlines === true)) - && ($after === $this->spacing || ($after === 'newline' && $this->ignoreNewlines === true)) - ) { - return; - } - - if ($this->spacing === 0) { - $message = 'Concat operator must not be surrounded by spaces'; - $data = array(); - } else { - if ($this->spacing > 1) { - $message = 'Concat operator must be surrounded by %s spaces'; - } else { - $message = 'Concat operator must be surrounded by a single space'; - } - - $data = array($this->spacing); - } - - $fix = $phpcsFile->addFixableError($message, $stackPtr, 'PaddingFound', $data); - - if ($fix === true) { - $padding = str_repeat(' ', $this->spacing); - if ($before !== 'newline' || $this->ignoreNewlines === false) { - if ($tokens[($stackPtr - 1)]['code'] === T_WHITESPACE) { - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->replaceToken(($stackPtr - 1), $padding); - if ($this->spacing === 0 - && ($tokens[($stackPtr - 2)]['code'] === T_LNUMBER - || $tokens[($stackPtr - 2)]['code'] === T_DNUMBER) - ) { - $phpcsFile->fixer->replaceToken(($stackPtr - 2), '('.$tokens[($stackPtr - 2)]['content'].')'); - } - - $phpcsFile->fixer->endChangeset(); - } else if ($this->spacing > 0) { - $phpcsFile->fixer->addContent(($stackPtr - 1), $padding); - } - } - - if ($after !== 'newline' || $this->ignoreNewlines === false) { - if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) { - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->replaceToken(($stackPtr + 1), $padding); - if ($this->spacing === 0 - && ($tokens[($stackPtr + 2)]['code'] === T_LNUMBER - || $tokens[($stackPtr + 2)]['code'] === T_DNUMBER) - ) { - $phpcsFile->fixer->replaceToken(($stackPtr + 2), '('.$tokens[($stackPtr + 2)]['content'].')'); - } - - $phpcsFile->fixer->endChangeset(); - } else if ($this->spacing > 0) { - $phpcsFile->fixer->addContent($stackPtr, $padding); - } - } - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Strings/DoubleQuoteUsageSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Strings/DoubleQuoteUsageSniff.php deleted file mode 100644 index 102f4af..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Strings/DoubleQuoteUsageSniff.php +++ /dev/null @@ -1,153 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Strings_DoubleQuoteUsageSniff. - * - * Makes sure that any use of Double Quotes ("") are warranted. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Strings_DoubleQuoteUsageSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_CONSTANT_ENCAPSED_STRING, - T_DOUBLE_QUOTED_STRING, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // We are only interested in the first token in a multi-line string. - if ($tokens[$stackPtr]['code'] === $tokens[($stackPtr - 1)]['code']) { - return; - } - - $workingString = $tokens[$stackPtr]['content']; - $lastStringToken = $stackPtr; - - $i = ($stackPtr + 1); - if (isset($tokens[$i]) === true) { - while ($i < $phpcsFile->numTokens - && $tokens[$i]['code'] === $tokens[$stackPtr]['code'] - ) { - $workingString .= $tokens[$i]['content']; - $lastStringToken = $i; - $i++; - } - } - - // Check if it's a double quoted string. - if (strpos($workingString, '"') === false) { - return; - } - - // Make sure it's not a part of a string started in a previous line. - // If it is, then we have already checked it. - if ($workingString[0] !== '"') { - return; - } - - // The use of variables in double quoted strings is not allowed. - if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING) { - $stringTokens = token_get_all('addError($error, $stackPtr, 'ContainsVar', $data); - } - } - - return; - }//end if - - $allowedChars = array( - '\0', - '\1', - '\2', - '\3', - '\4', - '\5', - '\6', - '\7', - '\n', - '\r', - '\f', - '\t', - '\v', - '\x', - '\b', - '\e', - '\u', - '\'', - ); - - foreach ($allowedChars as $testChar) { - if (strpos($workingString, $testChar) !== false) { - return; - } - } - - $error = 'String %s does not require double quotes; use single quotes instead'; - $data = array(str_replace(array("\r", "\n"), array('\r', '\n'), $workingString)); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotRequired', $data); - - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $innerContent = substr($workingString, 1, -1); - $innerContent = str_replace('\"', '"', $innerContent); - $phpcsFile->fixer->replaceToken($stackPtr, "'$innerContent'"); - while ($lastStringToken !== $stackPtr) { - $phpcsFile->fixer->replaceToken($lastStringToken, ''); - $lastStringToken--; - } - - $phpcsFile->fixer->endChangeset(); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Strings/EchoedStringsSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Strings/EchoedStringsSniff.php deleted file mode 100644 index 1292f7d..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/Strings/EchoedStringsSniff.php +++ /dev/null @@ -1,103 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Strings_EchoedStringsSniff. - * - * Makes sure that any strings that are "echoed" are not enclosed in brackets - * like a function call. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_Strings_EchoedStringsSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_ECHO); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $firstContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - // If the first non-whitespace token is not an opening parenthesis, then we are not concerned. - if ($tokens[$firstContent]['code'] !== T_OPEN_PARENTHESIS) { - $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no'); - return; - } - - $end = $phpcsFile->findNext(array(T_SEMICOLON, T_CLOSE_TAG), $stackPtr, null, false); - - // If the token before the semi-colon is not a closing parenthesis, then we are not concerned. - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($end - 1), null, true); - if ($tokens[$prev]['code'] !== T_CLOSE_PARENTHESIS) { - $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no'); - return; - } - - // If the parenthesis don't match, then we are not concerned. - if ($tokens[$firstContent]['parenthesis_closer'] !== $prev) { - $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no'); - return; - } - - $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'yes'); - - if (($phpcsFile->findNext(PHP_CodeSniffer_Tokens::$operators, $stackPtr, $end, false)) === false) { - // There are no arithmetic operators in this. - $error = 'Echoed strings should not be bracketed'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'HasBracket'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->replaceToken($firstContent, ''); - if ($tokens[($firstContent - 1)]['code'] !== T_WHITESPACE) { - $phpcsFile->fixer->addContent(($firstContent - 1), ' '); - } - - $phpcsFile->fixer->replaceToken($prev, ''); - $phpcsFile->fixer->endChangeset(); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/CastSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/CastSpacingSniff.php deleted file mode 100644 index 0e7f250..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/CastSpacingSniff.php +++ /dev/null @@ -1,79 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_WhiteSpace_CastSpacingSniff. - * - * Ensure cast statements don't contain whitespace. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_WhiteSpace_CastSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return PHP_CodeSniffer_Tokens::$castTokens; - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $content = $tokens[$stackPtr]['content']; - $expected = str_replace(' ', '', $content); - $expected = str_replace("\t", '', $expected); - - if ($content !== $expected) { - $error = 'Cast statements must not contain whitespace; expected "%s" but found "%s"'; - $data = array( - $expected, - $content, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'ContainsWhiteSpace', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, $expected); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php deleted file mode 100644 index fb0914a..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ /dev/null @@ -1,316 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_WhiteSpace_ControlStructureSpacingSniff. - * - * Checks that control structures have the correct spacing around brackets. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_WhiteSpace_ControlStructureSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_IF, - T_WHILE, - T_FOREACH, - T_FOR, - T_SWITCH, - T_DO, - T_ELSE, - T_ELSEIF, - T_TRY, - T_CATCH, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (isset($tokens[$stackPtr]['parenthesis_opener']) === true - && isset($tokens[$stackPtr]['parenthesis_closer']) === true - ) { - $parenOpener = $tokens[$stackPtr]['parenthesis_opener']; - $parenCloser = $tokens[$stackPtr]['parenthesis_closer']; - if ($tokens[($parenOpener + 1)]['code'] === T_WHITESPACE) { - $gap = $tokens[($parenOpener + 1)]['length']; - - if ($gap === 0) { - $phpcsFile->recordMetric($stackPtr, 'Spaces after control structure open parenthesis', 'newline'); - $gap = 'newline'; - } else { - $phpcsFile->recordMetric($stackPtr, 'Spaces after control structure open parenthesis', $gap); - } - - $error = 'Expected 0 spaces after opening bracket; %s found'; - $data = array($gap); - $fix = $phpcsFile->addFixableError($error, ($parenOpener + 1), 'SpacingAfterOpenBrace', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($parenOpener + 1), ''); - } - } else { - $phpcsFile->recordMetric($stackPtr, 'Spaces after control structure open parenthesis', 0); - } - - if ($tokens[$parenOpener]['line'] === $tokens[$parenCloser]['line'] - && $tokens[($parenCloser - 1)]['code'] === T_WHITESPACE - ) { - $gap = $tokens[($parenCloser - 1)]['length']; - $error = 'Expected 0 spaces before closing bracket; %s found'; - $data = array($gap); - $fix = $phpcsFile->addFixableError($error, ($parenCloser - 1), 'SpaceBeforeCloseBrace', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($parenCloser - 1), ''); - } - - if ($gap === 0) { - $phpcsFile->recordMetric($stackPtr, 'Spaces before control structure close parenthesis', 'newline'); - } else { - $phpcsFile->recordMetric($stackPtr, 'Spaces before control structure close parenthesis', $gap); - } - } else { - $phpcsFile->recordMetric($stackPtr, 'Spaces before control structure close parenthesis', 0); - } - }//end if - - if (isset($tokens[$stackPtr]['scope_closer']) === false) { - return; - } - - $scopeOpener = $tokens[$stackPtr]['scope_opener']; - $scopeCloser = $tokens[$stackPtr]['scope_closer']; - - for ($firstContent = ($scopeOpener + 1); $firstContent < $phpcsFile->numTokens; $firstContent++) { - if ($tokens[$firstContent]['code'] !== T_WHITESPACE) { - break; - } - } - - // We ignore spacing for some structures that tend to have their own rules. - $ignore = array( - T_FUNCTION => true, - T_CLASS => true, - T_INTERFACE => true, - T_TRAIT => true, - T_DOC_COMMENT_OPEN_TAG => true, - ); - - if (isset($ignore[$tokens[$firstContent]['code']]) === false - && $tokens[$firstContent]['line'] >= ($tokens[$scopeOpener]['line'] + 2) - ) { - $error = 'Blank line found at start of control structure'; - $fix = $phpcsFile->addFixableError($error, $scopeOpener, 'SpacingAfterOpen'); - - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $i = ($scopeOpener + 1); - while ($tokens[$i]['line'] !== $tokens[$firstContent]['line']) { - $phpcsFile->fixer->replaceToken($i, ''); - $i++; - } - - $phpcsFile->fixer->addNewline($scopeOpener); - $phpcsFile->fixer->endChangeset(); - } - } - - if ($firstContent !== $scopeCloser) { - $lastContent = $phpcsFile->findPrevious( - T_WHITESPACE, - ($scopeCloser - 1), - null, - true - ); - - $lastNonEmptyContent = $phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, - ($scopeCloser - 1), - null, - true - ); - - $checkToken = $lastContent; - if (isset($tokens[$lastNonEmptyContent]['scope_condition']) === true) { - $checkToken = $tokens[$lastNonEmptyContent]['scope_condition']; - } - - if (isset($ignore[$tokens[$checkToken]['code']]) === false - && $tokens[$lastContent]['line'] <= ($tokens[$scopeCloser]['line'] - 2) - ) { - $errorToken = $scopeCloser; - for ($i = ($scopeCloser - 1); $i > $lastContent; $i--) { - if ($tokens[$i]['line'] < $tokens[$scopeCloser]['line']) { - $errorToken = $i; - break; - } - } - - $error = 'Blank line found at end of control structure'; - $fix = $phpcsFile->addFixableError($error, $errorToken, 'SpacingBeforeClose'); - - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $i = ($scopeCloser - 1); - for ($i = ($scopeCloser - 1); $i > $lastContent; $i--) { - if ($tokens[$i]['line'] === $tokens[$scopeCloser]['line']) { - continue; - } - - if ($tokens[$i]['line'] === $tokens[$lastContent]['line']) { - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - }//end if - }//end if - - $trailingContent = $phpcsFile->findNext( - T_WHITESPACE, - ($scopeCloser + 1), - null, - true - ); - - if ($tokens[$trailingContent]['code'] === T_COMMENT) { - // Special exception for code where the comment about - // an ELSE or ELSEIF is written between the control structures. - $nextCode = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, - ($scopeCloser + 1), - null, - true - ); - - if ($tokens[$nextCode]['code'] === T_ELSE - || $tokens[$nextCode]['code'] === T_ELSEIF - ) { - $trailingContent = $nextCode; - } - }//end if - - if ($tokens[$trailingContent]['code'] === T_ELSE) { - if ($tokens[$stackPtr]['code'] === T_IF) { - // IF with ELSE. - return; - } - } - - if ($tokens[$trailingContent]['code'] === T_WHILE - && $tokens[$stackPtr]['code'] === T_DO - ) { - // DO with WHILE. - return; - } - - if ($tokens[$trailingContent]['code'] === T_CLOSE_TAG) { - // At the end of the script or embedded code. - return; - } - - if (isset($tokens[$trailingContent]['scope_condition']) === true - && $tokens[$trailingContent]['scope_condition'] !== $trailingContent - && isset($tokens[$trailingContent]['scope_opener']) === true - && $tokens[$trailingContent]['scope_opener'] !== $trailingContent - ) { - // Another control structure's closing brace. - $owner = $tokens[$trailingContent]['scope_condition']; - if ($tokens[$owner]['code'] === T_FUNCTION) { - // The next content is the closing brace of a function - // so normal function rules apply and we can ignore it. - return; - } - - if ($tokens[$owner]['code'] === T_CLOSURE - && ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true - || $phpcsFile->hasCondition($stackPtr, T_CLOSURE) === true - || isset($tokens[$stackPtr]['nested_parenthesis']) === true) - ) { - return; - } - - if ($tokens[$trailingContent]['line'] !== ($tokens[$scopeCloser]['line'] + 1)) { - $error = 'Blank line found after control structure'; - $fix = $phpcsFile->addFixableError($error, $scopeCloser, 'LineAfterClose'); - - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $i = ($scopeCloser + 1); - while ($tokens[$i]['line'] !== $tokens[$trailingContent]['line']) { - $phpcsFile->fixer->replaceToken($i, ''); - $i++; - } - - $phpcsFile->fixer->addNewline($scopeCloser); - $phpcsFile->fixer->endChangeset(); - } - } - } else if ($tokens[$trailingContent]['code'] !== T_ELSE - && $tokens[$trailingContent]['code'] !== T_ELSEIF - && $tokens[$trailingContent]['code'] !== T_CATCH - && $tokens[$trailingContent]['line'] === ($tokens[$scopeCloser]['line'] + 1) - ) { - $error = 'No blank line found after control structure'; - $fix = $phpcsFile->addFixableError($error, $scopeCloser, 'NoLineAfterClose'); - if ($fix === true) { - $phpcsFile->fixer->addNewline($scopeCloser); - } - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/FunctionClosingBraceSpaceSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/FunctionClosingBraceSpaceSniff.php deleted file mode 100644 index 91568bf..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/FunctionClosingBraceSpaceSniff.php +++ /dev/null @@ -1,182 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_WhiteSpace_FunctionClosingBraceSpaceSniff. - * - * Checks that there is one empty line before the closing brace of a function. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_WhiteSpace_FunctionClosingBraceSpaceSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_FUNCTION, - T_CLOSURE, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (isset($tokens[$stackPtr]['scope_closer']) === false) { - // Probably an interface method. - return; - } - - $closeBrace = $tokens[$stackPtr]['scope_closer']; - $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, ($closeBrace - 1), null, true); - - // Special case for empty JS functions. - if ($phpcsFile->tokenizerType === 'JS' && $prevContent === $tokens[$stackPtr]['scope_opener']) { - // In this case, the opening and closing brace must be - // right next to each other. - if ($tokens[$stackPtr]['scope_closer'] !== ($tokens[$stackPtr]['scope_opener'] + 1)) { - $error = 'The opening and closing braces of empty functions must be directly next to each other; e.g., function () {}'; - $fix = $phpcsFile->addFixableError($error, $closeBrace, 'SpacingBetween'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($tokens[$stackPtr]['scope_opener'] + 1); $i < $closeBrace; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - } - - return; - } - - $nestedFunction = false; - if ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true - || $phpcsFile->hasCondition($stackPtr, T_CLOSURE) === true - || isset($tokens[$stackPtr]['nested_parenthesis']) === true - ) { - $nestedFunction = true; - } - - $braceLine = $tokens[$closeBrace]['line']; - $prevLine = $tokens[$prevContent]['line']; - $found = ($braceLine - $prevLine - 1); - - $afterKeyword = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - $beforeKeyword = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if ($nestedFunction === true) { - if ($found < 0) { - $error = 'Closing brace of nested function must be on a new line'; - $fix = $phpcsFile->addFixableError($error, $closeBrace, 'ContentBeforeClose'); - if ($fix === true) { - $phpcsFile->fixer->addNewlineBefore($closeBrace); - } - } else if ($found > 0) { - $error = 'Expected 0 blank lines before closing brace of nested function; %s found'; - $data = array($found); - $fix = $phpcsFile->addFixableError($error, $closeBrace, 'SpacingBeforeNestedClose', $data); - - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $changeMade = false; - for ($i = ($prevContent + 1); $i < $closeBrace; $i++) { - // Try and maintain indentation. - if ($tokens[$i]['line'] === ($braceLine - 1)) { - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - $changeMade = true; - } - - // Special case for when the last content contains the newline - // token as well, like with a comment. - if ($changeMade === false) { - $phpcsFile->fixer->replaceToken(($prevContent + 1), ''); - } - - $phpcsFile->fixer->endChangeset(); - }//end if - }//end if - } else { - if ($found !== 1) { - if ($found < 0) { - $found = 0; - } - - $error = 'Expected 1 blank line before closing function brace; %s found'; - $data = array($found); - $fix = $phpcsFile->addFixableError($error, $closeBrace, 'SpacingBeforeClose', $data); - - if ($fix === true) { - if ($found > 1) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($prevContent + 1); $i < ($closeBrace - 1); $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->replaceToken($i, $phpcsFile->eolChar); - $phpcsFile->fixer->endChangeset(); - } else { - // Try and maintain indentation. - if ($tokens[($closeBrace - 1)]['code'] === T_WHITESPACE) { - $phpcsFile->fixer->addNewlineBefore($closeBrace - 1); - } else { - $phpcsFile->fixer->addNewlineBefore($closeBrace); - } - } - } - }//end if - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/FunctionOpeningBraceSpaceSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/FunctionOpeningBraceSpaceSniff.php deleted file mode 100644 index 9760fbb..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/FunctionOpeningBraceSpaceSniff.php +++ /dev/null @@ -1,113 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_WhiteSpace_FunctionOpeningBraceSpaceSniff. - * - * Checks that there is no empty line after the opening brace of a function. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_WhiteSpace_FunctionOpeningBraceSpaceSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_FUNCTION, - T_CLOSURE, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (isset($tokens[$stackPtr]['scope_opener']) === false) { - // Probably an interface method. - return; - } - - $openBrace = $tokens[$stackPtr]['scope_opener']; - $nextContent = $phpcsFile->findNext(T_WHITESPACE, ($openBrace + 1), null, true); - - if ($nextContent === $tokens[$stackPtr]['scope_closer']) { - // The next bit of content is the closing brace, so this - // is an empty function and should have a blank line - // between the opening and closing braces. - return; - } - - $braceLine = $tokens[$openBrace]['line']; - $nextLine = $tokens[$nextContent]['line']; - - $found = ($nextLine - $braceLine - 1); - if ($found > 0) { - $error = 'Expected 0 blank lines after opening function brace; %s found'; - $data = array($found); - $fix = $phpcsFile->addFixableError($error, $openBrace, 'SpacingAfter', $data); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($openBrace + 1); $i < $nextContent; $i++) { - if ($tokens[$i]['line'] === $nextLine) { - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->addNewline($openBrace); - $phpcsFile->fixer->endChangeset(); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php deleted file mode 100644 index fbf66f3..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php +++ /dev/null @@ -1,239 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_WhiteSpace_FunctionSpacingSniff. - * - * Checks the separation between methods in a class or interface. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_WhiteSpace_FunctionSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * The number of blank lines between functions. - * - * @var int - */ - public $spacing = 2; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_FUNCTION); - - }//end register() - - - /** - * Processes this sniff when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $this->spacing = (int) $this->spacing; - - /* - Check the number of blank lines - after the function. - */ - - if (isset($tokens[$stackPtr]['scope_closer']) === false) { - // Must be an interface method, so the closer is the semicolon. - $closer = $phpcsFile->findNext(T_SEMICOLON, $stackPtr); - } else { - $closer = $tokens[$stackPtr]['scope_closer']; - } - - // Allow for comments on the same line as the closer. - for ($nextLineToken = ($closer + 1); $nextLineToken < $phpcsFile->numTokens; $nextLineToken++) { - if ($tokens[$nextLineToken]['line'] !== $tokens[$closer]['line']) { - break; - } - } - - $foundLines = 0; - if ($nextLineToken === ($phpcsFile->numTokens - 1)) { - // We are at the end of the file. - // Don't check spacing after the function because this - // should be done by an EOF sniff. - $foundLines = $this->spacing; - } else { - $nextContent = $phpcsFile->findNext(T_WHITESPACE, $nextLineToken, null, true); - if ($nextContent === false) { - // We are at the end of the file. - // Don't check spacing after the function because this - // should be done by an EOF sniff. - $foundLines = $this->spacing; - } else { - $foundLines += ($tokens[$nextContent]['line'] - $tokens[$nextLineToken]['line']); - } - } - - if ($foundLines !== $this->spacing) { - $error = 'Expected %s blank line'; - if ($this->spacing !== 1) { - $error .= 's'; - } - - $error .= ' after function; %s found'; - $data = array( - $this->spacing, - $foundLines, - ); - - $fix = $phpcsFile->addFixableError($error, $closer, 'After', $data); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = $nextLineToken; $i <= $nextContent; $i++) { - if ($tokens[$i]['line'] === $tokens[$nextContent]['line']) { - $phpcsFile->fixer->addContentBefore($i, str_repeat($phpcsFile->eolChar, $this->spacing)); - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - }//end if - }//end if - - /* - Check the number of blank lines - before the function. - */ - - $prevLineToken = null; - for ($i = $stackPtr; $i > 0; $i--) { - if (strpos($tokens[$i]['content'], $phpcsFile->eolChar) === false) { - continue; - } else { - $prevLineToken = $i; - break; - } - } - - if (is_null($prevLineToken) === true) { - // Never found the previous line, which means - // there are 0 blank lines before the function. - $foundLines = 0; - $prevContent = 0; - } else { - $currentLine = $tokens[$stackPtr]['line']; - - $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, $prevLineToken, null, true); - if ($tokens[$prevContent]['code'] === T_DOC_COMMENT_CLOSE_TAG - && $tokens[$prevContent]['line'] === ($currentLine - 1) - ) { - // Account for function comments. - $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, ($tokens[$prevContent]['comment_opener'] - 1), null, true); - } - - // Before we throw an error, check that we are not throwing an error - // for another function. We don't want to error for no blank lines after - // the previous function and no blank lines before this one as well. - $prevLine = ($tokens[$prevContent]['line'] - 1); - $i = ($stackPtr - 1); - $foundLines = 0; - while ($currentLine !== $prevLine && $currentLine > 1 && $i > 0) { - if (isset($tokens[$i]['scope_condition']) === true) { - $scopeCondition = $tokens[$i]['scope_condition']; - if ($tokens[$scopeCondition]['code'] === T_FUNCTION) { - // Found a previous function. - return; - } - } else if ($tokens[$i]['code'] === T_FUNCTION) { - // Found another interface function. - return; - } - - $currentLine = $tokens[$i]['line']; - if ($currentLine === $prevLine) { - break; - } - - if ($tokens[($i - 1)]['line'] < $currentLine && $tokens[($i + 1)]['line'] > $currentLine) { - // This token is on a line by itself. If it is whitespace, the line is empty. - if ($tokens[$i]['code'] === T_WHITESPACE) { - $foundLines++; - } - } - - $i--; - }//end while - }//end if - - if ($foundLines !== $this->spacing) { - $error = 'Expected %s blank line'; - if ($this->spacing !== 1) { - $error .= 's'; - } - - $error .= ' before function; %s found'; - $data = array( - $this->spacing, - $foundLines, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Before', $data); - if ($fix === true) { - if ($prevContent === 0) { - $nextSpace = 0; - } else { - $nextSpace = $phpcsFile->findNext(T_WHITESPACE, ($prevContent + 1), $stackPtr); - if ($nextSpace === false) { - $nextSpace = ($stackPtr - 1); - } - } - - if ($foundLines < $this->spacing) { - $padding = str_repeat($phpcsFile->eolChar, ($this->spacing - $foundLines)); - $phpcsFile->fixer->addContent($nextSpace, $padding); - } else { - $nextContent = $phpcsFile->findNext(T_WHITESPACE, ($nextSpace + 1), null, true); - $phpcsFile->fixer->beginChangeset(); - for ($i = $nextSpace; $i < ($nextContent - 1); $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->replaceToken($i, str_repeat($phpcsFile->eolChar, $this->spacing)); - $phpcsFile->fixer->endChangeset(); - } - }//end if - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/LanguageConstructSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/LanguageConstructSpacingSniff.php deleted file mode 100644 index d2f8528..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/LanguageConstructSpacingSniff.php +++ /dev/null @@ -1,100 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_WhiteSpace_LanguageConstructSpacingSniff. - * - * Ensures all language constructs (without brackets) contain a - * single space between themselves and their content. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_WhiteSpace_LanguageConstructSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_ECHO, - T_PRINT, - T_RETURN, - T_INCLUDE, - T_INCLUDE_ONCE, - T_REQUIRE, - T_REQUIRE_ONCE, - T_NEW, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[($stackPtr + 1)]['code'] === T_SEMICOLON) { - // No content for this language construct. - return; - } - - if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) { - $content = $tokens[($stackPtr + 1)]['content']; - $contentLength = strlen($content); - if ($contentLength !== 1) { - $error = 'Language constructs must be followed by a single space; expected 1 space but found %s'; - $data = array($contentLength); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'IncorrectSingle', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); - } - } - } else if ($tokens[($stackPtr + 1)]['code'] !== T_OPEN_PARENTHESIS) { - $error = 'Language constructs must be followed by a single space; expected "%s" but found "%s"'; - $data = array( - $tokens[$stackPtr]['content'].' '.$tokens[($stackPtr + 1)]['content'], - $tokens[$stackPtr]['content'].$tokens[($stackPtr + 1)]['content'], - ); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Incorrect', $data); - if ($fix === true) { - $phpcsFile->fixer->addContent($stackPtr, ' '); - } - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/LogicalOperatorSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/LogicalOperatorSpacingSniff.php deleted file mode 100644 index d48151b..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/LogicalOperatorSpacingSniff.php +++ /dev/null @@ -1,116 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Sniffs_Squiz_WhiteSpace_OperatorSpacingSniff. - * - * Verifies that operators have valid spacing surrounding them. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_WhiteSpace_LogicalOperatorSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return PHP_CodeSniffer_Tokens::$booleanOperators; - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The current file being checked. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Check there is one space before the operator. - if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) { - $error = 'Expected 1 space before logical operator; 0 found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceBefore'); - if ($fix === true) { - $phpcsFile->fixer->addContentBefore($stackPtr, ' '); - } - } else { - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if ($tokens[$stackPtr]['line'] === $tokens[$prev]['line'] - && strlen($tokens[($stackPtr - 1)]['content']) !== 1 - ) { - $found = strlen($tokens[($stackPtr - 1)]['content']); - $error = 'Expected 1 space before logical operator; %s found'; - $data = array($found); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'TooMuchSpaceBefore', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr - 1), ' '); - } - } - } - - // Check there is one space after the operator. - if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { - $error = 'Expected 1 space after logical operator; 0 found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceAfter'); - if ($fix === true) { - $phpcsFile->fixer->addContent($stackPtr, ' '); - } - } else { - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($tokens[$stackPtr]['line'] === $tokens[$next]['line'] - && strlen($tokens[($stackPtr + 1)]['content']) !== 1 - ) { - $found = strlen($tokens[($stackPtr + 1)]['content']); - $error = 'Expected 1 space after logical operator; %s found'; - $data = array($found); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'TooMuchSpaceAfter', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); - } - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php deleted file mode 100644 index f5cc07c..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php +++ /dev/null @@ -1,167 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found'); -} - -/** - * Verifies that class members are spaced correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_WhiteSpace_MemberVarSpacingSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff -{ - - - /** - * Processes the function tokens within the class. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. - * - * @return void - */ - protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $ignore = PHP_CodeSniffer_Tokens::$methodPrefixes; - $ignore[] = T_VAR; - $ignore[] = T_WHITESPACE; - - $start = $stackPtr; - $prev = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true); - if (isset(PHP_CodeSniffer_Tokens::$commentTokens[$tokens[$prev]['code']]) === true) { - // Assume the comment belongs to the member var if it is on a line by itself. - $prevContent = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($prev - 1), null, true); - if ($tokens[$prevContent]['line'] !== $tokens[$prev]['line']) { - // Check the spacing, but then skip it. - $foundLines = ($tokens[$stackPtr]['line'] - $tokens[$prev]['line'] - 1); - if ($foundLines > 0) { - $error = 'Expected 0 blank lines after member var comment; %s found'; - $data = array($foundLines); - $fix = $phpcsFile->addFixableError($error, $prev, 'AfterComment', $data); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - // Inline comments have the newline included in the content but - // docblock do not. - if ($tokens[$prev]['code'] === T_COMMENT) { - $phpcsFile->fixer->replaceToken($prev, rtrim($tokens[$prev]['content'])); - } - - for ($i = ($prev + 1); $i <= $stackPtr; $i++) { - if ($tokens[$i]['line'] === $tokens[$stackPtr]['line']) { - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->addNewline($prev); - $phpcsFile->fixer->endChangeset(); - } - }//end if - - $start = $prev; - }//end if - }//end if - - // There needs to be 1 blank line before the var, not counting comments. - if ($start === $stackPtr) { - // No comment found. - $first = $phpcsFile->findFirstOnLine(PHP_CodeSniffer_Tokens::$emptyTokens, $start, true); - if ($first === false) { - $first = $start; - } - } else if ($tokens[$start]['code'] === T_DOC_COMMENT_CLOSE_TAG) { - $first = $tokens[$start]['comment_opener']; - } else { - $first = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($start - 1), null, true); - $first = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$commentTokens, ($first + 1)); - } - - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($first - 1), null, true); - $foundLines = ($tokens[$first]['line'] - $tokens[$prev]['line'] - 1); - if ($foundLines === 1) { - return; - } - - $error = 'Expected 1 blank line before member var; %s found'; - $data = array($foundLines); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Incorrect', $data); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($prev + 1); $i < $first; $i++) { - if ($tokens[$i]['line'] === $tokens[$prev]['line']) { - continue; - } - - if ($tokens[$i]['line'] === $tokens[$first]['line']) { - $phpcsFile->fixer->addNewline(($i - 1)); - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - }//end if - - }//end processMemberVar() - - - /** - * Processes normal variables. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. - * - * @return void - */ - protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - /* - We don't care about normal variables. - */ - - }//end processVariable() - - - /** - * Processes variables in double quoted strings. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. - * - * @return void - */ - protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - /* - We don't care about normal variables. - */ - - }//end processVariableInString() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ObjectOperatorSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ObjectOperatorSpacingSniff.php deleted file mode 100644 index 554e872..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ObjectOperatorSpacingSniff.php +++ /dev/null @@ -1,154 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_WhiteSpace_ObjectOperatorSpacingSniff. - * - * Ensure there is no whitespace before/after an object operator. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_WhiteSpace_ObjectOperatorSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * Allow newlines instead of spaces. - * - * @var boolean - */ - public $ignoreNewlines = false; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OBJECT_OPERATOR); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) { - $before = 0; - } else { - if ($tokens[($stackPtr - 2)]['line'] !== $tokens[$stackPtr]['line']) { - $before = 'newline'; - } else { - $before = $tokens[($stackPtr - 1)]['length']; - } - } - - if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { - $after = 0; - } else { - if ($tokens[($stackPtr + 2)]['line'] !== $tokens[$stackPtr]['line']) { - $after = 'newline'; - } else { - $after = $tokens[($stackPtr + 1)]['length']; - } - } - - $phpcsFile->recordMetric($stackPtr, 'Spacing before object operator', $before); - $phpcsFile->recordMetric($stackPtr, 'Spacing after object operator', $after); - - $this->checkSpacingBeforeOperator($phpcsFile, $stackPtr, $before); - $this->checkSpacingAfterOperator($phpcsFile, $stackPtr, $after); - - }//end process() - - - /** - * Check the spacing before the operator. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param mixed $before The number of spaces found before the - * operator or the string 'newline'. - * - * @return boolean true if there was no error, false otherwise. - */ - protected function checkSpacingBeforeOperator(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $before) - { - if ($before !== 0 - && ($before !== 'newline' || $this->ignoreNewlines === false) - ) { - $error = 'Space found before object operator'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Before'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr - 1), ''); - } - - return false; - } - - return true; - - }//end checkSpacingBeforeOperator() - - - /** - * Check the spacing after the operator. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param mixed $after The number of spaces found after the - * operator or the string 'newline'. - * - * @return boolean true if there was no error, false otherwise. - */ - protected function checkSpacingAfterOperator(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $after) - { - if ($after !== 0 - && ($after !== 'newline' || $this->ignoreNewlines === false) - ) { - $error = 'Space found after object operator'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'After'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ''); - } - - return false; - } - - return true; - - }//end checkSpacingAfterOperator() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php deleted file mode 100644 index ec64e5e..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ /dev/null @@ -1,324 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Sniffs_Squiz_WhiteSpace_OperatorSpacingSniff. - * - * Verifies that operators have valid spacing surrounding them. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_WhiteSpace_OperatorSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - /** - * Allow newlines instead of spaces. - * - * @var boolean - */ - public $ignoreNewlines = false; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - $comparison = PHP_CodeSniffer_Tokens::$comparisonTokens; - $operators = PHP_CodeSniffer_Tokens::$operators; - $assignment = PHP_CodeSniffer_Tokens::$assignmentTokens; - $inlineIf = array( - T_INLINE_THEN, - T_INLINE_ELSE, - ); - - return array_unique( - array_merge($comparison, $operators, $assignment, $inlineIf) - ); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The current file being checked. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Skip default values in function declarations. - if ($tokens[$stackPtr]['code'] === T_EQUAL - || $tokens[$stackPtr]['code'] === T_MINUS - ) { - if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) { - $parenthesis = array_keys($tokens[$stackPtr]['nested_parenthesis']); - $bracket = array_pop($parenthesis); - if (isset($tokens[$bracket]['parenthesis_owner']) === true) { - $function = $tokens[$bracket]['parenthesis_owner']; - if ($tokens[$function]['code'] === T_FUNCTION - || $tokens[$function]['code'] === T_CLOSURE - ) { - return; - } - } - } - } - - if ($tokens[$stackPtr]['code'] === T_EQUAL) { - // Skip for '=&' case. - if (isset($tokens[($stackPtr + 1)]) === true - && $tokens[($stackPtr + 1)]['code'] === T_BITWISE_AND - ) { - return; - } - } - - // Skip short ternary such as: "$foo = $bar ?: true;". - if (($tokens[$stackPtr]['code'] === T_INLINE_THEN - && $tokens[($stackPtr + 1)]['code'] === T_INLINE_ELSE) - || ($tokens[($stackPtr - 1)]['code'] === T_INLINE_THEN - && $tokens[$stackPtr]['code'] === T_INLINE_ELSE) - ) { - return; - } - - if ($tokens[$stackPtr]['code'] === T_BITWISE_AND) { - // If it's not a reference, then we expect one space either side of the - // bitwise operator. - if ($phpcsFile->isReference($stackPtr) === true) { - return; - } - - // Check there is one space before the & operator. - if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) { - $error = 'Expected 1 space before "&" operator; 0 found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceBeforeAmp'); - if ($fix === true) { - $phpcsFile->fixer->addContentBefore($stackPtr, ' '); - } - - $phpcsFile->recordMetric($stackPtr, 'Space before operator', 0); - } else { - if ($tokens[($stackPtr - 2)]['line'] !== $tokens[$stackPtr]['line']) { - $found = 'newline'; - } else { - $found = $tokens[($stackPtr - 1)]['length']; - } - - $phpcsFile->recordMetric($stackPtr, 'Space before operator', $found); - if ($found !== 1 - && ($found !== 'newline' || $this->ignoreNewlines === false) - ) { - $error = 'Expected 1 space before "&" operator; %s found'; - $data = array($found); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBeforeAmp', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr - 1), ' '); - } - } - }//end if - - // Check there is one space after the & operator. - if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { - $error = 'Expected 1 space after "&" operator; 0 found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceAfterAmp'); - if ($fix === true) { - $phpcsFile->fixer->addContent($stackPtr, ' '); - } - - $phpcsFile->recordMetric($stackPtr, 'Space after operator', 0); - } else { - if ($tokens[($stackPtr + 2)]['line'] !== $tokens[$stackPtr]['line']) { - $found = 'newline'; - } else { - $found = $tokens[($stackPtr + 1)]['length']; - } - - $phpcsFile->recordMetric($stackPtr, 'Space after operator', $found); - if ($found !== 1 - && ($found !== 'newline' || $this->ignoreNewlines === false) - ) { - $error = 'Expected 1 space after "&" operator; %s found'; - $data = array($found); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterAmp', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); - } - } - }//end if - - return; - }//end if - - if ($tokens[$stackPtr]['code'] === T_MINUS || $tokens[$stackPtr]['code'] === T_PLUS) { - // Check minus spacing, but make sure we aren't just assigning - // a minus value or returning one. - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - if ($tokens[$prev]['code'] === T_RETURN) { - // Just returning a negative value; eg. (return -1). - return; - } - - if (isset(PHP_CodeSniffer_Tokens::$operators[$tokens[$prev]['code']]) === true) { - // Just trying to operate on a negative value; eg. ($var * -1). - return; - } - - if (isset(PHP_CodeSniffer_Tokens::$comparisonTokens[$tokens[$prev]['code']]) === true) { - // Just trying to compare a negative value; eg. ($var === -1). - return; - } - - if (isset(PHP_CodeSniffer_Tokens::$booleanOperators[$tokens[$prev]['code']]) === true) { - // Just trying to compare a negative value; eg. ($var || -1 === $b). - return; - } - - if (isset(PHP_CodeSniffer_Tokens::$assignmentTokens[$tokens[$prev]['code']]) === true) { - // Just trying to assign a negative value; eg. ($var = -1). - return; - } - - // A list of tokens that indicate that the token is not - // part of an arithmetic operation. - $invalidTokens = array( - T_COMMA => true, - T_OPEN_PARENTHESIS => true, - T_OPEN_SQUARE_BRACKET => true, - T_OPEN_SHORT_ARRAY => true, - T_DOUBLE_ARROW => true, - T_COLON => true, - T_INLINE_THEN => true, - T_INLINE_ELSE => true, - T_CASE => true, - ); - - if (isset($invalidTokens[$tokens[$prev]['code']]) === true) { - // Just trying to use a negative value; eg. myFunction($var, -2). - return; - } - }//end if - - $operator = $tokens[$stackPtr]['content']; - - if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) { - $error = "Expected 1 space before \"$operator\"; 0 found"; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceBefore'); - if ($fix === true) { - $phpcsFile->fixer->addContentBefore($stackPtr, ' '); - } - - $phpcsFile->recordMetric($stackPtr, 'Space before operator', 0); - } else if (isset(PHP_CodeSniffer_Tokens::$assignmentTokens[$tokens[$stackPtr]['code']]) === false) { - // Don't throw an error for assignments, because other standards allow - // multiple spaces there to align multiple assignments. - if ($tokens[($stackPtr - 2)]['line'] !== $tokens[$stackPtr]['line']) { - $found = 'newline'; - } else { - $found = $tokens[($stackPtr - 1)]['length']; - } - - $phpcsFile->recordMetric($stackPtr, 'Space before operator', $found); - if ($found !== 1 - && ($found !== 'newline' || $this->ignoreNewlines === false) - ) { - $error = 'Expected 1 space before "%s"; %s found'; - $data = array( - $operator, - $found, - ); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBefore', $data); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - if ($found === 'newline') { - $i = ($stackPtr - 2); - while ($tokens[$i]['code'] === T_WHITESPACE) { - $phpcsFile->fixer->replaceToken($i, ''); - $i--; - } - } - - $phpcsFile->fixer->replaceToken(($stackPtr - 1), ' '); - $phpcsFile->fixer->endChangeset(); - } - }//end if - }//end if - - if (isset($tokens[($stackPtr + 1)]) === false) { - return; - } - - if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { - $error = "Expected 1 space after \"$operator\"; 0 found"; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceAfter'); - if ($fix === true) { - $phpcsFile->fixer->addContent($stackPtr, ' '); - } - - $phpcsFile->recordMetric($stackPtr, 'Space after operator', 0); - } else { - if (isset($tokens[($stackPtr + 2)]) === true - && $tokens[($stackPtr + 2)]['line'] !== $tokens[$stackPtr]['line'] - ) { - $found = 'newline'; - } else { - $found = $tokens[($stackPtr + 1)]['length']; - } - - $phpcsFile->recordMetric($stackPtr, 'Space after operator', $found); - if ($found !== 1 - && ($found !== 'newline' || $this->ignoreNewlines === false) - ) { - $error = 'Expected 1 space after "%s"; %s found'; - $data = array( - $operator, - $found, - ); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfter', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); - } - } - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/PropertyLabelSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/PropertyLabelSpacingSniff.php deleted file mode 100644 index a54cd10..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/PropertyLabelSpacingSniff.php +++ /dev/null @@ -1,93 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_WhiteSpace_PropertyLabelSpacingSniff. - * - * Ensures that the colon in a property or label definition has a single - * space after it and no space before it. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_WhiteSpace_PropertyLabelSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array('JS'); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_PROPERTY, - T_LABEL, - ); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $colon = $phpcsFile->findNext(T_COLON, ($stackPtr + 1)); - - if ($colon !== ($stackPtr + 1)) { - $error = 'There must be no space before the colon in a property/label declaration'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Before'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ''); - } - } - - if ($tokens[($colon + 1)]['code'] !== T_WHITESPACE || $tokens[($colon + 1)]['content'] !== ' ') { - $error = 'There must be a single space after the colon in a property/label declaration'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'After'); - if ($fix === true) { - if ($tokens[($colon + 1)]['code'] === T_WHITESPACE) { - $phpcsFile->fixer->replaceToken(($colon + 1), ' '); - } else { - $phpcsFile->fixer->addContent($colon, ' '); - } - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php deleted file mode 100644 index 2dc188b..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php +++ /dev/null @@ -1,114 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_Whitespace_ScopeClosingBraceSniff. - * - * Checks that the closing braces of scopes are aligned correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_WhiteSpace_ScopeClosingBraceSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return PHP_CodeSniffer_Tokens::$scopeOpeners; - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // If this is an inline condition (ie. there is no scope opener), then - // return, as this is not a new scope. - if (isset($tokens[$stackPtr]['scope_closer']) === false) { - return; - } - - // We need to actually find the first piece of content on this line, - // as if this is a method with tokens before it (public, static etc) - // or an if with an else before it, then we need to start the scope - // checking from there, rather than the current token. - $lineStart = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true); - - $startColumn = $tokens[$lineStart]['column']; - $scopeStart = $tokens[$stackPtr]['scope_opener']; - $scopeEnd = $tokens[$stackPtr]['scope_closer']; - - // Check that the closing brace is on it's own line. - $lastContent = $phpcsFile->findPrevious(array(T_INLINE_HTML, T_WHITESPACE, T_OPEN_TAG), ($scopeEnd - 1), $scopeStart, true); - if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']) { - $error = 'Closing brace must be on a line by itself'; - $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'ContentBefore'); - if ($fix === true) { - $phpcsFile->fixer->addNewlineBefore($scopeEnd); - } - - return; - } - - // Check now that the closing brace is lined up correctly. - $lineStart = $phpcsFile->findFirstOnLine(T_WHITESPACE, $scopeEnd, true); - $braceIndent = $tokens[$lineStart]['column']; - if ($tokens[$stackPtr]['code'] !== T_DEFAULT - && $tokens[$stackPtr]['code'] !== T_CASE - && $braceIndent !== $startColumn - ) { - $error = 'Closing brace indented incorrectly; expected %s spaces, found %s'; - $data = array( - ($startColumn - 1), - ($braceIndent - 1), - ); - - $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'Indent', $data); - if ($fix === true) { - $diff = ($startColumn - $braceIndent); - if ($diff > 0) { - $phpcsFile->fixer->addContentBefore($scopeEnd, str_repeat(' ', $diff)); - } else { - $phpcsFile->fixer->substrToken(($scopeEnd - 1), 0, $diff); - } - } - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php deleted file mode 100644 index 5ff1831..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php +++ /dev/null @@ -1,92 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_WhiteSpace_ScopeKeywordSpacingSniff. - * - * Ensure there is a single space after scope keywords. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_WhiteSpace_ScopeKeywordSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - $register = PHP_CodeSniffer_Tokens::$scopeModifiers; - $register[] = T_STATIC; - return $register; - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - - if ($tokens[$stackPtr]['code'] === T_STATIC - && ($tokens[$nextToken]['code'] === T_DOUBLE_COLON - || $tokens[$prevToken]['code'] === T_NEW) - ) { - // Late static binding, e.g., static:: OR new static() usage. - return; - } - - if ($tokens[$prevToken]['code'] === T_AS) { - // Trait visibilty change, e.g., "use HelloWorld { sayHello as private; }". - return; - } - - $nextToken = $tokens[($stackPtr + 1)]; - if (strlen($nextToken['content']) !== 1 - || $nextToken['content'] === $phpcsFile->eolChar - ) { - $error = 'Scope keyword "%s" must be followed by a single space'; - $data = array($tokens[$stackPtr]['content']); - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Incorrect', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); - } - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/SemicolonSpacingSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/SemicolonSpacingSniff.php deleted file mode 100644 index 67d12af..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/SemicolonSpacingSniff.php +++ /dev/null @@ -1,106 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff. - * - * Ensure there is no whitespace before a semicolon. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_SEMICOLON); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $prevType = $tokens[($stackPtr - 1)]['code']; - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$prevType]) === false) { - return; - } - - $nonSpace = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 2), null, true); - if ($tokens[$nonSpace]['code'] === T_SEMICOLON) { - // Empty statement. - return; - } - - $expected = $tokens[$nonSpace]['content'].';'; - $found = $phpcsFile->getTokensAsString($nonSpace, ($stackPtr - $nonSpace)).';'; - $error = 'Space found before semicolon; expected "%s" but found "%s"'; - $data = array( - $expected, - $found, - ); - - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Incorrect', $data); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $i = ($stackPtr - 1); - while (($tokens[$i]['code'] === T_WHITESPACE) && ($i > $nonSpace)) { - $phpcsFile->fixer->replaceToken($i, ''); - $i--; - } - - $phpcsFile->fixer->addContent($nonSpace, ';'); - $phpcsFile->fixer->replaceToken($stackPtr, ''); - - $phpcsFile->fixer->endChangeset(); - } - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php b/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php deleted file mode 100644 index 802e72a..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php +++ /dev/null @@ -1,265 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Squiz_Sniffs_WhiteSpace_SuperfluousWhitespaceSniff. - * - * Checks that no whitespace preceeds the first content of the file, exists - * after the last content of the file, resides after content on any line, or - * are two empty lines in functions. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Squiz_Sniffs_WhiteSpace_SuperfluousWhitespaceSniff implements PHP_CodeSniffer_Sniff -{ - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - 'CSS', - ); - - /** - * If TRUE, whitespace rules are not checked for blank lines. - * - * Blank lines are those that contain only whitespace. - * - * @var boolean - */ - public $ignoreBlankLines = false; - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_OPEN_TAG, - T_CLOSE_TAG, - T_WHITESPACE, - T_COMMENT, - T_DOC_COMMENT_WHITESPACE, - T_CLOSURE, - ); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[$stackPtr]['code'] === T_OPEN_TAG) { - /* - Check for start of file whitespace. - */ - - if ($phpcsFile->tokenizerType !== 'PHP') { - // The first token is always the open tag inserted when tokenizsed - // and the second token is always the first piece of content in - // the file. If the second token is whitespace, there was - // whitespace at the start of the file. - if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { - return; - } - - if ($phpcsFile->fixer->enabled === true) { - $stackPtr = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - } - } else { - // If it's the first token, then there is no space. - if ($stackPtr === 0) { - return; - } - - for ($i = ($stackPtr - 1); $i >= 0; $i--) { - // If we find something that isn't inline html then there is something previous in the file. - if ($tokens[$i]['type'] !== 'T_INLINE_HTML') { - return; - } - - // If we have ended up with inline html make sure it isn't just whitespace. - $tokenContent = trim($tokens[$i]['content']); - if ($tokenContent !== '') { - return; - } - } - }//end if - - $fix = $phpcsFile->addFixableError('Additional whitespace found at start of file', $stackPtr, 'StartFile'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = 0; $i < $stackPtr; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - } else if ($tokens[$stackPtr]['code'] === T_CLOSE_TAG) { - /* - Check for end of file whitespace. - */ - - if ($phpcsFile->tokenizerType === 'PHP') { - if (isset($tokens[($stackPtr + 1)]) === false) { - // The close PHP token is the last in the file. - return; - } - - for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) { - // If we find something that isn't inline HTML then there - // is more to the file. - if ($tokens[$i]['type'] !== 'T_INLINE_HTML') { - return; - } - - // If we have ended up with inline html make sure it - // isn't just whitespace. - $tokenContent = trim($tokens[$i]['content']); - if (empty($tokenContent) === false) { - return; - } - } - } else { - // The last token is always the close tag inserted when tokenized - // and the second last token is always the last piece of content in - // the file. If the second last token is whitespace, there was - // whitespace at the end of the file. - $stackPtr--; - - // The pointer is now looking at the last content in the file and - // not the fake PHP end tag the tokenizer inserted. - if ($tokens[$stackPtr]['code'] !== T_WHITESPACE) { - return; - } - - // Allow a single newline at the end of the last line in the file. - if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE - && $tokens[$stackPtr]['content'] === $phpcsFile->eolChar - ) { - return; - } - - if ($phpcsFile->fixer->enabled === true) { - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); - $stackPtr = ($prev + 1); - } - }//end if - - $fix = $phpcsFile->addFixableError('Additional whitespace found at end of file', $stackPtr, 'EndFile'); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->endChangeset(); - } - } else { - /* - Check for end of line whitespace. - */ - - // Ignore whitespace that is not at the end of a line. - if (isset($tokens[($stackPtr + 1)]['line']) === true - && $tokens[($stackPtr + 1)]['line'] === $tokens[$stackPtr]['line'] - ) { - return; - } - - // Ignore blank lines if required. - if ($this->ignoreBlankLines === true - && $tokens[($stackPtr - 1)]['line'] !== $tokens[$stackPtr]['line'] - ) { - return; - } - - $tokenContent = rtrim($tokens[$stackPtr]['content'], $phpcsFile->eolChar); - if (empty($tokenContent) === false) { - if ($tokenContent !== rtrim($tokenContent)) { - $fix = $phpcsFile->addFixableError('Whitespace found at end of line', $stackPtr, 'EndLine'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($stackPtr, rtrim($tokenContent).$phpcsFile->eolChar); - } - } - } else if ($tokens[($stackPtr - 1)]['content'] !== rtrim($tokens[($stackPtr - 1)]['content']) - && $tokens[($stackPtr - 1)]['line'] === $tokens[$stackPtr]['line'] - ) { - $fix = $phpcsFile->addFixableError('Whitespace found at end of line', ($stackPtr - 1), 'EndLine'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($stackPtr - 1), rtrim($tokens[($stackPtr - 1)]['content'])); - } - } - - /* - Check for multiple blank lines in a function. - */ - - if (($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true - || $phpcsFile->hasCondition($stackPtr, T_CLOSURE) === true) - && $tokens[($stackPtr - 1)]['line'] < $tokens[$stackPtr]['line'] - && $tokens[($stackPtr - 2)]['line'] === $tokens[($stackPtr - 1)]['line'] - ) { - // This is an empty line and the line before this one is not - // empty, so this could be the start of a multiple empty - // line block. - $next = $phpcsFile->findNext(T_WHITESPACE, $stackPtr, null, true); - $lines = ($tokens[$next]['line'] - $tokens[$stackPtr]['line']); - if ($lines > 1) { - $error = 'Functions must not contain multiple empty lines in a row; found %s empty lines'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'EmptyLines', array($lines)); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - $i = $stackPtr; - while ($tokens[$i]['line'] !== $tokens[$next]['line']) { - $phpcsFile->fixer->replaceToken($i, ''); - $i++; - } - - $phpcsFile->fixer->addNewlineBefore($i); - $phpcsFile->fixer->endChangeset(); - } - } - }//end if - }//end if - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Squiz/ruleset.xml b/phpcs/CodeSniffer/Standards/Squiz/ruleset.xml deleted file mode 100644 index d6d47ae..0000000 --- a/phpcs/CodeSniffer/Standards/Squiz/ruleset.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - The Squiz coding standard. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - - - - - - - - - %2$s - - - - - - - - - - \ No newline at end of file diff --git a/phpcs/CodeSniffer/Standards/Zend/Docs/Debug/CodeAnalyzerStandard.xml b/phpcs/CodeSniffer/Standards/Zend/Docs/Debug/CodeAnalyzerStandard.xml deleted file mode 100644 index c462b4f..0000000 --- a/phpcs/CodeSniffer/Standards/Zend/Docs/Debug/CodeAnalyzerStandard.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - $bar + $baz; -} - ]]> - - - $bar + 2; -} - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Zend/Docs/Files/ClosingTagStandard.xml b/phpcs/CodeSniffer/Standards/Zend/Docs/Files/ClosingTagStandard.xml deleted file mode 100644 index aa60b8a..0000000 --- a/phpcs/CodeSniffer/Standards/Zend/Docs/Files/ClosingTagStandard.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - ?> - ]]> - - - diff --git a/phpcs/CodeSniffer/Standards/Zend/Docs/NamingConventions/ValidVariableNameStandard.xml b/phpcs/CodeSniffer/Standards/Zend/Docs/NamingConventions/ValidVariableNameStandard.xml deleted file mode 100644 index 5bcde4b..0000000 --- a/phpcs/CodeSniffer/Standards/Zend/Docs/NamingConventions/ValidVariableNameStandard.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - $testNumber = 1; - ]]> - - - $Test_Number = 1; - ]]> - - - - - _bar; -} - ]]> - - - - - - diff --git a/phpcs/CodeSniffer/Standards/Zend/Sniffs/Debug/CodeAnalyzerSniff.php b/phpcs/CodeSniffer/Standards/Zend/Sniffs/Debug/CodeAnalyzerSniff.php deleted file mode 100644 index 2559037..0000000 --- a/phpcs/CodeSniffer/Standards/Zend/Sniffs/Debug/CodeAnalyzerSniff.php +++ /dev/null @@ -1,107 +0,0 @@ - - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Zend_Sniffs_Debug_CodeAnalyzerSniff. - * - * Runs the Zend Code Analyzer (from Zend Studio) on the file. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Holger Kral - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Zend_Sniffs_Debug_CodeAnalyzerSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns the token types that this sniff is interested in. - * - * @return int[] - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return int - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $fileName = $phpcsFile->getFilename(); - $analyzerPath = PHP_CodeSniffer::getConfigData('zend_ca_path'); - if (is_null($analyzerPath) === true) { - return; - } - - // In the command, 2>&1 is important because the code analyzer sends its - // findings to stderr. $output normally contains only stdout, so using 2>&1 - // will pipe even stderr to stdout. - $cmd = escapeshellcmd($analyzerPath).' '.escapeshellarg($fileName).' 2>&1'; - - // There is the possibility to pass "--ide" as an option to the analyzer. - // This would result in an output format which would be easier to parse. - // The problem here is that no cleartext error messages are returnwd; only - // error-code-labels. So for a start we go for cleartext output. - $exitCode = exec($cmd, $output, $retval); - - // Variable $exitCode is the last line of $output if no error occures, on - // error it is numeric. Try to handle various error conditions and - // provide useful error reporting. - if (is_numeric($exitCode) === true && $exitCode > 0) { - if (is_array($output) === true) { - $msg = join('\n', $output); - } - - throw new PHP_CodeSniffer_Exception("Failed invoking ZendCodeAnalyzer, exitcode was [$exitCode], retval was [$retval], output was [$msg]"); - } - - if (is_array($output) === true) { - foreach ($output as $finding) { - // The first two lines of analyzer output contain - // something like this: - // > Zend Code Analyzer 1.2.2 - // > Analyzing ... - // So skip these... - $res = preg_match("/^.+\(line ([0-9]+)\):(.+)$/", $finding, $regs); - if (empty($regs) === true || $res === false) { - continue; - } - - $phpcsFile->addWarningOnLine(trim($regs[2]), $regs[1], 'ExternalTool'); - } - } - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Zend/Sniffs/Files/ClosingTagSniff.php b/phpcs/CodeSniffer/Standards/Zend/Sniffs/Files/ClosingTagSniff.php deleted file mode 100644 index 2d10c66..0000000 --- a/phpcs/CodeSniffer/Standards/Zend/Sniffs/Files/ClosingTagSniff.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Zend_Sniffs_Files_LineEndingsSniff. - * - * Checks that the file does not end with a closing tag. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Zend_Sniffs_Files_ClosingTagSniff implements PHP_CodeSniffer_Sniff -{ - - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return array(T_OPEN_TAG); - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - // Find the last non-empty token. - $tokens = $phpcsFile->getTokens(); - for ($last = ($phpcsFile->numTokens - 1); $last > 0; $last--) { - if (trim($tokens[$last]['content']) !== '') { - break; - } - } - - if ($tokens[$last]['code'] === T_CLOSE_TAG) { - $error = 'A closing tag is not permitted at the end of a PHP file'; - $fix = $phpcsFile->addFixableError($error, $last, 'NotAllowed'); - if ($fix === true) { - $phpcsFile->fixer->replaceToken($last, ''); - } - - $phpcsFile->recordMetric($stackPtr, 'PHP closing tag at EOF', 'yes'); - } else { - $phpcsFile->recordMetric($stackPtr, 'PHP closing tag at EOF', 'no'); - } - - // Ignore the rest of the file. - return ($phpcsFile->numTokens + 1); - - }//end process() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Zend/Sniffs/NamingConventions/ValidVariableNameSniff.php b/phpcs/CodeSniffer/Standards/Zend/Sniffs/NamingConventions/ValidVariableNameSniff.php deleted file mode 100644 index 03785e8..0000000 --- a/phpcs/CodeSniffer/Standards/Zend/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ /dev/null @@ -1,245 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found'); -} - -/** - * Squiz_Sniffs_NamingConventions_ValidVariableNameSniff. - * - * Checks the naming of variables and member variables. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Zend_Sniffs_NamingConventions_ValidVariableNameSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff -{ - - /** - * Tokens to ignore so that we can find a DOUBLE_COLON. - * - * @var array - */ - private $_ignore = array( - T_WHITESPACE, - T_COMMENT, - ); - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $varName = ltrim($tokens[$stackPtr]['content'], '$'); - - $phpReservedVars = array( - '_SERVER', - '_GET', - '_POST', - '_REQUEST', - '_SESSION', - '_ENV', - '_COOKIE', - '_FILES', - 'GLOBALS', - 'http_response_header', - 'HTTP_RAW_POST_DATA', - 'php_errormsg', - ); - - // If it's a php reserved var, then its ok. - if (in_array($varName, $phpReservedVars) === true) { - return; - } - - $objOperator = $phpcsFile->findNext(array(T_WHITESPACE), ($stackPtr + 1), null, true); - if ($tokens[$objOperator]['code'] === T_OBJECT_OPERATOR) { - // Check to see if we are using a variable from an object. - $var = $phpcsFile->findNext(array(T_WHITESPACE), ($objOperator + 1), null, true); - if ($tokens[$var]['code'] === T_STRING) { - // Either a var name or a function call, so check for bracket. - $bracket = $phpcsFile->findNext(array(T_WHITESPACE), ($var + 1), null, true); - - if ($tokens[$bracket]['code'] !== T_OPEN_PARENTHESIS) { - $objVarName = $tokens[$var]['content']; - - // There is no way for us to know if the var is public or private, - // so we have to ignore a leading underscore if there is one and just - // check the main part of the variable name. - $originalVarName = $objVarName; - if (substr($objVarName, 0, 1) === '_') { - $objVarName = substr($objVarName, 1); - } - - if (PHP_CodeSniffer::isCamelCaps($objVarName, false, true, false) === false) { - $error = 'Variable "%s" is not in valid camel caps format'; - $data = array($originalVarName); - $phpcsFile->addError($error, $var, 'NotCamelCaps', $data); - } else if (preg_match('|\d|', $objVarName) === 1) { - $warning = 'Variable "%s" contains numbers but this is discouraged'; - $data = array($originalVarName); - $phpcsFile->addWarning($warning, $stackPtr, 'ContainsNumbers', $data); - } - }//end if - }//end if - }//end if - - // There is no way for us to know if the var is public or private, - // so we have to ignore a leading underscore if there is one and just - // check the main part of the variable name. - $originalVarName = $varName; - if (substr($varName, 0, 1) === '_') { - $objOperator = $phpcsFile->findPrevious(array(T_WHITESPACE), ($stackPtr - 1), null, true); - if ($tokens[$objOperator]['code'] === T_DOUBLE_COLON) { - // The variable lives within a class, and is referenced like - // this: MyClass::$_variable, so we don't know its scope. - $inClass = true; - } else { - $inClass = $phpcsFile->hasCondition($stackPtr, array(T_CLASS, T_INTERFACE, T_TRAIT)); - } - - if ($inClass === true) { - $varName = substr($varName, 1); - } - } - - if (PHP_CodeSniffer::isCamelCaps($varName, false, true, false) === false) { - $error = 'Variable "%s" is not in valid camel caps format'; - $data = array($originalVarName); - $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $data); - } else if (preg_match('|\d|', $varName) === 1) { - $warning = 'Variable "%s" contains numbers but this is discouraged'; - $data = array($originalVarName); - $phpcsFile->addWarning($warning, $stackPtr, 'ContainsNumbers', $data); - } - - }//end processVariable() - - - /** - * Processes class member variables. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $varName = ltrim($tokens[$stackPtr]['content'], '$'); - $memberProps = $phpcsFile->getMemberProperties($stackPtr); - $public = ($memberProps['scope'] === 'public'); - - if ($public === true) { - if (substr($varName, 0, 1) === '_') { - $error = 'Public member variable "%s" must not contain a leading underscore'; - $data = array($varName); - $phpcsFile->addError($error, $stackPtr, 'PublicHasUnderscore', $data); - return; - } - } else { - if (substr($varName, 0, 1) !== '_') { - $scope = ucfirst($memberProps['scope']); - $error = '%s member variable "%s" must contain a leading underscore'; - $data = array( - $scope, - $varName, - ); - $phpcsFile->addError($error, $stackPtr, 'PrivateNoUnderscore', $data); - return; - } - } - - if (PHP_CodeSniffer::isCamelCaps($varName, false, $public, false) === false) { - $error = 'Member variable "%s" is not in valid camel caps format'; - $data = array($varName); - $phpcsFile->addError($error, $stackPtr, 'MemberVarNotCamelCaps', $data); - } else if (preg_match('|\d|', $varName) === 1) { - $warning = 'Member variable "%s" contains numbers but this is discouraged'; - $data = array($varName); - $phpcsFile->addWarning($warning, $stackPtr, 'MemberVarContainsNumbers', $data); - } - - }//end processMemberVar() - - - /** - * Processes the variable found within a double quoted string. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the double quoted - * string. - * - * @return void - */ - protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $phpReservedVars = array( - '_SERVER', - '_GET', - '_POST', - '_REQUEST', - '_SESSION', - '_ENV', - '_COOKIE', - '_FILES', - 'GLOBALS', - 'http_response_header', - 'HTTP_RAW_POST_DATA', - 'php_errormsg', - ); - - if (preg_match_all('|[^\\\]\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)|', $tokens[$stackPtr]['content'], $matches) !== 0) { - foreach ($matches[1] as $varName) { - // If it's a php reserved var, then its ok. - if (in_array($varName, $phpReservedVars) === true) { - continue; - } - - if (PHP_CodeSniffer::isCamelCaps($varName, false, true, false) === false) { - $error = 'Variable "%s" is not in valid camel caps format'; - $data = array($varName); - $phpcsFile->addError($error, $stackPtr, 'StringVarNotCamelCaps', $data); - } else if (preg_match('|\d|', $varName) === 1) { - $warning = 'Variable "%s" contains numbers but this is discouraged'; - $data = array($varName); - $phpcsFile->addWarning($warning, $stackPtr, 'StringVarContainsNumbers', $data); - } - }//end foreach - }//end if - - }//end processVariableInString() - - -}//end class diff --git a/phpcs/CodeSniffer/Standards/Zend/ruleset.xml b/phpcs/CodeSniffer/Standards/Zend/ruleset.xml deleted file mode 100644 index d303151..0000000 --- a/phpcs/CodeSniffer/Standards/Zend/ruleset.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - A coding standard based on an early Zend Framework coding standard. Note that this standard is out of date. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/phpcs/CodeSniffer/Tokenizers/CSS.php b/phpcs/CodeSniffer/Tokenizers/CSS.php deleted file mode 100644 index 8e4ba35..0000000 --- a/phpcs/CodeSniffer/Tokenizers/CSS.php +++ /dev/null @@ -1,537 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (class_exists('PHP_CodeSniffer_Tokenizers_PHP', true) === false) { - throw new Exception('Class PHP_CodeSniffer_Tokenizers_PHP not found'); -} - -/** - * Tokenizes CSS code. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Tokenizers_CSS extends PHP_CodeSniffer_Tokenizers_PHP -{ - - /** - * If TRUE, files that appear to be minified will not be processed. - * - * @var boolean - */ - public $skipMinified = true; - - - /** - * Creates an array of tokens when given some CSS code. - * - * Uses the PHP tokenizer to do all the tricky work - * - * @param string $string The string to tokenize. - * @param string $eolChar The EOL character to use for splitting strings. - * - * @return array - */ - public function tokenizeString($string, $eolChar='\n') - { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** START CSS TOKENIZING 1ST PASS ***".PHP_EOL; - } - - // If the content doesn't have an EOL char on the end, add one so - // the open and close tags we add are parsed correctly. - $eolAdded = false; - if (substr($string, (strlen($eolChar) * -1)) !== $eolChar) { - $string .= $eolChar; - $eolAdded = true; - } - - $string = str_replace('', '^PHPCS_CSS_T_CLOSE_TAG^', $string); - $tokens = parent::tokenizeString('', $eolChar); - - $finalTokens = array(); - $finalTokens[0] = array( - 'code' => T_OPEN_TAG, - 'type' => 'T_OPEN_TAG', - 'content' => '', - ); - - $newStackPtr = 1; - $numTokens = count($tokens); - $multiLineComment = false; - for ($stackPtr = 1; $stackPtr < $numTokens; $stackPtr++) { - $token = $tokens[$stackPtr]; - - // CSS files don't have lists, breaks etc, so convert these to - // standard strings early so they can be converted into T_STYLE - // tokens and joined with other strings if needed. - if ($token['code'] === T_BREAK - || $token['code'] === T_LIST - || $token['code'] === T_DEFAULT - || $token['code'] === T_SWITCH - || $token['code'] === T_FOR - || $token['code'] === T_FOREACH - || $token['code'] === T_WHILE - || $token['code'] === T_DEC - ) { - $token['type'] = 'T_STRING'; - $token['code'] = T_STRING; - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $token['type']; - $content = PHP_CodeSniffer::prepareForOutput($token['content']); - echo "\tProcess token $stackPtr: $type => $content".PHP_EOL; - } - - if ($token['code'] === T_BITWISE_XOR - && $tokens[($stackPtr + 1)]['content'] === 'PHPCS_CSS_T_OPEN_TAG' - ) { - $content = ''; - $stackPtr += 2; - break; - } else { - $content .= $tokens[$stackPtr]['content']; - } - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t=> Found embedded PHP code: "; - $cleanContent = PHP_CodeSniffer::prepareForOutput($content); - echo $cleanContent.PHP_EOL; - } - - $finalTokens[$newStackPtr] = array( - 'type' => 'T_EMBEDDED_PHP', - 'code' => T_EMBEDDED_PHP, - 'content' => $content, - ); - - $newStackPtr++; - continue; - }//end if - - if ($token['code'] === T_GOTO_LABEL) { - // Convert these back to T_STRING followed by T_COLON so we can - // more easily process style definitions. - $finalTokens[$newStackPtr] = array( - 'type' => 'T_STRING', - 'code' => T_STRING, - 'content' => substr($token['content'], 0, -1), - ); - $newStackPtr++; - $finalTokens[$newStackPtr] = array( - 'type' => 'T_COLON', - 'code' => T_COLON, - 'content' => ':', - ); - $newStackPtr++; - continue; - } - - if ($token['code'] === T_FUNCTION) { - // There are no functions in CSS, so convert this to a string. - $finalTokens[$newStackPtr] = array( - 'type' => 'T_STRING', - 'code' => T_STRING, - 'content' => $token['content'], - ); - - $newStackPtr++; - continue; - } - - if ($token['code'] === T_COMMENT - && substr($token['content'], 0, 2) === '/*' - ) { - // Multi-line comment. Record it so we can ignore other - // comment tags until we get out of this one. - $multiLineComment = true; - } - - if ($token['code'] === T_COMMENT - && $multiLineComment === false - && (substr($token['content'], 0, 2) === '//' - || $token['content']{0} === '#') - ) { - $content = ltrim($token['content'], '#/'); - - // Guard against PHP7+ syntax errors by stripping - // leading zeros so the content doesn't look like an invalid int. - $leadingZero = false; - if ($content{0} === '0') { - $content = '1'.$content; - $leadingZero = true; - } - - $commentTokens = parent::tokenizeString('', $eolChar); - - // The first and last tokens are the open/close tags. - array_shift($commentTokens); - array_pop($commentTokens); - - if ($leadingZero === true) { - $commentTokens[0]['content'] = substr($commentTokens[0]['content'], 1); - $content = substr($content, 1); - } - - if ($token['content']{0} === '#') { - // The # character is not a comment in CSS files, so - // determine what it means in this context. - $firstContent = $commentTokens[0]['content']; - - // If the first content is just a number, it is probably a - // colour like 8FB7DB, which PHP splits into 8 and FB7DB. - if (($commentTokens[0]['code'] === T_LNUMBER - || $commentTokens[0]['code'] === T_DNUMBER) - && $commentTokens[1]['code'] === T_STRING - ) { - $firstContent .= $commentTokens[1]['content']; - array_shift($commentTokens); - } - - // If the first content looks like a colour and not a class - // definition, join the tokens together. - if (preg_match('/^[ABCDEF0-9]+$/i', $firstContent) === 1 - && $commentTokens[1]['content'] !== '-' - ) { - array_shift($commentTokens); - // Work out what we trimmed off above and remember to re-add it. - $trimmed = substr($token['content'], 0, (strlen($token['content']) - strlen($content))); - $finalTokens[$newStackPtr] = array( - 'type' => 'T_COLOUR', - 'code' => T_COLOUR, - 'content' => $trimmed.$firstContent, - ); - } else { - $finalTokens[$newStackPtr] = array( - 'type' => 'T_HASH', - 'code' => T_HASH, - 'content' => '#', - ); - } - } else { - $finalTokens[$newStackPtr] = array( - 'type' => 'T_STRING', - 'code' => T_STRING, - 'content' => '//', - ); - }//end if - - $newStackPtr++; - - array_splice($tokens, $stackPtr, 1, $commentTokens); - $numTokens = count($tokens); - $stackPtr--; - continue; - }//end if - - if ($token['code'] === T_COMMENT - && substr($token['content'], -2) === '*/' - ) { - // Multi-line comment is done. - $multiLineComment = false; - } - - $finalTokens[$newStackPtr] = $token; - $newStackPtr++; - }//end for - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** END CSS TOKENIZING 1ST PASS ***".PHP_EOL; - echo "\t*** START CSS TOKENIZING 2ND PASS ***".PHP_EOL; - } - - // A flag to indicate if we are inside a style definition, - // which is defined using curly braces. - $inStyleDef = false; - - // A flag to indicate if an At-rule like "@media" is used, which will result - // in nested curly brackets. - $asperandStart = false; - - $numTokens = count($finalTokens); - for ($stackPtr = 0; $stackPtr < $numTokens; $stackPtr++) { - $token = $finalTokens[$stackPtr]; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $token['type']; - $content = PHP_CodeSniffer::prepareForOutput($token['content']); - echo "\tProcess token $stackPtr: $type => $content".PHP_EOL; - } - - switch ($token['code']) { - case T_OPEN_CURLY_BRACKET: - // Opening curly brackets for an At-rule do not start a style - // definition. We also reset the asperand flag here because the next - // opening curly bracket could be indeed the start of a style - // definition. - if ($asperandStart === true) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - if ($inStyleDef === true) { - echo "\t\t* style definition closed *".PHP_EOL; - } - - if ($asperandStart === true) { - echo "\t\t* at-rule definition closed *".PHP_EOL; - } - } - - $inStyleDef = false; - $asperandStart = false; - } else { - $inStyleDef = true; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* style definition opened *".PHP_EOL; - } - } - break; - case T_CLOSE_CURLY_BRACKET: - if (PHP_CODESNIFFER_VERBOSITY > 1) { - if ($inStyleDef === true) { - echo "\t\t* style definition closed *".PHP_EOL; - } - - if ($asperandStart === true) { - echo "\t\t* at-rule definition closed *".PHP_EOL; - } - } - - $inStyleDef = false; - $asperandStart = false; - break; - case T_MINUS: - // Minus signs are often used instead of spaces inside - // class names, IDs and styles. - if ($finalTokens[($stackPtr + 1)]['code'] === T_STRING) { - if ($finalTokens[($stackPtr - 1)]['code'] === T_STRING) { - $newContent = $finalTokens[($stackPtr - 1)]['content'].'-'.$finalTokens[($stackPtr + 1)]['content']; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* token is a string joiner; ignoring this and previous token".PHP_EOL; - $old = PHP_CodeSniffer::prepareForOutput($finalTokens[($stackPtr + 1)]['content']); - $new = PHP_CodeSniffer::prepareForOutput($newContent); - echo "\t\t=> token ".($stackPtr + 1)." content changed from \"$old\" to \"$new\"".PHP_EOL; - } - - $finalTokens[($stackPtr + 1)]['content'] = $newContent; - unset($finalTokens[$stackPtr]); - unset($finalTokens[($stackPtr - 1)]); - } else { - $newContent = '-'.$finalTokens[($stackPtr + 1)]['content']; - - $finalTokens[($stackPtr + 1)]['content'] = $newContent; - unset($finalTokens[$stackPtr]); - } - } else if ($finalTokens[($stackPtr + 1)]['code'] === T_LNUMBER) { - // They can also be used to provide negative numbers. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* token is part of a negative number; adding content to next token and ignoring *".PHP_EOL; - $content = PHP_CodeSniffer::prepareForOutput($finalTokens[($stackPtr + 1)]['content']); - echo "\t\t=> token ".($stackPtr + 1)." content changed from \"$content\" to \"-$content\"".PHP_EOL; - } - - $finalTokens[($stackPtr + 1)]['content'] = '-'.$finalTokens[($stackPtr + 1)]['content']; - unset($finalTokens[$stackPtr]); - }//end if - - break; - case T_COLON: - // Only interested in colons that are defining styles. - if ($inStyleDef === false) { - break; - } - - for ($x = ($stackPtr - 1); $x >= 0; $x--) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$finalTokens[$x]['code']]) === false) { - break; - } - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $finalTokens[$x]['type']; - echo "\t\t=> token $x changed from $type to T_STYLE".PHP_EOL; - } - - $finalTokens[$x]['type'] = 'T_STYLE'; - $finalTokens[$x]['code'] = T_STYLE; - break; - case T_STRING: - if (strtolower($token['content']) === 'url') { - // Find the next content. - for ($x = ($stackPtr + 1); $x < $numTokens; $x++) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$finalTokens[$x]['code']]) === false) { - break; - } - } - - // Needs to be in the format "url(" for it to be a URL. - if ($finalTokens[$x]['code'] !== T_OPEN_PARENTHESIS) { - continue; - } - - // Make sure the content isn't empty. - for ($y = ($x + 1); $y < $numTokens; $y++) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$finalTokens[$y]['code']]) === false) { - break; - } - } - - if ($finalTokens[$y]['code'] === T_CLOSE_PARENTHESIS) { - continue; - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - for ($i = ($stackPtr + 1); $i <= $y; $i++) { - $type = $finalTokens[$i]['type']; - $content = PHP_CodeSniffer::prepareForOutput($finalTokens[$i]['content']); - echo "\tProcess token $i: $type => $content".PHP_EOL; - } - - echo "\t\t* token starts a URL *".PHP_EOL; - } - - // Join all the content together inside the url() statement. - $newContent = ''; - for ($i = ($x + 2); $i < $numTokens; $i++) { - if ($finalTokens[$i]['code'] === T_CLOSE_PARENTHESIS) { - break; - } - - $newContent .= $finalTokens[$i]['content']; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput($finalTokens[$i]['content']); - echo "\t\t=> token $i added to URL string and ignored: $content".PHP_EOL; - } - - unset($finalTokens[$i]); - } - - $stackPtr = $i; - - // If the content inside the "url()" is in double quotes - // there will only be one token and so we don't have to do - // anything except change its type. If it is not empty, - // we need to do some token merging. - $finalTokens[($x + 1)]['type'] = 'T_URL'; - $finalTokens[($x + 1)]['code'] = T_URL; - - if ($newContent !== '') { - $finalTokens[($x + 1)]['content'] .= $newContent; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput($finalTokens[($x + 1)]['content']); - echo "\t\t=> token content changed to: $content".PHP_EOL; - } - } - } else if ($finalTokens[$stackPtr]['content'][0] === '-' - && $finalTokens[($stackPtr + 1)]['code'] === T_STRING - ) { - if (isset($finalTokens[($stackPtr - 1)]) === true - && $finalTokens[($stackPtr - 1)]['code'] === T_STRING - ) { - $newContent = $finalTokens[($stackPtr - 1)]['content'].$finalTokens[$stackPtr]['content'].$finalTokens[($stackPtr + 1)]['content']; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* token is a string joiner; ignoring this and previous token".PHP_EOL; - $old = PHP_CodeSniffer::prepareForOutput($finalTokens[($stackPtr + 1)]['content']); - $new = PHP_CodeSniffer::prepareForOutput($newContent); - echo "\t\t=> token ".($stackPtr + 1)." content changed from \"$old\" to \"$new\"".PHP_EOL; - } - - $finalTokens[($stackPtr + 1)]['content'] = $newContent; - unset($finalTokens[$stackPtr]); - unset($finalTokens[($stackPtr - 1)]); - } else { - $newContent = $finalTokens[$stackPtr]['content'].$finalTokens[($stackPtr + 1)]['content']; - - $finalTokens[($stackPtr + 1)]['content'] = $newContent; - unset($finalTokens[$stackPtr]); - } - }//end if - - break; - case T_ASPERAND: - $asperandStart = true; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* at-rule definition opened *".PHP_EOL; - } - break; - default: - // Nothing special to be done with this token. - break; - }//end switch - }//end for - - // Reset the array keys to avoid gaps. - $finalTokens = array_values($finalTokens); - $numTokens = count($finalTokens); - - // Blank out the content of the end tag. - $finalTokens[($numTokens - 1)]['content'] = ''; - - if ($eolAdded === true) { - // Strip off the extra EOL char we added for tokenizing. - $finalTokens[($numTokens - 2)]['content'] = substr( - $finalTokens[($numTokens - 2)]['content'], - 0, - (strlen($eolChar) * -1) - ); - - if ($finalTokens[($numTokens - 2)]['content'] === '') { - unset($finalTokens[($numTokens - 2)]); - $finalTokens = array_values($finalTokens); - $numTokens = count($finalTokens); - } - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** END CSS TOKENIZING 2ND PASS ***".PHP_EOL; - } - - return $finalTokens; - - }//end tokenizeString() - - - /** - * Performs additional processing after main tokenizing. - * - * @param array $tokens The array of tokens to process. - * @param string $eolChar The EOL character to use for splitting strings. - * - * @return void - */ - public function processAdditional(&$tokens, $eolChar) - { - /* - We override this method because we don't want the PHP version to - run during CSS processing because it is wasted processing time. - */ - - }//end processAdditional() - - -}//end class diff --git a/phpcs/CodeSniffer/Tokenizers/Comment.php b/phpcs/CodeSniffer/Tokenizers/Comment.php deleted file mode 100644 index 88885bd..0000000 --- a/phpcs/CodeSniffer/Tokenizers/Comment.php +++ /dev/null @@ -1,287 +0,0 @@ - - * @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Tokenizes doc block comments. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Tokenizers_Comment -{ - - - /** - * Creates an array of tokens when given some PHP code. - * - * Starts by using token_get_all() but does a lot of extra processing - * to insert information about the context of the token. - * - * @param string $string The string to tokenize. - * @param string $eolChar The EOL character to use for splitting strings. - * @param int $stackPtr The position of the first token in the file. - * - * @return array - */ - public function tokenizeString($string, $eolChar, $stackPtr) - { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t*** START COMMENT TOKENIZING ***".PHP_EOL; - } - - $tokens = array(); - $numChars = strlen($string); - - /* - Doc block comments start with /*, but typically contain an - extra star when they are used for function and class comments. - */ - - $char = ($numChars - strlen(ltrim($string, '/*'))); - $openTag = substr($string, 0, $char); - $string = ltrim($string, '/*'); - - $tokens[$stackPtr] = array( - 'content' => $openTag, - 'code' => T_DOC_COMMENT_OPEN_TAG, - 'type' => 'T_DOC_COMMENT_OPEN_TAG', - 'comment_tags' => array(), - ); - - $openPtr = $stackPtr; - $stackPtr++; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput($openTag); - echo "\t\tCreate comment token: T_DOC_COMMENT_OPEN_TAG => $content".PHP_EOL; - } - - /* - Strip off the close tag so it doesn't interfere with any - of our comment line processing. The token will be added to the - stack just before we return it. - */ - - $closeTag = array( - 'content' => substr($string, strlen(rtrim($string, '/*'))), - 'code' => T_DOC_COMMENT_CLOSE_TAG, - 'type' => 'T_DOC_COMMENT_CLOSE_TAG', - 'comment_opener' => $openPtr, - ); - - if ($closeTag['content'] === false) { - $closeTag['content'] = ''; - } - - $string = rtrim($string, '/*'); - - /* - Process each line of the comment. - */ - - $lines = explode($eolChar, $string); - $numLines = count($lines); - foreach ($lines as $lineNum => $string) { - if ($lineNum !== ($numLines - 1)) { - $string .= $eolChar; - } - - $char = 0; - $numChars = strlen($string); - - // We've started a new line, so process the indent. - $space = $this->_collectWhitespace($string, $char, $numChars); - if ($space !== null) { - $tokens[$stackPtr] = $space; - $stackPtr++; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput($space['content']); - echo "\t\tCreate comment token: T_DOC_COMMENT_WHITESPACE => $content".PHP_EOL; - } - - $char += strlen($space['content']); - if ($char === $numChars) { - break; - } - } - - if ($string === '') { - continue; - } - - if ($string[$char] === '*') { - // This is a function or class doc block line. - $char++; - $tokens[$stackPtr] = array( - 'content' => '*', - 'code' => T_DOC_COMMENT_STAR, - 'type' => 'T_DOC_COMMENT_STAR', - ); - - $stackPtr++; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\tCreate comment token: T_DOC_COMMENT_STAR => *".PHP_EOL; - } - } - - // Now we are ready to process the actual content of the line. - $lineTokens = $this->_processLine($string, $eolChar, $char, $numChars); - foreach ($lineTokens as $lineToken) { - $tokens[$stackPtr] = $lineToken; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput($lineToken['content']); - $type = $lineToken['type']; - echo "\t\tCreate comment token: $type => $content".PHP_EOL; - } - - if ($lineToken['code'] === T_DOC_COMMENT_TAG) { - $tokens[$openPtr]['comment_tags'][] = $stackPtr; - } - - $stackPtr++; - } - }//end foreach - - $tokens[$stackPtr] = $closeTag; - $tokens[$openPtr]['comment_closer'] = $stackPtr; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput($closeTag['content']); - echo "\t\tCreate comment token: T_DOC_COMMENT_CLOSE_TAG => $content".PHP_EOL; - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t*** END COMMENT TOKENIZING ***".PHP_EOL; - } - - return $tokens; - - }//end tokenizeString() - - - /** - * Process a single line of a comment. - * - * @param string $string The comment string being tokenized. - * @param string $eolChar The EOL character to use for splitting strings. - * @param int $start The position in the string to start processing. - * @param int $end The position in the string to end processing. - * - * @return array - */ - private function _processLine($string, $eolChar, $start, $end) - { - $tokens = array(); - - // Collect content padding. - $space = $this->_collectWhitespace($string, $start, $end); - if ($space !== null) { - $tokens[] = $space; - $start += strlen($space['content']); - } - - if (isset($string[$start]) === false) { - return $tokens; - } - - if ($string[$start] === '@') { - // The content up until the first whitespace is the tag name. - $matches = array(); - preg_match('/@[^\s]+/', $string, $matches, 0, $start); - if (isset($matches[0]) === true) { - $tagName = $matches[0]; - $start += strlen($tagName); - $tokens[] = array( - 'content' => $tagName, - 'code' => T_DOC_COMMENT_TAG, - 'type' => 'T_DOC_COMMENT_TAG', - ); - - // Then there will be some whitespace. - $space = $this->_collectWhitespace($string, $start, $end); - if ($space !== null) { - $tokens[] = $space; - $start += strlen($space['content']); - } - } - }//end if - - // Process the rest of the line. - $eol = strpos($string, $eolChar, $start); - if ($eol === false) { - $eol = $end; - } - - if ($eol > $start) { - $tokens[] = array( - 'content' => substr($string, $start, ($eol - $start)), - 'code' => T_DOC_COMMENT_STRING, - 'type' => 'T_DOC_COMMENT_STRING', - ); - } - - if ($eol !== $end) { - $tokens[] = array( - 'content' => substr($string, $eol, strlen($eolChar)), - 'code' => T_DOC_COMMENT_WHITESPACE, - 'type' => 'T_DOC_COMMENT_WHITESPACE', - ); - } - - return $tokens; - - }//end _processLine() - - - /** - * Collect consecutive whitespace into a single token. - * - * @param string $string The comment string being tokenized. - * @param int $start The position in the string to start processing. - * @param int $end The position in the string to end processing. - * - * @return array|null - */ - private function _collectWhitespace($string, $start, $end) - { - $space = ''; - for ($start; $start < $end; $start++) { - if ($string[$start] !== ' ' && $string[$start] !== "\t") { - break; - } - - $space .= $string[$start]; - } - - if ($space === '') { - return null; - } - - $token = array( - 'content' => $space, - 'code' => T_DOC_COMMENT_WHITESPACE, - 'type' => 'T_DOC_COMMENT_WHITESPACE', - ); - - return $token; - - }//end _collectWhitespace() - - -}//end class diff --git a/phpcs/CodeSniffer/Tokenizers/JS.php b/phpcs/CodeSniffer/Tokenizers/JS.php deleted file mode 100644 index 1dc82e4..0000000 --- a/phpcs/CodeSniffer/Tokenizers/JS.php +++ /dev/null @@ -1,1179 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Tokenizes JS code. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Tokenizers_JS -{ - - /** - * If TRUE, files that appear to be minified will not be processed. - * - * @var boolean - */ - public $skipMinified = true; - - /** - * A list of tokens that are allowed to open a scope. - * - * This array also contains information about what kind of token the scope - * opener uses to open and close the scope, if the token strictly requires - * an opener, if the token can share a scope closer, and who it can be shared - * with. An example of a token that shares a scope closer is a CASE scope. - * - * @var array - */ - public $scopeOpeners = array( - T_IF => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => false, - 'shared' => false, - 'with' => array(), - ), - T_TRY => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => true, - 'shared' => false, - 'with' => array(), - ), - T_CATCH => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => true, - 'shared' => false, - 'with' => array(), - ), - T_ELSE => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => false, - 'shared' => false, - 'with' => array(), - ), - T_FOR => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => false, - 'shared' => false, - 'with' => array(), - ), - T_FUNCTION => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => false, - 'shared' => false, - 'with' => array(), - ), - T_WHILE => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => false, - 'shared' => false, - 'with' => array(), - ), - T_DO => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => true, - 'shared' => false, - 'with' => array(), - ), - T_SWITCH => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => true, - 'shared' => false, - 'with' => array(), - ), - T_CASE => array( - 'start' => array(T_COLON => T_COLON), - 'end' => array( - T_BREAK => T_BREAK, - T_RETURN => T_RETURN, - T_CONTINUE => T_CONTINUE, - T_THROW => T_THROW, - ), - 'strict' => true, - 'shared' => true, - 'with' => array( - T_DEFAULT => T_DEFAULT, - T_CASE => T_CASE, - T_SWITCH => T_SWITCH, - ), - ), - T_DEFAULT => array( - 'start' => array(T_COLON => T_COLON), - 'end' => array( - T_BREAK => T_BREAK, - T_RETURN => T_RETURN, - T_CONTINUE => T_CONTINUE, - T_THROW => T_THROW, - ), - 'strict' => true, - 'shared' => true, - 'with' => array( - T_CASE => T_CASE, - T_SWITCH => T_SWITCH, - ), - ), - ); - - /** - * A list of tokens that end the scope. - * - * This array is just a unique collection of the end tokens - * from the _scopeOpeners array. The data is duplicated here to - * save time during parsing of the file. - * - * @var array - */ - public $endScopeTokens = array( - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, - T_BREAK => T_BREAK, - ); - - /** - * A list of special JS tokens and their types. - * - * @var array - */ - protected $tokenValues = array( - 'function' => 'T_FUNCTION', - 'prototype' => 'T_PROTOTYPE', - 'try' => 'T_TRY', - 'catch' => 'T_CATCH', - 'return' => 'T_RETURN', - 'throw' => 'T_THROW', - 'break' => 'T_BREAK', - 'switch' => 'T_SWITCH', - 'continue' => 'T_CONTINUE', - 'if' => 'T_IF', - 'else' => 'T_ELSE', - 'do' => 'T_DO', - 'while' => 'T_WHILE', - 'for' => 'T_FOR', - 'var' => 'T_VAR', - 'case' => 'T_CASE', - 'default' => 'T_DEFAULT', - 'true' => 'T_TRUE', - 'false' => 'T_FALSE', - 'null' => 'T_NULL', - 'this' => 'T_THIS', - 'typeof' => 'T_TYPEOF', - '(' => 'T_OPEN_PARENTHESIS', - ')' => 'T_CLOSE_PARENTHESIS', - '{' => 'T_OPEN_CURLY_BRACKET', - '}' => 'T_CLOSE_CURLY_BRACKET', - '[' => 'T_OPEN_SQUARE_BRACKET', - ']' => 'T_CLOSE_SQUARE_BRACKET', - '?' => 'T_INLINE_THEN', - '.' => 'T_OBJECT_OPERATOR', - '+' => 'T_PLUS', - '-' => 'T_MINUS', - '*' => 'T_MULTIPLY', - '%' => 'T_MODULUS', - '/' => 'T_DIVIDE', - '^' => 'T_LOGICAL_XOR', - ',' => 'T_COMMA', - ';' => 'T_SEMICOLON', - ':' => 'T_COLON', - '<' => 'T_LESS_THAN', - '>' => 'T_GREATER_THAN', - '<<' => 'T_SL', - '>>' => 'T_SR', - '>>>' => 'T_ZSR', - '<<=' => 'T_SL_EQUAL', - '>>=' => 'T_SR_EQUAL', - '>>>=' => 'T_ZSR_EQUAL', - '<=' => 'T_IS_SMALLER_OR_EQUAL', - '>=' => 'T_IS_GREATER_OR_EQUAL', - '=>' => 'T_DOUBLE_ARROW', - '!' => 'T_BOOLEAN_NOT', - '||' => 'T_BOOLEAN_OR', - '&&' => 'T_BOOLEAN_AND', - '|' => 'T_BITWISE_OR', - '&' => 'T_BITWISE_AND', - '!=' => 'T_IS_NOT_EQUAL', - '!==' => 'T_IS_NOT_IDENTICAL', - '=' => 'T_EQUAL', - '==' => 'T_IS_EQUAL', - '===' => 'T_IS_IDENTICAL', - '-=' => 'T_MINUS_EQUAL', - '+=' => 'T_PLUS_EQUAL', - '*=' => 'T_MUL_EQUAL', - '/=' => 'T_DIV_EQUAL', - '%=' => 'T_MOD_EQUAL', - '++' => 'T_INC', - '--' => 'T_DEC', - '//' => 'T_COMMENT', - '/*' => 'T_COMMENT', - '/**' => 'T_DOC_COMMENT', - '*/' => 'T_COMMENT', - ); - - /** - * A list string delimiters. - * - * @var array - */ - protected $stringTokens = array( - '\'' => '\'', - '"' => '"', - ); - - /** - * A list tokens that start and end comments. - * - * @var array - */ - protected $commentTokens = array( - '//' => null, - '/*' => '*/', - '/**' => '*/', - ); - - - /** - * Creates an array of tokens when given some JS code. - * - * @param string $string The string to tokenize. - * @param string $eolChar The EOL character to use for splitting strings. - * - * @return array - */ - public function tokenizeString($string, $eolChar='\n') - { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** START JS TOKENIZING ***".PHP_EOL; - } - - $maxTokenLength = 0; - foreach ($this->tokenValues as $token => $values) { - if (strlen($token) > $maxTokenLength) { - $maxTokenLength = strlen($token); - } - } - - $tokens = array(); - $inString = ''; - $stringChar = null; - $inComment = ''; - $buffer = ''; - $preStringBuffer = ''; - $cleanBuffer = false; - - $commentTokenizer = new PHP_CodeSniffer_Tokenizers_Comment(); - - $tokens[] = array( - 'code' => T_OPEN_TAG, - 'type' => 'T_OPEN_TAG', - 'content' => '', - ); - - // Convert newlines to single characters for ease of - // processing. We will change them back later. - $string = str_replace($eolChar, "\n", $string); - - $chars = str_split($string); - $numChars = count($chars); - for ($i = 0; $i < $numChars; $i++) { - $char = $chars[$i]; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput($char); - $bufferContent = PHP_CodeSniffer::prepareForOutput($buffer); - - if ($inString !== '') { - echo "\t"; - } - - if ($inComment !== '') { - echo "\t"; - } - - echo "\tProcess char $i => $content (buffer: $bufferContent)".PHP_EOL; - }//end if - - if ($inString === '' && $inComment === '' && $buffer !== '') { - // If the buffer only has whitespace and we are about to - // add a character, store the whitespace first. - if (trim($char) !== '' && trim($buffer) === '') { - $tokens[] = array( - 'code' => T_WHITESPACE, - 'type' => 'T_WHITESPACE', - 'content' => str_replace("\n", $eolChar, $buffer), - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput($buffer); - echo "\t=> Added token T_WHITESPACE ($content)".PHP_EOL; - } - - $buffer = ''; - } - - // If the buffer is not whitespace and we are about to - // add a whitespace character, store the content first. - if ($inString === '' - && $inComment === '' - && trim($char) === '' - && trim($buffer) !== '' - ) { - $tokens[] = array( - 'code' => T_STRING, - 'type' => 'T_STRING', - 'content' => str_replace("\n", $eolChar, $buffer), - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput($buffer); - echo "\t=> Added token T_STRING ($content)".PHP_EOL; - } - - $buffer = ''; - } - }//end if - - // Process strings. - if ($inComment === '' && isset($this->stringTokens[$char]) === true) { - if ($inString === $char) { - // This could be the end of the string, but make sure it - // is not escaped first. - $escapes = 0; - for ($x = ($i - 1); $x >= 0; $x--) { - if ($chars[$x] !== '\\') { - break; - } - - $escapes++; - } - - if ($escapes === 0 || ($escapes % 2) === 0) { - // There is an even number escape chars, - // so this is not escaped, it is the end of the string. - $tokens[] = array( - 'code' => T_CONSTANT_ENCAPSED_STRING, - 'type' => 'T_CONSTANT_ENCAPSED_STRING', - 'content' => str_replace("\n", $eolChar, $buffer).$char, - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* found end of string *".PHP_EOL; - $content = PHP_CodeSniffer::prepareForOutput($buffer.$char); - echo "\t=> Added token T_CONSTANT_ENCAPSED_STRING ($content)".PHP_EOL; - } - - $buffer = ''; - $preStringBuffer = ''; - $inString = ''; - $stringChar = null; - continue; - }//end if - } else if ($inString === '') { - $inString = $char; - $stringChar = $i; - $preStringBuffer = $buffer; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* looking for string closer *".PHP_EOL; - } - }//end if - }//end if - - if ($inString !== '' && $char === "\n") { - // Unless this newline character is escaped, the string did not - // end before the end of the line, which means it probably - // wasn't a string at all (maybe a regex). - if ($chars[($i - 1)] !== '\\') { - $i = $stringChar; - $buffer = $preStringBuffer; - $preStringBuffer = ''; - $inString = ''; - $stringChar = null; - $char = $chars[$i]; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* found newline before end of string, bailing *".PHP_EOL; - } - } - } - - $buffer .= $char; - - // We don't look for special tokens inside strings, - // so if we are in a string, we can continue here now - // that the current char is in the buffer. - if ($inString !== '') { - continue; - } - - // Special case for T_DIVIDE which can actually be - // the start of a regular expression. - if ($buffer === $char && $char === '/' && $chars[($i + 1)] !== '*') { - $regex = $this->getRegexToken( - $i, - $string, - $chars, - $tokens, - $eolChar - ); - - if ($regex !== null) { - $tokens[] = array( - 'code' => T_REGULAR_EXPRESSION, - 'type' => 'T_REGULAR_EXPRESSION', - 'content' => $regex['content'], - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput($regex['content']); - echo "\t=> Added token T_REGULAR_EXPRESSION ($content)".PHP_EOL; - } - - $i = $regex['end']; - $buffer = ''; - $cleanBuffer = false; - continue; - }//end if - }//end if - - // Check for known tokens, but ignore tokens found that are not at - // the end of a string, like FOR and this.FORmat. - if (isset($this->tokenValues[strtolower($buffer)]) === true - && (preg_match('|[a-zA-z0-9_]|', $char) === 0 - || isset($chars[($i + 1)]) === false - || preg_match('|[a-zA-z0-9_]|', $chars[($i + 1)]) === 0) - ) { - $matchedToken = false; - $lookAheadLength = ($maxTokenLength - strlen($buffer)); - - if ($lookAheadLength > 0) { - // The buffer contains a token type, but we need - // to look ahead at the next chars to see if this is - // actually part of a larger token. For example, - // FOR and FOREACH. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* buffer possibly contains token, looking ahead $lookAheadLength chars *".PHP_EOL; - } - - $charBuffer = $buffer; - for ($x = 1; $x <= $lookAheadLength; $x++) { - if (isset($chars[($i + $x)]) === false) { - break; - } - - $charBuffer .= $chars[($i + $x)]; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput($charBuffer); - echo "\t\t=> Looking ahead $x chars => $content".PHP_EOL; - } - - if (isset($this->tokenValues[strtolower($charBuffer)]) === true) { - // We've found something larger that matches - // so we can ignore this char. Except for 1 very specific - // case where a comment like /**/ needs to tokenize as - // T_COMMENT and not T_DOC_COMMENT. - $oldType = $this->tokenValues[strtolower($buffer)]; - $newType = $this->tokenValues[strtolower($charBuffer)]; - if ($oldType === 'T_COMMENT' - && $newType === 'T_DOC_COMMENT' - && $chars[($i + $x + 1)] === '/' - ) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* look ahead ignored T_DOC_COMMENT, continuing *".PHP_EOL; - } - } else { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* look ahead found more specific token ($newType), ignoring $i *".PHP_EOL; - } - - $matchedToken = true; - break; - } - }//end if - }//end for - }//end if - - if ($matchedToken === false) { - if (PHP_CODESNIFFER_VERBOSITY > 1 && $lookAheadLength > 0) { - echo "\t\t* look ahead found nothing *".PHP_EOL; - } - - $value = $this->tokenValues[strtolower($buffer)]; - - if ($value === 'T_FUNCTION' && $buffer !== 'function') { - // The function keyword needs to be all lowercase or else - // it is just a function called "Function". - $value = 'T_STRING'; - } - - $tokens[] = array( - 'code' => constant($value), - 'type' => $value, - 'content' => $buffer, - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput($buffer); - echo "\t=> Added token $value ($content)".PHP_EOL; - } - - $cleanBuffer = true; - }//end if - } else if (isset($this->tokenValues[strtolower($char)]) === true) { - // No matter what token we end up using, we don't - // need the content in the buffer any more because we have - // found a valid token. - $newContent = substr(str_replace("\n", $eolChar, $buffer), 0, -1); - if ($newContent !== '') { - $tokens[] = array( - 'code' => T_STRING, - 'type' => 'T_STRING', - 'content' => $newContent, - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput(substr($buffer, 0, -1)); - echo "\t=> Added token T_STRING ($content)".PHP_EOL; - } - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* char is token, looking ahead ".($maxTokenLength - 1).' chars *'.PHP_EOL; - } - - // The char is a token type, but we need to look ahead at the - // next chars to see if this is actually part of a larger token. - // For example, = and ===. - $charBuffer = $char; - $matchedToken = false; - for ($x = 1; $x <= $maxTokenLength; $x++) { - if (isset($chars[($i + $x)]) === false) { - break; - } - - $charBuffer .= $chars[($i + $x)]; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput($charBuffer); - echo "\t\t=> Looking ahead $x chars => $content".PHP_EOL; - } - - if (isset($this->tokenValues[strtolower($charBuffer)]) === true) { - // We've found something larger that matches - // so we can ignore this char. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $this->tokenValues[strtolower($charBuffer)]; - echo "\t\t* look ahead found more specific token ($type), ignoring $i *".PHP_EOL; - } - - $matchedToken = true; - break; - } - }//end for - - if ($matchedToken === false) { - $value = $this->tokenValues[strtolower($char)]; - $tokens[] = array( - 'code' => constant($value), - 'type' => $value, - 'content' => $char, - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* look ahead found nothing *".PHP_EOL; - $content = PHP_CodeSniffer::prepareForOutput($char); - echo "\t=> Added token $value ($content)".PHP_EOL; - } - - $cleanBuffer = true; - } else { - $buffer = $char; - }//end if - }//end if - - // Keep track of content inside comments. - if ($inComment === '' - && array_key_exists($buffer, $this->commentTokens) === true - ) { - // This is not really a comment if the content - // looks like \// (i.e., it is escaped). - if (isset($chars[($i - 2)]) === true && $chars[($i - 2)] === '\\') { - $lastToken = array_pop($tokens); - $lastContent = $lastToken['content']; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $value = $this->tokenValues[strtolower($lastContent)]; - $content = PHP_CodeSniffer::prepareForOutput($lastContent); - echo "\t=> Removed token $value ($content)".PHP_EOL; - } - - $lastChars = str_split($lastContent); - $lastNumChars = count($lastChars); - for ($x = 0; $x < $lastNumChars; $x++) { - $lastChar = $lastChars[$x]; - $value = $this->tokenValues[strtolower($lastChar)]; - $tokens[] = array( - 'code' => constant($value), - 'type' => $value, - 'content' => $lastChar, - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput($lastChar); - echo "\t=> Added token $value ($content)".PHP_EOL; - } - } - } else { - // We have started a comment. - $inComment = $buffer; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* looking for end of comment *".PHP_EOL; - } - }//end if - } else if ($inComment !== '') { - if ($this->commentTokens[$inComment] === null) { - // Comment ends at the next newline. - if (strpos($buffer, "\n") !== false) { - $inComment = ''; - } - } else { - if ($this->commentTokens[$inComment] === $buffer) { - $inComment = ''; - } - } - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - if ($inComment === '') { - echo "\t\t* found end of comment *".PHP_EOL; - } - } - - if ($inComment === '' && $cleanBuffer === false) { - $tokens[] = array( - 'code' => T_STRING, - 'type' => 'T_STRING', - 'content' => str_replace("\n", $eolChar, $buffer), - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput($buffer); - echo "\t=> Added token T_STRING ($content)".PHP_EOL; - } - - $buffer = ''; - } - }//end if - - if ($cleanBuffer === true) { - $buffer = ''; - $cleanBuffer = false; - } - }//end for - - if (empty($buffer) === false) { - // Buffer contains whitespace from the end of the file. - $tokens[] = array( - 'code' => T_WHITESPACE, - 'type' => 'T_WHITESPACE', - 'content' => str_replace("\n", $eolChar, $buffer), - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $content = PHP_CodeSniffer::prepareForOutput($buffer); - echo "\t=> Added token T_WHITESPACE ($content)".PHP_EOL; - } - } - - $tokens[] = array( - 'code' => T_CLOSE_TAG, - 'type' => 'T_CLOSE_TAG', - 'content' => '', - ); - - /* - Now that we have done some basic tokenizing, we need to - modify the tokens to join some together and split some apart - so they match what the PHP tokenizer does. - */ - - $finalTokens = array(); - $newStackPtr = 0; - $numTokens = count($tokens); - for ($stackPtr = 0; $stackPtr < $numTokens; $stackPtr++) { - $token = $tokens[$stackPtr]; - - /* - Look for comments and join the tokens together. - */ - - if ($token['code'] === T_COMMENT || $token['code'] === T_DOC_COMMENT) { - $newContent = ''; - $tokenContent = $token['content']; - - $endContent = null; - if (isset($this->commentTokens[$tokenContent]) === true) { - $endContent = $this->commentTokens[$tokenContent]; - } - - while ($tokenContent !== $endContent) { - if ($endContent === null - && strpos($tokenContent, $eolChar) !== false - ) { - // A null end token means the comment ends at the end of - // the line so we look for newlines and split the token. - $tokens[$stackPtr]['content'] = substr( - $tokenContent, - (strpos($tokenContent, $eolChar) + strlen($eolChar)) - ); - - $tokenContent = substr( - $tokenContent, - 0, - (strpos($tokenContent, $eolChar) + strlen($eolChar)) - ); - - // If the substr failed, skip the token as the content - // will now be blank. - if ($tokens[$stackPtr]['content'] !== false - && $tokens[$stackPtr]['content'] !== '' - ) { - $stackPtr--; - } - - break; - }//end if - - $stackPtr++; - $newContent .= $tokenContent; - if (isset($tokens[$stackPtr]) === false) { - break; - } - - $tokenContent = $tokens[$stackPtr]['content']; - }//end while - - if ($token['code'] === T_DOC_COMMENT) { - $commentTokens = $commentTokenizer->tokenizeString($newContent.$tokenContent, $eolChar, $newStackPtr); - foreach ($commentTokens as $commentToken) { - $finalTokens[$newStackPtr] = $commentToken; - $newStackPtr++; - } - - continue; - } else { - // Save the new content in the current token so - // the code below can chop it up on newlines. - $token['content'] = $newContent.$tokenContent; - } - }//end if - - /* - If this token has newlines in its content, split each line up - and create a new token for each line. We do this so it's easier - to ascertain where errors occur on a line. - Note that $token[1] is the token's content. - */ - - if (strpos($token['content'], $eolChar) !== false) { - $tokenLines = explode($eolChar, $token['content']); - $numLines = count($tokenLines); - - for ($i = 0; $i < $numLines; $i++) { - $newToken['content'] = $tokenLines[$i]; - if ($i === ($numLines - 1)) { - if ($tokenLines[$i] === '') { - break; - } - } else { - $newToken['content'] .= $eolChar; - } - - $newToken['type'] = $token['type']; - $newToken['code'] = $token['code']; - $finalTokens[$newStackPtr] = $newToken; - $newStackPtr++; - } - } else { - $finalTokens[$newStackPtr] = $token; - $newStackPtr++; - }//end if - - // Convert numbers, including decimals. - if ($token['code'] === T_STRING - || $token['code'] === T_OBJECT_OPERATOR - ) { - $newContent = ''; - $oldStackPtr = $stackPtr; - while (preg_match('|^[0-9\.]+$|', $tokens[$stackPtr]['content']) !== 0) { - $newContent .= $tokens[$stackPtr]['content']; - $stackPtr++; - } - - if ($newContent !== '' && $newContent !== '.') { - $finalTokens[($newStackPtr - 1)]['content'] = $newContent; - if (ctype_digit($newContent) === true) { - $finalTokens[($newStackPtr - 1)]['code'] = constant('T_LNUMBER'); - $finalTokens[($newStackPtr - 1)]['type'] = 'T_LNUMBER'; - } else { - $finalTokens[($newStackPtr - 1)]['code'] = constant('T_DNUMBER'); - $finalTokens[($newStackPtr - 1)]['type'] = 'T_DNUMBER'; - } - - $stackPtr--; - continue; - } else { - $stackPtr = $oldStackPtr; - } - }//end if - - // Convert the token after an object operator into a string, in most cases. - if ($token['code'] === T_OBJECT_OPERATOR) { - for ($i = ($stackPtr + 1); $i < $numTokens; $i++) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$i]['code']]) === true) { - continue; - } - - if ($tokens[$i]['code'] !== T_PROTOTYPE - && $tokens[$i]['code'] !== T_LNUMBER - && $tokens[$i]['code'] !== T_DNUMBER - ) { - $tokens[$i]['code'] = T_STRING; - $tokens[$i]['type'] = 'T_STRING'; - } - - break; - } - } - }//end for - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** END TOKENIZING ***".PHP_EOL; - } - - return $finalTokens; - - }//end tokenizeString() - - - /** - * Tokenizes a regular expression if one is found. - * - * If a regular expression is not found, NULL is returned. - * - * @param string $char The index of the possible regex start character. - * @param string $string The complete content of the string being tokenized. - * @param string $chars An array of characters being tokenized. - * @param string $tokens The current array of tokens found in the string. - * @param string $eolChar The EOL character to use for splitting strings. - * - * @return void - */ - public function getRegexToken($char, $string, $chars, $tokens, $eolChar) - { - $beforeTokens = array( - T_EQUAL => true, - T_IS_NOT_EQUAL => true, - T_IS_IDENTICAL => true, - T_IS_NOT_IDENTICAL => true, - T_OPEN_PARENTHESIS => true, - T_OPEN_SQUARE_BRACKET => true, - T_RETURN => true, - T_BOOLEAN_OR => true, - T_BOOLEAN_AND => true, - T_BITWISE_OR => true, - T_BITWISE_AND => true, - T_COMMA => true, - T_COLON => true, - T_TYPEOF => true, - T_INLINE_THEN => true, - T_INLINE_ELSE => true, - ); - - $afterTokens = array( - ',' => true, - ')' => true, - ']' => true, - ';' => true, - ' ' => true, - '.' => true, - ':' => true, - $eolChar => true, - ); - - // Find the last non-whitespace token that was added - // to the tokens array. - $numTokens = count($tokens); - for ($prev = ($numTokens - 1); $prev >= 0; $prev--) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$prev]['code']]) === false) { - break; - } - } - - if (isset($beforeTokens[$tokens[$prev]['code']]) === false) { - return null; - } - - // This is probably a regular expression, so look for the end of it. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t* token possibly starts a regular expression *".PHP_EOL; - } - - $numChars = count($chars); - for ($next = ($char + 1); $next < $numChars; $next++) { - if ($chars[$next] === '/') { - // Just make sure this is not escaped first. - if ($chars[($next - 1)] !== '\\') { - // In the simple form: /.../ so we found the end. - break; - } else if ($chars[($next - 2)] === '\\') { - // In the form: /...\\/ so we found the end. - break; - } - } else { - $possibleEolChar = substr($string, $next, strlen($eolChar)); - if ($possibleEolChar === $eolChar) { - // This is the last token on the line and regular - // expressions need to be defined on a single line, - // so this is not a regular expression. - break; - } - } - } - - if ($chars[$next] !== '/') { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t* could not find end of regular expression *".PHP_EOL; - } - - return null; - } - - while (preg_match('|[a-zA-Z]|', $chars[($next + 1)]) !== 0) { - // The token directly after the end of the regex can - // be modifiers like global and case insensitive - // (.e.g, /pattern/gi). - $next++; - } - - $regexEnd = $next; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t* found end of regular expression at token $regexEnd *".PHP_EOL; - } - - for ($next = ($next + 1); $next < $numChars; $next++) { - if ($chars[$next] !== ' ') { - break; - } else { - $possibleEolChar = substr($string, $next, strlen($eolChar)); - if ($possibleEolChar === $eolChar) { - // This is the last token on the line. - break; - } - } - } - - if (isset($afterTokens[$chars[$next]]) === false) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t* tokens after regular expression do not look correct *".PHP_EOL; - } - - return null; - } - - // This is a regular expression, so join all the tokens together. - $content = ''; - for ($x = $char; $x <= $regexEnd; $x++) { - $content .= $chars[$x]; - } - - $token = array( - 'start' => $char, - 'end' => $regexEnd, - 'content' => $content, - ); - - return $token; - - }//end getRegexToken() - - - /** - * Performs additional processing after main tokenizing. - * - * This additional processing looks for properties, closures, labels and objects. - * - * @param array $tokens The array of tokens to process. - * @param string $eolChar The EOL character to use for splitting strings. - * - * @return void - */ - public function processAdditional(&$tokens, $eolChar) - { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** START ADDITIONAL JS PROCESSING ***".PHP_EOL; - } - - $numTokens = count($tokens); - $classStack = array(); - - for ($i = 0; $i < $numTokens; $i++) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$i]['type']; - $content = PHP_CodeSniffer::prepareForOutput($tokens[$i]['content']); - - echo str_repeat("\t", count($classStack)); - echo "\tProcess token $i: $type => $content".PHP_EOL; - } - - // Looking for functions that are actually closures. - if ($tokens[$i]['code'] === T_FUNCTION && isset($tokens[$i]['scope_opener']) === true) { - for ($x = ($i + 1); $x < $numTokens; $x++) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x]['code']]) === false) { - break; - } - } - - if ($tokens[$x]['code'] === T_OPEN_PARENTHESIS) { - $tokens[$i]['code'] = T_CLOSURE; - $tokens[$i]['type'] = 'T_CLOSURE'; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $line = $tokens[$i]['line']; - echo str_repeat("\t", count($classStack)); - echo "\t* token $i on line $line changed from T_FUNCTION to T_CLOSURE".PHP_EOL; - } - - for ($x = ($tokens[$i]['scope_opener'] + 1); $x < $tokens[$i]['scope_closer']; $x++) { - if (isset($tokens[$x]['conditions'][$i]) === false) { - continue; - } - - $tokens[$x]['conditions'][$i] = T_CLOSURE; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$x]['type']; - echo str_repeat("\t", count($classStack)); - echo "\t\t* cleaned $x ($type) *".PHP_EOL; - } - } - }//end if - - continue; - } else if ($tokens[$i]['code'] === T_OPEN_CURLY_BRACKET - && isset($tokens[$i]['scope_condition']) === false - && isset($tokens[$i]['bracket_closer']) === true - ) { - $classStack[] = $i; - - $closer = $tokens[$i]['bracket_closer']; - $tokens[$i]['code'] = T_OBJECT; - $tokens[$i]['type'] = 'T_OBJECT'; - $tokens[$closer]['code'] = T_CLOSE_OBJECT; - $tokens[$closer]['type'] = 'T_CLOSE_OBJECT'; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", count($classStack)); - echo "\t* token $i converted from T_OPEN_CURLY_BRACKET to T_OBJECT *".PHP_EOL; - echo str_repeat("\t", count($classStack)); - echo "\t* token $closer converted from T_CLOSE_CURLY_BRACKET to T_CLOSE_OBJECT *".PHP_EOL; - } - - for ($x = ($i + 1); $x < $closer; $x++) { - $tokens[$x]['conditions'][$i] = T_OBJECT; - ksort($tokens[$x]['conditions'], SORT_NUMERIC); - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$x]['type']; - echo str_repeat("\t", count($classStack)); - echo "\t\t* added T_OBJECT condition to $x ($type) *".PHP_EOL; - } - } - } else if ($tokens[$i]['code'] === T_CLOSE_OBJECT) { - $opener = array_pop($classStack); - } else if ($tokens[$i]['code'] === T_COLON) { - // If it is a scope opener, it belongs to a - // DEFAULT or CASE statement. - if (isset($tokens[$i]['scope_condition']) === true) { - continue; - } - - // Make sure this is not part of an inline IF statement. - for ($x = ($i - 1); $x >= 0; $x--) { - if ($tokens[$x]['code'] === T_INLINE_THEN) { - $tokens[$i]['code'] = T_INLINE_ELSE; - $tokens[$i]['type'] = 'T_INLINE_ELSE'; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", count($classStack)); - echo "\t* token $i converted from T_COLON to T_INLINE_THEN *".PHP_EOL; - } - - continue(2); - } else if ($tokens[$x]['line'] < $tokens[$i]['line']) { - break; - } - } - - // The string to the left of the colon is either a property or label. - for ($label = ($i - 1); $label >= 0; $label--) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$label]['code']]) === false) { - break; - } - } - - if ($tokens[$label]['code'] !== T_STRING - && $tokens[$label]['code'] !== T_CONSTANT_ENCAPSED_STRING - ) { - continue; - } - - if (empty($classStack) === false) { - $tokens[$label]['code'] = T_PROPERTY; - $tokens[$label]['type'] = 'T_PROPERTY'; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", count($classStack)); - echo "\t* token $label converted from T_STRING to T_PROPERTY *".PHP_EOL; - } - } else { - $tokens[$label]['code'] = T_LABEL; - $tokens[$label]['type'] = 'T_LABEL'; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo str_repeat("\t", count($classStack)); - echo "\t* token $label converted from T_STRING to T_LABEL *".PHP_EOL; - } - }//end if - }//end if - }//end for - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** END ADDITIONAL JS PROCESSING ***".PHP_EOL; - } - - }//end processAdditional() - - -}//end class diff --git a/phpcs/CodeSniffer/Tokenizers/PHP.php b/phpcs/CodeSniffer/Tokenizers/PHP.php deleted file mode 100644 index fa54142..0000000 --- a/phpcs/CodeSniffer/Tokenizers/PHP.php +++ /dev/null @@ -1,1707 +0,0 @@ - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Tokenizes PHP code. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_Tokenizers_PHP -{ - - /** - * If TRUE, files that appear to be minified will not be processed. - * - * @var boolean - */ - public $skipMinified = false; - - /** - * A list of tokens that are allowed to open a scope. - * - * This array also contains information about what kind of token the scope - * opener uses to open and close the scope, if the token strictly requires - * an opener, if the token can share a scope closer, and who it can be shared - * with. An example of a token that shares a scope closer is a CASE scope. - * - * @var array - */ - public $scopeOpeners = array( - T_IF => array( - 'start' => array( - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, - T_COLON => T_COLON, - ), - 'end' => array( - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, - T_ENDIF => T_ENDIF, - T_ELSE => T_ELSE, - T_ELSEIF => T_ELSEIF, - ), - 'strict' => false, - 'shared' => false, - 'with' => array( - T_ELSE => T_ELSE, - T_ELSEIF => T_ELSEIF, - ), - ), - T_TRY => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => true, - 'shared' => false, - 'with' => array(), - ), - T_CATCH => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => true, - 'shared' => false, - 'with' => array(), - ), - T_FINALLY => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => true, - 'shared' => false, - 'with' => array(), - ), - T_ELSE => array( - 'start' => array( - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, - T_COLON => T_COLON, - ), - 'end' => array( - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, - T_ENDIF => T_ENDIF, - ), - 'strict' => false, - 'shared' => false, - 'with' => array( - T_IF => T_IF, - T_ELSEIF => T_ELSEIF, - ), - ), - T_ELSEIF => array( - 'start' => array( - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, - T_COLON => T_COLON, - ), - 'end' => array( - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, - T_ENDIF => T_ENDIF, - T_ELSE => T_ELSE, - T_ELSEIF => T_ELSEIF, - ), - 'strict' => false, - 'shared' => false, - 'with' => array( - T_IF => T_IF, - T_ELSE => T_ELSE, - ), - ), - T_FOR => array( - 'start' => array( - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, - T_COLON => T_COLON, - ), - 'end' => array( - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, - T_ENDFOR => T_ENDFOR, - ), - 'strict' => false, - 'shared' => false, - 'with' => array(), - ), - T_FOREACH => array( - 'start' => array( - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, - T_COLON => T_COLON, - ), - 'end' => array( - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, - T_ENDFOREACH => T_ENDFOREACH, - ), - 'strict' => false, - 'shared' => false, - 'with' => array(), - ), - T_INTERFACE => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => true, - 'shared' => false, - 'with' => array(), - ), - T_FUNCTION => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => true, - 'shared' => false, - 'with' => array(), - ), - T_CLASS => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => true, - 'shared' => false, - 'with' => array(), - ), - T_TRAIT => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => true, - 'shared' => false, - 'with' => array(), - ), - T_USE => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => false, - 'shared' => false, - 'with' => array(), - ), - T_DECLARE => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => false, - 'shared' => false, - 'with' => array(), - ), - T_NAMESPACE => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => false, - 'shared' => false, - 'with' => array(), - ), - T_WHILE => array( - 'start' => array( - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, - T_COLON => T_COLON, - ), - 'end' => array( - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, - T_ENDWHILE => T_ENDWHILE, - ), - 'strict' => false, - 'shared' => false, - 'with' => array(), - ), - T_DO => array( - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), - 'strict' => true, - 'shared' => false, - 'with' => array(), - ), - T_SWITCH => array( - 'start' => array( - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, - T_COLON => T_COLON, - ), - 'end' => array( - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, - T_ENDSWITCH => T_ENDSWITCH, - ), - 'strict' => true, - 'shared' => false, - 'with' => array(), - ), - T_CASE => array( - 'start' => array( - T_COLON => T_COLON, - T_SEMICOLON => T_SEMICOLON, - ), - 'end' => array( - T_BREAK => T_BREAK, - T_RETURN => T_RETURN, - T_CONTINUE => T_CONTINUE, - T_THROW => T_THROW, - T_EXIT => T_EXIT, - ), - 'strict' => true, - 'shared' => true, - 'with' => array( - T_DEFAULT => T_DEFAULT, - T_CASE => T_CASE, - T_SWITCH => T_SWITCH, - ), - ), - T_DEFAULT => array( - 'start' => array( - T_COLON => T_COLON, - T_SEMICOLON => T_SEMICOLON, - ), - 'end' => array( - T_BREAK => T_BREAK, - T_RETURN => T_RETURN, - T_CONTINUE => T_CONTINUE, - T_THROW => T_THROW, - T_EXIT => T_EXIT, - ), - 'strict' => true, - 'shared' => true, - 'with' => array( - T_CASE => T_CASE, - T_SWITCH => T_SWITCH, - ), - ), - T_START_HEREDOC => array( - 'start' => array(T_START_HEREDOC => T_START_HEREDOC), - 'end' => array(T_END_HEREDOC => T_END_HEREDOC), - 'strict' => true, - 'shared' => false, - 'with' => array(), - ), - ); - - /** - * A list of tokens that end the scope. - * - * This array is just a unique collection of the end tokens - * from the _scopeOpeners array. The data is duplicated here to - * save time during parsing of the file. - * - * @var array - */ - public $endScopeTokens = array( - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, - T_ENDIF => T_ENDIF, - T_ENDFOR => T_ENDFOR, - T_ENDFOREACH => T_ENDFOREACH, - T_ENDWHILE => T_ENDWHILE, - T_ENDSWITCH => T_ENDSWITCH, - T_BREAK => T_BREAK, - T_END_HEREDOC => T_END_HEREDOC, - ); - - /** - * A cache of different token types, resolved into arrays. - * - * @var array() - * @see standardiseToken() - */ - private static $_resolveTokenCache = array(); - - - /** - * Creates an array of tokens when given some PHP code. - * - * Starts by using token_get_all() but does a lot of extra processing - * to insert information about the context of the token. - * - * @param string $string The string to tokenize. - * @param string $eolChar The EOL character to use for splitting strings. - * - * @return array - */ - public function tokenizeString($string, $eolChar='\n') - { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** START PHP TOKENIZING ***".PHP_EOL; - $isWin = false; - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - $isWin = true; - } - } - - $tokens = @token_get_all($string); - $finalTokens = array(); - - $newStackPtr = 0; - $numTokens = count($tokens); - $lastNotEmptyToken = 0; - - $insideInlineIf = array(); - $insideUseGroup = false; - - $commentTokenizer = new PHP_CodeSniffer_Tokenizers_Comment(); - - for ($stackPtr = 0; $stackPtr < $numTokens; $stackPtr++) { - $token = (array) $tokens[$stackPtr]; - $tokenIsArray = isset($token[1]); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - if ($tokenIsArray === true) { - $type = token_name($token[0]); - $content = PHP_CodeSniffer::prepareForOutput($token[1]); - } else { - $newToken = self::resolveSimpleToken($token[0]); - $type = $newToken['type']; - $content = PHP_CodeSniffer::prepareForOutput($token[0]); - } - - echo "\tProcess token "; - if ($tokenIsArray === true) { - echo "[$stackPtr]"; - } else { - echo " $stackPtr "; - } - - echo ": $type => $content"; - }//end if - - if ($newStackPtr > 0 && $finalTokens[($newStackPtr - 1)]['code'] !== T_WHITESPACE) { - $lastNotEmptyToken = ($newStackPtr - 1); - } - - /* - If we are using \r\n newline characters, the \r and \n are sometimes - split over two tokens. This normally occurs after comments. We need - to merge these two characters together so that our line endings are - consistent for all lines. - */ - - if ($tokenIsArray === true && substr($token[1], -1) === "\r") { - if (isset($tokens[($stackPtr + 1)]) === true - && is_array($tokens[($stackPtr + 1)]) === true - && $tokens[($stackPtr + 1)][1][0] === "\n" - ) { - $token[1] .= "\n"; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - if ($isWin === true) { - echo '\n'; - } else { - echo "\033[30;1m\\n\033[0m"; - } - } - - if ($tokens[($stackPtr + 1)][1] === "\n") { - // This token's content has been merged into the previous, - // so we can skip it. - $tokens[($stackPtr + 1)] = ''; - } else { - $tokens[($stackPtr + 1)][1] = substr($tokens[($stackPtr + 1)][1], 1); - } - } - }//end if - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo PHP_EOL; - } - - /* - Parse doc blocks into something that can be easily iterated over. - */ - - if ($tokenIsArray === true && $token[0] === T_DOC_COMMENT) { - $commentTokens = $commentTokenizer->tokenizeString($token[1], $eolChar, $newStackPtr); - foreach ($commentTokens as $commentToken) { - $finalTokens[$newStackPtr] = $commentToken; - $newStackPtr++; - } - - continue; - } - - /* - If this is a double quoted string, PHP will tokenize the whole - thing which causes problems with the scope map when braces are - within the string. So we need to merge the tokens together to - provide a single string. - */ - - if ($tokenIsArray === false && ($token[0] === '"' || $token[0] === 'b"')) { - // Binary casts need a special token. - if ($token[0] === 'b"') { - $finalTokens[$newStackPtr] = array( - 'code' => T_BINARY_CAST, - 'type' => 'T_BINARY_CAST', - 'content' => 'b', - ); - $newStackPtr++; - } - - $tokenContent = '"'; - $nestedVars = array(); - for ($i = ($stackPtr + 1); $i < $numTokens; $i++) { - $subToken = (array) $tokens[$i]; - $subTokenIsArray = isset($subToken[1]); - - if ($subTokenIsArray === true) { - $tokenContent .= $subToken[1]; - if ($subToken[1] === '{' - && $subToken[0] !== T_ENCAPSED_AND_WHITESPACE - ) { - $nestedVars[] = $i; - } - } else { - $tokenContent .= $subToken[0]; - if ($subToken[0] === '}') { - array_pop($nestedVars); - } - } - - if ($subTokenIsArray === false - && $subToken[0] === '"' - && empty($nestedVars) === true - ) { - // We found the other end of the double quoted string. - break; - } - }//end for - - $stackPtr = $i; - - // Convert each line within the double quoted string to a - // new token, so it conforms with other multiple line tokens. - $tokenLines = explode($eolChar, $tokenContent); - $numLines = count($tokenLines); - $newToken = array(); - - for ($j = 0; $j < $numLines; $j++) { - $newToken['content'] = $tokenLines[$j]; - if ($j === ($numLines - 1)) { - if ($tokenLines[$j] === '') { - break; - } - } else { - $newToken['content'] .= $eolChar; - } - - $newToken['code'] = T_DOUBLE_QUOTED_STRING; - $newToken['type'] = 'T_DOUBLE_QUOTED_STRING'; - $finalTokens[$newStackPtr] = $newToken; - $newStackPtr++; - } - - // Continue, as we're done with this token. - continue; - }//end if - - /* - If this is a heredoc, PHP will tokenize the whole - thing which causes problems when heredocs don't - contain real PHP code, which is almost never. - We want to leave the start and end heredoc tokens - alone though. - */ - - if ($tokenIsArray === true && $token[0] === T_START_HEREDOC) { - // Add the start heredoc token to the final array. - $finalTokens[$newStackPtr] = self::standardiseToken($token); - - // Check if this is actually a nowdoc and use a different token - // to help the sniffs. - $nowdoc = false; - if ($token[1][3] === "'") { - $finalTokens[$newStackPtr]['code'] = T_START_NOWDOC; - $finalTokens[$newStackPtr]['type'] = 'T_START_NOWDOC'; - $nowdoc = true; - } - - $tokenContent = ''; - for ($i = ($stackPtr + 1); $i < $numTokens; $i++) { - $subTokenIsArray = is_array($tokens[$i]); - if ($subTokenIsArray === true - && $tokens[$i][0] === T_END_HEREDOC - ) { - // We found the other end of the heredoc. - break; - } - - if ($subTokenIsArray === true) { - $tokenContent .= $tokens[$i][1]; - } else { - $tokenContent .= $tokens[$i]; - } - } - - if ($i === $numTokens) { - // We got to the end of the file and never - // found the closing token, so this probably wasn't - // a heredoc. - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $finalTokens[$newStackPtr]['type']; - echo "\t\t* failed to find the end of the here/nowdoc".PHP_EOL; - echo "\t\t* token $stackPtr changed from $type to T_STRING".PHP_EOL; - } - - $finalTokens[$newStackPtr]['code'] = T_STRING; - $finalTokens[$newStackPtr]['type'] = 'T_STRING'; - $newStackPtr++; - continue; - } - - $stackPtr = $i; - $newStackPtr++; - - // Convert each line within the heredoc to a - // new token, so it conforms with other multiple line tokens. - $tokenLines = explode($eolChar, $tokenContent); - $numLines = count($tokenLines); - $newToken = array(); - - for ($j = 0; $j < $numLines; $j++) { - $newToken['content'] = $tokenLines[$j]; - if ($j === ($numLines - 1)) { - if ($tokenLines[$j] === '') { - break; - } - } else { - $newToken['content'] .= $eolChar; - } - - if ($nowdoc === true) { - $newToken['code'] = T_NOWDOC; - $newToken['type'] = 'T_NOWDOC'; - } else { - $newToken['code'] = T_HEREDOC; - $newToken['type'] = 'T_HEREDOC'; - } - - $finalTokens[$newStackPtr] = $newToken; - $newStackPtr++; - }//end for - - // Add the end heredoc token to the final array. - $finalTokens[$newStackPtr] = self::standardiseToken($tokens[$stackPtr]); - - if ($nowdoc === true) { - $finalTokens[$newStackPtr]['code'] = T_END_NOWDOC; - $finalTokens[$newStackPtr]['type'] = 'T_END_NOWDOC'; - $nowdoc = true; - } - - $newStackPtr++; - - // Continue, as we're done with this token. - continue; - }//end if - - /* - Before PHP 5.6, the ... operator was tokenized as three - T_STRING_CONCAT tokens in a row. So look for and combine - these tokens in earlier versions. - */ - - if ($tokenIsArray === false - && $token[0] === '.' - && isset($tokens[($stackPtr + 1)]) === true - && isset($tokens[($stackPtr + 2)]) === true - && $tokens[($stackPtr + 1)] === '.' - && $tokens[($stackPtr + 2)] === '.' - ) { - $newToken = array(); - $newToken['code'] = T_ELLIPSIS; - $newToken['type'] = 'T_ELLIPSIS'; - $newToken['content'] = '...'; - $finalTokens[$newStackPtr] = $newToken; - - $newStackPtr++; - $stackPtr += 2; - continue; - } - - /* - Before PHP 5.6, the ** operator was tokenized as two - T_MULTIPLY tokens in a row. So look for and combine - these tokens in earlier versions. - */ - - if ($tokenIsArray === false - && $token[0] === '*' - && isset($tokens[($stackPtr + 1)]) === true - && $tokens[($stackPtr + 1)] === '*' - ) { - $newToken = array(); - $newToken['code'] = T_POW; - $newToken['type'] = 'T_POW'; - $newToken['content'] = '**'; - $finalTokens[$newStackPtr] = $newToken; - - $newStackPtr++; - $stackPtr++; - continue; - } - - /* - Before PHP 5.6, the **= operator was tokenized as - T_MULTIPLY followed by T_MUL_EQUAL. So look for and combine - these tokens in earlier versions. - */ - - if ($tokenIsArray === false - && $token[0] === '*' - && isset($tokens[($stackPtr + 1)]) === true - && is_array($tokens[($stackPtr + 1)]) === true - && $tokens[($stackPtr + 1)][1] === '*=' - ) { - $newToken = array(); - $newToken['code'] = T_POW_EQUAL; - $newToken['type'] = 'T_POW_EQUAL'; - $newToken['content'] = '**='; - $finalTokens[$newStackPtr] = $newToken; - - $newStackPtr++; - $stackPtr++; - continue; - } - - /* - Before PHP 7, the ??= operator was tokenized as - T_INLINE_THEN, T_INLINE_THEN, T_EQUAL. - Between PHP 7.0 and 7.2, the ??= operator was tokenized as - T_COALESCE, T_EQUAL. - So look for and combine these tokens in earlier versions. - */ - - if (($tokenIsArray === false - && $token[0] === '?' - && isset($tokens[($stackPtr + 1)]) === true - && $tokens[($stackPtr + 1)][0] === '?' - && isset($tokens[($stackPtr + 2)]) === true - && $tokens[($stackPtr + 2)][0] === '=') - || ($tokenIsArray === true - && $token[0] === T_COALESCE - && isset($tokens[($stackPtr + 1)]) === true - && $tokens[($stackPtr + 1)][0] === '=') - ) { - $newToken = array(); - $newToken['code'] = T_COALESCE_EQUAL; - $newToken['type'] = 'T_COALESCE_EQUAL'; - $newToken['content'] = '??='; - $finalTokens[$newStackPtr] = $newToken; - - $newStackPtr++; - $stackPtr++; - - if ($tokenIsArray === false) { - // Pre PHP 7. - $stackPtr++; - } - - continue; - } - - /* - Before PHP 7, the ?? operator was tokenized as - T_INLINE_THEN followed by T_INLINE_THEN. - So look for and combine these tokens in earlier versions. - */ - - if ($tokenIsArray === false - && $token[0] === '?' - && isset($tokens[($stackPtr + 1)]) === true - && $tokens[($stackPtr + 1)][0] === '?' - ) { - $newToken = array(); - $newToken['code'] = T_COALESCE; - $newToken['type'] = 'T_COALESCE'; - $newToken['content'] = '??'; - $finalTokens[$newStackPtr] = $newToken; - - $newStackPtr++; - $stackPtr++; - continue; - } - - /* - Convert ? to T_NULLABLE OR T_INLINE_THEN - */ - - if ($tokenIsArray === false && $token[0] === '?') { - $newToken = array(); - $newToken['content'] = '?'; - - for ($i = ($stackPtr - 1); $i >= 0; $i--) { - if (is_array($tokens[$i]) === true) { - $tokenType = $tokens[$i][0]; - } else { - $tokenType = $tokens[$i]; - } - - if ($tokenType === T_FUNCTION) { - $newToken['code'] = T_NULLABLE; - $newToken['type'] = 'T_NULLABLE'; - break; - } else if (in_array($tokenType, array(T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, '{', ';')) === true) { - $newToken['code'] = T_INLINE_THEN; - $newToken['type'] = 'T_INLINE_THEN'; - - $insideInlineIf[] = $stackPtr; - break; - } - } - - $finalTokens[$newStackPtr] = $newToken; - $newStackPtr++; - continue; - }//end if - - /* - Tokens after a double colon may be look like scope openers, - such as when writing code like Foo::NAMESPACE, but they are - only ever variables or strings. - */ - - if ($stackPtr > 1 - && (is_array($tokens[($stackPtr - 1)]) === true - && $tokens[($stackPtr - 1)][0] === T_PAAMAYIM_NEKUDOTAYIM) - && $tokenIsArray === true - && $token[0] !== T_STRING - && $token[0] !== T_VARIABLE - && $token[0] !== T_DOLLAR - && isset(PHP_CodeSniffer_Tokens::$emptyTokens[$token[0]]) === false - ) { - $newToken = array(); - $newToken['code'] = T_STRING; - $newToken['type'] = 'T_STRING'; - $newToken['content'] = $token[1]; - $finalTokens[$newStackPtr] = $newToken; - - $newStackPtr++; - continue; - } - - /* - The string-like token after a function keyword should always be - tokenized as T_STRING even if it appears to be a different token, - such as when writing code like: function default(): foo - so go forward and change the token type before it is processed. - */ - - if ($tokenIsArray === true && $token[0] === T_FUNCTION) { - for ($x = ($stackPtr + 1); $x < $numTokens; $x++) { - if (is_array($tokens[$x]) === false - || isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x][0]]) === false - ) { - // Non-empty content. - break; - } - } - - if ($x < $numTokens && is_array($tokens[$x]) === true) { - $tokens[$x][0] = T_STRING; - } - } - - /* - Before PHP 7, the <=> operator was tokenized as - T_IS_SMALLER_OR_EQUAL followed by T_GREATER_THAN. - So look for and combine these tokens in earlier versions. - */ - - if ($tokenIsArray === true - && $token[0] === T_IS_SMALLER_OR_EQUAL - && isset($tokens[($stackPtr + 1)]) === true - && $tokens[($stackPtr + 1)][0] === '>' - ) { - $newToken = array(); - $newToken['code'] = T_SPACESHIP; - $newToken['type'] = 'T_SPACESHIP'; - $newToken['content'] = '<=>'; - $finalTokens[$newStackPtr] = $newToken; - - $newStackPtr++; - $stackPtr++; - continue; - } - - /* - Emulate traits in PHP versions less than 5.4. - */ - - if ($tokenIsArray === true - && $token[0] === T_STRING - && strtolower($token[1]) === 'trait' - && $tokens[($stackPtr - 1)][0] !== T_OBJECT_OPERATOR - && $tokens[($stackPtr - 1)][0] !== T_PAAMAYIM_NEKUDOTAYIM - ) { - $finalTokens[$newStackPtr] = array( - 'content' => $token[1], - 'code' => T_TRAIT, - 'type' => 'T_TRAIT', - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* token $stackPtr changed from T_STRING to T_TRAIT".PHP_EOL; - } - - $newStackPtr++; - continue; - } - - /* - PHP doesn't assign a token to goto labels, so we have to. - These are just string tokens with a single colon after them. Double - colons are already tokenized and so don't interfere with this check. - But we do have to account for CASE statements, that look just like - goto labels. - */ - - if ($tokenIsArray === true - && $token[0] === T_STRING - && isset($tokens[($stackPtr + 1)]) === true - && $tokens[($stackPtr + 1)] === ':' - && $tokens[($stackPtr - 1)][0] !== T_PAAMAYIM_NEKUDOTAYIM - ) { - $stopTokens = array( - T_CASE => true, - T_SEMICOLON => true, - T_OPEN_CURLY_BRACKET => true, - T_INLINE_THEN => true, - ); - - for ($x = ($newStackPtr - 1); $x > 0; $x--) { - if (isset($stopTokens[$finalTokens[$x]['code']]) === true) { - break; - } - } - - if ($finalTokens[$x]['code'] !== T_CASE - && $finalTokens[$x]['code'] !== T_INLINE_THEN - ) { - $finalTokens[$newStackPtr] = array( - 'content' => $token[1].':', - 'code' => T_GOTO_LABEL, - 'type' => 'T_GOTO_LABEL', - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* token $stackPtr changed from T_STRING to T_GOTO_LABEL".PHP_EOL; - echo "\t\t* skipping T_COLON token ".($stackPtr + 1).PHP_EOL; - } - - $newStackPtr++; - $stackPtr++; - continue; - } - }//end if - - /* - HHVM 3.5 tokenizes "else[\s]+if" as a T_ELSEIF token while PHP - proper only tokenizes "elseif" as a T_ELSEIF token. So split - up the HHVM token to make it looks like proper PHP. - */ - - if ($tokenIsArray === true - && $token[0] === T_ELSEIF - && strtolower($token[1]) !== 'elseif' - ) { - $finalTokens[$newStackPtr] = array( - 'content' => substr($token[1], 0, 4), - 'code' => T_ELSE, - 'type' => 'T_ELSE', - ); - - $newStackPtr++; - $finalTokens[$newStackPtr] = array( - 'content' => substr($token[1], 4, -2), - 'code' => T_WHITESPACE, - 'type' => 'T_WHITESPACE', - ); - - $newStackPtr++; - $finalTokens[$newStackPtr] = array( - 'content' => substr($token[1], -2), - 'code' => T_IF, - 'type' => 'T_IF', - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* token $stackPtr changed from T_ELSEIF to T_ELSE/T_WHITESPACE/T_IF".PHP_EOL; - } - - $newStackPtr++; - continue; - }//end if - - /* - HHVM 3.5 and 3.6 tokenizes a hashbang line such as #!/usr/bin/php - as T_HASHANG while PHP proper uses T_INLINE_HTML. - */ - - if ($tokenIsArray === true && token_name($token[0]) === 'T_HASHBANG') { - $finalTokens[$newStackPtr] = array( - 'content' => $token[1], - 'code' => T_INLINE_HTML, - 'type' => 'T_INLINE_HTML', - ); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* token $stackPtr changed from T_HASHBANG to T_INLINE_HTML".PHP_EOL; - } - - $newStackPtr++; - continue; - }//end if - - /* - If this token has newlines in its content, split each line up - and create a new token for each line. We do this so it's easier - to ascertain where errors occur on a line. - Note that $token[1] is the token's content. - */ - - if ($tokenIsArray === true && strpos($token[1], $eolChar) !== false) { - $tokenLines = explode($eolChar, $token[1]); - $numLines = count($tokenLines); - $newToken = array( - 'type' => token_name($token[0]), - 'code' => $token[0], - 'content' => '', - ); - - for ($i = 0; $i < $numLines; $i++) { - $newToken['content'] = $tokenLines[$i]; - if ($i === ($numLines - 1)) { - if ($tokenLines[$i] === '') { - break; - } - } else { - $newToken['content'] .= $eolChar; - } - - $finalTokens[$newStackPtr] = $newToken; - $newStackPtr++; - } - } else { - if ($tokenIsArray === true && $token[0] === T_STRING) { - // Some T_STRING tokens should remain that way - // due to their context. - $context = array( - T_OBJECT_OPERATOR => true, - T_FUNCTION => true, - T_CLASS => true, - T_EXTENDS => true, - T_IMPLEMENTS => true, - T_NEW => true, - T_CONST => true, - T_NS_SEPARATOR => true, - T_USE => true, - T_NAMESPACE => true, - T_PAAMAYIM_NEKUDOTAYIM => true, - ); - if (isset($context[$finalTokens[$lastNotEmptyToken]['code']]) === true) { - // Special case for syntax like: return new self - // where self should not be a string. - if ($finalTokens[$lastNotEmptyToken]['code'] === T_NEW - && strtolower($token[1]) === 'self' - ) { - $finalTokens[$newStackPtr] = array( - 'content' => $token[1], - 'code' => T_SELF, - 'type' => 'T_SELF', - ); - } else { - $finalTokens[$newStackPtr] = array( - 'content' => $token[1], - 'code' => T_STRING, - 'type' => 'T_STRING', - ); - } - - $newStackPtr++; - continue; - }//end if - }//end if - - $newToken = null; - if ($tokenIsArray === false) { - if (isset(self::$_resolveTokenCache[$token[0]]) === true) { - $newToken = self::$_resolveTokenCache[$token[0]]; - } - } else { - $cacheKey = null; - if ($token[0] === T_STRING) { - $cacheKey = strtolower($token[1]); - } else if ($token[0] !== T_CURLY_OPEN) { - $cacheKey = $token[0]; - } - - if ($cacheKey !== null && isset(self::$_resolveTokenCache[$cacheKey]) === true) { - $newToken = self::$_resolveTokenCache[$cacheKey]; - $newToken['content'] = $token[1]; - } - } - - if ($newToken === null) { - $newToken = self::standardiseToken($token); - } - - // Convert colons that are actually the ELSE component of an - // inline IF statement. - if (empty($insideInlineIf) === false && $newToken['code'] === T_COLON) { - array_pop($insideInlineIf); - $newToken['code'] = T_INLINE_ELSE; - $newToken['type'] = 'T_INLINE_ELSE'; - } - - // This is a special condition for T_ARRAY tokens used for - // type hinting function arguments as being arrays. We want to keep - // the parenthesis map clean, so let's tag these tokens as - // T_ARRAY_HINT. - if ($newToken['code'] === T_ARRAY) { - for ($i = $stackPtr; $i < $numTokens; $i++) { - if ($tokens[$i] === '(') { - break; - } else if ($tokens[$i][0] === T_VARIABLE) { - $newToken['code'] = T_ARRAY_HINT; - $newToken['type'] = 'T_ARRAY_HINT'; - break; - } - } - } - - // This is a special case when checking PHP 5.5+ code in PHP < 5.5 - // where "finally" should be T_FINALLY instead of T_STRING. - if ($newToken['code'] === T_STRING - && strtolower($newToken['content']) === 'finally' - ) { - $newToken['code'] = T_FINALLY; - $newToken['type'] = 'T_FINALLY'; - } - - // This is a special case for the PHP 5.5 classname::class syntax - // where "class" should be T_STRING instead of T_CLASS. - if (($newToken['code'] === T_CLASS - || $newToken['code'] === T_FUNCTION) - && $finalTokens[($newStackPtr - 1)]['code'] === T_DOUBLE_COLON - ) { - $newToken['code'] = T_STRING; - $newToken['type'] = 'T_STRING'; - } - - // This is a special case for PHP 5.6 use function and use const - // where "function" and "const" should be T_STRING instead of T_FUNCTION - // and T_CONST. - if (($newToken['code'] === T_FUNCTION - || $newToken['code'] === T_CONST) - && $finalTokens[$lastNotEmptyToken]['code'] === T_USE - ) { - $newToken['code'] = T_STRING; - $newToken['type'] = 'T_STRING'; - } - - // This is a special case for use groups in PHP 7+ where leaving - // the curly braces as their normal tokens would confuse - // the scope map and sniffs. - if ($newToken['code'] === T_OPEN_CURLY_BRACKET - && $finalTokens[$lastNotEmptyToken]['code'] === T_NS_SEPARATOR - ) { - $newToken['code'] = T_OPEN_USE_GROUP; - $newToken['type'] = 'T_OPEN_USE_GROUP'; - $insideUseGroup = true; - } - - if ($insideUseGroup === true && $newToken['code'] === T_CLOSE_CURLY_BRACKET) { - $newToken['code'] = T_CLOSE_USE_GROUP; - $newToken['type'] = 'T_CLOSE_USE_GROUP'; - $insideUseGroup = false; - } - - $finalTokens[$newStackPtr] = $newToken; - $newStackPtr++; - }//end if - }//end for - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** END PHP TOKENIZING ***".PHP_EOL; - } - - return $finalTokens; - - }//end tokenizeString() - - - /** - * Performs additional processing after main tokenizing. - * - * This additional processing checks for CASE statements that are using curly - * braces for scope openers and closers. It also turns some T_FUNCTION tokens - * into T_CLOSURE when they are not standard function definitions. It also - * detects short array syntax and converts those square brackets into new tokens. - * It also corrects some usage of the static and class keywords. It also - * assigns tokens to function return types. - * - * @param array $tokens The array of tokens to process. - * @param string $eolChar The EOL character to use for splitting strings. - * - * @return void - */ - public function processAdditional(&$tokens, $eolChar) - { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** START ADDITIONAL PHP PROCESSING ***".PHP_EOL; - } - - $numTokens = count($tokens); - for ($i = ($numTokens - 1); $i >= 0; $i--) { - // Check for any unset scope conditions due to alternate IF/ENDIF syntax. - if (isset($tokens[$i]['scope_opener']) === true - && isset($tokens[$i]['scope_condition']) === false - ) { - $tokens[$i]['scope_condition'] = $tokens[$tokens[$i]['scope_opener']]['scope_condition']; - } - - if ($tokens[$i]['code'] === T_FUNCTION) { - /* - Detect functions that are actually closures and - assign them a different token. - */ - - if (isset($tokens[$i]['scope_opener']) === true) { - for ($x = ($i + 1); $x < $numTokens; $x++) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x]['code']]) === false - && $tokens[$x]['code'] !== T_BITWISE_AND - ) { - break; - } - } - - if ($tokens[$x]['code'] === T_OPEN_PARENTHESIS) { - $tokens[$i]['code'] = T_CLOSURE; - $tokens[$i]['type'] = 'T_CLOSURE'; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $line = $tokens[$i]['line']; - echo "\t* token $i on line $line changed from T_FUNCTION to T_CLOSURE".PHP_EOL; - } - - for ($x = ($tokens[$i]['scope_opener'] + 1); $x < $tokens[$i]['scope_closer']; $x++) { - if (isset($tokens[$x]['conditions'][$i]) === false) { - continue; - } - - $tokens[$x]['conditions'][$i] = T_CLOSURE; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$x]['type']; - echo "\t\t* cleaned $x ($type) *".PHP_EOL; - } - } - } - - $tokenAfterReturnTypeHint = $tokens[$i]['scope_opener']; - } else if (isset($tokens[$i]['parenthesis_closer']) === true) { - $tokenAfterReturnTypeHint = null; - for ($x = ($tokens[$i]['parenthesis_closer'] + 1); $x < $numTokens; $x++) { - if ($tokens[$x]['code'] === T_SEMICOLON) { - $tokenAfterReturnTypeHint = $x; - break; - } - } - - if ($tokenAfterReturnTypeHint === null) { - // Probably a syntax error. - continue; - } - } else { - // Probably a syntax error. - continue; - }//end if - - /* - Detect function return values and assign them - a special token, because PHP doesn't. - */ - - for ($x = ($tokenAfterReturnTypeHint - 1); $x > $i; $x--) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x]['code']]) === false) { - if (in_array($tokens[$x]['code'], array(T_STRING, T_ARRAY, T_ARRAY_HINT, T_CALLABLE, T_SELF, T_PARENT), true) === true) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $line = $tokens[$x]['line']; - $type = $tokens[$x]['type']; - echo "\t* token $x on line $line changed from $type to T_RETURN_TYPE".PHP_EOL; - } - - $tokens[$x]['code'] = T_RETURN_TYPE; - $tokens[$x]['type'] = 'T_RETURN_TYPE'; - } - - break; - } - } - - continue; - } else if ($tokens[$i]['code'] === T_CLASS && isset($tokens[$i]['scope_opener']) === true) { - /* - Detect anonymous classes and assign them a different token. - */ - - for ($x = ($i + 1); $x < $numTokens; $x++) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x]['code']]) === false) { - break; - } - } - - if ($tokens[$x]['code'] === T_OPEN_PARENTHESIS - || $tokens[$x]['code'] === T_OPEN_CURLY_BRACKET - || $tokens[$x]['code'] === T_EXTENDS - || $tokens[$x]['code'] === T_IMPLEMENTS - ) { - $tokens[$i]['code'] = T_ANON_CLASS; - $tokens[$i]['type'] = 'T_ANON_CLASS'; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $line = $tokens[$i]['line']; - echo "\t* token $i on line $line changed from T_CLASS to T_ANON_CLASS".PHP_EOL; - } - - for ($x = ($tokens[$i]['scope_opener'] + 1); $x < $tokens[$i]['scope_closer']; $x++) { - if (isset($tokens[$x]['conditions'][$i]) === false) { - continue; - } - - $tokens[$x]['conditions'][$i] = T_ANON_CLASS; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$x]['type']; - echo "\t\t* cleaned $x ($type) *".PHP_EOL; - } - } - } - - continue; - } else if ($tokens[$i]['code'] === T_OPEN_SQUARE_BRACKET) { - if (isset($tokens[$i]['bracket_closer']) === false) { - continue; - } - - // Unless there is a variable or a bracket before this token, - // it is the start of an array being defined using the short syntax. - $isShortArray = false; - $allowed = array( - T_CLOSE_SQUARE_BRACKET => T_CLOSE_SQUARE_BRACKET, - T_CLOSE_PARENTHESIS => T_CLOSE_PARENTHESIS, - T_VARIABLE => T_VARIABLE, - T_OBJECT_OPERATOR => T_OBJECT_OPERATOR, - T_STRING => T_STRING, - ); - - for ($x = ($i - 1); $x > 0; $x--) { - // If we hit a scope opener, the statement has ended - // without finding anything, so it's probably an array - // using PHP 7.1 short list syntax. - if (isset($tokens[$x]['scope_opener']) === true) { - $isShortArray = true; - break; - } - - if (isset($tokens[$x]['bracket_opener']) === true - && $x > $tokens[$x]['bracket_opener'] - ) { - $x = $tokens[$x]['bracket_opener']; - continue; - } - - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x]['code']]) === false) { - if (isset($allowed[$tokens[$x]['code']]) === false) { - $isShortArray = true; - } - - break; - } - }//end for - - if ($isShortArray === true) { - $tokens[$i]['code'] = T_OPEN_SHORT_ARRAY; - $tokens[$i]['type'] = 'T_OPEN_SHORT_ARRAY'; - - $closer = $tokens[$i]['bracket_closer']; - $tokens[$closer]['code'] = T_CLOSE_SHORT_ARRAY; - $tokens[$closer]['type'] = 'T_CLOSE_SHORT_ARRAY'; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $line = $tokens[$i]['line']; - echo "\t* token $i on line $line changed from T_OPEN_SQUARE_BRACKET to T_OPEN_SHORT_ARRAY".PHP_EOL; - $line = $tokens[$closer]['line']; - echo "\t* token $closer on line $line changed from T_CLOSE_SQUARE_BRACKET to T_CLOSE_SHORT_ARRAY".PHP_EOL; - } - } - - continue; - } else if ($tokens[$i]['code'] === T_STATIC) { - for ($x = ($i - 1); $x > 0; $x--) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x]['code']]) === false) { - break; - } - } - - if ($tokens[$x]['code'] === T_INSTANCEOF) { - $tokens[$i]['code'] = T_STRING; - $tokens[$i]['type'] = 'T_STRING'; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $line = $tokens[$i]['line']; - echo "\t* token $i on line $line changed from T_STATIC to T_STRING".PHP_EOL; - } - } - - continue; - } else if ($tokens[$i]['code'] === T_ECHO && $tokens[$i]['content'] === ' 1) { - $line = $tokens[$i]['line']; - echo "\t* token $i on line $line changed from T_ECHO to T_OPEN_TAG_WITH_ECHO".PHP_EOL; - } - } else if ($tokens[$i]['code'] === T_TRUE - || $tokens[$i]['code'] === T_FALSE - || $tokens[$i]['code'] === T_NULL - ) { - for ($x = ($i + 1); $i < $numTokens; $x++) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x]['code']]) === false) { - // Non-whitespace content. - break; - } - } - - $context = array( - T_OBJECT_OPERATOR => true, - T_NS_SEPARATOR => true, - T_PAAMAYIM_NEKUDOTAYIM => true, - ); - if (isset($context[$tokens[$x]['code']]) === true) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $line = $tokens[$i]['line']; - $type = $tokens[$i]['type']; - echo "\t* token $i on line $line changed from $type to T_STRING".PHP_EOL; - } - - $tokens[$i]['code'] = T_STRING; - $tokens[$i]['type'] = 'T_STRING'; - } - } else if ($tokens[$i]['code'] === T_CONST) { - // Context sensitive keywords support. - for ($x = ($i + 1); $i < $numTokens; $x++) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x]['code']]) === false) { - // Non-whitespace content. - break; - } - } - - if ($tokens[$x]['code'] !== T_STRING) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $line = $tokens[$x]['line']; - $type = $tokens[$x]['type']; - echo "\t* token $x on line $line changed from $type to T_STRING".PHP_EOL; - } - - $tokens[$x]['code'] = T_STRING; - $tokens[$x]['type'] = 'T_STRING'; - } - }//end if - - if (($tokens[$i]['code'] !== T_CASE - && $tokens[$i]['code'] !== T_DEFAULT) - || isset($tokens[$i]['scope_opener']) === false - ) { - // Only interested in CASE and DEFAULT statements from here on in. - continue; - } - - $scopeOpener = $tokens[$i]['scope_opener']; - $scopeCloser = $tokens[$i]['scope_closer']; - - // If the first char after the opener is a curly brace - // and that brace has been ignored, it is actually - // opening this case statement and the opener and closer are - // probably set incorrectly. - for ($x = ($scopeOpener + 1); $x < $numTokens; $x++) { - if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x]['code']]) === false) { - // Non-whitespace content. - break; - } - } - - if ($tokens[$x]['code'] === T_CASE || $tokens[$x]['code'] === T_DEFAULT) { - // Special case for multiple CASE statements that share the same - // closer. Because we are going backwards through the file, this next - // CASE/DEFAULT statement is already fixed, so just use its closer - // and don't worry about fixing anything. - $newCloser = $tokens[$x]['scope_closer']; - $tokens[$i]['scope_closer'] = $newCloser; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $oldType = $tokens[$scopeCloser]['type']; - $newType = $tokens[$newCloser]['type']; - $line = $tokens[$i]['line']; - echo "\t* token $i (T_CASE) on line $line closer changed from $scopeCloser ($oldType) to $newCloser ($newType)".PHP_EOL; - } - - continue; - } - - if ($tokens[$x]['code'] !== T_OPEN_CURLY_BRACKET - || isset($tokens[$x]['scope_condition']) === true - ) { - // Not a CASE/DEFAULT with a curly brace opener. - continue; - } - - // The closer for this CASE/DEFAULT should be the closing curly brace and - // not whatever it already is. The opener needs to be the opening curly - // brace so everything matches up. - $newCloser = $tokens[$x]['bracket_closer']; - foreach (array($i, $x, $newCloser) as $index) { - $tokens[$index]['scope_condition'] = $i; - $tokens[$index]['scope_opener'] = $x; - $tokens[$index]['scope_closer'] = $newCloser; - } - - unset($tokens[$scopeOpener]['scope_condition']); - unset($tokens[$scopeOpener]['scope_opener']); - unset($tokens[$scopeOpener]['scope_closer']); - unset($tokens[$scopeCloser]['scope_condition']); - unset($tokens[$scopeCloser]['scope_opener']); - unset($tokens[$scopeCloser]['scope_closer']); - unset($tokens[$x]['bracket_opener']); - unset($tokens[$x]['bracket_closer']); - unset($tokens[$newCloser]['bracket_opener']); - unset($tokens[$newCloser]['bracket_closer']); - $tokens[$scopeCloser]['conditions'][] = $i; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $line = $tokens[$i]['line']; - $tokenType = $tokens[$i]['type']; - - $oldType = $tokens[$scopeOpener]['type']; - $newType = $tokens[$x]['type']; - echo "\t* token $i ($tokenType) on line $line opener changed from $scopeOpener ($oldType) to $x ($newType)".PHP_EOL; - - $oldType = $tokens[$scopeCloser]['type']; - $newType = $tokens[$newCloser]['type']; - echo "\t* token $i ($tokenType) on line $line closer changed from $scopeCloser ($oldType) to $newCloser ($newType)".PHP_EOL; - } - - // Now fix up all the tokens that think they are - // inside the CASE/DEFAULT statement when they are really outside. - for ($x = $newCloser; $x < $scopeCloser; $x++) { - foreach ($tokens[$x]['conditions'] as $num => $oldCond) { - if ($oldCond === $tokens[$i]['code']) { - $oldConditions = $tokens[$x]['conditions']; - unset($tokens[$x]['conditions'][$num]); - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $type = $tokens[$x]['type']; - $oldConds = ''; - foreach ($oldConditions as $condition) { - $oldConds .= token_name($condition).','; - } - - $oldConds = rtrim($oldConds, ','); - - $newConds = ''; - foreach ($tokens[$x]['conditions'] as $condition) { - $newConds .= token_name($condition).','; - } - - $newConds = rtrim($newConds, ','); - - echo "\t\t* cleaned $x ($type) *".PHP_EOL; - echo "\t\t\t=> conditions changed from $oldConds to $newConds".PHP_EOL; - } - - break; - }//end if - }//end foreach - }//end for - }//end for - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t*** END ADDITIONAL PHP PROCESSING ***".PHP_EOL; - } - - }//end processAdditional() - - - /** - * Takes a token produced from token_get_all() and produces a - * more uniform token. - * - * @param string|array $token The token to convert. - * - * @return array The new token. - */ - public static function standardiseToken($token) - { - if (isset($token[1]) === false) { - if (isset(self::$_resolveTokenCache[$token[0]]) === true) { - return self::$_resolveTokenCache[$token[0]]; - } - } else { - $cacheKey = null; - if ($token[0] === T_STRING) { - $cacheKey = strtolower($token[1]); - } else if ($token[0] !== T_CURLY_OPEN) { - $cacheKey = $token[0]; - } - - if ($cacheKey !== null && isset(self::$_resolveTokenCache[$cacheKey]) === true) { - $newToken = self::$_resolveTokenCache[$cacheKey]; - $newToken['content'] = $token[1]; - return $newToken; - } - } - - if (isset($token[1]) === false) { - return self::resolveSimpleToken($token[0]); - } - - if ($token[0] === T_STRING) { - switch ($cacheKey) { - case 'false': - $newToken['type'] = 'T_FALSE'; - break; - case 'true': - $newToken['type'] = 'T_TRUE'; - break; - case 'null': - $newToken['type'] = 'T_NULL'; - break; - case 'self': - $newToken['type'] = 'T_SELF'; - break; - case 'parent': - $newToken['type'] = 'T_PARENT'; - break; - default: - $newToken['type'] = 'T_STRING'; - break; - } - - $newToken['code'] = constant($newToken['type']); - - self::$_resolveTokenCache[$cacheKey] = $newToken; - } else if ($token[0] === T_CURLY_OPEN) { - $newToken = array( - 'code' => T_OPEN_CURLY_BRACKET, - 'type' => 'T_OPEN_CURLY_BRACKET', - ); - } else { - $newToken = array( - 'code' => $token[0], - 'type' => token_name($token[0]), - ); - - self::$_resolveTokenCache[$token[0]] = $newToken; - }//end if - - $newToken['content'] = $token[1]; - return $newToken; - - }//end standardiseToken() - - - /** - * Converts simple tokens into a format that conforms to complex tokens - * produced by token_get_all(). - * - * Simple tokens are tokens that are not in array form when produced from - * token_get_all(). - * - * @param string $token The simple token to convert. - * - * @return array The new token in array format. - */ - public static function resolveSimpleToken($token) - { - $newToken = array(); - - switch ($token) { - case '{': - $newToken['type'] = 'T_OPEN_CURLY_BRACKET'; - break; - case '}': - $newToken['type'] = 'T_CLOSE_CURLY_BRACKET'; - break; - case '[': - $newToken['type'] = 'T_OPEN_SQUARE_BRACKET'; - break; - case ']': - $newToken['type'] = 'T_CLOSE_SQUARE_BRACKET'; - break; - case '(': - $newToken['type'] = 'T_OPEN_PARENTHESIS'; - break; - case ')': - $newToken['type'] = 'T_CLOSE_PARENTHESIS'; - break; - case ':': - $newToken['type'] = 'T_COLON'; - break; - case '.': - $newToken['type'] = 'T_STRING_CONCAT'; - break; - case ';': - $newToken['type'] = 'T_SEMICOLON'; - break; - case '=': - $newToken['type'] = 'T_EQUAL'; - break; - case '*': - $newToken['type'] = 'T_MULTIPLY'; - break; - case '/': - $newToken['type'] = 'T_DIVIDE'; - break; - case '+': - $newToken['type'] = 'T_PLUS'; - break; - case '-': - $newToken['type'] = 'T_MINUS'; - break; - case '%': - $newToken['type'] = 'T_MODULUS'; - break; - case '^': - $newToken['type'] = 'T_BITWISE_XOR'; - break; - case '&': - $newToken['type'] = 'T_BITWISE_AND'; - break; - case '|': - $newToken['type'] = 'T_BITWISE_OR'; - break; - case '<': - $newToken['type'] = 'T_LESS_THAN'; - break; - case '>': - $newToken['type'] = 'T_GREATER_THAN'; - break; - case '!': - $newToken['type'] = 'T_BOOLEAN_NOT'; - break; - case ',': - $newToken['type'] = 'T_COMMA'; - break; - case '@': - $newToken['type'] = 'T_ASPERAND'; - break; - case '$': - $newToken['type'] = 'T_DOLLAR'; - break; - case '`': - $newToken['type'] = 'T_BACKTICK'; - break; - default: - $newToken['type'] = 'T_NONE'; - break; - }//end switch - - $newToken['code'] = constant($newToken['type']); - $newToken['content'] = $token; - - self::$_resolveTokenCache[$token] = $newToken; - return $newToken; - - }//end resolveSimpleToken() - - -}//end class diff --git a/phpcs/CodeSniffer/Tokens.php b/phpcs/CodeSniffer/Tokens.php deleted file mode 100644 index 2b30ca3..0000000 --- a/phpcs/CodeSniffer/Tokens.php +++ /dev/null @@ -1,777 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -define('T_NONE', 'PHPCS_T_NONE'); -define('T_OPEN_CURLY_BRACKET', 'PHPCS_T_OPEN_CURLY_BRACKET'); -define('T_CLOSE_CURLY_BRACKET', 'PHPCS_T_CLOSE_CURLY_BRACKET'); -define('T_OPEN_SQUARE_BRACKET', 'PHPCS_T_OPEN_SQUARE_BRACKET'); -define('T_CLOSE_SQUARE_BRACKET', 'PHPCS_T_CLOSE_SQUARE_BRACKET'); -define('T_OPEN_PARENTHESIS', 'PHPCS_T_OPEN_PARENTHESIS'); -define('T_CLOSE_PARENTHESIS', 'PHPCS_T_CLOSE_PARENTHESIS'); -define('T_COLON', 'PHPCS_T_COLON'); -define('T_NULLABLE', 'PHPCS_T_NULLABLE'); -define('T_STRING_CONCAT', 'PHPCS_T_STRING_CONCAT'); -define('T_INLINE_THEN', 'PHPCS_T_INLINE_THEN'); -define('T_INLINE_ELSE', 'PHPCS_T_INLINE_ELSE'); -define('T_NULL', 'PHPCS_T_NULL'); -define('T_FALSE', 'PHPCS_T_FALSE'); -define('T_TRUE', 'PHPCS_T_TRUE'); -define('T_SEMICOLON', 'PHPCS_T_SEMICOLON'); -define('T_EQUAL', 'PHPCS_T_EQUAL'); -define('T_MULTIPLY', 'PHPCS_T_MULTIPLY'); -define('T_DIVIDE', 'PHPCS_T_DIVIDE'); -define('T_PLUS', 'PHPCS_T_PLUS'); -define('T_MINUS', 'PHPCS_T_MINUS'); -define('T_MODULUS', 'PHPCS_T_MODULUS'); -define('T_BITWISE_AND', 'PHPCS_T_BITWISE_AND'); -define('T_BITWISE_OR', 'PHPCS_T_BITWISE_OR'); -define('T_BITWISE_XOR', 'PHPCS_T_BITWISE_XOR'); -define('T_ARRAY_HINT', 'PHPCS_T_ARRAY_HINT'); -define('T_GREATER_THAN', 'PHPCS_T_GREATER_THAN'); -define('T_LESS_THAN', 'PHPCS_T_LESS_THAN'); -define('T_BOOLEAN_NOT', 'PHPCS_T_BOOLEAN_NOT'); -define('T_SELF', 'PHPCS_T_SELF'); -define('T_PARENT', 'PHPCS_T_PARENT'); -define('T_DOUBLE_QUOTED_STRING', 'PHPCS_T_DOUBLE_QUOTED_STRING'); -define('T_COMMA', 'PHPCS_T_COMMA'); -define('T_HEREDOC', 'PHPCS_T_HEREDOC'); -define('T_PROTOTYPE', 'PHPCS_T_PROTOTYPE'); -define('T_THIS', 'PHPCS_T_THIS'); -define('T_REGULAR_EXPRESSION', 'PHPCS_T_REGULAR_EXPRESSION'); -define('T_PROPERTY', 'PHPCS_T_PROPERTY'); -define('T_LABEL', 'PHPCS_T_LABEL'); -define('T_OBJECT', 'PHPCS_T_OBJECT'); -define('T_CLOSE_OBJECT', 'PHPCS_T_CLOSE_OBJECT'); -define('T_COLOUR', 'PHPCS_T_COLOUR'); -define('T_HASH', 'PHPCS_T_HASH'); -define('T_URL', 'PHPCS_T_URL'); -define('T_STYLE', 'PHPCS_T_STYLE'); -define('T_ASPERAND', 'PHPCS_T_ASPERAND'); -define('T_DOLLAR', 'PHPCS_T_DOLLAR'); -define('T_TYPEOF', 'PHPCS_T_TYPEOF'); -define('T_CLOSURE', 'PHPCS_T_CLOSURE'); -define('T_ANON_CLASS', 'PHPCS_T_ANON_CLASS'); -define('T_BACKTICK', 'PHPCS_T_BACKTICK'); -define('T_START_NOWDOC', 'PHPCS_T_START_NOWDOC'); -define('T_NOWDOC', 'PHPCS_T_NOWDOC'); -define('T_END_NOWDOC', 'PHPCS_T_END_NOWDOC'); -define('T_OPEN_SHORT_ARRAY', 'PHPCS_T_OPEN_SHORT_ARRAY'); -define('T_CLOSE_SHORT_ARRAY', 'PHPCS_T_CLOSE_SHORT_ARRAY'); -define('T_GOTO_LABEL', 'PHPCS_T_GOTO_LABEL'); -define('T_BINARY_CAST', 'PHPCS_T_BINARY_CAST'); -define('T_EMBEDDED_PHP', 'PHPCS_T_EMBEDDED_PHP'); -define('T_RETURN_TYPE', 'PHPCS_T_RETURN_TYPE'); -define('T_OPEN_USE_GROUP', 'PHPCS_T_OPEN_USE_GROUP'); -define('T_CLOSE_USE_GROUP', 'PHPCS_T_CLOSE_USE_GROUP'); -define('T_ZSR', 'PHPCS_T_ZSR'); -define('T_ZSR_EQUAL', 'PHPCS_T_ZSR_EQUAL'); - -// Some PHP 5.3 tokens, replicated for lower versions. -if (defined('T_NAMESPACE') === false) { - define('T_NAMESPACE', 'PHPCS_T_NAMESPACE'); -} - -if (defined('T_NS_C') === false) { - define('T_NS_C', 'PHPCS_T_NS_C'); -} - -if (defined('T_NS_SEPARATOR') === false) { - define('T_NS_SEPARATOR', 'PHPCS_T_NS_SEPARATOR'); -} - -if (defined('T_GOTO') === false) { - define('T_GOTO', 'PHPCS_T_GOTO'); -} - -if (defined('T_DIR') === false) { - define('T_DIR', 'PHPCS_T_DIR'); -} - -// Some PHP 5.4 tokens, replicated for lower versions. -if (defined('T_TRAIT') === false) { - define('T_TRAIT', 'PHPCS_T_TRAIT'); -} - -if (defined('T_TRAIT_C') === false) { - define('T_TRAIT_C', 'PHPCS_T_TRAIT_C'); -} - -if (defined('T_INSTEADOF') === false) { - define('T_INSTEADOF', 'PHPCS_T_INSTEADOF'); -} - -if (defined('T_CALLABLE') === false) { - define('T_CALLABLE', 'PHPCS_T_CALLABLE'); -} - -// Some PHP 5.5 tokens, replicated for lower versions. -if (defined('T_FINALLY') === false) { - define('T_FINALLY', 'PHPCS_T_FINALLY'); -} - -if (defined('T_YIELD') === false) { - define('T_YIELD', 'PHPCS_T_YIELD'); -} - -// Some PHP 5.6 tokens, replicated for lower versions. -if (defined('T_ELLIPSIS') === false) { - define('T_ELLIPSIS', 'PHPCS_T_ELLIPSIS'); -} - -if (defined('T_POW') === false) { - define('T_POW', 'PHPCS_T_POW'); -} - -if (defined('T_POW_EQUAL') === false) { - define('T_POW_EQUAL', 'PHPCS_T_POW_EQUAL'); -} - -// Some PHP 7 tokens, replicated for lower versions. -if (defined('T_SPACESHIP') === false) { - define('T_SPACESHIP', 'PHPCS_T_SPACESHIP'); -} - -if (defined('T_COALESCE') === false) { - define('T_COALESCE', 'PHPCS_T_COALESCE'); -} - -if (defined('T_COALESCE_EQUAL') === false) { - define('T_COALESCE_EQUAL', 'PHPCS_T_COALESCE_EQUAL'); -} - -// Tokens used for parsing doc blocks. -define('T_DOC_COMMENT_STAR', 'PHPCS_T_DOC_COMMENT_STAR'); -define('T_DOC_COMMENT_WHITESPACE', 'PHPCS_T_DOC_COMMENT_WHITESPACE'); -define('T_DOC_COMMENT_TAG', 'PHPCS_T_DOC_COMMENT_TAG'); -define('T_DOC_COMMENT_OPEN_TAG', 'PHPCS_T_DOC_COMMENT_OPEN_TAG'); -define('T_DOC_COMMENT_CLOSE_TAG', 'PHPCS_T_DOC_COMMENT_CLOSE_TAG'); -define('T_DOC_COMMENT_STRING', 'PHPCS_T_DOC_COMMENT_STRING'); - -/** - * The Tokens class contains weightings for tokens based on their - * probability of occurrence in a file. - * - * The less the chance of a high occurrence of an arbitrary token, the higher - * the weighting. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -final class PHP_CodeSniffer_Tokens -{ - - /** - * The token weightings. - * - * @var array(int => int) - */ - public static $weightings = array( - T_CLASS => 1000, - T_INTERFACE => 1000, - T_TRAIT => 1000, - T_NAMESPACE => 1000, - T_FUNCTION => 100, - T_CLOSURE => 100, - - /* - Conditions. - */ - - T_WHILE => 50, - T_FOR => 50, - T_FOREACH => 50, - T_IF => 50, - T_ELSE => 50, - T_ELSEIF => 50, - T_DO => 50, - T_TRY => 50, - T_CATCH => 50, - T_FINALLY => 50, - T_SWITCH => 50, - - T_SELF => 25, - T_PARENT => 25, - - /* - Operators and arithmetic. - */ - - T_BITWISE_AND => 8, - T_BITWISE_OR => 8, - T_BITWISE_XOR => 8, - - T_MULTIPLY => 5, - T_DIVIDE => 5, - T_PLUS => 5, - T_MINUS => 5, - T_MODULUS => 5, - T_POW => 5, - T_SPACESHIP => 5, - T_COALESCE => 5, - T_COALESCE_EQUAL => 5, - - T_SL => 5, - T_SR => 5, - T_SL_EQUAL => 5, - T_SR_EQUAL => 5, - - T_EQUAL => 5, - T_AND_EQUAL => 5, - T_CONCAT_EQUAL => 5, - T_DIV_EQUAL => 5, - T_MINUS_EQUAL => 5, - T_MOD_EQUAL => 5, - T_MUL_EQUAL => 5, - T_OR_EQUAL => 5, - T_PLUS_EQUAL => 5, - T_XOR_EQUAL => 5, - - T_BOOLEAN_AND => 5, - T_BOOLEAN_OR => 5, - - /* - Equality. - */ - - T_IS_EQUAL => 5, - T_IS_NOT_EQUAL => 5, - T_IS_IDENTICAL => 5, - T_IS_NOT_IDENTICAL => 5, - T_IS_SMALLER_OR_EQUAL => 5, - T_IS_GREATER_OR_EQUAL => 5, - ); - - /** - * The token weightings. - * - * @var array(int => int) - */ - public static $knownLengths = array( - T_ABSTRACT => 8, - T_AND_EQUAL => 2, - T_ARRAY => 5, - T_AS => 2, - T_BOOLEAN_AND => 2, - T_BOOLEAN_OR => 2, - T_BREAK => 5, - T_CALLABLE => 8, - T_CASE => 4, - T_CATCH => 5, - T_CLASS => 5, - T_CLASS_C => 9, - T_CLONE => 5, - T_CONCAT_EQUAL => 2, - T_CONST => 5, - T_CONTINUE => 8, - T_CURLY_OPEN => 2, - T_DEC => 2, - T_DECLARE => 7, - T_DEFAULT => 7, - T_DIR => 7, - T_DIV_EQUAL => 2, - T_DO => 2, - T_DOLLAR_OPEN_CURLY_BRACES => 2, - T_DOUBLE_ARROW => 2, - T_DOUBLE_COLON => 2, - T_ECHO => 4, - T_ELSE => 4, - T_ELSEIF => 6, - T_EMPTY => 5, - T_ENDDECLARE => 10, - T_ENDFOR => 6, - T_ENDFOREACH => 10, - T_ENDIF => 5, - T_ENDSWITCH => 9, - T_ENDWHILE => 8, - T_EVAL => 4, - T_EXTENDS => 7, - T_FILE => 8, - T_FINAL => 5, - T_FINALLY => 7, - T_FOR => 3, - T_FOREACH => 7, - T_FUNCTION => 8, - T_FUNC_C => 12, - T_GLOBAL => 6, - T_GOTO => 4, - T_HALT_COMPILER => 15, - T_IF => 2, - T_IMPLEMENTS => 10, - T_INC => 2, - T_INCLUDE => 7, - T_INCLUDE_ONCE => 12, - T_INSTANCEOF => 10, - T_INSTEADOF => 9, - T_INTERFACE => 9, - T_ISSET => 5, - T_IS_EQUAL => 2, - T_IS_GREATER_OR_EQUAL => 2, - T_IS_IDENTICAL => 3, - T_IS_NOT_EQUAL => 2, - T_IS_NOT_IDENTICAL => 3, - T_IS_SMALLER_OR_EQUAL => 2, - T_LINE => 8, - T_LIST => 4, - T_LOGICAL_AND => 3, - T_LOGICAL_OR => 2, - T_LOGICAL_XOR => 3, - T_METHOD_C => 10, - T_MINUS_EQUAL => 2, - T_POW_EQUAL => 3, - T_MOD_EQUAL => 2, - T_MUL_EQUAL => 2, - T_NAMESPACE => 9, - T_NS_C => 13, - T_NS_SEPARATOR => 1, - T_NEW => 3, - T_OBJECT_OPERATOR => 2, - T_OPEN_TAG_WITH_ECHO => 3, - T_OR_EQUAL => 2, - T_PLUS_EQUAL => 2, - T_PRINT => 5, - T_PRIVATE => 7, - T_PUBLIC => 6, - T_PROTECTED => 9, - T_REQUIRE => 7, - T_REQUIRE_ONCE => 12, - T_RETURN => 6, - T_STATIC => 6, - T_SWITCH => 6, - T_THROW => 5, - T_TRAIT => 5, - T_TRAIT_C => 9, - T_TRY => 3, - T_UNSET => 5, - T_USE => 3, - T_VAR => 3, - T_WHILE => 5, - T_XOR_EQUAL => 2, - T_YIELD => 5, - T_OPEN_CURLY_BRACKET => 1, - T_CLOSE_CURLY_BRACKET => 1, - T_OPEN_SQUARE_BRACKET => 1, - T_CLOSE_SQUARE_BRACKET => 1, - T_OPEN_PARENTHESIS => 1, - T_CLOSE_PARENTHESIS => 1, - T_COLON => 1, - T_NULLABLE => 1, - T_STRING_CONCAT => 1, - T_INLINE_THEN => 1, - T_INLINE_ELSE => 1, - T_NULL => 4, - T_FALSE => 5, - T_TRUE => 4, - T_SEMICOLON => 1, - T_EQUAL => 1, - T_MULTIPLY => 1, - T_DIVIDE => 1, - T_PLUS => 1, - T_MINUS => 1, - T_MODULUS => 1, - T_POW => 2, - T_SPACESHIP => 3, - T_COALESCE => 2, - T_COALESCE_EQUAL => 3, - T_BITWISE_AND => 1, - T_BITWISE_OR => 1, - T_BITWISE_XOR => 1, - T_SL => 2, - T_SR => 2, - T_SL_EQUAL => 3, - T_SR_EQUAL => 3, - T_ARRAY_HINT => 5, - T_GREATER_THAN => 1, - T_LESS_THAN => 1, - T_BOOLEAN_NOT => 1, - T_SELF => 4, - T_PARENT => 6, - T_COMMA => 1, - T_THIS => 4, - T_CLOSURE => 8, - T_BACKTICK => 1, - T_OPEN_SHORT_ARRAY => 1, - T_CLOSE_SHORT_ARRAY => 1, - ); - - /** - * Tokens that represent assignments. - * - * @var array(int) - */ - public static $assignmentTokens = array( - T_EQUAL => T_EQUAL, - T_AND_EQUAL => T_AND_EQUAL, - T_OR_EQUAL => T_OR_EQUAL, - T_CONCAT_EQUAL => T_CONCAT_EQUAL, - T_DIV_EQUAL => T_DIV_EQUAL, - T_MINUS_EQUAL => T_MINUS_EQUAL, - T_POW_EQUAL => T_POW_EQUAL, - T_MOD_EQUAL => T_MOD_EQUAL, - T_MUL_EQUAL => T_MUL_EQUAL, - T_PLUS_EQUAL => T_PLUS_EQUAL, - T_XOR_EQUAL => T_XOR_EQUAL, - T_DOUBLE_ARROW => T_DOUBLE_ARROW, - T_SL_EQUAL => T_SL_EQUAL, - T_SR_EQUAL => T_SR_EQUAL, - ); - - /** - * Tokens that represent equality comparisons. - * - * @var array(int) - */ - public static $equalityTokens = array( - T_IS_EQUAL => T_IS_EQUAL, - T_IS_NOT_EQUAL => T_IS_NOT_EQUAL, - T_IS_IDENTICAL => T_IS_IDENTICAL, - T_IS_NOT_IDENTICAL => T_IS_NOT_IDENTICAL, - T_IS_SMALLER_OR_EQUAL => T_IS_SMALLER_OR_EQUAL, - T_IS_GREATER_OR_EQUAL => T_IS_GREATER_OR_EQUAL, - ); - - /** - * Tokens that represent comparison operator. - * - * @var array(int) - */ - public static $comparisonTokens = array( - T_IS_EQUAL => T_IS_EQUAL, - T_IS_IDENTICAL => T_IS_IDENTICAL, - T_IS_NOT_EQUAL => T_IS_NOT_EQUAL, - T_IS_NOT_IDENTICAL => T_IS_NOT_IDENTICAL, - T_LESS_THAN => T_LESS_THAN, - T_GREATER_THAN => T_GREATER_THAN, - T_IS_SMALLER_OR_EQUAL => T_IS_SMALLER_OR_EQUAL, - T_IS_GREATER_OR_EQUAL => T_IS_GREATER_OR_EQUAL, - ); - - /** - * Tokens that represent arithmetic operators. - * - * @var array(int) - */ - public static $arithmeticTokens = array( - T_PLUS => T_PLUS, - T_MINUS => T_MINUS, - T_MULTIPLY => T_MULTIPLY, - T_DIVIDE => T_DIVIDE, - T_MODULUS => T_MODULUS, - ); - - /** - * Tokens that represent casting. - * - * @var array(int) - */ - public static $castTokens = array( - T_INT_CAST => T_INT_CAST, - T_STRING_CAST => T_STRING_CAST, - T_DOUBLE_CAST => T_DOUBLE_CAST, - T_ARRAY_CAST => T_ARRAY_CAST, - T_BOOL_CAST => T_BOOL_CAST, - T_OBJECT_CAST => T_OBJECT_CAST, - T_UNSET_CAST => T_UNSET_CAST, - T_BINARY_CAST => T_BINARY_CAST, - ); - - /** - * Token types that open parenthesis. - * - * @var array(int) - */ - public static $parenthesisOpeners = array( - T_ARRAY => T_ARRAY, - T_FUNCTION => T_FUNCTION, - T_CLOSURE => T_CLOSURE, - T_WHILE => T_WHILE, - T_FOR => T_FOR, - T_FOREACH => T_FOREACH, - T_SWITCH => T_SWITCH, - T_IF => T_IF, - T_ELSEIF => T_ELSEIF, - T_CATCH => T_CATCH, - T_DECLARE => T_DECLARE, - ); - - /** - * Tokens that are allowed to open scopes. - * - * @var array(int) - */ - public static $scopeOpeners = array( - T_CLASS => T_CLASS, - T_ANON_CLASS => T_ANON_CLASS, - T_INTERFACE => T_INTERFACE, - T_TRAIT => T_TRAIT, - T_NAMESPACE => T_NAMESPACE, - T_FUNCTION => T_FUNCTION, - T_CLOSURE => T_CLOSURE, - T_IF => T_IF, - T_SWITCH => T_SWITCH, - T_CASE => T_CASE, - T_DECLARE => T_DECLARE, - T_DEFAULT => T_DEFAULT, - T_WHILE => T_WHILE, - T_ELSE => T_ELSE, - T_ELSEIF => T_ELSEIF, - T_FOR => T_FOR, - T_FOREACH => T_FOREACH, - T_DO => T_DO, - T_TRY => T_TRY, - T_CATCH => T_CATCH, - T_FINALLY => T_FINALLY, - T_PROPERTY => T_PROPERTY, - T_OBJECT => T_OBJECT, - T_USE => T_USE, - ); - - /** - * Tokens that represent scope modifiers. - * - * @var array(int) - */ - public static $scopeModifiers = array( - T_PRIVATE => T_PRIVATE, - T_PUBLIC => T_PUBLIC, - T_PROTECTED => T_PROTECTED, - ); - - /** - * Tokens that can prefix a method name - * - * @var array(int) - */ - public static $methodPrefixes = array( - T_PRIVATE => T_PRIVATE, - T_PUBLIC => T_PUBLIC, - T_PROTECTED => T_PROTECTED, - T_ABSTRACT => T_ABSTRACT, - T_STATIC => T_STATIC, - T_FINAL => T_FINAL, - ); - - /** - * Tokens that perform operations. - * - * @var array(int) - */ - public static $operators = array( - T_MINUS => T_MINUS, - T_PLUS => T_PLUS, - T_MULTIPLY => T_MULTIPLY, - T_DIVIDE => T_DIVIDE, - T_MODULUS => T_MODULUS, - T_POW => T_POW, - T_SPACESHIP => T_SPACESHIP, - T_COALESCE => T_COALESCE, - T_COALESCE_EQUAL => T_COALESCE_EQUAL, - T_BITWISE_AND => T_BITWISE_AND, - T_BITWISE_OR => T_BITWISE_OR, - T_BITWISE_XOR => T_BITWISE_XOR, - T_SL => T_SL, - T_SR => T_SR, - ); - - /** - * Tokens that perform boolean operations. - * - * @var array(int) - */ - public static $booleanOperators = array( - T_BOOLEAN_AND => T_BOOLEAN_AND, - T_BOOLEAN_OR => T_BOOLEAN_OR, - T_LOGICAL_AND => T_LOGICAL_AND, - T_LOGICAL_OR => T_LOGICAL_OR, - T_LOGICAL_XOR => T_LOGICAL_XOR, - ); - - /** - * Tokens that open code blocks. - * - * @var array(int) - */ - public static $blockOpeners = array( - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, - T_OPEN_SQUARE_BRACKET => T_OPEN_SQUARE_BRACKET, - T_OPEN_PARENTHESIS => T_OPEN_PARENTHESIS, - T_OBJECT => T_OBJECT, - ); - - /** - * Tokens that don't represent code. - * - * @var array(int) - */ - public static $emptyTokens = array( - T_WHITESPACE => T_WHITESPACE, - T_COMMENT => T_COMMENT, - T_DOC_COMMENT => T_DOC_COMMENT, - T_DOC_COMMENT_STAR => T_DOC_COMMENT_STAR, - T_DOC_COMMENT_WHITESPACE => T_DOC_COMMENT_WHITESPACE, - T_DOC_COMMENT_TAG => T_DOC_COMMENT_TAG, - T_DOC_COMMENT_OPEN_TAG => T_DOC_COMMENT_OPEN_TAG, - T_DOC_COMMENT_CLOSE_TAG => T_DOC_COMMENT_CLOSE_TAG, - T_DOC_COMMENT_STRING => T_DOC_COMMENT_STRING, - ); - - /** - * Tokens that are comments. - * - * @var array(int) - */ - public static $commentTokens = array( - T_COMMENT => T_COMMENT, - T_DOC_COMMENT => T_DOC_COMMENT, - T_DOC_COMMENT_STAR => T_DOC_COMMENT_STAR, - T_DOC_COMMENT_WHITESPACE => T_DOC_COMMENT_WHITESPACE, - T_DOC_COMMENT_TAG => T_DOC_COMMENT_TAG, - T_DOC_COMMENT_OPEN_TAG => T_DOC_COMMENT_OPEN_TAG, - T_DOC_COMMENT_CLOSE_TAG => T_DOC_COMMENT_CLOSE_TAG, - T_DOC_COMMENT_STRING => T_DOC_COMMENT_STRING, - ); - - /** - * Tokens that represent strings. - * - * Note that T_STRINGS are NOT represented in this list. - * - * @var array(int) - */ - public static $stringTokens = array( - T_CONSTANT_ENCAPSED_STRING => T_CONSTANT_ENCAPSED_STRING, - T_DOUBLE_QUOTED_STRING => T_DOUBLE_QUOTED_STRING, - ); - - /** - * Tokens that represent brackets and parenthesis. - * - * @var array(int) - */ - public static $bracketTokens = array( - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, - T_OPEN_SQUARE_BRACKET => T_OPEN_SQUARE_BRACKET, - T_CLOSE_SQUARE_BRACKET => T_CLOSE_SQUARE_BRACKET, - T_OPEN_PARENTHESIS => T_OPEN_PARENTHESIS, - T_CLOSE_PARENTHESIS => T_CLOSE_PARENTHESIS, - ); - - /** - * Tokens that include files. - * - * @var array(int) - */ - public static $includeTokens = array( - T_REQUIRE_ONCE => T_REQUIRE_ONCE, - T_REQUIRE => T_REQUIRE, - T_INCLUDE_ONCE => T_INCLUDE_ONCE, - T_INCLUDE => T_INCLUDE, - ); - - /** - * Tokens that make up a heredoc string. - * - * @var array(int) - */ - public static $heredocTokens = array( - T_START_HEREDOC => T_START_HEREDOC, - T_END_HEREDOC => T_END_HEREDOC, - T_HEREDOC => T_HEREDOC, - T_START_NOWDOC => T_START_NOWDOC, - T_END_NOWDOC => T_END_NOWDOC, - T_NOWDOC => T_NOWDOC, - ); - - /** - * Tokens that represent the names of called functions. - * - * Mostly, these are just strings. But PHP tokeizes some language - * constructs and functions using their own tokens. - * - * @var array(int) - */ - public static $functionNameTokens = array( - T_STRING => T_STRING, - T_EVAL => T_EVAL, - T_EXIT => T_EXIT, - T_INCLUDE => T_INCLUDE, - T_INCLUDE_ONCE => T_INCLUDE_ONCE, - T_REQUIRE => T_REQUIRE, - T_REQUIRE_ONCE => T_REQUIRE_ONCE, - T_ISSET => T_ISSET, - T_UNSET => T_UNSET, - T_EMPTY => T_EMPTY, - ); - - - /** - * A PHP_CodeSniffer_Tokens class cannot be constructed. - * - * Only static calls are allowed. - */ - private function __construct() - { - - }//end __construct() - - - /** - * Returns the highest weighted token type. - * - * Tokens are weighted by their approximate frequency of appearance in code - * - the less frequently they appear in the code, the higher the weighting. - * For example T_CLASS tokens appear very infrequently in a file, and - * therefore have a high weighting. - * - * Returns false if there are no weightings for any of the specified tokens. - * - * @param array(int) $tokens The token types to get the highest weighted - * type for. - * - * @return int The highest weighted token. - */ - public static function getHighestWeightedToken(array $tokens) - { - $highest = -1; - $highestType = false; - - $weights = self::$weightings; - - foreach ($tokens as $token) { - if (isset($weights[$token]) === true) { - $weight = $weights[$token]; - } else { - $weight = 0; - } - - if ($weight > $highest) { - $highest = $weight; - $highestType = $token; - } - } - - return $highestType; - - }//end getHighestWeightedToken() - - -}//end class diff --git a/phpcs/README.md b/phpcs/README.md deleted file mode 100644 index c17cf17..0000000 --- a/phpcs/README.md +++ /dev/null @@ -1,75 +0,0 @@ -About ------ - -PHP\_CodeSniffer is a set of two PHP scripts; the main `phpcs` script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second `phpcbf` script to automatically correct coding standard violations. PHP\_CodeSniffer is an essential development tool that ensures your code remains clean and consistent. - -[![Build Status](https://travis-ci.org/squizlabs/PHP_CodeSniffer.svg?branch=phpcs-fixer)](https://travis-ci.org/squizlabs/PHP_CodeSniffer) [![Code consistency](http://squizlabs.github.io/PHP_CodeSniffer/analysis/squizlabs/PHP_CodeSniffer/grade.svg)](http://squizlabs.github.io/PHP_CodeSniffer/analysis/squizlabs/PHP_CodeSniffer) - -[![Join the chat at https://gitter.im/squizlabs/PHP_CodeSniffer](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/squizlabs/PHP_CodeSniffer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - -Requirements ------------- - -PHP\_CodeSniffer requires PHP version 5.1.2 or greater, although individual sniffs may have additional requirements such as external applications and scripts. See the [Configuration Options manual page](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options) for a list of these requirements. - -The SVN pre-commit hook requires PHP version 5.2.4 or greater due to its use of the vertical whitespace character. - -Installation ------------- - -The easiest way to get started with PHP\_CodeSniffer is to download the [Phar](http://php.net/manual/en/intro.phar.php) files for each of the commands: - - curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar - php phpcs.phar -h - - curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar - php phpcbf.phar -h - -If you use PEAR, you can install PHP\_CodeSniffer using the PEAR installer. This will make the `phpcs` and `phpcbf` commands immediately available for use. To install PHP\_CodeSniffer using the PEAR installer, first ensure you have [installed PEAR](http://pear.php.net/manual/en/installation.getting.php) and then run the following command: - - pear install PHP_CodeSniffer - -If you prefer using [Composer](http://getcomposer.org/) you can easily install PHP_CodeSniffer system-wide with the following command: - - composer global require "squizlabs/php_codesniffer=*" - -Make sure you have the composer bin dir in your PATH. The default value is `~/.composer/vendor/bin/`, but you can check the value that you need to use by running `composer global config bin-dir --absolute`. - -Or alternatively, include a dependency for `squizlabs/php_codesniffer` in your `composer.json` file. For example: - -```json -{ - "require-dev": { - "squizlabs/php_codesniffer": "2.*" - } -} -``` - -You will then be able to run PHP_CodeSniffer from the vendor bin directory: - - ./vendor/bin/phpcs -h - ./vendor/bin/phpcbf -h - -You can also download the PHP\_CodeSniffer source and run the `phpcs` and `phpcbf` commands directly from the Git clone: - - git clone https://github.com/squizlabs/PHP_CodeSniffer.git - cd PHP_CodeSniffer - php scripts/phpcs -h - php scripts/phpcbf -h - -Documentation -------------- - -The documentation for PHP\_CodeSniffer is available on the [Github wiki](https://github.com/squizlabs/PHP_CodeSniffer/wiki). - -Information about upcoming features and releases is available on the [Squiz Labs blog](http://www.squizlabs.com/php-codesniffer). - -Issues ------- - -Bug reports and feature requests can be submitted on the [Github Issue Tracker](https://github.com/squizlabs/PHP_CodeSniffer/issues) or the [PEAR bug tracker](http://pear.php.net/package/PHP_CodeSniffer/bugs). - -Contributing -------------- - -See [CONTRIBUTING.md](CONTRIBUTING.md) for information. diff --git a/phpcs/composer.json b/phpcs/composer.json deleted file mode 100644 index 9199c1a..0000000 --- a/phpcs/composer.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "name": "squizlabs/php_codesniffer", - "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "type": "library", - "keywords": [ - "phpcs", - "standards" - ], - "homepage": "http://www.squizlabs.com/php-codesniffer", - "license": "BSD-3-Clause", - "authors": [ - { - "name": "Greg Sherwood", - "role": "lead" - } - ], - "support": { - "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", - "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki", - "source": "https://github.com/squizlabs/PHP_CodeSniffer" - }, - "extra": { - "branch-alias": { - "dev-master": "2.x-dev" - } - }, - "autoload": { - "classmap": [ - "CodeSniffer.php", - "CodeSniffer/CLI.php", - "CodeSniffer/Exception.php", - "CodeSniffer/File.php", - "CodeSniffer/Fixer.php", - "CodeSniffer/Report.php", - "CodeSniffer/Reporting.php", - "CodeSniffer/Sniff.php", - "CodeSniffer/Tokens.php", - "CodeSniffer/Reports/", - "CodeSniffer/Tokenizers/", - "CodeSniffer/DocGenerators/", - "CodeSniffer/Standards/AbstractPatternSniff.php", - "CodeSniffer/Standards/AbstractScopeSniff.php", - "CodeSniffer/Standards/AbstractVariableSniff.php", - "CodeSniffer/Standards/IncorrectPatternException.php", - "CodeSniffer/Standards/Generic/Sniffs/", - "CodeSniffer/Standards/MySource/Sniffs/", - "CodeSniffer/Standards/PEAR/Sniffs/", - "CodeSniffer/Standards/PSR1/Sniffs/", - "CodeSniffer/Standards/PSR2/Sniffs/", - "CodeSniffer/Standards/Squiz/Sniffs/", - "CodeSniffer/Standards/Zend/Sniffs/" - ] - }, - "require": { - "php": ">=5.1.2", - "ext-tokenizer": "*", - "ext-xmlwriter": "*", - "ext-simplexml": "*" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "bin": [ - "scripts/phpcs", - "scripts/phpcbf" - ] -} diff --git a/phpcs/licence.txt b/phpcs/licence.txt deleted file mode 100644 index f95432c..0000000 --- a/phpcs/licence.txt +++ /dev/null @@ -1,24 +0,0 @@ -Copyright (c) 2012, Squiz Pty Ltd (ABN 77 084 670 600) -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of Squiz Pty Ltd nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/phpcs/php5-testingConfig.ini b/phpcs/php5-testingConfig.ini deleted file mode 100644 index 4f0aa04..0000000 --- a/phpcs/php5-testingConfig.ini +++ /dev/null @@ -1,12 +0,0 @@ -; Defines the default timezone used by the date functions -; http://php.net/date.timezone -date.timezone = "Australia/Sydney" - -; This directive determines whether or not PHP will recognize code between -; tags as PHP source which should be processed as such. -; http://php.net/short-open-tag -short_open_tag = On - -; Allow ASP-style <% %> tags. -; http://php.net/asp-tags -asp_tags = On diff --git a/phpcs/php7-testingConfig.ini b/phpcs/php7-testingConfig.ini deleted file mode 100644 index ac00864..0000000 --- a/phpcs/php7-testingConfig.ini +++ /dev/null @@ -1,8 +0,0 @@ -; Defines the default timezone used by the date functions -; http://php.net/date.timezone -date.timezone = "Australia/Sydney" - -; This directive determines whether or not PHP will recognize code between -; tags as PHP source which should be processed as such. -; http://php.net/short-open-tag -short_open_tag = On diff --git a/phpcs/phpcs.xml.dist b/phpcs/phpcs.xml.dist deleted file mode 100644 index 85b313e..0000000 --- a/phpcs/phpcs.xml.dist +++ /dev/null @@ -1,14 +0,0 @@ - - - The coding standard for PHP_CodeSniffer itself. - - CodeSniffer.php - CodeSniffer - scripts - - */Tests/* - - - - - diff --git a/phpcs/phpunit.xml.dist b/phpcs/phpunit.xml.dist deleted file mode 100644 index 811178e..0000000 --- a/phpcs/phpunit.xml.dist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - tests/AllTests.php - - - diff --git a/phpcs/scripts/build-phar.php b/phpcs/scripts/build-phar.php deleted file mode 100644 index 370a099..0000000 --- a/phpcs/scripts/build-phar.php +++ /dev/null @@ -1,128 +0,0 @@ -#!/usr/bin/env php - - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -error_reporting(E_ALL | E_STRICT); - -if (ini_get('phar.readonly') === '1') { - echo 'Unable to build, phar.readonly in php.ini is set to read only.'.PHP_EOL; - exit(1); -} - -$cwd = getCwd(); -require_once __DIR__.'/../CodeSniffer.php'; - -$scripts = array( - 'phpcs', - 'phpcbf', - ); - -foreach ($scripts as $script) { - echo "Building $script phar".PHP_EOL; - - $pharFile = $cwd.'/'.$script.'.phar'; - echo "\t=> $pharFile".PHP_EOL; - if (file_exists($pharFile) === true) { - echo "\t** file exists, removing **".PHP_EOL; - unlink($pharFile); - } - - $phar = new Phar($pharFile, 0, $script.'.phar'); - - echo "\t=> adding files from package.xml... "; - buildFromPackage($phar); - echo 'done'.PHP_EOL; - - echo "\t=> adding stub... "; - $stub = '#!/usr/bin/env php'."\n"; - $stub .= 'run'.$script.'();'."\n"; - $stub .= '__HALT_COMPILER();'; - $phar->setStub($stub); - echo 'done'.PHP_EOL; -}//end foreach - - -/** - * Build from a package list. - * - * @param object $phar The Phar class. - * - * @return void - */ -function buildFromPackage(&$phar) -{ - $packageFile = realpath(__DIR__.'/../package.xml'); - $dom = new DOMDocument('1.0', 'utf-8'); - $loaded = $dom->loadXML(file_get_contents($packageFile)); - if ($loaded === false) { - echo "Unable to load package file: $packageFile".PHP_EOL; - exit(1); - } - - $contents = $dom->getElementsByTagName('contents'); - $topLevels = $contents->item(0)->childNodes; - $tlLength = $topLevels->length; - for ($l = 0; $l < $tlLength; $l++) { - $currentLevel = $topLevels->item($l); - buildFromNode($phar, $currentLevel, ''); - } - - // Add licence file. - $phar->addFile(realpath(__DIR__.'/../licence.txt'), 'licence.txt'); - $phar['licence.txt']->compress(Phar::GZ); - -}//end buildFromPackage() - - -/** - * Add from a node. - * - * @param object $phar The Phar class. - * @param object $node The node to add. - * @param string $prefix The prefix of the structure. - * - * @return void - */ -function buildFromNode(&$phar, $node, $prefix='') -{ - $nodeName = $node->nodeName; - if ($nodeName !== 'dir' && $nodeName !== 'file') { - // Invalid node. - return; - } - - $path = $prefix.$node->getAttribute('name'); - if ($node->getAttribute('role') === 'php' || $node->getAttribute('role') === 'data') { - $path = ltrim($path, '/'); - $phar->addFile(realpath(__DIR__.'/../'.$path), $path); - $phar[$path]->compress(Phar::GZ); - } - - if ($nodeName === 'dir') { - // Descend into the depths. - $path = rtrim($path, '/').'/'; - $children = $node->childNodes; - $childLn = $children->length; - for ($c = 0; $c < $childLn; $c++) { - $child = $children->item($c); - buildFromNode($phar, $child, $path); - } - } - -}//end buildFromNode() diff --git a/phpcs/scripts/phpcbf b/phpcs/scripts/phpcbf deleted file mode 100755 index bcb9404..0000000 --- a/phpcs/scripts/phpcbf +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env php - - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (is_file(dirname(__FILE__).'/../CodeSniffer/CLI.php') === true) { - include_once dirname(__FILE__).'/../CodeSniffer/CLI.php'; -} else { - include_once 'PHP/CodeSniffer/CLI.php'; -} - -$cli = new PHP_CodeSniffer_CLI(); -$cli->runphpcbf(); diff --git a/phpcs/scripts/phpcbf.bat b/phpcs/scripts/phpcbf.bat deleted file mode 100644 index 1894a51..0000000 --- a/phpcs/scripts/phpcbf.bat +++ /dev/null @@ -1,19 +0,0 @@ -@echo off -REM PHP Code Beautifier and Fixer -REM -REM PHP version 5 -REM -REM @category PHP -REM @package PHP_CodeSniffer -REM @author Greg Sherwood -REM @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) -REM @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence -REM @link http://pear.php.net/package/PHP_CodeSniffer - -if "%PHPBIN%" == "" set PHPBIN=@php_bin@ -if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH -GOTO RUN -:USE_PEAR_PATH -set PHPBIN=%PHP_PEAR_PHP_BIN% -:RUN -"%PHPBIN%" "@bin_dir@\phpcbf" %* \ No newline at end of file diff --git a/phpcs/scripts/phpcs b/phpcs/scripts/phpcs deleted file mode 100755 index fa9616d..0000000 --- a/phpcs/scripts/phpcs +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env php - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (is_file(dirname(__FILE__).'/../CodeSniffer/CLI.php') === true) { - include_once dirname(__FILE__).'/../CodeSniffer/CLI.php'; -} else { - include_once 'PHP/CodeSniffer/CLI.php'; -} - -$cli = new PHP_CodeSniffer_CLI(); -$cli->runphpcs(); diff --git a/phpcs/scripts/phpcs-svn-pre-commit b/phpcs/scripts/phpcs-svn-pre-commit deleted file mode 100755 index 46fc628..0000000 --- a/phpcs/scripts/phpcs-svn-pre-commit +++ /dev/null @@ -1,229 +0,0 @@ -#!/usr/bin/env php - - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -if (is_file(dirname(__FILE__).'/../CodeSniffer/CLI.php') === true) { - include_once dirname(__FILE__).'/../CodeSniffer/CLI.php'; -} else { - include_once 'PHP/CodeSniffer/CLI.php'; -} - -define('PHP_CODESNIFFER_SVNLOOK', '/usr/bin/svnlook'); - - -/** - * A class to process command line options. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Jack Bates - * @author Greg Sherwood - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class PHP_CodeSniffer_SVN_Hook extends PHP_CodeSniffer_CLI -{ - - - /** - * Get a list of default values for all possible command line arguments. - * - * @return array - */ - public function getDefaults() - { - $defaults = parent::getDefaults(); - - $defaults['svnArgs'] = array(); - return $defaults; - - }//end getDefaults() - - - /** - * Processes an unknown command line argument. - * - * Assumes all unknown arguments are files and folders to check. - * - * @param string $arg The command line argument. - * @param int $pos The position of the argument on the command line. - * - * @return void - */ - public function processUnknownArgument($arg, $pos) - { - $this->values['svnArgs'][] = escapeshellarg($arg); - - }//end processUnknownArgument() - - - /** - * Runs PHP_CodeSniffer over files are directories. - * - * @param array $values An array of values determined from CLI args. - * - * @return int The number of error and warning messages shown. - * @see getCommandLineValues() - */ - public function process($values=array()) - { - if (empty($values) === true) { - $values = $this->getCommandLineValues(); - } else { - $values = array_merge($this->getDefaults(), $values); - $this->values = $values; - } - - // Get list of files in this transaction. - $command = PHP_CODESNIFFER_SVNLOOK.' changed '.implode(' ', $values['svnArgs']); - $handle = popen($command, 'r'); - if ($handle === false) { - echo 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL; - exit(2); - } - - $contents = stream_get_contents($handle); - fclose($handle); - - // Do not check deleted paths. - $contents = preg_replace('/^D.*/m', null, $contents); - - // Drop the four characters representing the action which precede the path on - // each line. - $contents = preg_replace('/^.{4}/m', null, $contents); - - $values['standard'] = $this->validateStandard($values['standard']); - foreach ($values['standard'] as $standard) { - if (PHP_CodeSniffer::isInstalledStandard($standard) === false) { - // They didn't select a valid coding standard, so help them - // out by letting them know which standards are installed. - echo 'ERROR: the "'.$standard.'" coding standard is not installed. '; - $this->printInstalledStandards(); - exit(2); - } - } - - $phpcs = new PHP_CodeSniffer( - $values['verbosity'], - $values['tabWidth'], - $values['encoding'] - ); - - // Set file extensions if they were specified. Otherwise, - // let PHP_CodeSniffer decide on the defaults. - if (empty($values['extensions']) === false) { - $phpcs->setAllowedFileExtensions($values['extensions']); - } else { - $phpcs->setAllowedFileExtensions(array_keys($phpcs->defaultFileExtensions)); - } - - // Set ignore patterns if they were specified. - if (empty($values['ignored']) === false) { - $phpcs->setIgnorePatterns($values['ignored']); - } - - // Set some convenience member vars. - if ($values['errorSeverity'] === null) { - $this->errorSeverity = PHPCS_DEFAULT_ERROR_SEV; - } else { - $this->errorSeverity = $values['errorSeverity']; - } - - if ($values['warningSeverity'] === null) { - $this->warningSeverity = PHPCS_DEFAULT_WARN_SEV; - } else { - $this->warningSeverity = $values['warningSeverity']; - } - - if (empty($values['reports']) === true) { - $this->values['reports']['full'] = $values['reportFile']; - } - - // Initialize PHP_CodeSniffer listeners but don't process any files. - $phpcs->setCli($this); - $phpcs->initStandard($values['standard'], $values['sniffs']); - - // Need double quotes around the following regex beause the vertical whitespace - // char is not always treated correctly for whatever reason. - foreach (preg_split("/\v|\n/", $contents, -1, PREG_SPLIT_NO_EMPTY) as $path) { - // No need to process folders as each changed file is checked. - if (substr($path, -1) === '/') { - continue; - } - - // We need to check ignore rules ourself because they are - // not checked when processing a single file. - if ($phpcs->shouldProcessFile($path, dirname($path)) === false) { - continue; - } - - // Get the contents of each file, as it would be after this transaction. - $command = PHP_CODESNIFFER_SVNLOOK.' cat '.implode(' ', $values['svnArgs']).' '.escapeshellarg($path); - $handle = popen($command, 'r'); - if ($handle === false) { - echo 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL; - exit(2); - } - - $contents = stream_get_contents($handle); - fclose($handle); - - $phpcs->processFile($path, $contents); - }//end foreach - - return $this->printErrorReport( - $phpcs, - $values['reports'], - $values['showSources'], - $values['reportFile'], - $values['reportWidth'] - ); - - }//end process() - - - /** - * Prints out the usage information for this script. - * - * @return void - */ - public function printUsage() - { - parent::printUsage(); - - echo PHP_EOL; - echo ' Each additional argument is passed to the `svnlook changed ...`'.PHP_EOL; - echo ' and `svnlook cat ...` commands. The report is printed on standard output,'.PHP_EOL; - echo ' however Subversion displays only standard error to the user, so in a'.PHP_EOL; - echo ' pre-commit hook, this script should be invoked as follows:'.PHP_EOL; - echo PHP_EOL; - echo ' '.basename($_SERVER['argv'][0]).' ... "$REPOS" -t "$TXN" >&2 || exit 1'.PHP_EOL; - - }//end printUsage() - - -}//end class - -$phpcs = new PHP_CodeSniffer_SVN_Hook(); - -PHP_CodeSniffer_Reporting::startTiming(); -$phpcs->checkRequirements(); - -$numErrors = $phpcs->process(); -if ($numErrors !== 0) { - exit(1); -} diff --git a/phpcs/scripts/phpcs.bat b/phpcs/scripts/phpcs.bat deleted file mode 100755 index e4c3233..0000000 --- a/phpcs/scripts/phpcs.bat +++ /dev/null @@ -1,21 +0,0 @@ -@echo off -REM PHP_CodeSniffer tokenizes PHP code and detects violations of a -REM defined set of coding standards. -REM -REM PHP version 5 -REM -REM @category PHP -REM @package PHP_CodeSniffer -REM @author Greg Sherwood -REM @author Marc McIntyre -REM @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) -REM @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence -REM @link http://pear.php.net/package/PHP_CodeSniffer - -if "%PHPBIN%" == "" set PHPBIN=@php_bin@ -if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH -GOTO RUN -:USE_PEAR_PATH -set PHPBIN=%PHP_PEAR_PHP_BIN% -:RUN -"%PHPBIN%" "@bin_dir@\phpcs" %* \ No newline at end of file diff --git a/phpcsx b/phpcsx index fd52d6d..fc2d21f 100755 --- a/phpcsx +++ b/phpcsx @@ -1,18 +1,27 @@ #!/usr/bin/env php implode(',', array( - dirname(__FILE__) . '/wpcs/', - dirname(__FILE__) . '/justcoded/', - )), -); +$root = dirname(__FILE__); -$cs = dirname(__FILE__).'/phpcs/CodeSniffer/CLI.php'; +require_once $root . '/vendor/squizlabs/php_codesniffer/autoload.php'; +/* +$argv = [ $_SERVER['argv'][0] ]; +$argv[] = '--config-set'; +$argv[] = 'installed_paths'; +$argv[] = implode(',', array( + $root . '/vendor/wp-coding-standards/wpcs/', + $root . '/justcoded/', +)); -if (is_file($cs) === true) { - include_once $cs; - - $cli = new PHP_CodeSniffer_CLI(); - $cli->runphpcs(); -} +// patch command options to add new paths +$_SERVER['argc'] += 3; +$_SERVER['argv'][] = '--config-set'; +$_SERVER['argv'][] = 'installed_paths'; +$_SERVER['argv'][] = implode(',', array( + $root . '/vendor/wp-coding-standards/wpcs/', + $root . '/justcoded/', +)); +*/ +$runner = new PHP_CodeSniffer\Runner(); +$exitCode = $runner->runPHPCS(); +exit($exitCode); diff --git a/wpcs/.gitignore b/wpcs/.gitignore deleted file mode 100644 index 8142c98..0000000 --- a/wpcs/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.buildpath -.project -.settings/ -vendor -composer.lock diff --git a/wpcs/.travis.yml b/wpcs/.travis.yml deleted file mode 100644 index 89ae2f9..0000000 --- a/wpcs/.travis.yml +++ /dev/null @@ -1,65 +0,0 @@ -sudo: false - -language: - - php - -php: - - 5.2 - - 5.3 - - 5.4 - - 5.5 - - 5.6 - - 7.0 - - 7.1 - -env: - - PHPCS_BRANCH=master - - PHPCS_BRANCH=2.8.1 - -matrix: - fast_finish: true - include: - # Run PHPCS against WPCS. I just picked to run it against 5.5. - - php: 5.5 - env: PHPCS_BRANCH=master SNIFF=1 - # Run against PHPCS 3.0. I just picked to run it against 5.6. - - php: 5.6 - env: PHPCS_BRANCH=3.0 - # Run against HHVM and PHP nightly. - - php: hhvm - sudo: required - dist: trusty - group: edge - env: PHPCS_BRANCH=master - - php: nightly - env: PHPCS_BRANCH=master - allow_failures: - # Allow failures for unstable builds. - - php: nightly - - php: hhvm - - env: PHPCS_BRANCH=3.0 - -before_install: - - export PHPCS_DIR=/tmp/phpcs - - export PHPUNIT_DIR=/tmp/phpunit - - export PHPCS_BIN=$(if [[ $PHPCS_BRANCH == 3.0 ]]; then echo $PHPCS_DIR/bin/phpcs; else echo $PHPCS_DIR/scripts/phpcs; fi) - - mkdir -p $PHPCS_DIR && git clone --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git -b $PHPCS_BRANCH $PHPCS_DIR - - $PHPCS_BIN --config-set installed_paths $(pwd) - # Download PHPUnit 5.x for builds on PHP 7, nightly and HHVM as - # PHPCS test suite is currently not compatible with PHPUnit 6.x. - - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." ]]; then wget -P $PHPUNIT_DIR https://phar.phpunit.de/phpunit-5.7.phar && chmod +x $PHPUNIT_DIR/phpunit-5.7.phar; fi - -script: - - if find . -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; - - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." ]]; then phpunit --filter WordPress /tmp/phpcs/tests/AllTests.php; fi - - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." ]]; then php $PHPUNIT_DIR/phpunit-5.7.phar --filter WordPress /tmp/phpcs/tests/AllTests.php; fi - # WordPress Coding Standards. - # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards - # @link http://pear.php.net/package/PHP_CodeSniffer/ - # -p flag: Show progress of the run. - # -s flag: Show sniff codes in all reports. - # -v flag: Print verbose output. - # -n flag: Do not print warnings. (shortcut for --warning-severity=0) - # --standard: Use WordPress as the standard. - # --extensions: Only sniff PHP files. - - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs -p -s -n . --standard=./bin/phpcs.xml --extensions=php; fi diff --git a/wpcs/CHANGELOG.md b/wpcs/CHANGELOG.md deleted file mode 100644 index 8ff3e65..0000000 --- a/wpcs/CHANGELOG.md +++ /dev/null @@ -1,380 +0,0 @@ -# Change Log for WordPress Coding Standards - -All notable changes to this project will be documented in this file. - -This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a CHANGELOG](http://keepachangelog.com/). - -## [Unreleased] - -_Nothing yet._ - -## [0.11.0] - 2017-03-20 - -### Important notes for end-users: - -If you use the WordPress Coding Standards with a custom ruleset, please be aware that some of the checks have been moved between sniffs and that the naming of a number of error codes has changed. -If you exclude some sniffs or error codes, you may have to update your custom ruleset to be compatible with WPCS 0.11.0. - -Additionally, to make it easier for you to customize your ruleset, two new wiki pages have been published with information on the properties you can adjust from your ruleset: -* [WPCS customizable sniff properties](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties) -* [PHPCS customizable sniff properties](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties) - -For more detailed information about the changed sniff names and error codes, please refer to PR [#633](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/633) and PR [#814](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/814). - -### Important notes for sniff developers: - -If you maintain or develop sniffs based upon the WordPress Coding Standards, most notably, if you use methods and properties from the `WordPress_Sniff` class, extend one of the abstract sniff classes WPCS provides or extend other sniffs from WPCS to use their properties, please be aware that this release contains significant changes which will, more likely than not, affect your sniffs. - -Please read this changelog carefully to understand how this will affect you. -For more detailed information on the most significant changes, please refer to PR [#795](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/795), PR [#833](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/833) and PR [#841](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/841). -You are also encouraged to check the file history of any WPCS classes you extend. - -### Added -- `WordPress.WP.DeprecatedFunctions` sniff to the `WordPress-Extra` ruleset to check for usage of deprecated WP version and show errors/warnings depending on a `minimum_supported_version` which [can be passed to the sniff from a custom ruleset](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-and-function-parameters). The default value for the `minimum_supported_version` property is three versions before the current WP version. -- `WordPress.WP.I18n`: ability to check for missing _translators comments_ when a I18n function call contains translatable text strings containing placeholders. This check will also verify that the _translators comment_ is correctly placed in the code and uses the correct comment type for optimal compatibility with the various tools available to create `.pot` files. -- `WordPress.WP.I18n`: ability to pass the `text_domain` to check for [from the command line](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#setting-text_domain-from-the-command-line). -- `WordPress.Arrays.ArrayDeclarationSpacing`: check + fixer for single line associative arrays. The [handbook](https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#indentation) states that these should always be multi-line. -- `WordPress.Files.FileName`: verification that files containing a class reflect this in the file name as per the core guidelines. This particular check can be disabled in a custom ruleset by setting the new [`strict_class_file_names` property](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#disregard-class-file-name-rules). -- `WordPress.Files.FileName`: verification that files in `/wp-includes/` containing template tags - annotated with `@subpackage Template` in the file header - use the `-template` suffix. -- `WordPress.Files.FileName`: [`is_theme` property](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#themes-allow-filename-exceptions) which can be set in a custom ruleset. This property can be used to indicate that the project being checked is a theme and will allow for a predefined theme hierarchy based set of exceptions to the file name rules. -- `WordPress.VIP.AdminBarRemoval`: check for hiding the admin bar using CSS. -- `WordPress.VIP.AdminBarRemoval`: customizable [`remove_only` property](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#admin-bar-visibility-manipulations) to toggle whether to error of all manipulation of the visibility of the admin bar or to execute more thorough checking for removal only. -- `WordPress.WhiteSpace.ControlStructureSpacing`: support for checking the whitespace in `try`/`catch` constructs. -- `WordPress.WhiteSpace.ControlStructureSpacing`: check that the space after the open parenthesis and before the closing parenthesis of control structures and functions is *exactly* one space. Includes auto-fixer. -- `WordPress.WhiteSpace.CastStructureSpacing`: ability to automatically fix errors thrown by the sniff. -- `WordPress.VIP.SessionFunctionsUsage`: detection of the `session_abort()`, `session_create_id()`, `session_gc()` and `session_reset()` functions. -- `WordPress.CSRF.NonceVerification`: ability to pass [custom sanitization functions](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#custom-input-sanitization-functions) to the sniff. -- The `get_the_ID()` function to the `autoEscapedFunctions` list used by the `WordPress.XSS.EscapeOutput` sniff. -- The `wp_strip_all_tags()`, `sanitize_hex_color_no_hash()` and `sanitize_hex_color()` functions to the `sanitizingFunctions` list used by the `WordPress.CSRF.NonceVerification`, `WordPress.VIP.ValidatedSanitizedInput` and `WordPress.XSS.EscapeOutput` sniffs. -- The `floatval()` function to the `escapingFunctions`, `sanitizingFunctions`, `unslashingSanitizingFunctions`, `SQLEscapingFunctions` lists used by the `WordPress.CSRF.NonceVerification`, `WordPress.VIP.ValidatedSanitizedInput`, `WordPress.XSS.EscapeOutput` and `WordPress.WP.PreparedSQL` sniffs. -- The table name based `clean_*_cache()` functions to the `cacheDeleteFunctions` list used by the `WordPress.VIP.DirectDatabaseQuery` sniff. -- Abstract `AbstractFunctionParameter` parent class to allow for examining parameters passed in function calls. -- A number of utility functions to the `WordPress_Sniff` class: `strip_quotes()`, `addMessage()`, `addFixableMessage()`, `string_to_errorcode()`, `does_function_call_have_parameters()`, `get_function_call_parameter_count()`, `get_function_call_parameters()`, `get_function_call_parameter()`, `has_html_open_tag()`. -- `Squiz.Commenting.LongConditionClosingComment`, `Squiz.WhiteSpace.CastSpacing`, `Generic.Formatting.DisallowMultipleStatements` to the `WordPress-Core` ruleset. -- `Squiz.PHP.NonExecutableCode`, `Squiz.Operators.IncrementDecrementUsage`, `Squiz.Operators.ValidLogicalOperators`, `Squiz.Functions.FunctionDuplicateArgument`, `Generic.PHP.BacktickOperator`, `Squiz.PHP.DisallowSizeFunctionsInLoops` to the `WordPress-Extra` ruleset. -- Numerous additional unit tests covering the correct handling of properties overruled via a custom ruleset by various sniffs. -- Instructions on how to use WPCS with Visual Studio to the Readme. -- Section on how to use WPCS with CI Tools to the Readme, initially covering integration with Travis CI. -- Section on considerations when writing sniffs for WPCS to `Contributing.md`. - -### Changed -- The minimum required PHP version to 5.2 (was 5.1). -- The minimum required PHP_CodeSniffer version to 2.8.1 (was 2.6). -- Improved support for detecting issues in code using closures (anonymous functions), short array syntax and anonymous classes. -- Improved sniff efficiency and performance for a number of sniffs. -- The discouraged/restricted functions sniffs have been reorganized and made more modular. - * The new `WordPress.PHP.DevelopmentFunctions` sniff now contains the checks related to PHP functions typically used during development which are discouraged in production code. - * The new `WordPress.PHP.DiscouragedPHPFunctions` sniff now contains checks related to various PHP functions, use of which is discouraged for various reasons. - * The new `WordPress.WP.AlternativeFunctions` sniff contains the checks related to PHP functions for which WP offers an alternative which should be used instead. - * The new `WordPress.WP.DiscouragedFunctions` sniff contains checks related to various WP functions, use of which is discouraged for various reasons. - * A number of checks contained in the `WordPress.VIP.RestrictedFunctions` sniff have been moved to other sniffs. - * The `WordPress.PHP.DiscouragedFunctions` sniff has been deprecated and is no longer used. The checks which were previously contained herein have been moved to other sniffs. - * The reorganized sniffs also detect a number of additional functions which were previously ignored by these sniffs. For more detail, please refer to the [summary of the PR](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/633#issuecomment-269693016) and to [PR #759](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/759). -- The error codes for these sniffs as well as for `WordPress.DB.RestrictedClasses`, `WordPress.DB.RestrictedFunctions`, `WordPress.Functions.DontExtract`, `WordPress.PHP.POSIXFunctions` and a number of the `VIP` sniffs have changed. They were previously based on function group names and will now be based on function group name in combination with the identified function name. Complete function groups can still be silenced by using the [`exclude` property](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#excluding-a-group-of-checks) in a custom ruleset. -- `WordPress.NamingConventions.ValidVariableName`: The `customVariablesWhitelist` property which could be passed from the ruleset has been renamed to [`customPropertiesWhitelist`](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#mixed-case-property-name-exceptions) as it is only usable to whitelist class properties. -- `WordPress.WP.I18n`: now allows for an array of text domain names to be passed to the `text_domain` property from a custom ruleset. -- `WordPress.WhiteSpace.CastStructureSpacing`: the error level for the checks in this sniff has been raised from `warning` to `error`. -- `WordPress.Variables.GlobalVariables`: will no longer throw errors if the global variable override is done from within a test method. Whether something is considered a "test method" is based on whether the method is in a class which extends a predefined set of known unit test classes. This list can be enhanced by setting the [`custom_test_class_whitelist` property](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#global-variable-overloads-in-unit-tests) in your ruleset. -- The `WordPress.Arrays.ArrayDeclaration` sniff has been split into two sniffs: `WordPress.Arrays.ArrayDeclaration` and `WordPress.Arrays.ArrayDeclarationSpacing` for better compatibility with PHPCS upstream. -- The `WordPress.Arrays.ArrayDeclaration` sniff has been synced with the PHPCS upstream version to get the benefit of some bug fixes and improvements which had been made upstream since the sniff was originally copied over. -- The `WordPress.VIP.FileSystemWritesDisallow`, `WordPress.VIP.TimezoneChange` and `WordPress.VIP.SessionFunctionsUsage` sniffs now extend the `WordPress_AbstractFunctionRestrictionsSniff`. -- Property handling of custom properties set via a custom ruleset where the property is expected to be set in array format (`type="array"`) has been made more lenient and will now also handle properties passed as a comma delimited lists correctly. This affects all customizable properties which expect array format. -- Moved `Squiz.PHP.DisallowMultipleAssignments` from the `WordPress-Extra` to the `WordPress-Core` ruleset. -- Replaced the `WordPress.Classes.ValidClassName`, `WordPress.PHP.DisallowAlternativePHPTags` and the `WordPress.Classes.ClassOpeningStatement` sniffs with the existing `PEAR.NamingConventions.ValidClassName` and the new upstream `Generic.PHP.DisallowAlternativePHPTags` and `Generic.Classes.OpeningBraceSameLine` sniffs in the `WordPress-Core` ruleset. -- Use the upstream `Squiz.PHP.Eval` sniff for detecting the use of `eval()` instead of a WPCS native implementation. -- Made the `Generic.WhiteSpace.ScopeIndent` sniff in the `WordPress-Core` ruleset more lenient to allow for different indentation in inline HTML, heredoc and nowdoc structures. -- Made the `Generic.Strings.UnnecessaryStringConcat` sniff in the `WordPress-Extra` ruleset more lenient to allow for multi-line string concatenation. -- All sniffs are now also being tested against PHP 7.1 for consistent sniff results. -- The requirements for running the sniffs have been made more explicit in the readme. -- Updated composer installation instructions in the readme. -- Updated information about the rulesets in the readme and moved the information up to make it easier to find. -- Improved the information about running the unit tests in `Contributing.md`. -- Improved the inline documentation of the rulesets. -- Various other code quality and code consistency improvements under the hood, including refactoring of some of the abstract sniff classes, closer coupling of the child classes to the `WordPress_Sniff` parent class and changes to the visibility and staticness of properties for a large number of sniffs. - -### Removed -- Warnings thrown by individual sniffs about parse errors they encounter. This is left up to the `Generic.PHP.Syntax` sniff which is included in the `WordPress-Extra` ruleset. -- The `post_class()` function from the `autoEscapedFunctions` list used by the `WordPress.XSS.EscapeOutput` sniff. -- The `Generic.Files.LowercasedFilename` sniff from the `WordPress-Core` ruleset in favour of the improved `WordPress.Files.FileName` sniff to prevent duplicate messages being thrown. -- Some temporary work-arounds for changes which were pulled and merged into PHPCS upstream. - -### Fixed -- `WordPress.Variables.GlobalVariables`: **_All known bugs have been fixed. If you'd previously disabled the sniff in your custom ruleset because of these bugs, it should be fine to re-enable it now._** - * Assignments to global variables using other assignment operators than the `=` operator were not detected. - * If a `global ...;` statement was detected, the whole file would be checked for the variables which were made global, not just the code after the global statement. - * If a `global ...;` statement was detected, the whole file would be checked for the variables which were made global, including code contained within a function/closure/class scope where there is no access to the global variable. - * If a `global ...;` statement was detected within a function call or closure, the whole file would be checked for the variables which were made global, not just the code within the function or closure. - * If a `global ...;` statement was detected and an assignment was made to a static class variable using the same name as one of the variables made global, an error would incorrectly be thrown. - * An override of a protected global via `$GLOBALS` in combination with simple string concatenation obfuscation was not being detected. -- `WordPress.WP.I18n`: all reported bugs have been fixed. - * A superfluous `UnorderedPlaceholders` error was being thrown when `%%` (a literal % sign) was encountered in a string. - * The sniff would sometimes erroneously trigger errors when a literal `%` was found in a translatable string without placeholders. - * Not all type of placeholders were being recognized. - * No warning was being thrown when encountering a mix of ordered and unordered placeholders. - * The fixer for unordered placeholders was erroneously replacing all placeholders as if they were the first one. - * The fixer for unordered placeholders could cause faulty replacements in double quoted strings. - * Compatibility with PHP nightly / PHP 7.2. -- `WordPress.WhiteSpace.ControlStructureSpacing`: synced in fixes from the upstream version. - * The fixer would bork on control structures which contained only a single empty line. - * The sniff did not check the spacing used for `do {} while ()` control structures. - * Conditional function declarations could cause an infinite loop when using the fixer. -- `WordPress.VIP.PluginMenuSlug`: the sniff would potentially incorrectly process method calls and namespaced functions with the same function name as the targeted WordPress native functions. -- `WordPress.VIP.CronInterval`: the native WP time constants were not recognized leading to false positives. -- `WordPress.VIP.CronInterval`: the finding of the referenced function declaration has been made more accurate. -- `WordPress.PHP.YodaConditions`: minor clarification of the error message. -- `WordPress.NamingConventions.ValidVariableName`: now allows for a predefined list of known mixed case global variables coming from WordPress itself reducing false positives. -- The `unslashingSanitizingFunctions` list was not consistently taken into account when verifying whether a variable was sanitized for the `WordPress.VIP.ValidatedSanitizedInput` and `WordPress.CSRF.NonceVerification` sniffs. -- The passing of properties via the ruleset was buggy for a number of sniffs - most notably those sniffs using custom properties in array format - and could lead to unintended bleed-through between sniffs. -- Various (potential) `Undefined variable`, `Undefined index` and `Undefined offset` notices. -- An issue with placeholder replacement not taking place in some error messages. -- A (potential) issue which could play up when sniffs examined text strings which contained quotes. - - -## [0.10.0] - 2016-08-29 - -### Added -- `WordPress.WP.I18n` sniff to the `WordPress-Core` ruleset to flag dynamic translatable strings and textdomains. -- `WordPress.PHP.DisallowAlternativePHPTags` sniff to the `WordPress-Core` ruleset to flag - and fix - ASP and ` - -'; -echo ''; \ No newline at end of file diff --git a/wpcs/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php b/wpcs/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php deleted file mode 100644 index 51c29b5..0000000 --- a/wpcs/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php +++ /dev/null @@ -1,56 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 1 => 1, - 2 => 1, - 6 => 1, - 7 => 1, - 10 => 1, - 11 => 1, - ); - - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array(); - - } - -} // End class. diff --git a/wpcs/WordPress/Tests/WP/I18nUnitTest.1.inc b/wpcs/WordPress/Tests/WP/I18nUnitTest.1.inc deleted file mode 100644 index 2d9a38c..0000000 --- a/wpcs/WordPress/Tests/WP/I18nUnitTest.1.inc +++ /dev/null @@ -1,104 +0,0 @@ - => - */ - public function getErrorList( $testFile = 'I18nUnitTest.inc' ) { - - switch ( $testFile ) { - case 'I18nUnitTest.inc': - return array( - 3 => 1, - 6 => 1, - 9 => 1, - 11 => 1, - 13 => 1, - 15 => 1, - 17 => 1, - 19 => 1, - 21 => 1, - 23 => 1, - 25 => 1, - 27 => 1, - 33 => 1, - 35 => 1, - 37 => 1, - 39 => 1, - 41 => 1, - 43 => 1, - 45 => 1, - 47 => 1, - 48 => 1, - 50 => 1, - 52 => 1, - 53 => 1, - 55 => 1, - 56 => 2, - 58 => 1, - 59 => 1, - 60 => 1, - 62 => 1, - 63 => 2, - 65 => 1, - 66 => 1, - 67 => 1, - 72 => 1, - 74 => 1, - 75 => 1, - 76 => 1, - 77 => 1, - 78 => 1, - 93 => 1, - 95 => 2, - 100 => 1, - 101 => 1, - 102 => 1, - 103 => 1, - 105 => 1, - 106 => 1, - 107 => 1, - 120 => 1, - 121 => 1, - 122 => 1, - 123 => 1, - 124 => 1, - 125 => 1, - 128 => 1, - 129 => 1, - ); - - case 'I18nUnitTest.1.inc': - return array( - 104 => 2, - ); - - default: - return array(); - - } // End switch(). - - } // end getErrorList() - - /** - * Returns the lines where warnings should occur. - * - * @param string $testFile The name of the file being tested. - * @return array => - */ - public function getWarningList( $testFile = 'I18nUnitTest.inc' ) { - switch ( $testFile ) { - case 'I18nUnitTest.inc': - return array( - 69 => 1, - 70 => 1, - 100 => 1, - 101 => 1, - 102 => 1, - 103 => 1, - ); - - case 'I18nUnitTest.1.inc': - return array( - 8 => 1, - 43 => 1, - 49 => 1, - 52 => 1, - 74 => 1, - 85 => 1, - ); - - default: - return array(); - - } - } - -} // End class. diff --git a/wpcs/WordPress/Tests/WP/PreparedSQLUnitTest.inc b/wpcs/WordPress/Tests/WP/PreparedSQLUnitTest.inc deleted file mode 100644 index ff20f58..0000000 --- a/wpcs/WordPress/Tests/WP/PreparedSQLUnitTest.inc +++ /dev/null @@ -1,33 +0,0 @@ -query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . $_GET['title'] . "';" ); // Bad. -$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '{$_GET['title']}';" ); // Bad. -$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '$var';" ); // Bad. -$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE 'Hello World!';" ); // Ok. -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '{$_GET['title']}';" ) ); // Bad. -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '$var';" ) ); // Bad. -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE %s;", $_GET['title'] ) ); // Ok. - -$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . $escaped_var . "';" ); // WPCS: unprepared SQL OK. -$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '{$escaped_var}';" ); // WPCS: unprepared SQL OK. - -$wpdb->query( $wpdb->prepare( "SELECT SUBSTRING( post_name, %d + 1 ) REGEXP '^[0-9]+$'", array( 123 ) ) ); // Ok. -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The \$_GET var can be evil.' AND ID = %s", array( 123 ) ) ); // Ok. -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The $_GET[foo] var is evil.' AND ID = %s", array( 123 ) ) ); // Bad. -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The \\$_GET[foo]// var is evil again.' AND ID = %s", array( 123 ) ) ); // Bad. -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The \$_GET var can be evil, but $_GET[foo] var is evil.' AND ID = %s", array( 123 ) ) ); // Bad. - -$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . foo() . "';" ); // Bad. -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . foo() . "';" ) ); // Bad. - -$wpdb->query( "SELECT * FROM " . $wpdb->posts . " WHERE post_title LIKE 'foo';" ); // Ok. - -// All OK. -$all_post_meta = $wpdb->get_results( $wpdb->prepare( sprintf( - 'SELECT `post_id`, `meta_value` FROM `%s` WHERE `meta_key` = "sort_order" AND `post_id` IN (%s)', - $wpdb->postmeta, - implode( ',', array_fill( 0, count( $post_ids ), '%d' ) ) -), $post_ids ) ); - -$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . esc_sql( $foo ) . "';" ); // Ok. -$wpdb->query( "SELECT * FROM $wpdb->posts WHERE ID = " . absint( $foo ) . ";" ); // Ok. diff --git a/wpcs/WordPress/Tests/WP/PreparedSQLUnitTest.php b/wpcs/WordPress/Tests/WP/PreparedSQLUnitTest.php deleted file mode 100644 index 6058ae7..0000000 --- a/wpcs/WordPress/Tests/WP/PreparedSQLUnitTest.php +++ /dev/null @@ -1,52 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 3 => 1, - 4 => 1, - 5 => 1, - 7 => 1, - 8 => 1, - 16 => 1, - 17 => 1, - 18 => 1, - 20 => 1, - 21 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @since 0.8.0 - * - * @return array => - */ - public function getWarningList() { - return array(); - - } - -} // End class. diff --git a/wpcs/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc b/wpcs/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc deleted file mode 100644 index b17bc2c..0000000 --- a/wpcs/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc +++ /dev/null @@ -1,22 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 3 => 2, - 6 => 2, - 9 => 2, - 12 => 2, - 15 => 2, - 18 => 2, - 21 => 2, - ); - - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array(); - - } - -} // End class. diff --git a/wpcs/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc b/wpcs/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc deleted file mode 100644 index dbd0d4e..0000000 --- a/wpcs/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc +++ /dev/null @@ -1,213 +0,0 @@ - => - */ - public function getErrorList() { - $ret = array( - 4 => 2, - 17 => 2, - 29 => 5, - 37 => 1, - 41 => 1, - 42 => 1, - 49 => 5, - 58 => 3, - 67 => 1, - 68 => 1, - 69 => 1, - 71 => 1, - 72 => 1, - 81 => 3, - 82 => 1, - 85 => 1, - 91 => 2, - 92 => 1, - 94 => 1, - 95 => 1, - 97 => 1, - 98 => 1, - 135 => 2, - 137 => 5, - 144 => 1, - 152 => 2, - 179 => 1, - 180 => 1, - 182 => 1, - 184 => 1, - 190 => 1, - 192 => 1, - 196 => 2, - 200 => 2, - ); - - /* - Uncomment when "$blank_line_check" parameter will be "true" by default. - - $ret[29] += 1; - $ret[33] = 1; - $ret[36] = 1; - $ret[38] = 1; - */ - - return $ret; - - } // end getErrorList() - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array(); - - } - -} // End class. diff --git a/wpcs/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc b/wpcs/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc deleted file mode 100644 index fc9dab4..0000000 --- a/wpcs/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc +++ /dev/null @@ -1,55 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 5 => 4, - 18 => 1, - 45 => 1, - 49 => 1, - ); - - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array(); - - } - -} // End class. diff --git a/wpcs/WordPress/Tests/XSS/EscapeOutputUnitTest.inc b/wpcs/WordPress/Tests/XSS/EscapeOutputUnitTest.inc deleted file mode 100644 index 8999a0a..0000000 --- a/wpcs/WordPress/Tests/XSS/EscapeOutputUnitTest.inc +++ /dev/null @@ -1,207 +0,0 @@ - -
- - -

-

-

- - '; - -echo ent2ncr( $text ); // Bad. - -echo number_format( 1024 ); - -echo ent2ncr( esc_html( $_data ) ); - -echo $foo ? $foo : 'no foo'; // Bad. -echo empty( $foo ) ? 'no foo' : $foo; // Bad. -echo $foo ? esc_html( $foo ) : 'no foo'; // Ok. - -echo 4; // Ok. - -exit( $foo ); // Bad. -exit( esc_html( $foo ) ); // Ok. - -die( $foo ); // Bad. -die( esc_html( $foo ) ); // Ok. - -printf( 'Hello %s', $foo ); // Bad. -printf( 'Hello %s', esc_html( $foo ) ); // Ok. -printf( 'Hello %s! Hi %s!', esc_html( $foo ), $bar ); // Bad. - -vprintf( 'Hello %s', array( $foo ) ); // Bad. -vprintf( 'Hello %s', array( esc_html( $foo ) ) ); // Ok. - -// The below checks that functions which are marked as needed further sanitization -// don't spill over into later arguments when nested in a function call. There was -// a bug which would cause line 84 to be marked as needing sanitization because _x() -// is marked as needing sanitization. -do_something( - _x( 'Some string', 'context', 'domain' ) - , array( $foo ) // Ok. -); - -// There was a bug where an empty exit followed by other code would give an error. -if ( ! defined( 'ABSPATH' ) ) { - exit; // Ok. -} else { - other(); -} - -printf( - /* translators: this comment is just for you. */ - esc_html__( 'Hello %s.', 'domain' ) - , 'world' - // There were other long arguments down here "in real life", which is why this was multi-line. -); - -wp_die( $message ); // Bad. -wp_die( esc_html( $message ) ); // Ok. -wp_die( esc_html( $message ), $title ); // Bad. -wp_die( esc_html( $message ), esc_html( $title ) ); // Ok. -wp_die( esc_html( $message ), '', array( 'back_link' => true ) ); // Ok. -wp_die( esc_html( $message ), '', array( 'back_link' => false ) ); // Ok. -wp_die( esc_html( $message ), '', array( 'response' => 200 ) ); // Ok. - -echo '

', esc_html( $foo ), '

'; // Ok. -echo 'a', 'b'; // Ok. -echo 'Hello, ', $foo; // Bad. -echo esc_html( $foo ), $bar; // Bad. -echo (int) $foo, $bar; // Bad. -echo (int) get_post_meta( $post_id, SOME_NUMBER, true ), do_something( $else ); // Bad. - -wp_die( -1 ); // Ok. - -?> -

- - -' . sprintf( esc_html__( 'Some text -> %sLink text%s', 'textdomain' ), '', '' ). '

'; // Ok. - -echo '
' . sprintf( esc_html__( 'Found %d results', 'textdomain' ), (int) $result_count ) . '

'; // Ok. - -echo sprintf( 'Hello %s', $foo ); // Bad. -echo sprintf( 'Hello %s', esc_html( $foo ) ); // Ok. -echo sprintf( 'Hello %s! Hi %s!', esc_html( $foo ), $bar ); // Bad. - -echo vsprintf( 'Hello %s', array( $foo ) ); // Bad. -echo vsprintf( 'Hello %s', array( esc_html( $foo ) ) ); // Ok. - -echo sprintf( __( 'Welcome to Genesis %s', 'genesis' ), PARENT_THEME_BRANCH ); // Bad x 2. -echo sprintf( esc_html__( 'Welcome to Genesis %s', 'genesis' ), esc_html( PARENT_THEME_BRANCH ) ); // Ok. - -echo esc_html( strval( $_var ) ? $_var : gettype( $_var ) ); // Ok. -echo ( $is_hidden ) ? ' style="display:none;"' : ''; // Ok. -echo sprintf( 'Howdy, %s', esc_html( $name ? $name : __( 'Partner' ) ) ); // Ok. - -_e( 'Something' ); // Bad. -esc_html_e( 'Something' ); // Ok. - -echo $something // Bad. - . esc_attr( 'baz-' // Rest is OK. - . $r - . ( $r === $active_round ? ' foo' : '' ) - . ( $r < $active_round ? ' bar' : '' ) - ) . 'something'; - -echo implode( '
', $items ); // Bad. -echo implode( '
', urlencode_deep( $items ) ); // Ok. -echo implode( '
', array_map( 'esc_html', $items ) ); // Ok. -echo implode( '
', array_map( 'foo', $items ) ); // Bad. -echo join( '
', $items ); // Bad. -echo join( '
', array_map( 'esc_html', $items ) ); // Ok. - -echo ''; - -_deprecated_hook( 'some_filter', '1.3.0', esc_html__( 'The $arg is deprecated.' ), 'some_other_filter' ); // Ok. -_deprecated_hook( "filter_{$context}", '1.3.0', __( 'The $arg is deprecated.' ), sprintf( __( 'Some parsed message %s', $variable ) ) ); // Bad. - -echo add_filter( get_the_excerpt( get_the_ID() ) ; // Bad, but ignored as code contains a parse error. - -/* - * Test using custom properties, setting & unsetting (resetting). - */ -// @codingStandardsChangeSetting WordPress.XSS.EscapeOutput customPrintingFunctions to_screen,my_print -to_screen( $var1, esc_attr( $var2 ) ); // Bad x 1. -my_print( $var1, $var2 ); // Bad x 2. - -// @codingStandardsChangeSetting WordPress.XSS.EscapeOutput customEscapingFunctions esc_form_field -// @codingStandardsChangeSetting WordPress.XSS.EscapeOutput customAutoEscapedFunctions post_info,cpt_info - -echo esc_form_field( $var ); // Ok. -echo post_info( $post_id, 'field' ); // Ok. -echo cpt_info( $post_type, 'query' ); // Ok. -to_screen( esc_form_field( $var1), esc_attr( $var2 ) ); // Ok. - -// @codingStandardsChangeSetting WordPress.XSS.EscapeOutput customPrintingFunctions false -// @codingStandardsChangeSetting WordPress.XSS.EscapeOutput customEscapingFunctions false -// @codingStandardsChangeSetting WordPress.XSS.EscapeOutput customAutoEscapedFunctions false - -echo esc_form_field( $var ); // Bad. -echo post_info( $post_id, 'field' ); // Bad. -echo cpt_info( $post_type, 'query' ); // Bad. diff --git a/wpcs/WordPress/Tests/XSS/EscapeOutputUnitTest.php b/wpcs/WordPress/Tests/XSS/EscapeOutputUnitTest.php deleted file mode 100644 index 8d8831c..0000000 --- a/wpcs/WordPress/Tests/XSS/EscapeOutputUnitTest.php +++ /dev/null @@ -1,80 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 17 => 1, - 19 => 1, - 36 => 1, - 39 => 1, - 40 => 1, - 41 => 1, - 43 => 1, - 46 => 1, - 53 => 1, - 59 => 1, - 60 => 1, - 65 => 1, - 68 => 1, - 71 => 1, - 73 => 1, - 75 => 1, - 101 => 1, - 103 => 1, - 111 => 1, - 112 => 1, - 113 => 1, - 114 => 1, - 125 => 1, - 131 => 1, - 135 => 1, - 138 => 1, - 145 => 1, - 147 => 1, - 149 => 1, - 152 => 2, - 159 => 1, - 162 => 1, - 169 => 1, - 172 => 1, - 173 => 1, - 182 => 3, - 190 => 1, - 191 => 2, - 205 => 1, - 206 => 1, - 207 => 1, - ); - - } // end getErrorList() - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array(); - - } - -} // End class. diff --git a/wpcs/WordPress/ruleset.xml b/wpcs/WordPress/ruleset.xml deleted file mode 100644 index 6fb1742..0000000 --- a/wpcs/WordPress/ruleset.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - WordPress Coding Standards - - - - - - - - - - - - - - diff --git a/wpcs/bin/phpcs.xml b/wpcs/bin/phpcs.xml deleted file mode 100644 index f6a7e6e..0000000 --- a/wpcs/bin/phpcs.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - The Coding standard for the WordPress Coding Standards itself. - - - - - - - - - diff --git a/wpcs/bin/pre-commit b/wpcs/bin/pre-commit deleted file mode 100755 index 24de124..0000000 --- a/wpcs/bin/pre-commit +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -set -e -cd "$(git rev-parse --show-toplevel)" - -phpcs_root="$(dirname $(dirname $(which phpcs)))" - -if [ -z "$phpcs_root" ] || [ ! -d "$phpcs_root" ] || [ ! -e "$phpcs_root/tests/AllTests.php" ]; then - echo "Unable to locate phpcs on path to locate the root of the PHP_CodeSniffer project" 1>&2 - exit 1 -fi - -find . \( -name '*.php' \) -exec php -lf {} \; - -phpunit --filter WordPress "$phpcs_root/tests/AllTests.php" diff --git a/wpcs/composer.json b/wpcs/composer.json deleted file mode 100644 index aced619..0000000 --- a/wpcs/composer.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name" : "wp-coding-standards/wpcs", - "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", - "keywords" : ["phpcs", "standards", "WordPress"], - "license" : "MIT", - "authors" : [ - { - "name" : "Contributors", - "homepage": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/graphs/contributors" - - } - ], - "require" : { - "squizlabs/php_codesniffer": "^2.8.1" - }, - "minimum-stability" : "RC", - "support" : { - "issues": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues" - }, - "scripts" : { - "post-install-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths ../../..", - "post-update-cmd" : "\"vendor/bin/phpcs\" --config-set installed_paths ../../.." - } -} diff --git a/wpcs/myconfig.ini b/wpcs/myconfig.ini deleted file mode 100644 index 8c5f68f..0000000 --- a/wpcs/myconfig.ini +++ /dev/null @@ -1,3 +0,0 @@ -; Allow ASP-style <% %> tags. -; http://php.net/asp-tags -asp_tags = On diff --git a/wpcs/project.ruleset.xml.example b/wpcs/project.ruleset.xml.example deleted file mode 100644 index 8893a4e..0000000 --- a/wpcs/project.ruleset.xml.example +++ /dev/null @@ -1,34 +0,0 @@ - - - A custom set of rules to check for a WPized WordPress project - - /docroot/wp-admin/* - /docroot/wp-includes/* - /docroot/wp-*.php - /docroot/index.php - /docroot/xmlrpc.php - /docroot/wp-content/plugins/* - *.twig - - - - - - - - - - - - - - -