ClassicPress / classic-commerce

A simple but powerful e-commerce platform built for ClassicPress. Forked from WooCommerce and compatible with many Woo extensions.
https://classiccommerce.cc/
GNU General Public License v3.0
50 stars 15 forks source link

Coding standards #191

Open nylen opened 4 years ago

nylen commented 4 years ago

As of https://github.com/ClassicPress-research/classic-commerce/pull/190 the coding standards checks on every PR are disabled. This is because the coding standards checks run whenever a file is changed in a PR against that whole file, but there are many pre-existing standards violations, for example: https://travis-ci.com/ClassicPress-research/classic-commerce/jobs/278382606

The Woo team fixes these as they go along, but this isn't something we want to do (lots of extra work, makes PRs messier). Future approaches to fix this could include:

timbocode commented 4 years ago

Tabs vs spaces might be a good one to start with using PHPCBF.

nylen commented 4 years ago

I used the following command to run phpcs on all PHP files:

git ls-files -z | grep -z '\.php$' | xargs -0 ./vendor/bin/phpcs --encoding=utf-8 -s -n -p | pv > cc-phpcs.txt

Results: https://nylen.io/cc-phpcs.txt

Total number of violations:

grep -P '^\s*\|\s*\|\s*\([^) ]+\)$' cc-phpcs.txt | sed 's/^.*(//; s/)$//' | wc -l
3985

Rules broken with number of violations per rule:

click to expand ```sh grep -P '^\s*\|\s*\|\s*\([^) ]+\)$' cc-phpcs.txt | sed 's/^.*(//; s/)$//' | sort | uniq -c 45 Core.Commenting.CommentTags.AccessTag 120 Core.Commenting.CommentTags.AuthorTag 42 Core.Commenting.CommentTags.CategoryTag 1 Generic.CodeAnalysis.EmptyStatement.DetectedIf 1 Generic.Commenting.DocComment.LongNotCapital 2 Generic.Commenting.DocComment.MissingShort 21 Generic.Commenting.DocComment.ShortNotCapital 10 Generic.Commenting.DocComment.SpacingBeforeTags 1 Generic.Files.EndFileNewline.NotFound 2 Generic.Formatting.SpaceAfterCast.NoSpace 1 Generic.Functions.FunctionCallArgumentSpacing.SpaceBeforeComma 2 Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma 15 Generic.PHP.ForbiddenFunctions.FoundWithAlternative 1 Generic.Strings.UnnecessaryStringConcat.Found 15 Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed 9 Generic.WhiteSpace.ScopeIndent.Incorrect 67 Generic.WhiteSpace.ScopeIndent.IncorrectExact 1 PEAR.Functions.FunctionCallSignature.Indent 99 PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket 99 PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket 1 PEAR.NamingConventions.ValidClassName.Invalid 1 PHPCompatibility.Classes.NewClasses.phardataFound 1 PHPCompatibility.Constants.NewConstants.debug_backtrace_ignore_argsFound 3 PHPCompatibility.FunctionDeclarations.NewClosure.Found 1 PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.Changed 2 PHPCompatibility.FunctionUse.ArgumentFunctionsUsage.InParameterList 2 PHPCompatibility.FunctionUse.NewFunctionParameters.round_modeFound 1 PHPCompatibility.FunctionUse.NewFunctions.array_columnFound 1 PHPCompatibility.FunctionUse.NewFunctions.array_replaceFound 2 PHPCompatibility.FunctionUse.NewFunctions.gc_enableFound 1 PHPCompatibility.Keywords.NewKeywords.t_constFound 1 PHPCompatibility.Keywords.NewKeywords.t_namespaceFound 4 PHPCompatibility.LanguageConstructs.NewEmptyNonVariable.Found 15 PHPCompatibility.LanguageConstructs.NewLanguageConstructs.t_ns_separatorFound 9 PHPCompatibility.ParameterValues.NewHTMLEntitiesEncodingDefault.NotSet 7 PHPCompatibility.ParameterValues.NewIconvMbstringCharsetDefault.NotSet 54 PHPCompatibility.Syntax.NewShortArray.Found 18 PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonCASE 3 PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonDEFAULT 3 Squiz.Classes.SelfMemberReference.NotUsed 15 Squiz.Commenting.BlockComment.HasEmptyLineBefore 4 Squiz.Commenting.ClassComment.Missing 19 Squiz.Commenting.ClassComment.SpacingAfter 26 Squiz.Commenting.FileComment.Missing 19 Squiz.Commenting.FileComment.MissingPackageTag 9 Squiz.Commenting.FileComment.SpacingAfterComment 2 Squiz.Commenting.FileComment.SpacingAfterOpen 6 Squiz.Commenting.FunctionComment.EmptyThrows 1 Squiz.Commenting.FunctionComment.InvalidNoReturn 2 Squiz.Commenting.FunctionComment.InvalidReturnVoid 222 Squiz.Commenting.FunctionComment.MissingParamComment 16 Squiz.Commenting.FunctionComment.MissingParamName 57 Squiz.Commenting.FunctionComment.MissingParamTag 45 Squiz.Commenting.FunctionComment.ParamCommentFullStop 5 Squiz.Commenting.FunctionComment.ParamNameNoMatch 32 Squiz.Commenting.FunctionComment.SpacingAfterParamType 7 Squiz.Commenting.FunctionCommentThrowTag.Missing 1 Squiz.Commenting.FunctionCommentThrowTag.WrongNumber 4 Squiz.Commenting.FunctionComment.WrongStyle 541 Squiz.Commenting.InlineComment.InvalidEndChar 4 Squiz.Commenting.InlineComment.NoSpaceBefore 20 Squiz.Commenting.VariableComment.Missing 5 Squiz.Commenting.VariableComment.MissingVar 3 Squiz.Commenting.VariableComment.WrongStyle 3 Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace 1 Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace 2 Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword 1 Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceAfterEquals 1 Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceBeforeEquals 6 Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpen 10 Squiz.PHP.DisallowMultipleAssignments.Found 56 Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure 7 Squiz.PHP.EmbeddedPhp.ContentAfterEnd 11 Squiz.PHP.EmbeddedPhp.ContentAfterOpen 7 Squiz.PHP.EmbeddedPhp.ContentBeforeEnd 7 Squiz.PHP.EmbeddedPhp.ContentBeforeOpen 12 Squiz.PHP.EmbeddedPhp.NoSemicolon 3 Squiz.PHP.EmbeddedPhp.SpacingBeforeClose 85 Squiz.Scope.MethodScope.Missing 72 Squiz.Strings.ConcatenationSpacing.PaddingFound 15 Squiz.Strings.DoubleQuoteUsage.NotRequired 5 Squiz.WhiteSpace.SuperfluousWhitespace.EndLine 8 WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound 11 WordPress.Arrays.ArrayDeclarationSpacing.NoSpaceAfterArrayOpener 11 WordPress.Arrays.ArrayDeclarationSpacing.NoSpaceBeforeArrayCloser 1 WordPress.Arrays.ArrayIndentation.CloseBraceNotAligned 23 WordPress.Arrays.ArrayKeySpacingRestrictions.NoSpacesAroundArrayKeys 5 WordPress.Arrays.CommaAfterArrayItem.NoComma 8 WordPress.Arrays.CommaAfterArrayItem.SpaceAfterComma 30 WordPress.Classes.ClassInstantiation.MissingParenthesis 33 WordPress.DateTime.CurrentTimeTimestamp.RequestedUTC 65 WordPress.DateTime.RestrictedFunctions.date_date 21 WordPress.DB.PreparedSQL.InterpolatedNotPrepared 13 WordPress.DB.PreparedSQL.NotPrepared 1 WordPress.Files.FileName.InvalidClassFileName 3 WordPress.Files.FileName.NotHyphenatedLowercase 1 WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid 15 WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 2 WordPress.PHP.DontExtract.extract_extract 1 WordPress.PHP.IniSet.display_errors_Blacklisted 4 WordPress.PHP.TypeCasts.DoubleRealFound 18 WordPress.PHP.YodaConditions.NotYoda 345 WordPress.Security.EscapeOutput.OutputNotEscaped 186 WordPress.Security.EscapeOutput.UnsafePrintingFunction 240 WordPress.Security.NonceVerification.Missing 130 WordPress.Security.ValidatedSanitizedInput.InputNotSanitized 174 WordPress.Security.ValidatedSanitizedInput.InputNotValidated 213 WordPress.Security.ValidatedSanitizedInput.MissingUnslash 2 WordPress.WhiteSpace.ControlStructureSpacing.BlankLineAfterEnd 52 WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceAfterOpenParenthesis 2 WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceAfterStructureOpen 52 WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceBeforeCloseParenthesis 2 WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceBeforeOpenParenthesis 61 WordPress.WhiteSpace.DisallowInlineTabs.NonIndentTabsUsed 25 WordPress.WhiteSpace.OperatorSpacing.NoSpaceAfter 28 WordPress.WhiteSpace.OperatorSpacing.NoSpaceBefore 1 WordPress.WhiteSpace.OperatorSpacing.SpacingAfter 4 WordPress.WhiteSpace.OperatorSpacing.SpacingBefore 1 WordPress.WP.DeprecatedParameters.Wp_upload_bitsParam2Found 1 WordPress.WP.EnqueuedResourceParameters.MissingVersion 1 WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet 50 WordPress.WP.GlobalVariablesOverride.Prohibited 4 WordPress.WP.I18n.MissingArgDomain 3 WordPress.WP.I18n.MissingSingularPlaceholder 81 WordPress.WP.I18n.MissingTranslatorsComment ```

Some of these can probably be ignored in phpcs.xml, some can probably be fixed and then enabled for future PRs. I think this should wait until after v1 since there is plenty more urgent work to do.