diff --git a/DataStorage/Cache/Connection/FileCache.php b/DataStorage/Cache/Connection/FileCache.php index 18309d8dd..e5c210295 100755 --- a/DataStorage/Cache/Connection/FileCache.php +++ b/DataStorage/Cache/Connection/FileCache.php @@ -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; diff --git a/Message/Mail/Smtp.php b/Message/Mail/Smtp.php index 403e9d6ee..12bf3916f 100755 --- a/Message/Mail/Smtp.php +++ b/Message/Mail/Smtp.php @@ -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)) { diff --git a/Utils/IO/Spreadsheet/SpreadsheetDatabaseMapper.php b/Utils/IO/Spreadsheet/SpreadsheetDatabaseMapper.php index e30593754..d70b44066 100755 --- a/Utils/IO/Spreadsheet/SpreadsheetDatabaseMapper.php +++ b/Utils/IO/Spreadsheet/SpreadsheetDatabaseMapper.php @@ -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()); diff --git a/Utils/StringUtils.php b/Utils/StringUtils.php index 589e326e2..06e8c18b7 100755 --- a/Utils/StringUtils.php +++ b/Utils/StringUtils.php @@ -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; + } }