Skip to content

Commit

Permalink
reremake
Browse files Browse the repository at this point in the history
  • Loading branch information
maximtrunnikov committed Oct 15, 2022
1 parent e008c97 commit f0511eb
Show file tree
Hide file tree
Showing 79 changed files with 294 additions and 278 deletions.
4 changes: 2 additions & 2 deletions src/Arrayable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
/**
* Arrayable.
*/
interface Arrayable extends Scalar, Countable, IteratorAggregate
interface Arrayable extends Countable, IteratorAggregate
{
/**
* @return array<mixed>
* @throws Exception
*/
public function value(): array;
public function asArray(): array;
}
6 changes: 3 additions & 3 deletions src/Arrayable/ArrCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
namespace Maxonfjvipon\Elegant_Elephant\Arrayable;

use Maxonfjvipon\Elegant_Elephant\Arrayable;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastScalar;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastMixed;

/**
* Array cast.
*/
final class ArrCast extends ArrEnvelope
{
use CastScalar;
use CastMixed;

/**
* Ctor.
Expand All @@ -24,7 +24,7 @@ public function __construct($arr)
parent::__construct(
new ArrMapped(
$arr,
fn ($value) => $this->scalarCast($value)
fn ($value) => $this->mixedCast($value)
)
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Arrayable/ArrCombined.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use Exception;
use Maxonfjvipon\Elegant_Elephant\Arrayable;
use Maxonfjvipon\Elegant_Elephant\Number;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastScalar;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastMixed;

/**
* Array combined of keys and values.
*/
final class ArrCombined extends ArrEnvelope
{
use CastScalar;
use CastMixed;

/**
* @var array<mixed>|Arrayable<mixed> $keys
Expand All @@ -38,10 +38,10 @@ public function __construct($keys, $values)
new ArrFromCallback(
function () use ($keys, $values) {
/** @var array<mixed> $keys */
$keys = (array) $this->scalarCast($keys);
$keys = (array) $this->mixedCast($keys);

/** @var array<mixed> $values */
$values = (array) $this->scalarCast($values);
$values = (array) $this->mixedCast($values);

if (count($keys) !== count($values)) {
throw new Exception("Keys and values arrays must have the same length");
Expand All @@ -65,7 +65,7 @@ private function mapped(array $array): array
{
return array_map(
function ($item) {
if (is_array($cast = $this->scalarCast($item))) {
if (is_array($cast = $this->mixedCast($item))) {
throw new Exception("Array can't be the key of array");
}

Expand Down
4 changes: 2 additions & 2 deletions src/Arrayable/ArrEnvelope.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function __construct(Arrayable $origin)
* @return array<mixed>
* @throws Exception
*/
public function value(): array
public function asArray(): array
{
return $this->origin->value();
return $this->origin->asArray();
}
}
8 changes: 4 additions & 4 deletions src/Arrayable/ArrExploded.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
namespace Maxonfjvipon\Elegant_Elephant\Arrayable;

use Exception;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastScalar;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastMixed;
use Maxonfjvipon\Elegant_Elephant\Text;

/**
* Array exploded.
*/
final class ArrExploded extends ArrEnvelope
{
use CastScalar;
use CastMixed;

/**
* Exploded by comma.
Expand All @@ -38,9 +38,9 @@ public function __construct($separator, $text)
new ArrFromCallback(
function () use ($separator, $text) {
/** @var non-empty-string $separator */
$separator = (string) $this->scalarCast($separator);
$separator = (string) $this->mixedCast($separator);

$exploded = explode($separator, (string) $this->scalarCast($text));
$exploded = explode($separator, (string) $this->mixedCast($text));

if (!is_array($exploded)) {
throw new Exception("Separator can't be an empty string or instance of TxtBlank class");
Expand Down
6 changes: 3 additions & 3 deletions src/Arrayable/ArrFiltered.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

use Exception;
use Maxonfjvipon\Elegant_Elephant\Arrayable;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastScalar;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastMixed;

/**
* Filtered array.
*/
final class ArrFiltered extends ArrEnvelope
{
use CastScalar;
use CastMixed;

/**
* Ctor.
Expand All @@ -25,7 +25,7 @@ public function __construct($arr, callable $callback)
{
parent::__construct(
new ArrFromCallback(
fn () => array_filter((array) $this->scalarCast($arr), $callback, ARRAY_FILTER_USE_BOTH)
fn () => array_filter((array) $this->mixedCast($arr), $callback, ARRAY_FILTER_USE_BOTH)
)
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Arrayable/ArrFlatten.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

use Exception;
use Maxonfjvipon\Elegant_Elephant\Arrayable;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastScalar;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastMixed;

/**
* Flatten array.
*/
final class ArrFlatten extends ArrEnvelope
{
use CastScalar;
use CastMixed;

/**
* Ctor.
Expand All @@ -25,7 +25,7 @@ public function __construct($arr, int $deep = 1)
{
parent::__construct(
new ArrFromCallback(
fn () => $this->flat($this->scalarCast($arr), [], $deep)
fn () => $this->flat($this->mixedCast($arr), [], $deep)
)
);
}
Expand All @@ -42,7 +42,7 @@ private function flat(array $arr, array $new, int $neededDeep, int $currentDeep
{
foreach ($arr as $item) {
if ($neededDeep !== $currentDeep && (is_array($item) || $item instanceof Arrayable)) {
$new = $this->flat($this->scalarCast($item), $new, $neededDeep, $currentDeep + 1);
$new = $this->flat($this->mixedCast($item), $new, $neededDeep, $currentDeep + 1);
} else {
$new[] = $item;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Arrayable/ArrFromCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

use Exception;
use Maxonfjvipon\Elegant_Elephant\Arrayable;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastScalar;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastMixed;

/**
* Array from callback
*/
final class ArrFromCallback implements Arrayable
{
use CastScalar;
use CastMixed;
use CountArrayable;
use HasArrayableIterator;

Expand Down Expand Up @@ -47,9 +47,9 @@ public function __construct(callable $callback)
* @return array<mixed>
* @throws Exception
*/
public function value(): array
public function asArray(): array
{
if (!is_array($res = $this->scalarOrCallableCast($this->callback))) {
if (!is_array($res = $this->mixedOrCallableCast($this->callback))) {
throw new Exception("Callback must return an array or Arrayable!");
}

Expand Down
6 changes: 3 additions & 3 deletions src/Arrayable/ArrKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

use Exception;
use Maxonfjvipon\Elegant_Elephant\Arrayable;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastScalar;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastMixed;

/**
* Array keys.
*/
final class ArrKeys extends ArrEnvelope
{
use CastScalar;
use CastMixed;

/**
* Ctor.
Expand All @@ -24,7 +24,7 @@ public function __construct($arr)
{
parent::__construct(
new ArrFromCallback(
fn () => array_keys((array) $this->scalarCast($arr))
fn () => array_keys((array) $this->mixedCast($arr))
)
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Arrayable/ArrMapped.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

use Closure;
use Maxonfjvipon\Elegant_Elephant\Arrayable;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastScalar;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastMixed;
use ReflectionFunction;

/**
* Mapped array.
*/
final class ArrMapped extends ArrEnvelope
{
use CastScalar;
use CastMixed;

/**
* Ctor.
Expand All @@ -30,7 +30,7 @@ function () use ($arr, $callback) {
$count = (new ReflectionFunction(Closure::fromCallable($callback)))->getNumberOfParameters();

/** @var array<mixed> $array */
$array = $this->scalarCast($arr);
$array = $this->mixedCast($arr);

/** @var array<array<mixed>> $arguments */
$arguments = $count > 1 ? [array_keys($array), $array] : [$array];
Expand Down
6 changes: 3 additions & 3 deletions src/Arrayable/ArrMerged.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
namespace Maxonfjvipon\Elegant_Elephant\Arrayable;

use Maxonfjvipon\Elegant_Elephant\Arrayable;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastScalar;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastMixed;

/**
* Merged array.
*/
final class ArrMerged extends ArrEnvelope
{
use CastScalar;
use CastMixed;

/**
* Ctor.
Expand All @@ -23,7 +23,7 @@ public function __construct(...$items)
{
parent::__construct(
new ArrFromCallback(
fn () => array_merge(...$this->scalarsCast(...$items))
fn () => array_merge(...$this->mixedArrCast(...$items))
)
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Arrayable/ArrObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
namespace Maxonfjvipon\Elegant_Elephant\Arrayable;

use Maxonfjvipon\Elegant_Elephant\Number;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastScalar;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastMixed;
use Maxonfjvipon\Elegant_Elephant\Text;

/**
* Array as object.
*/
final class ArrObject extends ArrEnvelope
{
use CastScalar;
use CastMixed;

/**
* Ctor.
Expand All @@ -25,7 +25,7 @@ public function __construct($key, $object)
{
parent::__construct(
new ArrFromCallback(
fn () => [$this->scalarCast($key) => $this->scalarCast($object)]
fn () => [$this->mixedCast($key) => $this->mixedCast($object)]
)
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Arrayable/ArrRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

use Exception;
use Maxonfjvipon\Elegant_Elephant\Number;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastScalar;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastMixed;

/**
* Array range.
*/
final class ArrRange extends ArrEnvelope
{
use CastScalar;
use CastMixed;

/**
* Ctor.
Expand All @@ -26,7 +26,7 @@ public function __construct($from, $to, $step = 1)
{
parent::__construct(
new ArrFromCallback(
fn () => range(...$this->scalarsCast($from, $to, $step))
fn () => range(...$this->mixedArrCast($from, $to, $step))
)
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Arrayable/ArrReversed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
namespace Maxonfjvipon\Elegant_Elephant\Arrayable;

use Maxonfjvipon\Elegant_Elephant\Arrayable;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastScalar;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastMixed;

/**
* Reversed array.
*/
final class ArrReversed extends ArrEnvelope
{
use CastScalar;
use CastMixed;

/**
* Ctor.
Expand All @@ -23,7 +23,7 @@ public function __construct($arr)
{
parent::__construct(
new ArrFromCallback(
fn () => array_reverse((array) $this->scalarCast($arr))
fn () => array_reverse((array) $this->mixedCast($arr))
)
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Arrayable/ArrSorted.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

use Exception;
use Maxonfjvipon\Elegant_Elephant\Arrayable;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastScalar;
use Maxonfjvipon\Elegant_Elephant\Scalar\CastMixed;

/**
* Array sorted.
*/
final class ArrSorted extends ArrEnvelope
{
use CastScalar;
use CastMixed;

/**
* Ctor.
Expand All @@ -26,7 +26,7 @@ public function __construct($arr, $compare = null)
parent::__construct(
new ArrFromCallback(
function () use ($arr, $compare) {
$arr = (array) $this->scalarCast($arr);
$arr = (array) $this->mixedCast($arr);

if ($compare != null) {
usort($arr, is_string($compare)
Expand Down
Loading

0 comments on commit f0511eb

Please sign in to comment.