From 4f6c310baa0b4423f9b8b74e3195501c2b106787 Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Sun, 11 Dec 2022 11:24:49 +0100 Subject: [PATCH 01/21] Initial commit --- .github/workflows/test.yml | 40 ++++ .gitignore | 5 + composer.json | 36 ++++ phpcs.xml | 9 + phpstan.neon | 7 + phpunit.xml.dist | 23 ++ src/Doctrine/DBAL/Types/TypeArrayType.php | 97 +++++++++ src/Exception/IncorrectDataTypeException.php | 13 ++ src/Exception/InvalidIndexException.php | 13 ++ src/TypeArray.php | 207 ++++++++++++++++++ tests/TypeArrayTest.php | 216 +++++++++++++++++++ 11 files changed, 666 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 .gitignore create mode 100644 composer.json create mode 100644 phpcs.xml create mode 100644 phpstan.neon create mode 100644 phpunit.xml.dist create mode 100644 src/Doctrine/DBAL/Types/TypeArrayType.php create mode 100644 src/Exception/IncorrectDataTypeException.php create mode 100644 src/Exception/InvalidIndexException.php create mode 100644 src/TypeArray.php create mode 100644 tests/TypeArrayTest.php diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..7ea0796 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,40 @@ +name: Continuous integration + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + tests: + runs-on: ubuntu-20.04 + strategy: + max-parallel: 3 + matrix: + php: [ 8.0, 8.1, 8.2 ] + composer_flags: [ "", "--prefer-lowest" ] + name: PHP ${{ matrix.php }} ${{ matrix.composer_flags}} + env: + PHP: ${{ matrix.os }} + COMPOSER_MEMORY_LIMIT: -1 + COMPOSER_FLAGS: ${{ matrix.composer_flags }} + PHP_VERSION: ${{ matrix.php }} + steps: + - uses: actions/checkout@v2 + - name: Install PHP + uses: shivammathur/setup-php@master + with: + php-version: ${{ matrix.php }} + extensions: xdebug + - name: Install dependencies + run: | + composer self-update + COMPOSER_MEMORY_LIMIT=-1 composer update --prefer-dist --no-interaction $COMPOSER_FLAGS + composer suggests | xargs composer require {} + - name: Execute tests (Unit and Feature) + run: vendor/bin/phpunit --coverage-text + - name: Static analysis with PHPStan + run: vendor/bin/phpstan analyse + - name: Coding style PSR12 Check + run: vendor/bin/phpcs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..28e83da --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +clover.xml +html/ +vendor/* +composer.lock +.phpunit.result.cache diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..9d1ca21 --- /dev/null +++ b/composer.json @@ -0,0 +1,36 @@ +{ + "name": "jaytaph/typearray", + "description": "Typed Array", + "type": "library", + "require": { + "php": ">=8.0.2", + "symfony/property-access": "^6.2" + }, + "require-dev": { + "phpunit/phpunit": "^9.5", + "squizlabs/php_codesniffer": "^3.6", + "phpstan/phpstan": "^1.0" + }, + "suggest": { + "doctrine/dbal": "For using type_array directly with Doctrine" + }, + "license": "BSD-3-Clause", + "autoload": { + "psr-4": { + "Jaytaph\\TypeArray\\": "src/" + } + }, + "authors": [ + { + "name": "Joshua Thijssen", + "email": "jthijssen@noxlogic.nl" + } + ], + "scripts": { + "test": [ + "vendor/bin/phpcs", + "vendor/bin/phpstan", + "vendor/bin/phpunit" + ] + } +} diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..733ac87 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,9 @@ + + + + + ./src + ./tests + + + diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..b4a5b25 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,7 @@ +parameters: + paths: + - src + level: 8 + inferPrivatePropertyTypeFromConstructor: true + checkMissingIterableValueType: false + reportUnmatchedIgnoredErrors: false diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..589a7cf --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,23 @@ + + + + + + tests + + + + + + ./src + + + diff --git a/src/Doctrine/DBAL/Types/TypeArrayType.php b/src/Doctrine/DBAL/Types/TypeArrayType.php new file mode 100644 index 0000000..2dcc82e --- /dev/null +++ b/src/Doctrine/DBAL/Types/TypeArrayType.php @@ -0,0 +1,97 @@ +getJsonTypeDeclarationSQL($column); + } + + /** + * {@inheritdoc} + */ + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + if ($value === null) { + return null; + } + + if (! $value instanceof TypeArray) { + throw ConversionException::conversionFailedInvalidType($value, self::TYPE, ['null', TypeArray::class]); + } + + try { + return json_encode($value->toArray(), JSON_THROW_ON_ERROR | JSON_PRESERVE_ZERO_FRACTION); + } catch (JsonException $e) { + throw ConversionException::conversionFailedSerialization($value, self::TYPE, $e->getMessage(), $e); + } + } + + /** + * {@inheritdoc} + */ + public function convertToPHPValue($value, AbstractPlatform $platform) + { + if ($value === null || $value === '') { + return null; + } + + if (is_resource($value)) { + $value = stream_get_contents($value); + } + + try { + return TypeArray::fromJson(strval($value)); + } catch (JsonException $e) { + throw ConversionException::conversionFailed($value, $this->getName(), $e); + } + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return self::TYPE; + } + + /** + * {@inheritdoc} + * + * @deprecated + */ + public function requiresSQLCommentHint(AbstractPlatform $platform) + { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5509', + '%s is deprecated.', + __METHOD__, + ); + + return ! $platform->hasNativeJsonType(); + } +} diff --git a/src/Exception/IncorrectDataTypeException.php b/src/Exception/IncorrectDataTypeException.php new file mode 100644 index 0000000..70d7a0a --- /dev/null +++ b/src/Exception/IncorrectDataTypeException.php @@ -0,0 +1,13 @@ +propertyAccessor = PropertyAccess::createPropertyAccessorBuilder() + ->enableExceptionOnInvalidIndex() + ->enableExceptionOnInvalidPropertyPath() + ->disableMagicCall() + ->disableMagicGet() + ->disableMagicMethods() + ->disableMagicSet() + ->getPropertyAccessor() + ; + + $this->data = $data; + } + + // Creates a new TypeArray from a JSON string + public static function fromJson(string $json): self + { + $data = json_decode($json, true, 512, JSON_THROW_ON_ERROR); + if (!is_array($data)) { + $data = [$data]; + } + + return new self($data); + } + + /** + * Returns the array in the TypeArray + * + * @return mixed[] + */ + public function toArray(): array + { + return $this->data; + } + + // Returns the string at the given path, or $default if not found. If the path doesn't point to + // a string, it will throw an exception. + public function getString(string $path, ?string $default = null): string + { + $value = $this->getValue($path, $default); + if (!is_string($value)) { + throw new IncorrectDataTypeException('string', gettype($value)); + } + + return $value; + } + + // Returns the string at the given path, or null when the path is not found. If the value on path is not a + // string, it will throw an exception. + public function getStringOrNull(string $path): ?string + { + if (!$this->propertyAccessor->isReadable($this->data, $path)) { + return null; + } + + $value = $this->propertyAccessor->getValue($this->data, $path); + if (!is_string($value) && !is_null($value)) { + throw new IncorrectDataTypeException('string', gettype($value)); + } + + return $value; + } + + // Returns int from given path + public function getInt(string $path, ?int $default = null): int + { + $value = $this->getValue($path, $default); + if (!is_int($value)) { + throw new IncorrectDataTypeException('int', gettype($value)); + } + + return $value; + } + + // Returns int on given path, or null when not found + public function getIntOrNull(string $path): ?int + { + if (!$this->propertyAccessor->isReadable($this->data, $path)) { + return null; + } + + $value = $this->propertyAccessor->getValue($this->data, $path); + if (!is_int($value) && !is_null($value)) { + throw new IncorrectDataTypeException('int', gettype($value)); + } + + return $value; + } + + // Returns bool from given path + public function getBool(string $path, bool $default = false): bool + { + $value = $this->getValue($path, $default); + if (!is_bool($value)) { + throw new IncorrectDataTypeException('bool', gettype($value)); + } + + return $value; + } + + // Returns a TypeArray from the given path + public function getTypeArray(string $path, ?TypeArray $default = null): TypeArray + { + $value = $this->getValue($path, $default); + if (!is_array($value) && ! $value instanceof TypeArray) { + throw new IncorrectDataTypeException('array', gettype($value)); + } + + return ($value instanceof TypeArray) ? $value : new TypeArray($value); + } + + // Returns a TypeArray from the given path, or null when not found + public function getTypeArrayOrNull(string $path): ?TypeArray + { + if (!$this->propertyAccessor->isReadable($this->data, $path)) { + return null; + } + + $value = $this->propertyAccessor->getValue($this->data, $path); + if (!is_array($value) && !is_null($value)) { + throw new IncorrectDataTypeException('array', gettype($value)); + } + + return new TypeArray($value ?? []); + } + + // Returns true when the given path is an array or TypeArray + public function isTypeArray(string $path): bool + { + $value = $this->propertyAccessor->getValue($this->data, $path); + + return is_array($value) || $value instanceof TypeArray; + } + + // Returns an empty TypeArray + public static function empty(): self + { + return new TypeArray([]); + } + + // Returns true when the object is empty + public function isEmpty(): bool + { + return count($this->data) === 0; + } + + // REturns true when the given path exists + public function exists(string $path): bool + { + return $this->propertyAccessor->isReadable($this->data, $path); + } + + // Returns true when the given path does not exist or is null + public function isNullOrNotExists(string $path): bool + { + if (!$this->propertyAccessor->isReadable($this->data, $path)) { + return true; + } + + $value = $this->propertyAccessor->getValue($this->data, $path); + return is_null($value); + } + + protected function getValue(string $path, mixed $default = null): mixed + { + if (!$this->propertyAccessor->isReadable($this->data, $path)) { + if ($default !== null) { + return $default; + } + throw new InvalidIndexException($path); + } + + $value = $this->propertyAccessor->getValue($this->data, $path); + if ($value === null && $default !== null) { + return $default; + } + + return $value; + } + + public function jsonSerialize(): mixed + { + return $this->data; + } +} diff --git a/tests/TypeArrayTest.php b/tests/TypeArrayTest.php new file mode 100644 index 0000000..aaf76b5 --- /dev/null +++ b/tests/TypeArrayTest.php @@ -0,0 +1,216 @@ +createTypeArray(); + + $this->assertEquals('def', $typeArray->getString('[not-exists]', 'def')); + $this->assertEquals('foo', $typeArray->getString('[level0.1]', 'def')); + + $this->assertEquals('def', $typeArray->getString('[level0.4][not-exists]', 'def')); + $this->assertEquals('bar', $typeArray->getString('[level0.4][level1.1]', 'def')); + + $a = new TypeArray(['level2.1' => 'baz', 'level2.2' => 2, 'level2.3' => true, 'level2.5' => null]); + $b = new TypeArray(['foo', 'bar']); + $this->assertEquals($a, $typeArray->getTypeArray('[level0.4][not-exists]', $a)); + $this->assertEquals($a, $typeArray->getTypeArray('[level0.4][level1.4]', $b)); + $this->assertEquals($b, $typeArray->getTypeArray('[level0.4][notexists]', $b)); + + $this->assertEquals(123, $typeArray->getInt('[not-exists]', 123)); + } + + public function testGetString(): void + { + $typeArray = $this->createTypeArray(); + + $this->assertIsString($typeArray->getString('[level0.4][level1.4][level2.1]')); + $this->assertEquals('baz', $typeArray->getString('[level0.4][level1.4][level2.1]')); + $this->assertNull($typeArray->getStringOrNull('[doesNotExist]')); + $this->assertNotNull($typeArray->getStringOrNull('[level0.1]')); + + + $typeArray->getString('[level0.4][level1.4][level2.5]', 'baz'); + } + + public function testGetInt(): void + { + $typeArray = $this->createTypeArray(); + + $this->assertIsInt($typeArray->getInt('[level0.2]')); + $this->assertEquals(0, $typeArray->getInt('[level0.2]')); + + $this->assertNull($typeArray->getIntOrNull('[doesNotExist]')); + $this->assertNotNull($typeArray->getIntOrNull('[level0.4][level1.2]')); + } + + public function testIntNotFoundThrowException(): void + { + $typeArray = $this->createTypeArray(); + + $this->expectException(InvalidIndexException::class); + $this->expectExceptionMessage('Invalid index: "[doesNotExist]"'); + $typeArray->getInt('[doesNotExist]'); + } + + public function testIntWithDefaultValue(): void + { + $typeArray = $this->createTypeArray(); + + $this->assertEquals(123, $typeArray->getInt('[doesNotExist]', 123)); + } + + public function testBool(): void + { + $typeArray = $this->createTypeArray(); + + $this->assertIsBool($typeArray->getBool('[level0.3]')); + $this->assertFalse($typeArray->getBool('[level0.3]')); + $this->assertFalse($typeArray->getBool('[level0.4][level1.3]')); + $this->assertTrue($typeArray->getBool('[level0.4][level1.4][level2.3]')); + } + + public function testEmpty(): void + { + $typeArray = $this->createTypeArray(); + $this->assertFalse($typeArray->isEmpty()); + + $typeArray = TypeArray::empty(); + $this->assertTrue($typeArray->isEmpty()); + } + + public function testExists(): void + { + $typeArray = $this->createTypeArray(); + $this->assertTrue($typeArray->exists('[level0.4][level1.4][level2.1]')); + $this->assertTrue($typeArray->exists('[level0.4][level1.4]')); + $this->assertTrue($typeArray->exists('[level0.4]')); + $this->assertFalse($typeArray->exists('doesnotexist')); + $this->assertFalse($typeArray->exists('[doesnotexist]')); + + + $this->assertTrue($typeArray->isNullOrNotExists('[level0.5]')); + $this->assertTrue($typeArray->isNullOrNotExists('[notexists]')); + $this->assertFalse($typeArray->isNullOrNotExists('[level0.1]')); + } + + public function testIsTypeArray(): void + { + $typeArray = $this->createTypeArray(); + + $this->assertTrue($typeArray->isTypeArray('[level0.4][level1.4]')); + $this->assertTrue($typeArray->isTypeArray('[level0.4]')); + $this->assertFalse($typeArray->isTypeArray('[level0.1]')); + } + + public function testJsonSerialize() + { + $typeArray = $this->createTypeArray(); + $this->assertEquals($typeArray->toArray(), $typeArray->jsonSerialize()); + } + + public function testStringException(): void + { + $typeArray = $this->createTypeArray(); + + $this->expectException(IncorrectDataTypeException::class); + $typeArray->getString('[level0.2]'); + } + + public function testTypeArray(): void + { + $typeArray = $this->createTypeArray(); + + $this->assertNull($typeArray->getTypeArrayOrNull('[doesNotExist]')); + $this->assertNotNull($typeArray->getTypeArrayOrNull('[level0.4]')); + + $this->expectException(IncorrectDataTypeException::class); + $typeArray->getTypeArrayOrNull('[level0.1]'); + } + + public function testStringOrNullException(): void + { + $typeArray = $this->createTypeArray(); + + $this->expectException(IncorrectDataTypeException::class); + $typeArray->getStringOrNull('[level0.2]'); + } + + public function testIntException(): void + { + $typeArray = $this->createTypeArray(); + + $this->expectException(IncorrectDataTypeException::class); + $typeArray->getInt('[level0.1]'); + } + + public function testIntOrNullException(): void + { + $typeArray = $this->createTypeArray(); + + $this->expectException(IncorrectDataTypeException::class); + $typeArray->getIntOrNull('[level0.1]'); + } + + public function testBoolException(): void + { + $typeArray = $this->createTypeArray(); + + $this->expectException(IncorrectDataTypeException::class); + $typeArray->getBool('[level0.1]'); + } + + public function testTypeArrayException(): void + { + $typeArray = $this->createTypeArray(); + + $this->expectException(IncorrectDataTypeException::class); + $typeArray->getTypeArray('[level0.1]'); + } + + public function testFromJson(): void + { + $typeArray = TypeArray::fromJson('{"foo": "bar"}'); + $this->assertEquals('bar', $typeArray->getString('[foo]')); + + $typeArray = TypeArray::fromJson('"foo"'); + $this->assertEquals('foo', $typeArray->getString('[0]')); + + $this->expectException(\JsonException::class); + TypeArray::fromJson('aap'); + } + + protected function createTypeArray(): TypeArray + { + $data = [ + 'level0.1' => 'foo', + 'level0.2' => 0, + 'level0.3' => false, + 'level0.4' => [ + 'level1.1' => 'bar', + 'level1.2' => 1, + 'level1.3' => false, + 'level1.4' => [ + 'level2.1' => 'baz', + 'level2.2' => 2, + 'level2.3' => true, + 'level2.5' => null, + ], + 'level1.5' => null, + ], + 'level0.5' => null, + ]; + + return new TypeArray($data); + } +} From a82c483e459521f117ca3f2f3b5a59673b33406e Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Sun, 11 Dec 2022 11:25:52 +0100 Subject: [PATCH 02/21] using 6.0 since we support php 8.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9d1ca21..6ac5661 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "library", "require": { "php": ">=8.0.2", - "symfony/property-access": "^6.2" + "symfony/property-access": "^6.0" }, "require-dev": { "phpunit/phpunit": "^9.5", From fc78695d51cbf56fdb8dd1af3ee6e873c39cc38f Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Sun, 11 Dec 2022 11:27:30 +0100 Subject: [PATCH 03/21] fixed xargs --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7ea0796..e59e15a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,7 +31,7 @@ jobs: run: | composer self-update COMPOSER_MEMORY_LIMIT=-1 composer update --prefer-dist --no-interaction $COMPOSER_FLAGS - composer suggests | xargs composer require {} + composer suggests | xargs -i composer require {} - name: Execute tests (Unit and Feature) run: vendor/bin/phpunit --coverage-text - name: Static analysis with PHPStan From e8a4d2aee2bcdbc0024322dd7842bc1c07459339 Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Sun, 11 Dec 2022 11:28:42 +0100 Subject: [PATCH 04/21] fixed install suggestions --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e59e15a..ac6a3ab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,7 +31,7 @@ jobs: run: | composer self-update COMPOSER_MEMORY_LIMIT=-1 composer update --prefer-dist --no-interaction $COMPOSER_FLAGS - composer suggests | xargs -i composer require {} + composer suggests --list | xargs -i composer require {} - name: Execute tests (Unit and Feature) run: vendor/bin/phpunit --coverage-text - name: Static analysis with PHPStan From a14247fa6072fe38ee84e120ddfdf6e8c4994368 Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Sun, 11 Dec 2022 11:31:02 +0100 Subject: [PATCH 05/21] directly install dbal --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ac6a3ab..1a0d83e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,7 +31,7 @@ jobs: run: | composer self-update COMPOSER_MEMORY_LIMIT=-1 composer update --prefer-dist --no-interaction $COMPOSER_FLAGS - composer suggests --list | xargs -i composer require {} + composer require doctrine/dbal - name: Execute tests (Unit and Feature) run: vendor/bin/phpunit --coverage-text - name: Static analysis with PHPStan From b27dcc250b5e4a68b459498447048fedca070717 Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Sun, 11 Dec 2022 11:32:39 +0100 Subject: [PATCH 06/21] Create LICENSE --- LICENSE | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..84a8c8d --- /dev/null +++ b/LICENSE @@ -0,0 +1,28 @@ +BSD 3-Clause License + +Copyright (c) 2022, Joshua Thijssen + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From e21a82603ee4b896972b3b29aafdccaaddd0d453 Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Sun, 11 Dec 2022 11:36:32 +0100 Subject: [PATCH 07/21] Create README.md --- README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 67bcaad..e3e806b 100644 --- a/README.md +++ b/README.md @@ -1 +1,19 @@ -Auto-generated README for icore-php-typearray +# Typed Array + +Simple wrapper around property-accessor to fetch elements in a typed way. This package is created because I was fiddling around with a lot of json-arrays +that were not typed and phpstan had a big issue with that. + +So, instead of having `mixed[] $myarray`, we can use `TypeArray`, and fetch elements with: + +``` +$arr = new TypeArray(['foo' => 'string', 'bar' => 4 ]); + +$arr->getString('[foo]'); // always returns a string +$arr->getString('[notexists]', 'defaultval'); // Returns default val when not found + +$arr->getInt('[bar]'); // returns int(4) +$arr->getInt('[foo]'); // Returns InvalidTypeException as this element is a string, not an int + +``` + +See symfony propertyaccess component for the path syntax used. From 3189c63635b8b8f40374f1998ed4a774bd9b33b5 Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Sat, 31 Dec 2022 12:11:53 +0100 Subject: [PATCH 08/21] Making sure we add D2CTYPE comments to typearray doctrine fields --- src/Doctrine/DBAL/Types/TypeArrayType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Doctrine/DBAL/Types/TypeArrayType.php b/src/Doctrine/DBAL/Types/TypeArrayType.php index 2dcc82e..c3c55f4 100644 --- a/src/Doctrine/DBAL/Types/TypeArrayType.php +++ b/src/Doctrine/DBAL/Types/TypeArrayType.php @@ -92,6 +92,6 @@ public function requiresSQLCommentHint(AbstractPlatform $platform) __METHOD__, ); - return ! $platform->hasNativeJsonType(); + return true; } } From e14dddf36731f31fea30c8123b7382b9254cb49f Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Wed, 7 Jun 2023 09:41:21 +0200 Subject: [PATCH 09/21] Added floats --- src/TypeArray.php | 26 ++++++++++++++++++++++++++ tests/TypeArrayTest.php | 23 ++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/TypeArray.php b/src/TypeArray.php index 6481fe1..f35a77e 100644 --- a/src/TypeArray.php +++ b/src/TypeArray.php @@ -146,6 +146,32 @@ public function getTypeArrayOrNull(string $path): ?TypeArray return new TypeArray($value ?? []); } + // Returns float from given path + public function getFloat(string $path, ?float $default = null): float + { + $value = $this->getValue($path, $default); + if (!is_float($value)) { + throw new IncorrectDataTypeException('float', gettype($value)); + } + + return $value; + } + + // Returns float on given path, or null when not found + public function getFloatOrNull(string $path): ?float + { + if (!$this->propertyAccessor->isReadable($this->data, $path)) { + return null; + } + + $value = $this->propertyAccessor->getValue($this->data, $path); + if (!is_float($value) && !is_null($value)) { + throw new IncorrectDataTypeException('float', gettype($value)); + } + + return $value; + } + // Returns true when the given path is an array or TypeArray public function isTypeArray(string $path): bool { diff --git a/tests/TypeArrayTest.php b/tests/TypeArrayTest.php index aaf76b5..3e029ba 100644 --- a/tests/TypeArrayTest.php +++ b/tests/TypeArrayTest.php @@ -21,7 +21,7 @@ public function testDefaultValues(): void $this->assertEquals('def', $typeArray->getString('[level0.4][not-exists]', 'def')); $this->assertEquals('bar', $typeArray->getString('[level0.4][level1.1]', 'def')); - $a = new TypeArray(['level2.1' => 'baz', 'level2.2' => 2, 'level2.3' => true, 'level2.5' => null]); + $a = new TypeArray(['level2.1' => 'baz', 'level2.2' => 2, 'level2.3' => true, 'level2.5' => null, 'level2.6' => 1.5335]); $b = new TypeArray(['foo', 'bar']); $this->assertEquals($a, $typeArray->getTypeArray('[level0.4][not-exists]', $a)); $this->assertEquals($a, $typeArray->getTypeArray('[level0.4][level1.4]', $b)); @@ -162,6 +162,26 @@ public function testIntOrNullException(): void $typeArray->getIntOrNull('[level0.1]'); } + public function testGetFloat(): void + { + $typeArray = $this->createTypeArray(); + + $this->assertIsFloat($typeArray->getFloat('[level0.4][level1.4][level2.6]')); + $this->assertEquals(1.5335, $typeArray->getFloat('[level0.4][level1.4][level2.6]')); + + $this->assertNull($typeArray->getFloatOrNull('[doesNotExist]')); + $this->assertNotNull($typeArray->getFloatOrNull('[level0.4][level1.4][level2.6]')); + } + + + public function testFloatException(): void + { + $typeArray = $this->createTypeArray(); + + $this->expectException(IncorrectDataTypeException::class); + $typeArray->getFloat('[level0.4][level1.1]'); + } + public function testBoolException(): void { $typeArray = $this->createTypeArray(); @@ -205,6 +225,7 @@ protected function createTypeArray(): TypeArray 'level2.2' => 2, 'level2.3' => true, 'level2.5' => null, + 'level2.6' => 1.5335, ], 'level1.5' => null, ], From 543b4d5251d79953cbaf3c750a955cb8ac519538 Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Wed, 7 Jun 2023 10:04:44 +0200 Subject: [PATCH 10/21] Added iterable --- src/TypeArray.php | 12 ++++++++++++ tests/TypeArrayTest.php | 20 +++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/TypeArray.php b/src/TypeArray.php index f35a77e..79f8ff6 100644 --- a/src/TypeArray.php +++ b/src/TypeArray.php @@ -230,4 +230,16 @@ public function jsonSerialize(): mixed { return $this->data; } + + public function getIterable(string $path): iterable + { + $data = $this->propertyAccessor->getValue($this->data, $path); + if (!is_array($data)) { + throw new IncorrectDataTypeException('iterable', 'Data is not iterable'); + } + + foreach ($data as $key => $value) { + yield $key => $value; + } + } } diff --git a/tests/TypeArrayTest.php b/tests/TypeArrayTest.php index 3e029ba..a964602 100644 --- a/tests/TypeArrayTest.php +++ b/tests/TypeArrayTest.php @@ -173,7 +173,6 @@ public function testGetFloat(): void $this->assertNotNull($typeArray->getFloatOrNull('[level0.4][level1.4][level2.6]')); } - public function testFloatException(): void { $typeArray = $this->createTypeArray(); @@ -210,6 +209,25 @@ public function testFromJson(): void TypeArray::fromJson('aap'); } + public function testIterable(): void + { + $typeArray = $this->createTypeArray(); + + $retKeys = []; + $retVals = []; + foreach ($typeArray->getIterable('[level0.4]') as $key => $value) { + $retKeys[] = $key; + $retVals[] = $value; + } + + $this->assertEquals(['level1.1', 'level1.2', 'level1.3', 'level1.4', 'level1.5'], $retKeys); + + $this->assertEquals('bar', $retVals[0]); + $this->assertEquals(1, $retVals[1]); + $this->assertEquals(false, $retVals[2]); + $this->assertIsArray($retVals[3]); + } + protected function createTypeArray(): TypeArray { $data = [ From 9021e260328bdaf8a99527f6e51df7206036716d Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Thu, 8 Jun 2023 10:20:23 +0200 Subject: [PATCH 11/21] returning typearray instead of arrays --- src/TypeArray.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/TypeArray.php b/src/TypeArray.php index 79f8ff6..e0b7c43 100644 --- a/src/TypeArray.php +++ b/src/TypeArray.php @@ -239,6 +239,11 @@ public function getIterable(string $path): iterable } foreach ($data as $key => $value) { + if (is_array($value)) { + yield $key => new TypeArray($value); + continue; + } + yield $key => $value; } } From 3180d4eb6b333ab442de3bd888b92cd0666c0d78 Mon Sep 17 00:00:00 2001 From: Rein Schaap Date: Thu, 6 Feb 2025 11:50:03 +0100 Subject: [PATCH 12/21] rename in composer Signed-off-by: Rein Schaap --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6ac5661..be16cce 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "jaytaph/typearray", + "name": "minvws/icore-php-typearray", "description": "Typed Array", "type": "library", "require": { From 2c7800a4739bd6c08b22cec48a07b1e441d6e92b Mon Sep 17 00:00:00 2001 From: Rein Schaap Date: Thu, 6 Feb 2025 11:55:24 +0100 Subject: [PATCH 13/21] Update test.yml --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1a0d83e..cd32a84 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,11 +8,11 @@ on: jobs: tests: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: max-parallel: 3 matrix: - php: [ 8.0, 8.1, 8.2 ] + php: [ 8.2, 8.3 ] composer_flags: [ "", "--prefer-lowest" ] name: PHP ${{ matrix.php }} ${{ matrix.composer_flags}} env: From 03c733d755f553060ac48afb4a16fc48184700a7 Mon Sep 17 00:00:00 2001 From: Rein Schaap Date: Thu, 6 Feb 2025 11:58:49 +0100 Subject: [PATCH 14/21] new schema (phpunit) Signed-off-by: Rein Schaap --- phpunit.xml.dist | 32 +++++++++++--------------------- phpunit.xml.dist.bak | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 phpunit.xml.dist.bak diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 589a7cf..6f75377 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,23 +1,13 @@ - - - - - tests - - - - - - ./src - - + + + + ./src + + + + + tests + + diff --git a/phpunit.xml.dist.bak b/phpunit.xml.dist.bak new file mode 100644 index 0000000..589a7cf --- /dev/null +++ b/phpunit.xml.dist.bak @@ -0,0 +1,23 @@ + + + + + + tests + + + + + + ./src + + + From d4dd76424437bcc6e66c49d00b6e8dbdbcbe84f1 Mon Sep 17 00:00:00 2001 From: Peter-Paul van Gemerden Date: Wed, 26 Feb 2025 14:32:26 +0100 Subject: [PATCH 15/21] assert getIterable returns TypeArray instead of array matches expected behavior since v0.0.5 (1c9d8aa / 9021e26) Co-authored-by: Jan Klopper --- tests/TypeArrayTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TypeArrayTest.php b/tests/TypeArrayTest.php index a964602..6146a4a 100644 --- a/tests/TypeArrayTest.php +++ b/tests/TypeArrayTest.php @@ -225,7 +225,7 @@ public function testIterable(): void $this->assertEquals('bar', $retVals[0]); $this->assertEquals(1, $retVals[1]); $this->assertEquals(false, $retVals[2]); - $this->assertIsArray($retVals[3]); + $this->assertInstanceOf(TypeArray::class, $retVals[3]); } protected function createTypeArray(): TypeArray From 9b4d1ca7c86a691cd11e7e79c56f4bab4b516b8f Mon Sep 17 00:00:00 2001 From: Peter-Paul van Gemerden Date: Thu, 27 Feb 2025 10:58:36 +0100 Subject: [PATCH 16/21] chore: fix code style --- tests/TypeArrayTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/TypeArrayTest.php b/tests/TypeArrayTest.php index 6146a4a..dd6ae52 100644 --- a/tests/TypeArrayTest.php +++ b/tests/TypeArrayTest.php @@ -21,7 +21,13 @@ public function testDefaultValues(): void $this->assertEquals('def', $typeArray->getString('[level0.4][not-exists]', 'def')); $this->assertEquals('bar', $typeArray->getString('[level0.4][level1.1]', 'def')); - $a = new TypeArray(['level2.1' => 'baz', 'level2.2' => 2, 'level2.3' => true, 'level2.5' => null, 'level2.6' => 1.5335]); + $a = new TypeArray([ + 'level2.1' => 'baz', + 'level2.2' => 2, + 'level2.3' => true, + 'level2.5' => null, + 'level2.6' => 1.5335 + ]); $b = new TypeArray(['foo', 'bar']); $this->assertEquals($a, $typeArray->getTypeArray('[level0.4][not-exists]', $a)); $this->assertEquals($a, $typeArray->getTypeArray('[level0.4][level1.4]', $b)); From 41300e514135d5724595ca704220beed61675e13 Mon Sep 17 00:00:00 2001 From: Peter-Paul van Gemerden Date: Thu, 27 Feb 2025 11:12:28 +0100 Subject: [PATCH 17/21] ci: fix and refactor workflow (#5) --- .github/actions/setup/action.yml | 35 +++++++++++++++++++ .github/workflows/ci.yml | 59 ++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 40 ---------------------- phpstan.neon | 1 - 4 files changed, 94 insertions(+), 41 deletions(-) create mode 100644 .github/actions/setup/action.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/test.yml diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 0000000..053c54d --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,35 @@ +name: Setup +description: "Setup PHP and composer and install dependencies" + +inputs: + php-version: + default: "8.3" + coverage: + default: xdebug + composer-flags: + default: "" + +runs: + using: "composite" + steps: + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ inputs.php-version }} + coverage: ${{ inputs.coverage }} + + - name: Get composer cache directory + id: composer-cache + shell: bash + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + shell: bash + run: composer update --prefer-dist --no-interaction ${{ inputs.composer-flags }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4f6c488 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,59 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + phpcs: + runs-on: ubuntu-24.04 + name: PHPCS + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup + uses: ./.github/actions/setup + with: + coverage: none + + - name: Run PHPCS + run: vendor/bin/phpcs + + phpstan: + runs-on: ubuntu-24.04 + name: PHPStan + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup + uses: ./.github/actions/setup + with: + coverage: none + + - name: Run PHPStan + run: vendor/bin/phpstan analyse + + test: + runs-on: ubuntu-24.04 + strategy: + max-parallel: 3 + matrix: + php-version: [ 8.2, 8.3 ] + composer-flags: [ "", "--prefer-lowest" ] + name: Test on PHP ${{ matrix.php-version }} ${{ matrix.composer-flags }} + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup + uses: ./.github/actions/setup + with: + php-version: ${{ matrix.php-version }} + composer-flags: ${{ matrix.composer-flags }} + + - name: Run tests (Unit and Feature) + run: vendor/bin/phpunit --coverage-text diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index cd32a84..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Continuous integration - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - tests: - runs-on: ubuntu-22.04 - strategy: - max-parallel: 3 - matrix: - php: [ 8.2, 8.3 ] - composer_flags: [ "", "--prefer-lowest" ] - name: PHP ${{ matrix.php }} ${{ matrix.composer_flags}} - env: - PHP: ${{ matrix.os }} - COMPOSER_MEMORY_LIMIT: -1 - COMPOSER_FLAGS: ${{ matrix.composer_flags }} - PHP_VERSION: ${{ matrix.php }} - steps: - - uses: actions/checkout@v2 - - name: Install PHP - uses: shivammathur/setup-php@master - with: - php-version: ${{ matrix.php }} - extensions: xdebug - - name: Install dependencies - run: | - composer self-update - COMPOSER_MEMORY_LIMIT=-1 composer update --prefer-dist --no-interaction $COMPOSER_FLAGS - composer require doctrine/dbal - - name: Execute tests (Unit and Feature) - run: vendor/bin/phpunit --coverage-text - - name: Static analysis with PHPStan - run: vendor/bin/phpstan analyse - - name: Coding style PSR12 Check - run: vendor/bin/phpcs diff --git a/phpstan.neon b/phpstan.neon index b4a5b25..9bd72ef 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,5 +3,4 @@ parameters: - src level: 8 inferPrivatePropertyTypeFromConstructor: true - checkMissingIterableValueType: false reportUnmatchedIgnoredErrors: false From ca5868c9157260383d9624cccf88240eb88c16f7 Mon Sep 17 00:00:00 2001 From: Peter-Paul van Gemerden Date: Thu, 27 Feb 2025 11:25:56 +0100 Subject: [PATCH 18/21] chore: improve getIterable return type annotation --- src/TypeArray.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/TypeArray.php b/src/TypeArray.php index e0b7c43..66f3d26 100644 --- a/src/TypeArray.php +++ b/src/TypeArray.php @@ -231,6 +231,9 @@ public function jsonSerialize(): mixed return $this->data; } + /** + * @return iterable + */ public function getIterable(string $path): iterable { $data = $this->propertyAccessor->getValue($this->data, $path); From 5c4031fbe0be6d580e3b7ccf0bd6199b4c84eb86 Mon Sep 17 00:00:00 2001 From: Peter-Paul van Gemerden Date: Thu, 27 Feb 2025 11:34:18 +0100 Subject: [PATCH 19/21] ci: install doctrine/dbal types before running PHPStan --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4f6c488..f96ddcf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,9 @@ jobs: with: coverage: none + - name: Install optional dependency doctrine/dbal + run: composer require doctrine/dbal + - name: Run PHPStan run: vendor/bin/phpstan analyse From 7f5d73e7a2c30fa32e65bc4548c5e5a5143aef9e Mon Sep 17 00:00:00 2001 From: Randhir Gulraj Date: Thu, 27 Feb 2025 12:19:29 +0100 Subject: [PATCH 20/21] fix: improve type annotations and thrown exceptions --- src/Doctrine/DBAL/Types/TypeArrayType.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Doctrine/DBAL/Types/TypeArrayType.php b/src/Doctrine/DBAL/Types/TypeArrayType.php index c3c55f4..15f4402 100644 --- a/src/Doctrine/DBAL/Types/TypeArrayType.php +++ b/src/Doctrine/DBAL/Types/TypeArrayType.php @@ -5,7 +5,9 @@ namespace Jaytaph\TypeArray\Doctrine\DBAL\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Exception\InvalidType; +use Doctrine\DBAL\Types\Exception\SerializationFailed; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use Doctrine\DBAL\Types\Type; use Doctrine\Deprecations\Deprecation; use JsonException; @@ -25,7 +27,7 @@ class TypeArrayType extends Type /** * {@inheritdoc} */ - public function getSQLDeclaration(array $column, AbstractPlatform $platform) + public function getSQLDeclaration(array $column, AbstractPlatform $platform): string { return $platform->getJsonTypeDeclarationSQL($column); } @@ -33,27 +35,27 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform) /** * {@inheritdoc} */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue($value, AbstractPlatform $platform): false|string|null { if ($value === null) { return null; } if (! $value instanceof TypeArray) { - throw ConversionException::conversionFailedInvalidType($value, self::TYPE, ['null', TypeArray::class]); + throw InvalidType::new($value, self::TYPE, ['null', TypeArray::class]); } try { return json_encode($value->toArray(), JSON_THROW_ON_ERROR | JSON_PRESERVE_ZERO_FRACTION); } catch (JsonException $e) { - throw ConversionException::conversionFailedSerialization($value, self::TYPE, $e->getMessage(), $e); + throw SerializationFailed::new($value, self::TYPE, $e->getMessage(), $e); } } /** * {@inheritdoc} */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue($value, AbstractPlatform $platform): ?TypeArray { if ($value === null || $value === '') { return null; @@ -66,14 +68,14 @@ public function convertToPHPValue($value, AbstractPlatform $platform) try { return TypeArray::fromJson(strval($value)); } catch (JsonException $e) { - throw ConversionException::conversionFailed($value, $this->getName(), $e); + throw ValueNotConvertible::new($value, $this->getName(), $e->getMessage(), $e); } } /** * {@inheritdoc} */ - public function getName() + public function getName(): string { return self::TYPE; } @@ -83,7 +85,7 @@ public function getName() * * @deprecated */ - public function requiresSQLCommentHint(AbstractPlatform $platform) + public function requiresSQLCommentHint(AbstractPlatform $platform): bool { Deprecation::triggerIfCalledFromOutside( 'doctrine/dbal', From 9f5543ccfccad1efe25b656d93717624918c048a Mon Sep 17 00:00:00 2001 From: Peter-Paul van Gemerden Date: Thu, 27 Feb 2025 12:23:00 +0100 Subject: [PATCH 21/21] chore: change namespace from Jaytaph to MinVWS (#4) --- composer.json | 2 +- src/Doctrine/DBAL/Types/TypeArrayType.php | 4 ++-- src/Exception/IncorrectDataTypeException.php | 2 +- src/Exception/InvalidIndexException.php | 2 +- src/TypeArray.php | 6 +++--- tests/TypeArrayTest.php | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index be16cce..13d92a5 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "license": "BSD-3-Clause", "autoload": { "psr-4": { - "Jaytaph\\TypeArray\\": "src/" + "MinVWS\\TypeArray\\": "src/" } }, "authors": [ diff --git a/src/Doctrine/DBAL/Types/TypeArrayType.php b/src/Doctrine/DBAL/Types/TypeArrayType.php index 15f4402..a64f745 100644 --- a/src/Doctrine/DBAL/Types/TypeArrayType.php +++ b/src/Doctrine/DBAL/Types/TypeArrayType.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Jaytaph\TypeArray\Doctrine\DBAL\Types; +namespace MinVWS\TypeArray\Doctrine\DBAL\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Exception\InvalidType; @@ -11,7 +11,7 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Deprecations\Deprecation; use JsonException; -use Jaytaph\TypeArray\TypeArray; +use MinVWS\TypeArray\TypeArray; use function is_resource; use function json_encode; diff --git a/src/Exception/IncorrectDataTypeException.php b/src/Exception/IncorrectDataTypeException.php index 70d7a0a..b384297 100644 --- a/src/Exception/IncorrectDataTypeException.php +++ b/src/Exception/IncorrectDataTypeException.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Jaytaph\TypeArray\Exception; +namespace MinVWS\TypeArray\Exception; class IncorrectDataTypeException extends \Exception { diff --git a/src/Exception/InvalidIndexException.php b/src/Exception/InvalidIndexException.php index dccc3fb..274ea7c 100644 --- a/src/Exception/InvalidIndexException.php +++ b/src/Exception/InvalidIndexException.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Jaytaph\TypeArray\Exception; +namespace MinVWS\TypeArray\Exception; class InvalidIndexException extends \Exception { diff --git a/src/TypeArray.php b/src/TypeArray.php index 66f3d26..4cc361f 100644 --- a/src/TypeArray.php +++ b/src/TypeArray.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace Jaytaph\TypeArray; +namespace MinVWS\TypeArray; -use Jaytaph\TypeArray\Exception\IncorrectDataTypeException; -use Jaytaph\TypeArray\Exception\InvalidIndexException; +use MinVWS\TypeArray\Exception\IncorrectDataTypeException; +use MinVWS\TypeArray\Exception\InvalidIndexException; use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; diff --git a/tests/TypeArrayTest.php b/tests/TypeArrayTest.php index dd6ae52..5bdf2fc 100644 --- a/tests/TypeArrayTest.php +++ b/tests/TypeArrayTest.php @@ -4,9 +4,9 @@ namespace Tests; -use Jaytaph\TypeArray\Exception\IncorrectDataTypeException; -use Jaytaph\TypeArray\Exception\InvalidIndexException; -use Jaytaph\TypeArray\TypeArray; +use MinVWS\TypeArray\Exception\IncorrectDataTypeException; +use MinVWS\TypeArray\Exception\InvalidIndexException; +use MinVWS\TypeArray\TypeArray; use PHPUnit\Framework\TestCase; class TypeArrayTest extends TestCase