Skip to content

Commit

Permalink
[RequestMapper] Update Dependencies, update functional library with b…
Browse files Browse the repository at this point in the history
…reaking changes
  • Loading branch information
fractalzombie committed Dec 26, 2023
1 parent 63e3f2a commit ab4dd8a
Show file tree
Hide file tree
Showing 113 changed files with 1,375 additions and 144 deletions.
59 changes: 51 additions & 8 deletions .php-cs-fixer.dist.php
@@ -1,13 +1,41 @@
<?php

/** @noinspection DuplicatedCode */

declare(strict_types=1);

/**
* 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.
*
* Copyright (c) 2023 Mykhailo Shtanko fractalzombie@gmail.com
*
* For the full copyright and license information, please view the LICENSE.MD
* file that was distributed with this source code.
*/
$owner = 'Mykhailo Shtanko';
$email = 'fractalzombie@gmail.com';
$year = date('Y');
$projectDirectory = __DIR__;

$header = <<<'EOF'
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.
Copyright (c) {{YEAR}} {{OWNER}} {{EMAIL}}
For the full copyright and license information, please view the LICENSE.MD
file that was distributed with this source code.
EOF;

$finder = PhpCsFixer\Finder::create()
->exclude('var')
->exclude('vendor')
->exclude('Documentation')
->notPath('#Enum#')
->in(__DIR__)
->ignoreDotFiles(true)
->in($projectDirectory)
;

$rules = [
Expand All @@ -18,15 +46,30 @@
'@PhpCsFixer' => true,
'@PHP80Migration' => true,
'@PHP80Migration:risky' => true,
'@PHPUnit84Migration:risky' => true,
'phpdoc_line_span' => ['const' => 'single', 'property' => 'single', 'method' => 'single'],
'comment_to_phpdoc' => ['ignored_tags' => ['scrutinizer']],
'phpdoc_to_comment' => ['ignored_tags' => ['scrutinizer']],
'@PHP81Migration' => true,
'@PHP82Migration' => true,
'@PHP83Migration' => true,
'@PHPUnit100Migration:risky' => true,
'date_time_immutable' => true,
'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => true],
'single_line_throw' => true,
'php_unit_internal_class' => false,
'phpdoc_align' => ['align' => 'left'],
'php_unit_test_case_static_method_calls' => false,
'php_unit_test_class_requires_covers' => false,
'php_unit_internal_class' => false,
'comment_to_phpdoc' => ['ignored_tags' => ['scrutinizer']],
'phpdoc_to_comment' => ['ignored_tags' => ['scrutinizer']],
'phpdoc_line_span' => ['const' => 'single', 'property' => 'single', 'method' => 'single'],
'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => true],
'header_comment' => [
'comment_type' => 'PHPDoc',
'header' => str_replace(
['{{YEAR}}', '{{OWNER}}', '{{EMAIL}}'],
[$year, $owner, $email],
$header,
),
'location' => 'after_declare_strict',
'separate' => 'top',
],
];

return (new PhpCsFixer\Config())
Expand Down
14 changes: 12 additions & 2 deletions Attribute/ArrayType.php
Expand Up @@ -2,13 +2,23 @@

declare(strict_types=1);

/**
* 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.
*
* Copyright (c) 2023 Mykhailo Shtanko fractalzombie@gmail.com
*
* For the full copyright and license information, please view the LICENSE.MD
* file that was distributed with this source code.
*/

namespace FRZB\Component\RequestMapper\Attribute;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
final class ArrayType
{
public function __construct(
public readonly string $typeName,
) {
}
) {}
}
17 changes: 16 additions & 1 deletion Attribute/RequestBody.php
Expand Up @@ -2,19 +2,34 @@

declare(strict_types=1);

/**
* 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.
*
* Copyright (c) 2023 Mykhailo Shtanko fractalzombie@gmail.com
*
* For the full copyright and license information, please view the LICENSE.MD
* file that was distributed with this source code.
*/

namespace FRZB\Component\RequestMapper\Attribute;

use FRZB\Component\RequestMapper\Helper\PropertyHelper;
use JetBrains\PhpStorm\Immutable;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;

/** @final */
#[Immutable]
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD | \Attribute::TARGET_FUNCTION)]
class RequestBody
{
public const DEFAULT_VALIDATION_GROUPS = ['Default'];
public const DEFAULT_SERIALIZER_CONTEXT = [AbstractObjectNormalizer::DISABLE_TYPE_ENFORCEMENT => true];
public const DEFAULT_SERIALIZER_CONTEXT = [
AbstractObjectNormalizer::DISABLE_TYPE_ENFORCEMENT => true,
DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true,
];

public readonly array $validationGroups;
public readonly array $serializerContext;
Expand Down
17 changes: 13 additions & 4 deletions ClassMapper/ClassMapper.php
Expand Up @@ -2,6 +2,17 @@

declare(strict_types=1);

/**
* 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.
*
* Copyright (c) 2023 Mykhailo Shtanko fractalzombie@gmail.com
*
* For the full copyright and license information, please view the LICENSE.MD
* file that was distributed with this source code.
*/

namespace FRZB\Component\RequestMapper\ClassMapper;

use Fp\Collections\ArrayList;
Expand All @@ -13,16 +24,14 @@ final class ClassMapper implements ClassMapperInterface
{
public function __construct(
private readonly PropertyMapperLocator $mapperLocator,
) {
}
) {}

public function map(string $className, mixed $value): array
{
try {
return ArrayList::collect((new \ReflectionClass($className))->getProperties())
->map(fn (\ReflectionProperty $property) => $this->mapperLocator->get($property)->map($property, $value) ?? [])
->reduce(array_merge(...))
->getOrElse([])
->toMergedArray()
;
} catch (\ReflectionException) {
return [];
Expand Down
11 changes: 11 additions & 0 deletions ClassMapper/ClassMapperInterface.php
Expand Up @@ -2,6 +2,17 @@

declare(strict_types=1);

/**
* 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.
*
* Copyright (c) 2023 Mykhailo Shtanko fractalzombie@gmail.com
*
* For the full copyright and license information, please view the LICENSE.MD
* file that was distributed with this source code.
*/

namespace FRZB\Component\RequestMapper\ClassMapper;

use FRZB\Component\DependencyInjection\Attribute\AsAlias;
Expand Down
11 changes: 11 additions & 0 deletions Data/ErrorContract.php
Expand Up @@ -2,6 +2,17 @@

declare(strict_types=1);

/**
* 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.
*
* Copyright (c) 2023 Mykhailo Shtanko fractalzombie@gmail.com
*
* For the full copyright and license information, please view the LICENSE.MD
* file that was distributed with this source code.
*/

namespace FRZB\Component\RequestMapper\Data;

interface ErrorContract extends \Stringable, \JsonSerializable
Expand Down
11 changes: 11 additions & 0 deletions Data/ErrorInterface.php
Expand Up @@ -2,6 +2,17 @@

declare(strict_types=1);

/**
* 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.
*
* Copyright (c) 2023 Mykhailo Shtanko fractalzombie@gmail.com
*
* For the full copyright and license information, please view the LICENSE.MD
* file that was distributed with this source code.
*/

namespace FRZB\Component\RequestMapper\Data;

use Symfony\Component\Validator\ConstraintViolationInterface as ConstraintViolation;
Expand Down
20 changes: 14 additions & 6 deletions Data/FormattedError.php
Expand Up @@ -2,9 +2,19 @@

declare(strict_types=1);

/**
* 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.
*
* Copyright (c) 2023 Mykhailo Shtanko fractalzombie@gmail.com
*
* For the full copyright and license information, please view the LICENSE.MD
* file that was distributed with this source code.
*/

namespace FRZB\Component\RequestMapper\Data;

use Fp\Collections\Entry;
use Fp\Collections\HashMap;
use JetBrains\PhpStorm\ArrayShape;
use JetBrains\PhpStorm\Immutable;
Expand All @@ -17,15 +27,13 @@ public function __construct(
private readonly int $status,
private readonly array $errors = [],
private readonly array $trace = [],
) {
}
) {}

public function __toString(): string
{
$errors = HashMap::collect($this->errors)
->map(static fn (Entry $e) => sprintf('%s: [%s]', $e->key, $e->value))
->toAssocArray()
->getOrElse([])
->mapKV(static fn (string $key, string $value) => [$key => sprintf('%s: [%s]', $key, $value)])
->toMergedArray()
;

return sprintf('message: %s, status: %s, errors: %s', $this->message, $this->status, implode(', ', $errors));
Expand Down
11 changes: 11 additions & 0 deletions Data/HasHeaders.php
Expand Up @@ -2,6 +2,17 @@

declare(strict_types=1);

/**
* 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.
*
* Copyright (c) 2023 Mykhailo Shtanko fractalzombie@gmail.com
*
* For the full copyright and license information, please view the LICENSE.MD
* file that was distributed with this source code.
*/

namespace FRZB\Component\RequestMapper\Data;

interface HasHeaders
Expand Down
14 changes: 12 additions & 2 deletions Data/TypeError.php
Expand Up @@ -2,6 +2,17 @@

declare(strict_types=1);

/**
* 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.
*
* Copyright (c) 2023 Mykhailo Shtanko fractalzombie@gmail.com
*
* For the full copyright and license information, please view the LICENSE.MD
* file that was distributed with this source code.
*/

namespace FRZB\Component\RequestMapper\Data;

use FRZB\Component\RequestMapper\Exception\TypeErrorInvalidArgumentException;
Expand All @@ -17,8 +28,7 @@ public function __construct(
public readonly int $position,
public readonly string $expected,
public readonly string $proposed,
) {
}
) {}

public static function fromArray(array $params): self
{
Expand Down
14 changes: 12 additions & 2 deletions Data/ValidationError.php
Expand Up @@ -2,6 +2,17 @@

declare(strict_types=1);

/**
* 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.
*
* Copyright (c) 2023 Mykhailo Shtanko fractalzombie@gmail.com
*
* For the full copyright and license information, please view the LICENSE.MD
* file that was distributed with this source code.
*/

namespace FRZB\Component\RequestMapper\Data;

use FRZB\Component\RequestMapper\Exception\ClassExtractorException;
Expand All @@ -16,8 +27,7 @@ public function __construct(
private readonly string $type,
private readonly string $field,
private readonly string $message,
) {
}
) {}

public function __toString()
{
Expand Down
14 changes: 12 additions & 2 deletions Event/ListenerExceptionEvent.php
Expand Up @@ -2,6 +2,17 @@

declare(strict_types=1);

/**
* 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.
*
* Copyright (c) 2023 Mykhailo Shtanko fractalzombie@gmail.com
*
* For the full copyright and license information, please view the LICENSE.MD
* file that was distributed with this source code.
*/

namespace FRZB\Component\RequestMapper\Event;

use FRZB\Component\RequestMapper\Data\ErrorContract;
Expand All @@ -14,8 +25,7 @@ public function __construct(
private readonly \Throwable $exception,
private readonly string $listenerClass,
private readonly ?ErrorContract $errorContract = null,
) {
}
) {}

public function getEvent(): Event
{
Expand Down

0 comments on commit ab4dd8a

Please sign in to comment.