Skip to content

Commit 7989b2a

Browse files
committed
- added new function extended_arguments()
1 parent e19c884 commit 7989b2a

2 files changed

Lines changed: 36 additions & 26 deletions

File tree

functions.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,41 @@
4545
* with optional arbitrary number of arguments.
4646
*
4747
* @param array ...$values
48-
*
4948
* @return Argument
5049
*/
5150
function arguments(...$values): Argument
5251
{
5352
return new Arguments(...$values);
5453
}
5554

55+
/**
56+
* Creates a new ExtendedArguments instance
57+
* with optional arbitrary number of arguments.
58+
*
59+
* @param array ...$values
60+
* @return Argument
61+
*/
62+
function extended_arguments(...$values): Argument
63+
{
64+
return new ExtendedArguments(...$values);
65+
}
66+
67+
/**
68+
* Creates a new Data instance (Immutable)
69+
* with optional arbitrary number of arguments.
70+
*
71+
* @param array ...$values
72+
* @return Data
73+
*/
74+
function value(...$values): Data
75+
{
76+
return new Immutable(...$values);
77+
}
78+
5679
/**
5780
* Transforms simple CamelCaseName into camel_case_name (lower case underscored).
5881
*
5982
* @param string $string CamelCase string to be underscored
60-
*
6183
* @return string Transformed string (for weird strings, you get what you deserve)
6284
*/
6385
function camel_to_snake_case(string $string): string
@@ -113,7 +135,6 @@ function env(
113135
*
114136
* @param string $input The input string
115137
* @param string $encoding The encoding
116-
*
117138
* @return string
118139
*/
119140
function htmlencode(string $input, string $encoding = 'UTF-8'): string
@@ -133,7 +154,6 @@ function htmlencode(string $input, string $encoding = 'UTF-8'): string
133154
* the sane programming an ugly Array Oriented Programming hackery.
134155
*
135156
* @param array $array
136-
*
137157
* @return bool
138158
*/
139159
function is_associative(array $array): bool
@@ -148,7 +168,6 @@ function is_associative(array $array): bool
148168
* @param int $options [optional] JSON bitmask options for JSON encoding.
149169
* [WARNING]: uses {@JsonSerializer::OPTIONS} as defaults;
150170
* instead of adding, it may remove the option (if set in OPTIONS)
151-
*
152171
* @return string JSON encoded string, or EMPTY STRING if encoding failed
153172
* @see http://php.net/manual/en/function.json-encode.php
154173
*/
@@ -163,7 +182,6 @@ function json_serialize(mixed $value, int $options = 0): string
163182
* @param string $json A JSON string
164183
* @param bool $associative When TRUE, returned objects will be
165184
* converted into associative arrays
166-
*
167185
* @return mixed The decoded value, or EMPTY STRING on error
168186
*/
169187
function json_unserialize(string $json, bool $associative = false): mixed
@@ -210,7 +228,6 @@ function randomstring(
210228
* Removes a directory.
211229
*
212230
* @param string $dirname The folder name
213-
*
214231
* @return bool TRUE on success, FALSE otherwise
215232
*/
216233
function rmdir(string $dirname): bool
@@ -230,7 +247,6 @@ function rmdir(string $dirname): bool
230247
* Transforms the simple snake_case string into CamelCaseName.
231248
*
232249
* @param string $string
233-
*
234250
* @return string Camel-cased string
235251
*/
236252
function snake_to_camel_case(string $string): string
@@ -244,7 +260,6 @@ function snake_to_camel_case(string $string): string
244260
*
245261
* @param string $string
246262
* @param int $delimiter chr() of the delimiter character
247-
*
248263
* @return string The converted string with the provided delimiter
249264
*/
250265
function to_delimited_string(string $string, int $delimiter): string
@@ -257,33 +272,18 @@ function to_delimited_string(string $string, int $delimiter): string
257272
* Converts the string to-kebab-case
258273
*
259274
* @param string $string
260-
*
261275
* @return string
262276
*/
263277
function to_kebab_string(string $string): string
264278
{
265279
return strtolower(to_delimited_string($string, ord('-')));
266280
}
267281

268-
/**
269-
* Creates a new Data instance (Immutable)
270-
* with optional arbitrary number of arguments.
271-
*
272-
* @param array ...$values
273-
*
274-
* @return Data
275-
*/
276-
function value(...$values): Data
277-
{
278-
return new Immutable(...$values);
279-
}
280-
281282
/**
282283
* Serializes the data into XML document.
283284
*
284285
* @param string $root The XML document root name
285286
* @param iterable $data The data to be encoded
286-
*
287287
* @return string XML document
288288
*/
289289
function xml_serialize(string $root, iterable $data): string
@@ -297,7 +297,6 @@ function xml_serialize(string $root, iterable $data): string
297297
* of complicated XML structures.
298298
*
299299
* @param string $xml The XML document to be decoded into array
300-
*
301300
* @return array Decoded version of the XML string,
302301
* or empty array on malformed XML
303302
*/

tests/FunctionsTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace Tests\Koded\Stdlib;
44

5-
use Koded\Stdlib\{Arguments, Immutable};
5+
use Koded\Stdlib\{Arguments, ExtendedArguments, Immutable};
66
use PHPUnit\Framework\TestCase;
77
use function Koded\Stdlib\{arguments,
88
camel_to_snake_case,
9+
extended_arguments,
910
htmlencode,
1011
is_associative,
1112
now,
@@ -36,6 +37,16 @@ public function test_arguments_function()
3637
$this->assertSame([1, 2, 3, 'foo' => 'bar'], $value->toArray());
3738
}
3839

40+
public function test_extended_arguments_function()
41+
{
42+
$value = extended_arguments([1, 2, 3]);
43+
$this->assertInstanceOf(ExtendedArguments::class, $value);
44+
$this->assertSame([1, 2, 3], $value->toArray());
45+
46+
$value->foo = 'bar';
47+
$this->assertSame([1, 2, 3, 'foo' => 'bar'], $value->toArray());
48+
}
49+
3950
public function test_htmlescape_function()
4051
{
4152
$value = htmlencode('<script>');

0 commit comments

Comments
 (0)