PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.6
Kubio AI Page Builder v2.8.6
2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / vendor / fzaninotto / faker / src / Faker / Calculator / Ean.php
kubio / vendor / fzaninotto / faker / src / Faker / Calculator Last commit date
Ean.php 1 year ago Iban.php 1 year ago Inn.php 1 year ago Luhn.php 1 year ago TCNo.php 1 year ago
Ean.php
56 lines
1 <?php
2
3 namespace Faker\Calculator;
4
5 /**
6 * Utility class for validating EAN-8 and EAN-13 numbers
7 *
8 * @package Faker\Calculator
9 */
10 class Ean
11 {
12 /** @var string EAN validation pattern */
13 const PATTERN = '/^(?:\d{8}|\d{13})$/';
14
15 /**
16 * Computes the checksum of an EAN number.
17 *
18 * @see https://en.wikipedia.org/wiki/International_Article_Number
19 *
20 * @param string $digits
21 * @return int
22 */
23 public static function checksum($digits)
24 {
25 $length = strlen($digits);
26
27 $even = 0;
28 for ($i = $length - 1; $i >= 0; $i -= 2) {
29 $even += $digits[$i];
30 }
31
32 $odd = 0;
33 for ($i = $length - 2; $i >= 0; $i -= 2) {
34 $odd += $digits[$i];
35 }
36
37 return (10 - ((3 * $even + $odd) % 10)) % 10;
38 }
39
40 /**
41 * Checks whether the provided number is an EAN compliant number and that
42 * the checksum is correct.
43 *
44 * @param string $ean An EAN number
45 * @return boolean
46 */
47 public static function isValid($ean)
48 {
49 if (!preg_match(self::PATTERN, $ean)) {
50 return false;
51 }
52
53 return self::checksum(substr($ean, 0, -1)) === intval(substr($ean, -1));
54 }
55 }
56