Problem/Motivation

PHPCS is reporting a total of 208 problems. Here is a summary of them:

--------------------------------------------------------------------------------
    SOURCE                                                                 COUNT
--------------------------------------------------------------------------------
[x] Squiz.WhiteSpace.OperatorSpacing.NoSpaceAfter                          28
[x] Squiz.WhiteSpace.OperatorSpacing.NoSpaceBefore                         28
[ ] Drupal.Files.LineLength.TooLong                                        22
[x] SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses.Incorrectl  15
[x] SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator.  11
[x] Squiz.WhiteSpace.SuperfluousWhitespace.EndLine                         9
[x] Generic.PHP.UpperCaseConstant.Found                                    8
[x] Drupal.WhiteSpace.Comma.NoSpace                                        7
[x] Drupal.Commenting.TodoComment.TodoFormat                               6
[ ] Drupal.Commenting.VariableComment.Missing                              6
[x] Drupal.ControlStructures.InlineControlStructure.NotAllowed             6
[x] Generic.Formatting.SpaceAfterCast.NoSpace                              6
[x] Drupal.Classes.UnusedUseStatement.UnusedUse                            5
[x] Drupal.ControlStructures.ControlSignature.SpaceAfterKeyword            4
[x] Drupal.Arrays.Array.ArrayIndentation                                   3
[x] Drupal.Commenting.FunctionComment.Missing                              3
[ ] Drupal.NamingConventions.ValidVariableName.LowerCamelName              3
[x] SlevomatCodingStandard.PHP.ShortList.LongListUsed                      3
[x] Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceAfterEquals    3
[x] Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceBeforeEquals   3
[x] Drupal.Arrays.Array.ArrayClosingIndentation                            2
[x] Drupal.Arrays.Array.CommaLastItem                                      2
[x] Drupal.Commenting.DataTypeNamespace.DataTypeNamespace                  2
[ ] Drupal.Commenting.FunctionComment.MissingReturnComment                 2
[x] SlevomatCodingStandard.TypeHints.DeclareStrictTypes.IncorrectStrictTy  2
[ ] Drupal.Arrays.Array.LongLineDeclaration                                1
[x] Drupal.Classes.ClassDeclaration.CloseBraceAfterBody                    1
[x] Drupal.Classes.UseGlobalClass.RedundantUseStatement                    1
[x] Drupal.Commenting.ClassComment.Missing                                 1
[x] Drupal.Commenting.ClassComment.SpacingAfter                            1
[x] Drupal.Commenting.DocComment.SpacingBeforeTags                         1
[ ] Drupal.Commenting.FunctionComment.MissingParamType                     1
[x] Drupal.Commenting.FunctionComment.WrongStyle                           1
[x] Drupal.Commenting.InlineComment.NotCapital                             1
[x] Drupal.Commenting.PostStatementComment.Found                           1
[x] Drupal.ControlStructures.ControlSignature.SpaceBeforeSemicolon         1
[ ] Drupal.NamingConventions.ValidFunctionName.InvalidPrefix               1
[ ] Drupal.Semantics.FunctionT.NotLiteralString                            1
[x] Drupal.WhiteSpace.OpenTagNewline.BlankLine                             1
[ ] Generic.CodeAnalysis.UselessOverridingMethod.Found                     1
[x] Generic.PHP.LowerCaseKeyword.Found                                     1
[x] Squiz.Functions.MultiLineFunctionDeclaration.OneParamPerLine           1
[x] Squiz.WhiteSpace.FunctionSpacing.AfterLast                             1
[x] Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines                      1
--------------------------------------------------------------------------------
A TOTAL OF 208 SNIFF VIOLATIONS WERE FOUND IN 44 SOURCES
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 35 MARKED SOURCES AUTOMATICALLY (170 VIOLATIONS IN TOTAL)
--------------------------------------------------------------------------------

Trying to fix all of them in one issue would be difficult to review, and would risk introducing unintended errors, so I suggest splitting the fixes into a number of issues.

For this issue just fixing the first two on the list would cut out a quarter of the problems.

Steps to reproduce

Open GitLab in browser and view latest pipeline: https://git.drupalcode.org/issue/smart_date-3433051/-/jobs/1140092

Proposed resolution

For this issue, I suggest foxusing on the first two types of error:

Squiz.WhiteSpace.OperatorSpacing.NoSpaceAfter
Squiz.WhiteSpace.OperatorSpacing.NoSpaceBefore

These relate to spaces before and after operators.

In ParseDates.php, there are a number of instances of 24*60*60, relating to the number of seconds in a day. I think it would be clearer to add a constant to the start of the class as follows:

const SECONDS_IN_DAY = 24 * 60 * 60;

Then replace all the hard coded values with the constant.

As PHP problems do not overlap JavaScript errors, these issues can be worked on in parallel with the ESLint fixes.

Remaining tasks

Related issue #3433051: Add Gitlab CI needs to be merged first.

Insert spaces around operators where mandated.

Replace 24*60*60 with constant in ParseDates.php.

When all PHPCS errors have been resolved, the phpcs tests can be set to require passing.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Issue fork smart_date-3433216

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lostcarpark created an issue. See original summary.

lostcarpark’s picture

Fixed missing spaces around operators.
There were several instances of 24*60*60 so replaced with a "ONE_DAY" constant. Also added "TWENTY_THREE_HOURS" and "FIFTY_NINE_MINUTES" constants for improved clarity.
There were also a couple of cases of 86400 that I replaced with the ONE_DAY constant.

After these changes, PHPCS reported the following:

A TOTAL OF 145 SNIFF VIOLATIONS WERE FOUND IN 42 SOURCES

lostcarpark’s picture

Status: Active » Needs review

mandclu made their first commit to this issue’s fork.

mandclu’s picture

Thanks for filing this and for providing a fix, @lostcarpark. It seemed like overkill to create two constants that were only used once, so I changed it to use the ALL_DAY constant again but subtract 60. Otherwise, this looks great. Merged in.

mandclu’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.