|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * DB expression converter |
4 | | - * |
5 | 3 | * Copyright © Magento, Inc. All rights reserved. |
6 | 4 | * See COPYING.txt for license details. |
7 | 5 | */ |
| 6 | + |
8 | 7 | namespace Magento\Framework\DB; |
9 | 8 |
|
| 9 | +/** |
| 10 | + * The Database expression converter |
| 11 | + */ |
10 | 12 | class ExpressionConverter |
11 | 13 | { |
12 | 14 | /** |
13 | 15 | * Maximum length for many MySql identifiers, including database, table, trigger, and column names |
14 | 16 | */ |
15 | | - const MYSQL_IDENTIFIER_LEN = 64; |
| 17 | + public const MYSQL_IDENTIFIER_LEN = 64; |
16 | 18 |
|
17 | 19 | /** |
18 | 20 | * Dictionary maps common words in identifiers to abbreviations |
@@ -90,6 +92,8 @@ public static function addTranslate($from, $to) |
90 | 92 | } |
91 | 93 |
|
92 | 94 | /** |
| 95 | + * Retrieves shorten entity name. |
| 96 | + * |
93 | 97 | * Shorten the name of a MySql identifier, by abbreviating common words and hashing if necessary. Prepends the |
94 | 98 | * given prefix to clarify what kind of entity the identifier represents, in case hashing is used. |
95 | 99 | * |
@@ -125,12 +129,14 @@ public static function shortenEntityName($entityName, $prefix) |
125 | 129 | * @param int $maxCharacters |
126 | 130 | * @return string |
127 | 131 | */ |
128 | | - private static function trimHash($hash, $prefix, $maxCharacters) |
129 | | - { |
130 | | - $diff = strlen($hash) + strlen($prefix) - $maxCharacters; |
131 | | - $superfluous = $diff / 2; |
132 | | - $odd = $diff % 2; |
133 | | - $hash = substr($hash, $superfluous, - ($superfluous + $odd)); |
134 | | - return $hash; |
| 132 | + private static function trimHash( |
| 133 | + string $hash, |
| 134 | + string $prefix, |
| 135 | + int $maxCharacters |
| 136 | + ): string { |
| 137 | + $diff = strlen($hash) + strlen($prefix) - $maxCharacters; |
| 138 | + $superfluous = intdiv($diff, 2); |
| 139 | + $odd = $diff % 2; |
| 140 | + return substr($hash, $superfluous, - ($superfluous + $odd)); |
135 | 141 | } |
136 | 142 | } |
0 commit comments