Skip to content

Commit

Permalink
Leeway (#158)
Browse files Browse the repository at this point in the history
* Leeway

* Doc

* Rector+ECS fix

* Minimum PHP version

* Rector rule restored
  • Loading branch information
Spomky authored Jun 24, 2022
1 parent 1799950 commit 7d32a0a
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.0', '8.1']
php-versions: ['8.1']
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mutation-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.0', '8.1']
php-versions: ['8.1']
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rector_checkstyle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
operating-system: [ ubuntu-latest ]
php-versions: ['8.0', '8.1']
php-versions: ['8.1']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.0', '8.1']
php-versions: ['8.1']
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
operating-system: [ ubuntu-latest ]
php-versions: ['8.0', '8.1']
php-versions: ['8.1']
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}

steps:
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"ext-mbstring": "*",
"paragonie/constant_time_encoding": "^2.0",
"beberlei/assert": "^3.0",
Expand All @@ -31,9 +31,9 @@
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.12.11",
"rector/rector": "^0.13",
"symfony/phpunit-bridge": "^6.0",
"symplify/easy-coding-standard": "^10.0",
"symplify/easy-coding-standard": "^11.0",
"thecodingmachine/phpstan-safe-rule": "^1.0"
},
"autoload": {
Expand Down
3 changes: 2 additions & 1 deletion doc/UPGRADE_v10-v11.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Upgrade from `v10.x` to `v11.x`

Congratulation, you have nothing to do!
Congratulation, you have nothing to do!
This version requires PHP8.1+, but no changes on your side are expected.
146 changes: 64 additions & 82 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveIssetsFixer;
use PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveUnsetsFixer;
use PhpCsFixer\Fixer\Phpdoc\AlignMultilineCommentFixer;
use PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer;
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocOrderFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocTrimConsecutiveBlankLineSeparationFixer;
Expand All @@ -28,91 +27,74 @@
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer;
use PhpCsFixer\Fixer\Whitespace\CompactNullableTypehintFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ContainerConfigurator $containerConfigurator): void {
$header = '';
$header = '';

$containerConfigurator->import(SetList::PSR_12);
$containerConfigurator->import(SetList::PHP_CS_FIXER);
$containerConfigurator->import(SetList::PHP_CS_FIXER_RISKY);
$containerConfigurator->import(SetList::CLEAN_CODE);
$containerConfigurator->import(SetList::SYMFONY);
$containerConfigurator->import(SetList::DOCTRINE_ANNOTATIONS);
$containerConfigurator->import(SetList::SPACES);
$containerConfigurator->import(SetList::PHPUNIT);
$containerConfigurator->import(SetList::SYMPLIFY);
$containerConfigurator->import(SetList::ARRAY);
$containerConfigurator->import(SetList::COMMON);
$containerConfigurator->import(SetList::COMMENTS);
$containerConfigurator->import(SetList::CONTROL_STRUCTURES);
$containerConfigurator->import(SetList::DOCBLOCK);
$containerConfigurator->import(SetList::NAMESPACES);
$containerConfigurator->import(SetList::STRICT);
return static function (ECSConfig $config) use ($header): void {
$config->import(SetList::PSR_12);
$config->import(SetList::CLEAN_CODE);
$config->import(SetList::DOCTRINE_ANNOTATIONS);
$config->import(SetList::SPACES);
$config->import(SetList::PHPUNIT);
$config->import(SetList::SYMPLIFY);
$config->import(SetList::ARRAY);
$config->import(SetList::COMMON);
$config->import(SetList::COMMENTS);
$config->import(SetList::CONTROL_STRUCTURES);
$config->import(SetList::DOCBLOCK);
$config->import(SetList::NAMESPACES);
$config->import(SetList::STRICT);

$services = $containerConfigurator->services();
$services->set(StrictParamFixer::class);
$services->set(StrictComparisonFixer::class);
$services->set(ArraySyntaxFixer::class)
->call('configure', [[
'syntax' => 'short',
]])
;
$services->set(ArrayIndentationFixer::class);
$services->set(OrderedImportsFixer::class);
$services->set(ProtectedToPrivateFixer::class);
$services->set(DeclareStrictTypesFixer::class);
$services->set(NativeConstantInvocationFixer::class);
$services->set(NativeFunctionInvocationFixer::class)
->call('configure', [[
'include' => ['@compiler_optimized'],
'scope' => 'namespaced',
'strict' => true,
]])
;
$services->set(MbStrFunctionsFixer::class);
$services->set(LinebreakAfterOpeningTagFixer::class);
$services->set(CombineConsecutiveIssetsFixer::class);
$services->set(CombineConsecutiveUnsetsFixer::class);
$services->set(CompactNullableTypehintFixer::class);
$services->set(NoSuperfluousElseifFixer::class);
$services->set(NoSuperfluousPhpdocTagsFixer::class);
$services->set(PhpdocTrimConsecutiveBlankLineSeparationFixer::class);
$services->set(PhpdocOrderFixer::class);
$services->set(SimplifiedNullReturnFixer::class);
$services->set(HeaderCommentFixer::class)
->call('configure', [[
'header' => $header,
]])
;
$services->set(AlignMultilineCommentFixer::class)
->call('configure', [[
'comment_type' => 'all_multiline',
]])
;
$services->set(PhpUnitTestAnnotationFixer::class)
->call('configure', [[
'style' => 'annotation',
]])
;
$services->set(PhpUnitTestCaseStaticMethodCallsFixer::class);
$services->set(GlobalNamespaceImportFixer::class)
->call('configure', [[
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
]])
;
$config->rule(StrictParamFixer::class);
$config->rule(StrictComparisonFixer::class);
$config->rule(ArrayIndentationFixer::class);
$config->rule(OrderedImportsFixer::class);
$config->rule(ProtectedToPrivateFixer::class);
$config->rule(DeclareStrictTypesFixer::class);
$config->rule(NativeConstantInvocationFixer::class);
$config->rule(MbStrFunctionsFixer::class);
$config->rule(LinebreakAfterOpeningTagFixer::class);
$config->rule(CombineConsecutiveIssetsFixer::class);
$config->rule(CombineConsecutiveUnsetsFixer::class);
$config->rule(CompactNullableTypehintFixer::class);
$config->rule(NoSuperfluousElseifFixer::class);
$config->rule(NoSuperfluousPhpdocTagsFixer::class);
$config->rule(PhpdocTrimConsecutiveBlankLineSeparationFixer::class);
$config->rule(PhpdocOrderFixer::class);
$config->rule(SimplifiedNullReturnFixer::class);
$config->rule(PhpUnitTestCaseStaticMethodCallsFixer::class);
$config->ruleWithConfiguration(ArraySyntaxFixer::class, [
'syntax' => 'short',
]);
$config->ruleWithConfiguration(NativeFunctionInvocationFixer::class, [
'include' => ['@compiler_optimized'],
'scope' => 'namespaced',
'strict' => true,
]);
$config->ruleWithConfiguration(HeaderCommentFixer::class, [
'header' => $header,
]);
$config->ruleWithConfiguration(AlignMultilineCommentFixer::class, [
'comment_type' => 'all_multiline',
]);
$config->ruleWithConfiguration(PhpUnitTestAnnotationFixer::class, [
'style' => 'annotation',
]);
$config->ruleWithConfiguration(GlobalNamespaceImportFixer::class, [
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
]);

$services->remove(GeneralPhpdocAnnotationRemoveFixer::class);
$services->remove(PhpUnitTestClassRequiresCoversFixer::class);

$parameters = $containerConfigurator->parameters();
$parameters
->set(Option::PARALLEL, true)
->set(Option::PATHS, [__DIR__])
->set(Option::SKIP, [__DIR__ . '/.github', __DIR__ . '/doc', __DIR__ . '/vendor'])
$config->services()
->remove(PhpUnitTestClassRequiresCoversFixer::class)
;

$config->parallel();
$config->paths([
__DIR__.'/src',
__DIR__.'/tests',
]);
};
10 changes: 9 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
</testsuite>
</testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
<arguments>
<array>
<element key="time-sensitive"><string>OTPHP</string></element>
<element key="time-sensitive"><string>OTPHP\TOTP</string></element>
</array>
</arguments>
</listener>
<listener class="Symfony\Bridge\PhpUnit\CoverageListener" />
</listeners>
</phpunit>
44 changes: 23 additions & 21 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@

declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Symfony\Set\SymfonyLevelSetList;
use Rector\Symfony\Set\SymfonySetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(SetList::DEAD_CODE);
$containerConfigurator->import(SetList::PHP_80);
$containerConfigurator->import(SymfonySetList::SYMFONY_52);
$containerConfigurator->import(SymfonySetList::SYMFONY_CODE_QUALITY);
$containerConfigurator->import(SymfonySetList::SYMFONY_52_VALIDATOR_ATTRIBUTES);
$containerConfigurator->import(SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION);
$containerConfigurator->import(SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES);
$containerConfigurator->import(DoctrineSetList::DOCTRINE_CODE_QUALITY);
$containerConfigurator->import(DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES);
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_EXCEPTION);
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD);
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_91);
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_YIELD_DATA_PROVIDER);
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/tests']);
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::IMPORT_SHORT_CLASSES, true);
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(SetList::DEAD_CODE);
$rectorConfig->import(LevelSetList::UP_TO_PHP_81);
$rectorConfig->import(SymfonyLevelSetList::UP_TO_SYMFONY_60);
$rectorConfig->import(SymfonySetList::SYMFONY_CODE_QUALITY);
$rectorConfig->import(SymfonySetList::SYMFONY_52_VALIDATOR_ATTRIBUTES);
$rectorConfig->import(SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION);
$rectorConfig->import(SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES);
$rectorConfig->import(DoctrineSetList::DOCTRINE_CODE_QUALITY);
$rectorConfig->import(DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES);
$rectorConfig->import(PHPUnitSetList::PHPUNIT_EXCEPTION);
$rectorConfig->import(PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD);
$rectorConfig->import(PHPUnitSetList::PHPUNIT_91);
$rectorConfig->import(PHPUnitSetList::PHPUNIT_YIELD_DATA_PROVIDER);
$rectorConfig->paths([__DIR__ . '/src']);
$rectorConfig->phpVersion(PhpVersion::PHP_81);
$rectorConfig->importNames();
$rectorConfig->importShortClasses();

$services = $containerConfigurator->services();
$services = $rectorConfig->services();
$services->set(TypedPropertyRector::class);
};
1 change: 0 additions & 1 deletion src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Assert\Assertion;
use function count;
use InvalidArgumentException;
use function Safe\sprintf;
use Throwable;

/**
Expand Down
17 changes: 7 additions & 10 deletions src/HOTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,13 @@ protected function setCounter(int $counter): void
*/
protected function getParameterMap(): array
{
return array_merge(
parent::getParameterMap(),
[
'counter' => static function ($value): int {
Assertion::greaterOrEqualThan((int) $value, 0, 'Counter must be at least 0.');

return (int) $value;
},
]
);
return [...parent::getParameterMap(), ...[
'counter' => static function ($value): int {
Assertion::greaterOrEqualThan((int) $value, 0, 'Counter must be at least 0.');

return (int) $value;
},
]];
}

private function updateCounter(int $counter): void
Expand Down
8 changes: 3 additions & 5 deletions src/OTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
use Exception;
use ParagonIE\ConstantTime\Base32;
use RuntimeException;
use function Safe\ksort;
use function Safe\sprintf;
use function Safe\unpack;
use const STR_PAD_LEFT;

Expand All @@ -33,9 +31,9 @@ public function getQrCodeUri(string $uri, string $placeholder): string
return str_replace($placeholder, $provisioning_uri, $uri);
}

public function at(int $timestamp): string
public function at(int $input): string
{
return $this->generateOTP($timestamp);
return $this->generateOTP($input);
}

/**
Expand Down Expand Up @@ -80,7 +78,7 @@ protected function generateURI(string $type, array $options): string
$label = $this->getLabel();
Assertion::string($label, 'The label is not set.');
Assertion::false($this->hasColon($label), 'Label must not contain a colon.');
$options = array_merge($options, $this->getParameters());
$options = [...$options, ...$this->getParameters()];
$this->filterOptions($options);
$params = str_replace(['+', '%7E'], ['%20', '~'], http_build_query($options));

Expand Down
2 changes: 1 addition & 1 deletion src/OTPInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface OTPInterface
/**
* @return string Return the OTP at the specified timestamp
*/
public function at(int $timestamp): string;
public function at(int $input): string;

/**
* Verify that the OTP is valid with the specified input. If no input is provided, the input is set to a default
Expand Down
1 change: 0 additions & 1 deletion src/ParameterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Assert\Assertion;
use InvalidArgumentException;
use ParagonIE\ConstantTime\Base32;
use function Safe\sprintf;

trait ParameterTrait
{
Expand Down
Loading

0 comments on commit 7d32a0a

Please sign in to comment.