Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F11723783
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/Collections/OmniArray.php b/src/Collections/OmniArray.php
index 30a60c1..d83676d 100644
--- a/src/Collections/OmniArray.php
+++ b/src/Collections/OmniArray.php
@@ -1,67 +1,69 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Collections;
use Keruald\OmniTools\Strings\Multibyte\OmniString;
class OmniArray {
/**
* @var array
*/
private $items = [];
///
/// Constructors
///
public function __construct (?iterable $items) {
if ($items === null) {
return;
}
if (is_array($items)) {
$this->items = $items;
return;
}
foreach ($items as $item) {
$this->items[] = $item;
}
}
- public static function explode (string $delimiter, string $string, int $limit = PHP_INT_MAX) : self {
- return new OmniArray(explode($delimiter, $string, $limit));
+ public static function explode (string $delimiter, string $string,
+ int $limit = PHP_INT_MAX) : self {
+ return (new OmniString($string))
+ ->explode($delimiter, $limit);
}
///
/// Transformation methods
///
public function toIntegers () : self {
array_walk($this->items, ArrayUtilities::toIntegerCallback());
return $this;
}
public function map (callable $callable) : self {
$items = array_map($callable, $this->items);
return new self($items);
}
public function implode(string $delimiter) : OmniString {
return new OmniString(implode($delimiter, $this->items));
}
///
/// Getters methods
///
public function toArray () : array {
return $this->items;
}
}
diff --git a/tests/Collections/OmniArrayTest.php b/tests/Collections/OmniArrayTest.php
index 473a78c..9b587f1 100644
--- a/tests/Collections/OmniArrayTest.php
+++ b/tests/Collections/OmniArrayTest.php
@@ -1,35 +1,47 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Tests\Collections;
use Keruald\OmniTools\Collections\OmniArray;
use PHPUnit\Framework\TestCase;
class OmniArrayTest extends TestCase {
public function testMap () : void {
$actual = (new OmniArray([1, 2, 3, 4, 5]))
->map(function ($x) { return $x * $x; })
->toArray();
$this->assertEquals([1, 4, 9, 16, 25], $actual);
}
public function testImplode() : void {
$actual = (new OmniArray(["a", "b", "c"]))
->implode(".")
->__toString();
$this->assertEquals("a.b.c", $actual);
}
public function testImplodeWithoutDelimiter() : void {
$actual = (new OmniArray(["a", "b", "c"]))
->implode("")
->__toString();
$this->assertEquals("abc", $actual);
}
+ public function testExplode() : void {
+ $actual = OmniArray::explode(".", "a.b.c");
+
+ $this->assertEquals(["a", "b", "c"], $actual->toArray());
+ }
+
+ public function testExplodeWithoutDelimiter() : void {
+ $actual = OmniArray::explode("", "a.b.c");
+
+ $this->assertEquals(["a.b.c"], $actual->toArray());
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Sep 18, 11:21 (19 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2987694
Default Alt Text
(3 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment