-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9b5d16
commit deb2e70
Showing
10 changed files
with
4,099 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
name: "Build" | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
phpstan: | ||
name: "phpstan" | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: "Checkout" | ||
uses: "actions/checkout@v4" | ||
|
||
- name: "Install PHP" | ||
uses: "shivammathur/setup-php@v2" | ||
with: | ||
coverage: "none" | ||
php-version: 8.1 | ||
|
||
- name: Get composer cache directory | ||
id: composerCache | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.composerCache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} | ||
restore-keys: ${{ runner.os }}-composer- | ||
|
||
- name: "Install latest dependencies" | ||
run: composer install --ansi --no-interaction --no-progress --prefer-dist | ||
working-directory: "." | ||
|
||
- name: "Run PHPStan" | ||
run: php vendor/bin/phpstan analyse --error-format=github | ||
working-directory: "." | ||
|
||
php-cs-fixer: | ||
name: "php-cs-fixer" | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: "Checkout" | ||
uses: "actions/checkout@v4" | ||
|
||
- name: "Install PHP" | ||
uses: "shivammathur/setup-php@v2" | ||
with: | ||
coverage: "none" | ||
php-version: 8.1 | ||
|
||
- name: Get composer cache directory | ||
id: composerCache | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.composerCache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} | ||
restore-keys: ${{ runner.os }}-composer- | ||
|
||
- name: "Install latest dependencies" | ||
run: composer install --ansi --no-interaction --no-progress --prefer-dist | ||
working-directory: "." | ||
|
||
- name: "Run php-cs-fixer" | ||
run: php vendor/bin/php-cs-fixer fix -v --dry-run --using-cache=no | ||
working-directory: "." | ||
|
||
test: | ||
name: "phpunit" | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: "Checkout" | ||
uses: "actions/checkout@v4" | ||
|
||
- name: "Install PHP" | ||
uses: "shivammathur/setup-php@verbose" | ||
with: | ||
coverage: "pcov" | ||
php-version: 8.1 | ||
|
||
- name: Get composer cache directory | ||
id: composerCache | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.composerCache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} | ||
restore-keys: ${{ runner.os }}-composer- | ||
|
||
- name: "Install latest dependencies" | ||
run: | | ||
composer install --ansi --no-interaction --no-progress --prefer-dist | ||
working-directory: "." | ||
|
||
- name: "Run PHPUnit" | ||
run: php vendor/bin/phpunit | ||
working-directory: "." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea/ | ||
vendor/ | ||
.php-cs-fixer.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
use PhpCsFixer\Config; | ||
use PhpCsFixer\Finder; | ||
|
||
$finder = (new Finder()) | ||
->in(__DIR__) | ||
->exclude('vendor') | ||
; | ||
|
||
return (new Config()) | ||
->setRules([ | ||
'@PhpCsFixer' => true, | ||
'php_unit_test_class_requires_covers' => false, | ||
]) | ||
->setRiskyAllowed(true) | ||
->setFinder($finder) | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Luhn mod n | ||
|
||
`luhn-mod-n` is a very simple solution to generate and verify luhn mod n checksums. Possible bases (value for n) are between 2 and 36. Luhn mod 10 is well known from the credit card number checksum. But also in different bases it can be useful to have this checksum functionality. | ||
|
||
## Example for base 2: | ||
|
||
Input | ||
``` | ||
1001001100101100000001011010010 | ||
``` | ||
|
||
Output (number with checksum) | ||
``` | ||
10010011001011000000010110100100 | ||
``` | ||
|
||
## Example for base 10: | ||
|
||
Input | ||
``` | ||
1234567890 | ||
``` | ||
|
||
Output (number with checksum) | ||
``` | ||
12345678903 | ||
``` | ||
|
||
## Example for base 16: | ||
|
||
Input | ||
``` | ||
499602d2 | ||
``` | ||
|
||
Output (number with checksum) | ||
``` | ||
499602d2f | ||
``` | ||
|
||
## Example for base 36: | ||
|
||
Input | ||
``` | ||
kf12oi | ||
``` | ||
Output (number with checksum) | ||
``` | ||
kf12ois | ||
``` | ||
|
||
## Installing | ||
You can use Composer to add the package to your project: | ||
``` | ||
composer require stocker4all/luhn-mod-n | ||
``` | ||
|
||
|
||
## Usage example | ||
``` | ||
<?php | ||
use S4A\LuhnModN\LuhnModN; | ||
include 'vendor/autoload.php'; | ||
// Base 10 example | ||
$luhnModN = new LuhnModN(); | ||
$number = 1234567890; | ||
// Generate checksum and return it concatenated to given number | ||
$numberWithChecksum = $luhnModN->createChecksum($number, 10); | ||
echo $numberWithChecksum."\n"; | ||
// Generate checksum and return only checksum | ||
$onlyChecksum = $luhnModN->createChecksum($number, 10, false); | ||
echo $onlyChecksum."\n"; | ||
// Verify the checksum | ||
if ($luhnModN->hasValidChecksum($numberWithChecksum, 10)) { | ||
echo "Valid checksum\n"; | ||
} | ||
``` | ||
This example will result in the following output: | ||
|
||
``` | ||
12345678903 | ||
3 | ||
Valid checksum | ||
``` | ||
|
||
## Tests | ||
Some very basic tests are provided in the tests/ directory. Run them with composer install --dev && vendor/bin/phpunit. | ||
|
||
### License | ||
`luhn-mod-n` is licensed under [MIT](./LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "stocker4all/luhn-mod-n", | ||
"description": "luhn-mod-n is a very simple solution to generate and verify luhn mod n checksums. Possible bases (value for n) are between 2 and 36. Luhn mod 10 is well known from the credit card number checksum. But also in different bases it can be useful to have this checksum functionality.", | ||
"type": "library", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"S4A\\LuhnModN\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Mathias Stocker", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"minimum-stability": "stable", | ||
"require-dev": { | ||
"friendsofphp/php-cs-fixer": "^3.48", | ||
"phpstan/phpstan": "^1.10", | ||
"phpstan/phpstan-phpunit": "^1.3", | ||
"phpstan/phpstan-deprecation-rules": "^1.1", | ||
"phpstan/phpstan-strict-rules": "^1.5", | ||
"phpstan/extension-installer": "^1.3", | ||
"phpro/grumphp-shim": "^2.4", | ||
"phpunit/phpunit": "^10" | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"phpstan/extension-installer": true, | ||
"phpro/grumphp-shim": true | ||
} | ||
} | ||
} |
Oops, something went wrong.