Skip to content

Commit

Permalink
used attribute Deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 29, 2024
1 parent b308c9b commit 8655bcb
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/DI/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class ContainerBuilder
ThisService = 'self',
ThisContainer = 'container';

/** @deprecated use ContainerBuilder::ThisService */
#[\Deprecated('use ContainerBuilder::ThisService')]
public const THIS_SERVICE = self::ThisService;

/** @deprecated use ContainerBuilder::ThisContainer */
#[\Deprecated('use ContainerBuilder::ThisContainer')]
public const THIS_CONTAINER = self::ThisContainer;

public array $parameters = [];
Expand Down
2 changes: 1 addition & 1 deletion src/DI/Definitions/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class Reference
{
public const Self = 'self';

/** @deprecated use Reference::Self */
#[\Deprecated('use Reference::Self')]
public const SELF = self::Self;

private string $value;
Expand Down
2 changes: 1 addition & 1 deletion src/DI/DependencyChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DependencyChecker
{
public const Version = 1;

/** @deprecated use DependencyChecker::Version */
#[\Deprecated('use DependencyChecker::Version')]
public const VERSION = self::Version;

/** @var array<ReflectionClass|\ReflectionFunctionAbstract|string> */
Expand Down
4 changes: 2 additions & 2 deletions src/DI/Extensions/InjectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class InjectExtension extends DI\CompilerExtension
{
public const TagInject = 'nette.inject';

/** @deprecated use InjectExtension::TagInject */
#[\Deprecated('use InjectExtension::TagInject')]
public const TAG_INJECT = self::TagInject;


Expand Down Expand Up @@ -119,7 +119,7 @@ public static function getInjectProperties(string $class): array
foreach ((new \ReflectionClass($class))->getProperties() as $rp) {
if (
$rp->getAttributes(DI\Attributes\Inject::class)
|| DI\Helpers::parseAnnotation($rp, 'inject') !== null
|| @DI\Helpers::parseAnnotation($rp, 'inject') !== null // @deprecated
) {
if (!$rp->getAttributes(DI\Attributes\Inject::class)) {
trigger_error('Annotation @inject is deprecated, use #[Nette\\DI\\Attributes\\Inject] (used in ' . Reflection::toString($rp) . ')', E_USER_DEPRECATED);
Expand Down
4 changes: 1 addition & 3 deletions src/DI/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ public static function prefixServiceName(mixed $config, string $namespace): mixe
}


/**
* Returns an annotation value.
*/
#[\Deprecated]
public static function parseAnnotation(\Reflector $ref, string $name): ?string
{
if (!Reflection::areCommentsAvailable()) {
Expand Down
22 changes: 9 additions & 13 deletions tests/DI/Helpers.parseAnnotation().phpt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<?php

/**
* Test: Nette\DI\Helpers::expand()
*/

declare(strict_types=1);

use Nette\DI\Helpers;
Expand All @@ -22,10 +18,10 @@ class TestClass

$rc = new ReflectionClass(TestClass::class);

Assert::same('', Helpers::parseAnnotation($rc, 'inject'));
Assert::same(null, Helpers::parseAnnotation($rc, 'injec'));
Assert::same('type', Helpers::parseAnnotation($rc, 'var'));
Assert::same('bool|int', Helpers::parseAnnotation($rc, 'return'));
Assert::same('', @Helpers::parseAnnotation($rc, 'inject'));
Assert::same(null, @Helpers::parseAnnotation($rc, 'injec'));
Assert::same('type', @Helpers::parseAnnotation($rc, 'var'));
Assert::same('bool|int', @Helpers::parseAnnotation($rc, 'return'));


/** @return*/
Expand All @@ -35,7 +31,7 @@ class TestClass2

$rc = new ReflectionClass(TestClass2::class);

Assert::same('', Helpers::parseAnnotation($rc, 'return'));
Assert::same('', @Helpers::parseAnnotation($rc, 'return'));


/** @return
Expand All @@ -47,7 +43,7 @@ class TestClass3

$rc = new ReflectionClass(TestClass3::class);

Assert::same('', Helpers::parseAnnotation($rc, 'return'));
Assert::same('', @Helpers::parseAnnotation($rc, 'return'));


/**
Expand All @@ -59,6 +55,6 @@ class TestClass4

$rc = new ReflectionClass(TestClass4::class);

Assert::same(null, Helpers::parseAnnotation($rc, 'inject'));
Assert::same(null, Helpers::parseAnnotation($rc, 'injec'));
Assert::same(null, Helpers::parseAnnotation($rc, 'var'));
Assert::same(null, @Helpers::parseAnnotation($rc, 'inject'));
Assert::same(null, @Helpers::parseAnnotation($rc, 'injec'));
Assert::same(null, @Helpers::parseAnnotation($rc, 'var'));

0 comments on commit 8655bcb

Please sign in to comment.