Skip to content

Commit 8981625

Browse files
authored
Merge pull request #2 from aochoae/develop
Luhn algorithm
2 parents b359348 + 2da92d6 commit 8981625

12 files changed

+52
-22
lines changed

.circleci/config.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This config was automatically generated from your source code
2+
# Stacks detected: deps:php:.
3+
version: 2.1
4+
orbs:
5+
php: circleci/php@1
6+
jobs:
7+
test-php:
8+
# Install php packages and run tests
9+
docker:
10+
- image: cimg/php:8.2.7-node
11+
steps:
12+
- checkout
13+
- php/install-packages
14+
- run:
15+
name: run tests
16+
command: ./vendor/bin/phpunit
17+
deploy:
18+
# This is an example deploy job, not actually used by the workflow
19+
docker:
20+
- image: cimg/base:stable
21+
steps:
22+
# Replace this with steps to deploy to users
23+
- run:
24+
name: deploy
25+
command: '#e.g. ./deploy.sh'
26+
workflows:
27+
build-and-test:
28+
jobs:
29+
- test-php
30+
# - deploy:
31+
# requires:
32+
# - test-php

.travis.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Check digit algorithms
2-
[![Build Status](https://app.travis-ci.com/aochoae/checkdigit-algorithms-php.svg?branch=main)](https://app.travis-ci.com/aochoae/checkdigit-algorithms-php)
32

43
Algorithms:
54

@@ -26,6 +25,6 @@ Algorithms:
2625

2726
## License
2827

29-
Copyright 2021 Luis A. Ochoa
28+
Copyright 2021, 2024 Luis A. Ochoa
3029

3130
See [LICENSE](LICENSE) for the full license text.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "luisalberto/checkdigit-algorithms",
33
"description": "Check Digit Algorithms",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"type": "library",
66
"keywords": [
77
"damm-algorithm",

src/CheckDigitInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* @copyright Copyright (c) Luis A. Ochoa
3+
* @copyright Copyright (c) 2021 Luis A. Ochoa
44
* @since 1.0.0
55
* @license https://opensource.org/licenses/MIT MIT License
66
*/

src/CheckDigitTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* @copyright Copyright (c) Luis A. Ochoa
3+
* @copyright Copyright (c) 2021 Luis A. Ochoa
44
* @since 1.0.0
55
* @license https://opensource.org/licenses/MIT MIT License
66
*/

src/DammCheckDigit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* @copyright Copyright (c) Luis A. Ochoa
3+
* @copyright Copyright (c) 2021 Luis A. Ochoa
44
* @since 1.0.0
55
* @license https://opensource.org/licenses/MIT MIT License
66
*/

src/LuhnCheckDigit.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* @copyright Copyright (c) Luis A. Ochoa
3+
* @copyright Copyright (c) 2021, 2024 Luis A. Ochoa
44
* @since 1.0.0
55
* @license https://opensource.org/licenses/MIT MIT License
66
*/
@@ -52,10 +52,10 @@ public function isValid(string $sequence)
5252
*/
5353
private function compute(array $sequence)
5454
{
55-
$newSequence = [];
55+
$newSequence = $sequence;
5656

57-
for ($i = 0; $i < count($sequence); $i++) {
58-
$newSequence[$i] = ($i % 2 === 0) ? self::SUBSTITUTE[$sequence[$i]] : $sequence[$i];
57+
for ($i = count($sequence) - 1; $i >= 0; $i -= 2) {
58+
$newSequence[$i] = self::SUBSTITUTE[$sequence[$i]];
5959
}
6060

6161
$summation = array_sum($newSequence);

src/VerhoeffCheckDigit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* @copyright Copyright (c) Luis A. Ochoa
3+
* @copyright Copyright (c) 2021 Luis A. Ochoa
44
* @since 1.0.0
55
* @license https://opensource.org/licenses/MIT MIT License
66
*/

tests/DammCheckDigitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* @copyright Copyright (c) Luis A. Ochoa
3+
* @copyright Copyright (c) 2021 Luis A. Ochoa
44
* @since 1.0.0
55
* @license https://opensource.org/licenses/MIT MIT License
66
*/

0 commit comments

Comments
 (0)