mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-14 11:08:40 +00:00
fix tests
This commit is contained in:
parent
6e0aebb074
commit
cf72e2f5ec
|
|
@ -583,7 +583,7 @@ final class FileCache extends ConnectionAbstract
|
|||
$cacheExpire = \substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1));
|
||||
$cacheExpire = ($cacheExpire === -1) ? $created : (int) $cacheExpire;
|
||||
|
||||
if ($cacheExpire >= 0 && $created + $cacheExpire + ($expire > 0 ? $expire : 0) < $now) {
|
||||
if ($cacheExpire >= 0 && $created + $cacheExpire + \max(0, $expire) < $now) {
|
||||
File::delete($path);
|
||||
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -545,12 +545,12 @@ class Smtp
|
|||
|
||||
if ($n === 0) {
|
||||
$name = $type;
|
||||
$fields = $fields[0];
|
||||
$fields = ($fields === false ? 0 : $fields[0]);
|
||||
} else {
|
||||
$name = \array_shift($fields);
|
||||
switch ($name) {
|
||||
case 'SIZE':
|
||||
$fields = ($fields ? $fields[0] : 0);
|
||||
$fields = ($fields === false ? 0 : $fields[0]);
|
||||
break;
|
||||
case 'AUTH':
|
||||
if (!\is_array($fields)) {
|
||||
|
|
|
|||
|
|
@ -45,8 +45,6 @@ class SpreadsheetDatabaseMapper implements IODatabaseMapper
|
|||
*/
|
||||
private string $path = '';
|
||||
|
||||
private const ALPHABET = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
|
@ -61,37 +59,6 @@ class SpreadsheetDatabaseMapper implements IODatabaseMapper
|
|||
$this->path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn ints into spreadsheet column names
|
||||
*
|
||||
* @param int $num Column number
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function intToString(int $num) : string
|
||||
{
|
||||
if ($num < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = '';
|
||||
|
||||
while ($num >= 0) {
|
||||
$remainder = $num % 26;
|
||||
$result = self::ALPHABET[$remainder] . $result;
|
||||
|
||||
if ($num < 26) {
|
||||
break;
|
||||
}
|
||||
|
||||
$num = (int) \floor($num / 26);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -119,7 +86,7 @@ class SpreadsheetDatabaseMapper implements IODatabaseMapper
|
|||
|
||||
// get column titles
|
||||
$column = 1;
|
||||
while (!empty($value = $workSheet->getCell(self::intToString($column) . 1)->getCalculatedValue())) {
|
||||
while (!empty($value = $workSheet->getCell(StringUtils::intToAlphabet($column) . 1)->getCalculatedValue())) {
|
||||
$titles[] = $value;
|
||||
++$column;
|
||||
}
|
||||
|
|
@ -183,7 +150,7 @@ class SpreadsheetDatabaseMapper implements IODatabaseMapper
|
|||
|
||||
// set column titles
|
||||
for ($i = 1; $i <= $colCount; ++$i) {
|
||||
$workSheet->setCellValue(self::intToString($i) . 1, $columns[$i - 1]);
|
||||
$workSheet->setCellValue(StringUtils::intToAlphabet($i) . 1, $columns[$i - 1]);
|
||||
}
|
||||
|
||||
// set data
|
||||
|
|
@ -191,7 +158,7 @@ class SpreadsheetDatabaseMapper implements IODatabaseMapper
|
|||
foreach ($results as $result) {
|
||||
$col = 1;
|
||||
foreach ($result as $value) {
|
||||
$workSheet->setCellValue(self::intToString($col) . $row, $value);
|
||||
$workSheet->setCellValue(StringUtils::intToAlphabet($col) . $row, $value);
|
||||
++$col;
|
||||
}
|
||||
|
||||
|
|
@ -235,7 +202,7 @@ class SpreadsheetDatabaseMapper implements IODatabaseMapper
|
|||
|
||||
// get column titles
|
||||
$column = 1;
|
||||
while (!empty($value = $workSheet->getCell(self::intToString($column) . 1)->getCalculatedValue())) {
|
||||
while (!empty($value = $workSheet->getCell(StringUtils::intToAlphabet($column) . 1)->getCalculatedValue())) {
|
||||
$titles[] = $value;
|
||||
++$column;
|
||||
}
|
||||
|
|
@ -249,7 +216,7 @@ class SpreadsheetDatabaseMapper implements IODatabaseMapper
|
|||
$query->update($table)->into($table);
|
||||
|
||||
for ($j = 2; $j <= $columns; ++$j) {
|
||||
$query->sets($titles[$j - 1], $workSheet->getCell(self::intToString($j) . $line)->getCalculatedValue());
|
||||
$query->sets($titles[$j - 1], $workSheet->getCell(StringUtils::intToAlphabet($j) . $line)->getCalculatedValue());
|
||||
}
|
||||
|
||||
$query->where($titles[0], '=', $workSheet->getCell('A' . $line)->getCalculatedValue());
|
||||
|
|
|
|||
|
|
@ -31,6 +31,14 @@ use phpOMS\Contract\SerializableInterface;
|
|||
*/
|
||||
final class StringUtils
|
||||
{
|
||||
/**
|
||||
* Alphabet list
|
||||
*
|
||||
* @var string[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private const ALPHABET = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
|
@ -418,4 +426,35 @@ final class StringUtils
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn ints into spreadsheet column names
|
||||
*
|
||||
* @param int $num Column number
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function intToAlphabet(int $num) : string
|
||||
{
|
||||
if ($num < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = '';
|
||||
|
||||
while ($num >= 0) {
|
||||
$remainder = $num % 26;
|
||||
$result = self::ALPHABET[$remainder] . $result;
|
||||
|
||||
if ($num < 26) {
|
||||
break;
|
||||
}
|
||||
|
||||
$num = (int) \floor($num / 26);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user