From 37fea00688428bdd2f29757a848c063eb7c66567 Mon Sep 17 00:00:00 2001 From: danolshev Date: Sat, 1 Aug 2020 18:16:59 +0500 Subject: [PATCH 1/2] fix naming --- src/TypedAccessor.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/TypedAccessor.php b/src/TypedAccessor.php index a8895dd..b7ab894 100644 --- a/src/TypedAccessor.php +++ b/src/TypedAccessor.php @@ -589,11 +589,11 @@ public function offsetGet($offset) throw new UnexpectedKeyTypeException($offset, $this->keySequence); } - $cloneKeySequence = $this->keySequence; - $cloneKeySequence[] = $offset; + $clonedKeySequence = $this->keySequence; + $clonedKeySequence[] = $offset; if (!$this->offsetExists($offset)) { - return new MissingValueAccessor($cloneKeySequence); + return new MissingValueAccessor($clonedKeySequence); } /** @@ -601,7 +601,7 @@ public function offsetGet($offset) */ $array = $this->value; - return (new self($array[$offset]))->setKeySequence($cloneKeySequence); + return (new self($array[$offset]))->setKeySequence($clonedKeySequence); } /** From 5c18640a9a0a6c48709352b43a37c1baa750311d Mon Sep 17 00:00:00 2001 From: danolshev Date: Sat, 1 Aug 2020 21:33:57 +0500 Subject: [PATCH 2/2] Add method for array of string to mixed --- composer.json | 2 +- src/Enum/TypeEnum.php | 1 + src/Mess.php | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 16f96ae..6adadc9 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ }, "autoload-dev": { "psr-4": { - "Zakirullin\\Mess\\Tests\\": "tests/unit" + "Zakirullin\\Mess\\Tests\\": "tests/unit/" } } } diff --git a/src/Enum/TypeEnum.php b/src/Enum/TypeEnum.php index 24ac5f4..60f4801 100644 --- a/src/Enum/TypeEnum.php +++ b/src/Enum/TypeEnum.php @@ -15,4 +15,5 @@ final class TypeEnum public const ARRAY_OF_STRING_TO_INT = 'array'; public const ARRAY_OF_STRING_TO_BOOL = 'array'; public const ARRAY_OF_STRING_TO_STRING = 'array'; + public const ARRAY_OF_STRING_TO_MIXED = 'array'; } \ No newline at end of file diff --git a/src/Mess.php b/src/Mess.php index 1416c8c..6e6ea79 100644 --- a/src/Mess.php +++ b/src/Mess.php @@ -13,6 +13,7 @@ use Zakirullin\Mess\Exception\UncastableValueException; use Zakirullin\Mess\Exception\UnexpectedKeyTypeException; use Zakirullin\Mess\Exception\UnexpectedTypeException; +use Zakirullin\Mess\Finder\ArrayOfStringToMixedFinder; use Zakirullin\Mess\Finder\ArrayOfStringToTypeFinder; use Zakirullin\Mess\Finder\ListOfTypeFinder; use function is_array; @@ -174,6 +175,22 @@ public function getArrayOfStringToString(): array return $this->value; } + /** + * @psalm-pure + * @psalm-return array + * + * @return array + */ + public function getArrayOfStringToMixed(): array + { + $this->assertType($this->findArrayOfStringToMixed(), TypeEnum::ARRAY_OF_STRING_TO_MIXED); + + /** + * @psalm-var array + */ + return $this->value; + } + /** * @psalm-pure * @@ -406,6 +423,20 @@ public function findArrayOfStringToString(): ?array return ArrayOfStringToTypeFinder::find($this->value, 'is_string'); } + /** + * @psalm-pure + * @psalm-return array|null + * + * @return array|null + */ + public function findArrayOfStringToMixed(): ?array + { + /** + * @psalm-var array|null + */ + return ArrayOfStringToMixedFinder::find($this->value); + } + /** * @psalm-pure *