| Total Complexity | 9 |
| Total Lines | 78 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | class HashHelper |
||
| 17 | { |
||
| 18 | const HASH_LENGTH = 20; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * generates a hash from alpha numeric characters of length 20. |
||
| 22 | * |
||
| 23 | * @return string |
||
| 24 | */ |
||
| 25 | public static function getHash() |
||
| 26 | { |
||
| 27 | $newHash = ''; |
||
| 28 | //0-9, A-Z, a-z |
||
| 29 | $allowedRanges = [[48, 57], [65, 90], [97, 122]]; |
||
| 30 | $rangeCount = \count($allowedRanges); |
||
| 31 | for ($i = 0; $i < static::HASH_LENGTH; ++$i) { |
||
| 32 | $rand = mt_rand(20, 160); |
||
| 33 | $allowed = false; |
||
| 34 | for ($j = 0; $j < $rangeCount; ++$j) { |
||
| 35 | if ($allowedRanges[$j][0] <= $rand && $allowedRanges[$j][1] >= $rand) { |
||
| 36 | $allowed = true; |
||
| 37 | } |
||
| 38 | } |
||
| 39 | if ($allowed) { |
||
| 40 | $newHash .= \chr($rand); |
||
| 41 | } else { |
||
| 42 | --$i; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | return $newHash; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * creates a hash from the entities using the guid. |
||
| 51 | * |
||
| 52 | * @param $entities |
||
| 53 | * |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | public static function hashEntities($entities) |
||
| 67 | ) |
||
| 68 | ); |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * creates a hash from a 2d arrays of entities using the guid. |
||
| 73 | * |
||
| 74 | * @param IdTrait[][] $entities |
||
| 75 | * |
||
| 76 | * @return string |
||
| 77 | */ |
||
| 78 | public static function hash2dEntities($entities) |
||
| 94 | } |
||
| 95 | } |
||
| 96 |