Skip to content

Commit 58e001c

Browse files
committed
mb_str_pad to functions.php
1 parent d756cde commit 58e001c

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"PhpSchool\\PhpWorkshop\\": "src"
4444
},
4545
"files": [
46-
"src/Event/functions.php"
46+
"src/Event/functions.php",
47+
"src/functions.php"
4748
]
4849
},
4950
"autoload-dev": {

src/ResultRenderer/ResultsRenderer.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function render(
113113

114114
foreach ($successes as $success) {
115115
$output->writeLine($this->center($this->style(str_repeat(' ', $longest), ['bg_green'])));
116-
$output->writeLine($this->center($this->style($this->mbStrPad($success, $longest), ['bg_green', 'white', 'bold'])));
116+
$output->writeLine($this->center($this->style(\mb_str_pad($success, $longest), ['bg_green', 'white', 'bold'])));
117117
$output->writeLine($this->center($this->style(str_repeat(' ', $longest), ['bg_green'])));
118118
$output->emptyLine();
119119
}
@@ -139,7 +139,7 @@ private function renderErrorInformation(
139139
foreach ($failures as $result) {
140140
list ($failure, $message) = $result;
141141
$output->writeLine($this->center($this->style(str_repeat(' ', $padLength), ['bg_red'])));
142-
$output->writeLine($this->center($this->style($this->mbStrPad($message, $padLength), ['bg_red'])));
142+
$output->writeLine($this->center($this->style(\mb_str_pad($message, $padLength), ['bg_red'])));
143143
$output->writeLine($this->center($this->style(str_repeat(' ', $padLength), ['bg_red'])));
144144

145145
$output->emptyLine();
@@ -292,17 +292,4 @@ public function lineBreak()
292292
{
293293
return $this->style(str_repeat('', $this->terminal->getWidth()), 'yellow');
294294
}
295-
296-
/**
297-
* @param string $input
298-
* @param int $padLength
299-
* @param string $padString
300-
* @param int $padType
301-
* @return string
302-
*/
303-
public function mbStrPad($input, $padLength, $padString = ' ', $padType = STR_PAD_RIGHT)
304-
{
305-
$diff = strlen($input) - mb_strlen($input);
306-
return str_pad($input, $padLength + $diff, $padString, $padType);
307-
}
308295
}

src/functions.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
if (!function_exists('mb_str_pad')) {
4+
5+
/**
6+
* @param string $input
7+
* @param int $padLength
8+
* @param string $padString
9+
* @param int $padType
10+
* @return string
11+
*/
12+
function mb_str_pad($input, $padLength, $padString = ' ', $padType = STR_PAD_RIGHT)
13+
{
14+
$diff = strlen($input) - mb_strlen($input);
15+
return str_pad($input, $padLength + $diff, $padString, $padType);
16+
}
17+
}

0 commit comments

Comments
 (0)