Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Adds php-cs-fixer on commit #16

Merged
merged 2 commits into from
Mar 10, 2022
Merged

Feat: Adds php-cs-fixer on commit #16

merged 2 commits into from
Mar 10, 2022

Conversation

jakobo
Copy link
Owner

@jakobo jakobo commented Feb 4, 2022

This builds on #13 and adds an on-commit hook using the composer-git-hooks library. It's not foolproof, but it offers some consistency in ensuring code is cleaned up to a common format when committed. Obviously VSCode and other tools do this for us, but if you're using a non PSR-12 editor, it's nice that the code is being cleaned up on commit.

EDIT There's a couple of additional changes required to make this work

  • PSR-12 formatting works now that trailing commas are allowed
  • Versions for existing libraries were widened to ensure coverage and tests can run in the 7.2 environment
  • Commit hooks use git's update index to re-add only staged files if changed

Resolves #14

@jrzepa
Copy link
Contributor

jrzepa commented Feb 5, 2022

I forgot one thing in the previous pull request. You could add a strict types declaration to all php files.

declare(strict_types=1);

And then you have to modify toHOTP method by changing the following line:

$str = str_pad($this->toDec(), $length, "0", STR_PAD_LEFT);

to

$str = str_pad((string)$this->toDec(), $length, '0', STR_PAD_LEFT);

tests/HOTPTest.php Outdated Show resolved Hide resolved
composer.json Outdated Show resolved Hide resolved
composer.json Show resolved Hide resolved
composer.json Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
.php-cs-fixer.php Outdated Show resolved Hide resolved
@jakobo
Copy link
Owner Author

jakobo commented Feb 10, 2022

I have a thought for the 7.2 CI issue.

  1. There is an env value for composer that lets us specify the composer json file to use
  2. Using GitHub workflows, we can create a legacy workflow that only requires the minimal libraries for testing. This would let us use modern tools like the cs fixer while still maintaining current coverage

@jakobo
Copy link
Owner Author

jakobo commented Feb 11, 2022

Just an update. I dug into PHP unit to find a version that was compatible with 7.2. It took quite a bit of shenanigans since brew blocked the old bottle from installing. Once I had a working version, I was able to build and test successfully. With 7.2 in the matrix, I also removed the breaking change / changelog issue. Before merging down, I'll squash these commits and keep our tree tidy.

This change enables PSR-12 syntax formatting on commit for developers.
It ensures that code is consistent on commit. In order for this to work
in CI, the versions for phpunit and php-cs-fixer needed to be widened by
enough to accomodate 7.2.

Resolves #14
"ockcyp/covers-validator": "1.3.3",
"phpunit/phpunit": "^8.5.13||^9.5.0",
"ockcyp/covers-validator": "^1.3.3",
"phpunit/phpunit": "^6.5.14||^7.0.15||^8.5.13||^9.5.0",
Copy link
Owner Author

@jakobo jakobo Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting the largest change for 7.2 compatibility in CI is here. Our tests need to run on phpunit 6.5+ which shouldn't be an issue

@jakobo
Copy link
Owner Author

jakobo commented Feb 24, 2022

@jrzepa strict typings were added. LMK if you see anything else

@jrzepa
Copy link
Contributor

jrzepa commented Mar 10, 2022

@jakobo Everything looks good for me. I think you can merge it :)

@jakobo jakobo merged commit fec132a into master Mar 10, 2022
@jakobo jakobo deleted the jakobo/linthooks branch March 10, 2022 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automated Syntax Formatting on Commit
3 participants