Skip to content

Commit 0757a1f

Browse files
authored
3954 machine name (#346)
* Replace direct access to sites with getSites * Trim machine names to 32 symbols
1 parent 31167cc commit 0757a1f

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/Utils/StringConverter.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ public function createMachineName($name)
3737
$machine_name = preg_replace(self::REGEX_MACHINE_NAME_CHARS, '_', strtolower($name));
3838
$machine_name = trim($machine_name, '_');
3939

40-
if (strlen($machine_name) > self::MAX_MACHINE_NAME) {
41-
$machine_name = substr($machine_name, 0, self::MAX_MACHINE_NAME);
42-
}
43-
44-
return $machine_name;
40+
return $this->trimMachineNameToMaxLength($machine_name);
4541
}
4642

4743
/**
@@ -57,6 +53,22 @@ public function camelCaseToMachineName($name)
5753
$machine_name = preg_replace(self::REGEX_MACHINE_NAME_CHARS, '_', strtolower($machine_name));
5854
$machine_name = trim($machine_name, '_');
5955

56+
return $this->trimMachineNameToMaxLength($machine_name);
57+
}
58+
59+
/**
60+
* Trim machine name if it exceed max number of symbols for machine names.
61+
*
62+
* @param string $machine_name
63+
* Machine name.
64+
*
65+
* @return string
66+
* Machine name.
67+
*/
68+
public function trimMachineNameToMaxLength($machine_name) {
69+
if (strlen($machine_name) > self::MAX_MACHINE_NAME) {
70+
$machine_name = substr($machine_name, 0, self::MAX_MACHINE_NAME);
71+
}
6072
return $machine_name;
6173
}
6274

0 commit comments

Comments
 (0)