From 5ddeacdc80265a0a9240141e5217cebe5fce67e1 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Fri, 24 Jan 2025 15:50:11 +0100 Subject: [PATCH] Allow `int` parts in `StringUtil::joinNonEmpty` (#47) --- CHANGELOG.md | 6 ++++++ src/FluidXPlate/FluidXScanner.php | 5 +++-- src/Microplate/Microplate.php | 4 +--- src/StringUtil.php | 2 +- tests/StringUtilTest.php | 10 +++++----- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8904380..26c1deb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ See [GitHub releases](https://github.com/mll-lab/php-utils/releases). ## Unreleased +## v5.11.0 + +### Added + +- Allow `int` parts in `StringUtil::joinNonEmpty` + ## v5.10.0 ### Added diff --git a/src/FluidXPlate/FluidXScanner.php b/src/FluidXPlate/FluidXScanner.php index 7021307..166ddf5 100644 --- a/src/FluidXPlate/FluidXScanner.php +++ b/src/FluidXPlate/FluidXScanner.php @@ -80,9 +80,10 @@ public static function parseRawContent(string $rawContent): FluidXPlate } if ($id === FluidXScanner::NO_READ) { - throw new ScanFluidXPlateException($barcodes === [] + $message = $barcodes === [] ? 'Weder Platten-Barcode noch Tube-Barcodes konnten gescannt werden. Bitte überprüfen Sie, dass die Platte korrekt in den FluidX-Scanner eingelegt wurde.' - : 'Platten-Barcode konnte nicht gescannt werden. Bitte überprüfen Sie, dass die Platte mit der korrekten Orientierung in den FluidX-Scanner eingelegt wurde.'); + : 'Platten-Barcode konnte nicht gescannt werden. Bitte überprüfen Sie, dass die Platte mit der korrekten Orientierung in den FluidX-Scanner eingelegt wurde.'; + throw new ScanFluidXPlateException($message); } $plate = new FluidXPlate($id); diff --git a/src/Microplate/Microplate.php b/src/Microplate/Microplate.php index f8d878a..f7905eb 100644 --- a/src/Microplate/Microplate.php +++ b/src/Microplate/Microplate.php @@ -72,9 +72,7 @@ public function setWell(Coordinates $coordinates, $content): void private function assertIsWellEmpty(Coordinates $coordinates, $content): void { if (! $this->isWellEmpty($coordinates)) { - throw new WellNotEmptyException( - 'Well with coordinates "' . $coordinates->toString() . '" is not empty. Use setWell() to overwrite the coordinate. Well content "' . serialize($content) . '" was not added.' - ); + throw new WellNotEmptyException('Well with coordinates "' . $coordinates->toString() . '" is not empty. Use setWell() to overwrite the coordinate. Well content "' . serialize($content) . '" was not added.'); } } diff --git a/src/StringUtil.php b/src/StringUtil.php index e3a291f..7e41148 100644 --- a/src/StringUtil.php +++ b/src/StringUtil.php @@ -21,7 +21,7 @@ class StringUtil /** https://en.wikipedia.org/wiki/Byte_order_mark#UTF-32 */ public const UTF_32_LITTLE_ENDIAN_BOM = "\xFF\xFE\x00\x00"; - /** @param iterable $parts */ + /** @param iterable $parts */ public static function joinNonEmpty(string $glue, iterable $parts): string { $nonEmptyParts = []; diff --git a/tests/StringUtilTest.php b/tests/StringUtilTest.php index 5cf423e..c0ac9bc 100644 --- a/tests/StringUtilTest.php +++ b/tests/StringUtilTest.php @@ -12,7 +12,7 @@ final class StringUtilTest extends TestCase /** * @dataProvider joinNonEmpty * - * @param iterable $parts + * @param iterable $parts */ #[DataProvider('joinNonEmpty')] public function testJoinNonEmpty(string $expectedJoined, string $glue, iterable $parts): void @@ -23,12 +23,12 @@ public function testJoinNonEmpty(string $expectedJoined, string $glue, iterable ); } - /** @return iterable}> */ + /** @return iterable}> */ public static function joinNonEmpty(): iterable { - yield ['a b', ' ', ['a', null, '', 'b']]; - yield ['ab', '', ['a', null, '', 'b']]; - yield ['a,b', ',', new Collection(['a', null, '', 'b'])]; + yield ['a b 0', ' ', ['a', null, 'b', '', 0]]; + yield ['ab1', '', ['a', null, '', 'b', 1]]; + yield ['a,b,2', ',', new Collection(['a', 'b', 2, null, ''])]; } /** @dataProvider shortenFirstname */