Skip to content

Commit

Permalink
Merge pull request #6 from fractalzombie/feature/update-fp-library
Browse files Browse the repository at this point in the history
[DependencyInjection] Update functional library with breaking changes
  • Loading branch information
fractalzombie authored Dec 25, 2023
2 parents 1981f99 + 4e09900 commit cd99129
Show file tree
Hide file tree
Showing 44 changed files with 347 additions and 262 deletions.
43 changes: 35 additions & 8 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,50 @@
<?php

/** @noinspection DuplicatedCode */

declare(strict_types=1);

$header = <<<EOF
This is package for Symfony framework.
/**
* 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.
(c) Mykhailo Shtanko <fractalzombie@gmail.com>
Copyright (c) {{YEAR}} {{OWNER}} {{EMAIL}}
For the full copyright and license information, please view the LICENSE
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')
->notPath('#Enum#')
->in(__DIR__)
->in($projectDirectory)
;

$rules = [
'header_comment' => ['header' => $header],
'@PSR2' => true,
'@PSR12' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@PhpCsFixer' => true,
'@PHP80Migration' => true,
'@PHP80Migration:risky' => true,
'@PHP81Migration' => true,
'@PHP80Migration:risky' => true,
'@PHPUnit84Migration:risky' => true,
'date_time_immutable' => true,
'single_line_throw' => true,
Expand All @@ -37,6 +54,16 @@
'php_unit_test_class_requires_covers' => false,
'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
10 changes: 6 additions & 4 deletions Attribute/AsAlias.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

declare(strict_types=1);

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

Expand Down
13 changes: 7 additions & 6 deletions Attribute/AsDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

declare(strict_types=1);

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

Expand All @@ -25,6 +27,5 @@ public function __construct(
public readonly ?string $innerName = null,
public readonly int $priority = 0,
public readonly InvalidType $onInvalid = InvalidType::ExceptionOnInvalidReference,
) {
}
) {}
}
13 changes: 7 additions & 6 deletions Attribute/AsDeprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

declare(strict_types=1);

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

Expand Down Expand Up @@ -35,6 +37,5 @@ public function __construct(
public readonly string $package,
public readonly string $version,
public readonly string $message = self::DEFAULT_DEPRECATION_TEMPLATE,
) {
}
) {}
}
14 changes: 7 additions & 7 deletions Attribute/AsIgnored.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

declare(strict_types=1);

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

Expand All @@ -28,7 +30,5 @@
#[\Attribute(\Attribute::TARGET_CLASS)]
final class AsIgnored
{
public function __construct()
{
}
public function __construct() {}
}
25 changes: 12 additions & 13 deletions Attribute/AsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

declare(strict_types=1);

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

namespace FRZB\Component\DependencyInjection\Attribute;

use Fp\Collections\ArrayList;
use Fp\Collections\Entry;
use Fp\Collections\HashMap;
use FRZB\Component\DependencyInjection\Exception\AttributeException;
use JetBrains\PhpStorm\Immutable;
Expand All @@ -34,11 +35,11 @@ public function __construct(
public readonly bool $isPublic = true,
public readonly bool $isAbstract = false,
public readonly ?string $id = null,
public readonly string|array|null $factory = null,
public readonly null|array|string $factory = null,
public readonly ?string $file = null,
array $arguments = [],
public readonly array $properties = [],
public readonly string|array|null $configurator = null,
public readonly null|array|string $configurator = null,
public readonly array $calls = [],
/** @var AsTagged[] */
public readonly array $tags = [],
Expand All @@ -47,12 +48,10 @@ public function __construct(
public readonly array $bindings = [],
) {
$this->arguments = HashMap::collect($arguments)
->mapKeys(static fn (Entry $argument) => match (true) {
str_contains($argument->key, self::PARAMETER_PREFIX) => $argument->key,
default => self::PARAMETER_PREFIX.$argument->key,
})
->toAssocArray()
->getOrElse([])
->mapKV(static fn (string $key, string $value) => match (true) {
str_contains($key, self::PARAMETER_PREFIX) => [$key => $value],
default => [self::PARAMETER_PREFIX.$key => $value],
})->toMergedArray()
;

ArrayList::collect($this->tags)
Expand Down
13 changes: 7 additions & 6 deletions Attribute/AsTagged.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

declare(strict_types=1);

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

Expand All @@ -26,8 +28,7 @@ public function __construct(
public readonly ?string $key = null,
public readonly ?int $priority = null,
public readonly array $attributes = [],
) {
}
) {}

public static function getNameProperty(): string
{
Expand Down
10 changes: 6 additions & 4 deletions Compiler/AbstractRegisterAttributePass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

declare(strict_types=1);

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

Expand Down
11 changes: 6 additions & 5 deletions Compiler/RegisterAsAliasAttributesPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

declare(strict_types=1);

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

Expand All @@ -34,7 +36,6 @@ public function __construct()
parent::__construct(AsAlias::class);
}

/** {@inheritdoc} */
public function process(ContainerBuilder $container): void
{
foreach ($container->getAliases() as $id => $alias) {
Expand Down
10 changes: 6 additions & 4 deletions Compiler/RegisterAsDecoratorAttributesPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

declare(strict_types=1);

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

Expand Down
10 changes: 6 additions & 4 deletions Compiler/RegisterAsDeprecatedAttributesPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

declare(strict_types=1);

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

Expand Down
10 changes: 6 additions & 4 deletions Compiler/RegisterAsIgnoredAttributesPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

declare(strict_types=1);

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

Expand Down
13 changes: 7 additions & 6 deletions Compiler/RegisterAsServiceAttributePass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

declare(strict_types=1);

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

Expand Down Expand Up @@ -42,8 +44,7 @@ protected function register(ContainerBuilder $container, \ReflectionClass $refle

$definition = ($container->hasDefinition($id = $attribute->id ?? $reflectionClass->getName()))
? $container->getDefinition($id)->setClass($reflectionClass->getName())
: $container->setDefinition($id, new Definition())->setClass($reflectionClass->getName())
;
: $container->setDefinition($id, new Definition())->setClass($reflectionClass->getName());

foreach (self::mapArguments($container, $definition, $reflectionClass, $attribute) as $method => $arguments) {
$definition->{$method}($arguments);
Expand Down
Loading

0 comments on commit cd99129

Please sign in to comment.