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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.gitattributes export-ignore
.gitignore export-ignore
.github/ export-ignore
.php-cs-fixer.php export-ignore
composer.json export-ignore
example.php export-ignore
phpunit.xml export-ignore
Expand Down
32 changes: 14 additions & 18 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ on:
pull_request:

jobs:
run:
run-ci:
name: PHP ${{ matrix.php-versions }} test
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -15,21 +16,16 @@ jobs:
- "7.4"
- "8.0"
- "8.1"

name: PHP ${{ matrix.php-versions }} test
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP with XDebug
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: xdebug
tools: composer

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run tests
run: composer test
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP with XDebug
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: xdebug
tools: composer
- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: Run tests
run: composer test
14 changes: 14 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude("tests")
->exclude("vendor")
->in(__DIR__);

$config = new PhpCsFixer\Config();

return $config->setRules([
'@PSR12' => true,
'trailing_comma_in_multiline' => true,
])->setUsingCache(false)
->setFinder($finder);
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Changelog

# next (planned @ 2.0.1)
- Adopts PSR-12 syntax everywhere (:heart: [jrzepa](https://github.com/jrzepa))
- Expands version range for phpunit to ensure tests run against 7.2 [#16](https://github.com/jakobo/hotp-php/pull/16)

# 2.0.0 (Dec 20, 2020)
- Code coverage reporting added (:heart: [reedy](https://github.com/reedy))
- Documentation updates and return type hints (:heart: [reedy](https://github.com/reedy))
- Github CI Support [ac0d8d](https://github.com/jakobo/hotp-php/commit/ac0d8d0d64adc5f7ef83952bde25425bf74184cf) (:heart: [legoktm](https://github.com/legoktm))

## Breaking Changes
- **Bump minimum version** - To stay current, the minimum version was bumped from 5.3.3 to 7.2. We encourage you to update your PHP version to stay on top of potential security vulnerabilities and receive the latest performance and bug fixes.

# 1.0.1 (Apr 11, 2019)
- Token replay mitigation [d24e0d](https://github.com/jakobo/hotp-php/commit/d24e0d021710718cb9104ffb5c6ffb447fce65ab) (:heart: [reedy](https://github.com/reedy))
- Created `composer.json` and made available through composer (:heart: [reedy](https://github.com/reedy))

# 1.0.0
- [reedy](https://github.com/reedy) joined the maintainer team
- Initial Release with a tag
28 changes: 24 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,37 @@
"php": ">=7.2"
},
"require-dev": {
"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

@thecodedrift thecodedrift 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

"php-parallel-lint/php-console-highlighter": "0.5",
"php-parallel-lint/php-parallel-lint": "1.3.1"
"php-parallel-lint/php-parallel-lint": "1.3.1",
"friendsofphp/php-cs-fixer": "^3.4||^3.5||^3.6",
"brainmaestro/composer-git-hooks": "^2.8"
},
"scripts": {
"post-install-cmd": "cghooks add --ignore-lock",
"post-update-cmd": "cghooks update",
"test": [
"parallel-lint . --exclude vendor",
"covers-validator",
"phpunit --coverage-text"
],
"cover": "phpunit --coverage-html coverage"
"cover": "phpunit --coverage-html coverage",
"cghooks": "vendor/bin/cghooks",
"fix": "php-cs-fixer fix --config=.php-cs-fixer.php"
},
"extra": {
"hooks": {
"config": {
"stop-on-failure": ["pre-commit"]
},
"pre-commit": [
"composer run-script fix",
thecodedrift marked this conversation as resolved.
Show resolved Hide resolved
"git update-index --again :/:"
],
"post-merge": [
"composer install"
]
}
}
}
42 changes: 21 additions & 21 deletions example.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* HOTP Example File
*/
Expand Down Expand Up @@ -106,24 +108,23 @@
echo "----------------------------------------------------------------------\n";

// loop over all HOTP table results, and calculate the matching value
foreach ( $table['HOTP'] as $seed => $results ) {
$hotp = HOTP::generateByCounter( $key, $seed );
foreach ($table['HOTP'] as $seed => $results) {
$hotp = HOTP::generateByCounter($key, $seed);
$first = true;
foreach ( $results as $type => $calc ) {
if ( $first ) {
echo str_pad( $seed, 4, ' ', STR_PAD_LEFT );
foreach ($results as $type => $calc) {
if ($first) {
echo str_pad($seed, 4, ' ', STR_PAD_LEFT);
$first = false;
}
else {
} else {
echo ' ';
}
echo ' ';
echo str_pad( $type, 5, ' ', STR_PAD_RIGHT);
echo str_pad($type, 5, ' ', STR_PAD_RIGHT);
echo ' ';
echo str_pad( $calc, 47, ' ', STR_PAD_RIGHT);
echo str_pad($calc, 47, ' ', STR_PAD_RIGHT);
echo ' ';
$method = 'to' . ( ucfirst( str_replace( 'HMAC', 'string', $type ) ) );
echo str_pad( ( $calc == $hotp->$method( 6 ) ) ? '[OK]' : '[FAIL]', 9, ' ', STR_PAD_LEFT );
$method = 'to' . (ucfirst(str_replace('HMAC', 'string', $type)));
echo str_pad(($calc == $hotp->$method(6)) ? '[OK]' : '[FAIL]', 9, ' ', STR_PAD_LEFT);
echo "\n";
}
}
Expand All @@ -138,22 +139,21 @@
echo "----------------------------------------------------------------------\n";

// now echo over the TOTP table
foreach ( $table['TOTP'] as $seed => $results ) {
$totp = HOTP::generateByTime( $key, 30, $seed );
foreach ($table['TOTP'] as $seed => $results) {
$totp = HOTP::generateByTime($key, 30, $seed);
$first = true;
foreach ( $results as $type => $calc ) {
if ( $first ) {
echo str_pad( $seed, 10, ' ', STR_PAD_LEFT );
foreach ($results as $type => $calc) {
if ($first) {
echo str_pad($seed, 10, ' ', STR_PAD_LEFT);
$first = false;
}
else {
} else {
echo ' ';
}
echo ' ';
echo str_pad( $calc, 47, ' ', STR_PAD_RIGHT );
echo str_pad($calc, 47, ' ', STR_PAD_RIGHT);
echo ' ';
$method = 'to' . ( ucfirst( str_replace( 'totp', 'hotp', $type ) ) );
echo str_pad( ( $calc == $totp->$method( 8 ) ) ? '[OK]' : '[FAIL]', 9, ' ', STR_PAD_LEFT );
$method = 'to' . (ucfirst(str_replace('totp', 'hotp', $type)));
echo str_pad(($calc == $totp->$method(8)) ? '[OK]' : '[FAIL]', 9, ' ', STR_PAD_LEFT);
echo "\n";
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/HOTP.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace jakobo\HOTP;

/**
Expand Down
4 changes: 3 additions & 1 deletion src/HOTPResult.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace jakobo\HOTP;

/**
Expand Down Expand Up @@ -83,7 +85,7 @@ public function toDec(): int
*/
public function toHOTP(int $length): string
{
$str = str_pad($this->toDec(), $length, "0", STR_PAD_LEFT);
$str = str_pad((string)$this->toDec(), $length, "0", STR_PAD_LEFT);
return substr($str, (-1 * $length));
}
}
26 changes: 13 additions & 13 deletions tests/HOTPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,79 +23,79 @@ public function provideHOTP(): array
'hex' => '4c93cf18',
'dec' => '1284755224',
'hotp' => '755224',
]
],
],
[
1, [
'HMAC' => '75a48a19d4cbe100644e8ac1397eea747a2d33ab',
'hex' => '41397eea',
'dec' => '1094287082',
'hotp' => '287082',
]
],
],
[
2, [
'HMAC' => '0bacb7fa082fef30782211938bc1c5e70416ff44',
'hex' => '82fef30',
'dec' => '137359152',
'hotp' => '359152',
]
],
],
[
3, [
'HMAC' => '66c28227d03a2d5529262ff016a1e6ef76557ece',
'hex' => '66ef7655',
'dec' => '1726969429',
'hotp' => '969429',
]
],
],
[
4, [
'HMAC' => 'a904c900a64b35909874b33e61c5938a8e15ed1c',
'hex' => '61c5938a',
'dec' => '1640338314',
'hotp' => '338314',
]
],
],
[
5, [
'HMAC' => 'a37e783d7b7233c083d4f62926c7a25f238d0316',
'hex' => '33c083d4',
'dec' => '868254676',
'hotp' => '254676',
]
],
],
[
6, [
'HMAC' => 'bc9cd28561042c83f219324d3c607256c03272ae',
'hex' => '7256c032',
'dec' => '1918287922',
'hotp' => '287922',
]
],
],
[
7, [
'HMAC' => 'a4fb960c0bc06e1eabb804e5b397cdc4b45596fa',
'hex' => '4e5b397',
'dec' => '82162583',
'hotp' => '162583',
]
],
],
[
8, [
'HMAC' => '1b3c89f65e6c9e883012052823443f048b4332db',
'hex' => '2823443f',
'dec' => '673399871',
'hotp' => '399871',
]
],
],
[
9, [
'HMAC' => '1637409809a679dc698207310c8c7fc07290d9e5',
'hex' => '2679dc69',
'dec' => '645520489',
'hotp' => '520489',
]
],
],
];
}
Expand Down Expand Up @@ -177,9 +177,9 @@ public function provideGenerateByTimeWindow(): array
"266759",
"306183",
"466594",
"754889"
]
]
"754889",
],
],
];
}

Expand Down