Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrenkoAnton committed Jan 25, 2024
1 parent c44f314 commit 5341711
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 158 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Anton Petrenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ inside:
docker exec -it ${CONTAINER_NAME} /bin/bash
.PHONY: inside

up80:
docker-compose -f docker/docker-compose-php80.yml up -d
.PHONY: up80

up81:
docker-compose -f docker/docker-compose-php81.yml up -d
.PHONY: up81
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ All getters are provided using the `__call()` magic method.

### Exceptions

Main library exception is [DtoException](./src/Exception/DtoException.php).
Main library exception is [DtoException](./src/Exception/DtoException.php).

There are [3 groups of exceptions](./src/Exception/DtoException): InitDtoException, SetupDtoException and
HandleDtoException
Expand All @@ -73,7 +73,7 @@ HandleDtoException
| 104 | Dto: %s | Property: %s | Err: Unsupported object property type declaration | ObjectDeclarationException | InitDtoException |
| 105 | Dto: %s | Property: %s | Err: Class must implement DtoInterface | NotDtoClassDeclarationException | InitDtoException |
| 106 | Dto: %s | Property: %s | Err: No backing value for enum | EnumNoBackingValueException | InitDtoException |
| 107 | DtoCollection: %s &#124 Err: Invalid constructor declaration | DtoCollectionConstructorException | InitDtoException |
| 107 | DtoCollection: %s | Err: Invalid constructor declaration | DtoCollectionConstructorException | InitDtoException |
| 201 | DtoCollection: %s | Expected Dto: %s | Given Dto: %s | AddDtoException | SetupDtoException |
| 202 | Dto: %s | Property: %s | Err: No data | InputDataException | SetupDtoException |
| 203 | Dto: %s | Property: %s | Expected type: %s | Given type: %s | Value: %s | SetValueException | SetupDtoException |
Expand Down Expand Up @@ -112,7 +112,7 @@ class ProductDto extends Dto
protected bool $available;
}

// Array or instance of Arrayable interface:
// Array or instance of Arrayable interface
$info = [
'key' => 'value',
];
Expand Down Expand Up @@ -336,8 +336,7 @@ composer check-all

## License

The [php-dto](https://github.com/PetrenkoAnton/php-dto/) library is open-sourced software licensed under the
[MIT license](https://opensource.org/licenses/MIT).
The [php-dto](https://github.com/PetrenkoAnton/php-dto/) library is open-sourced software licensed under the [MIT license](./LICENSE).

## Related projects

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.1.0
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions src/Dto.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Collection\Arrayable;
use Collection\Collectable;
use Collection\Helper;
use Dto\Exception\DtoException;
use Dto\Exception\DtoException\HandleDtoException\GetValueException;
use Dto\Exception\DtoException\InitDtoException\DeclarationException;
Expand Down Expand Up @@ -83,7 +84,7 @@ public function __construct(array $data)
);
} catch (EnumNoBackingValueException $e) {
throw $e;
} catch (Throwable) {
} catch (Throwable $e) {
throw new SetValueException(
dto: $this::class,
property: $name,
Expand Down Expand Up @@ -247,9 +248,6 @@ private function setBuiltinType(string $typeName, string $propertyName, mixed $v
$this->{$propertyName} = $value;
}

/**
* @throws ReflectionException
*/
private function setDtoCollectionType(string $typeName, string $propertyName, array $values): void
{
$collection = new $typeName();
Expand Down
20 changes: 10 additions & 10 deletions src/DtoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

use Collection\Collectable;
use Collection\Collection;
use Collection\Exception\CollectionException;
use Collection\Exception\CollectionException\InvalidItemTypeCollectionException;
use Collection\Exception\CollectionException\InvalidConstructorDeclarationException;
use Collection\Exception\CollectionException\InvalidItemTypeException;
use Collection\Helper;
use Dto\Exception\DtoException;
use Dto\Exception\DtoException\InitDtoException\DtoCollectionConstructorException;
use Dto\Exception\DtoException\SetupDtoException\AddDtoException;
use ReflectionException;

abstract class DtoCollection extends Collection
{
Expand All @@ -19,18 +21,16 @@ public function __construct(Dto ...$items)
}

/**
* @throws CollectionException
* @throws AddDtoException
* @throws ReflectionException
* @throws DtoException
*/
public function add(Collectable $item): void
{
try {
parent::add($item);
} catch (InvalidItemTypeCollectionException) {
$expectedDto = Helper::getConstructorFirstParameterClassName($this);

throw new AddDtoException($this::class, $expectedDto, $item::class);
} catch (InvalidItemTypeException) {
throw new AddDtoException($this::class, Helper::getConstructorFirstParameterClassName($this), $item::class);
} catch (InvalidConstructorDeclarationException) {
throw new DtoCollectionConstructorException($this::class);
}
}
}
26 changes: 0 additions & 26 deletions src/Helper.php

This file was deleted.

24 changes: 21 additions & 3 deletions tests/DtoCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
namespace Test;

use Collection\Exception\CollectionException;
use Collection\Exception\CollectionException\InvalidKeyCollectionException;
use Collection\Exception\CollectionException\InvalidKeyException;
use Dto\Exception\DtoException;
use Dto\Exception\DtoException\InitDtoException\DtoCollectionConstructorException;
use Dto\Exception\DtoException\SetupDtoException;
use PHPUnit\Framework\TestCase;
use Tests\Fixtures\PersonDto;
use Tests\Fixtures\PersonDtoCollection;
use Tests\Fixtures\ProductDto;
use Tests\Fixtures\Unsupported\EmptyClassDto;
use Tests\Fixtures\Unsupported\InvalidContructorDtoCollection;

class DtoCollectionTest extends TestCase
{
Expand Down Expand Up @@ -107,7 +110,7 @@ public function testAddMethodSuccess(): void
*/
public function testGetMethodThrowsInvalidKeyCollectionException(int $key): void
{
$this->expectException(InvalidKeyCollectionException::class);
$this->expectException(InvalidKeyException::class);
$this->expectExceptionMessage("Collection: Tests\Fixtures\PersonDtoCollection | Invalid key: $key");
$this->expectExceptionCode(200);
$this->dtoCollection->getItem($key);
Expand All @@ -127,7 +130,6 @@ public function dpInvalidKeys(): array

/**
* @throws DtoException
* @throws CollectionException
*
* @group ok
*/
Expand All @@ -153,4 +155,20 @@ public function testAddMethodThrowsSetupDtoException(): void
$this->expectExceptionCode(201);
$dtoCollection->add($productDto);
}

/**
* @throws DtoCollectionConstructorException
*
* @group ok
*/
public function testAddMethodThrowsDtoCollectionConstructorException(): void
{
$this->expectException(DtoCollectionConstructorException::class);
// phpcs:ignore
$this->expectExceptionMessage('DtoCollection: Tests\Fixtures\Unsupported\InvalidContructorDtoCollection | Err: Invalid constructor declaration');
$this->expectExceptionCode(107);

$dtoCollection = new InvalidContructorDtoCollection(1);
$dtoCollection->add(new EmptyClassDto([]));
}
}
9 changes: 0 additions & 9 deletions tests/Fixtures/EmptyClass.php

This file was deleted.

15 changes: 0 additions & 15 deletions tests/Fixtures/ProductDtoCollection.php

This file was deleted.

11 changes: 11 additions & 0 deletions tests/Fixtures/Unsupported/EmptyClassDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Tests\Fixtures\Unsupported;

use Dto\Dto;

class EmptyClassDto extends Dto
{
}
21 changes: 21 additions & 0 deletions tests/Fixtures/Unsupported/InvalidContructorDtoCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Tests\Fixtures\Unsupported;

use Dto\DtoCollection;

class InvalidContructorDtoCollection extends DtoCollection
{
/**
* @psalm-suppress UnusedProperty
*/
private int $id;

// Invalid constructor declaration
public function __construct(int $id)
{
$this->id = $id;
}
}
74 changes: 0 additions & 74 deletions tests/HelpersTest.php

This file was deleted.

0 comments on commit 5341711

Please sign in to comment.