Skip to content

Commit

Permalink
Merge pull request #31 from sevidmusic/PHPReflectionUtilities1685638355
Browse files Browse the repository at this point in the history
# Resolved issue #26 

commit 680f895 (HEAD -> PHPReflectionUtilities1685638355, origin/PHPReflectionUtilities1685638355)
Author: sevidmusic <sevidmusic@gmail.com>
Date:   Sat Jun 3 12:14:11 2023 -0400

    Revised documentation

commit 1cf514c
Author: sevidmusic <sevidmusic@gmail.com>
Date:   Sat Jun 3 12:11:41 2023 -0400

    Resolved issue #26.

commit a50fad0
Author: sevidmusic <sevidmusic@gmail.com>
Date:   Thu Jun 1 12:54:26 2023 -0400

    Composer update
  • Loading branch information
sevidmusic committed Jun 3, 2023
2 parents fe2386b + 680f895 commit 61fdd93
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 43 deletions.
24 changes: 12 additions & 12 deletions composer.lock

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

40 changes: 9 additions & 31 deletions src/classes/utilities/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ public function type(): ClassStringInterface
);
}

public function reflectionClass(): ReflectionClass
{
/**
* @var class-string $fullyQulifiedNamespaceAndClassname
*/
$fullyQulifiedNamespaceAndClassname = $this->classString->__toString();
return new ReflectionClass($fullyQulifiedNamespaceAndClassname);
}

/**
* For each property declared by the parents of the reflected
* class or object instance add a numerically indexed array of
Expand Down Expand Up @@ -750,36 +759,5 @@ private function addNamedTypeToArray(
}
}

/**
* Return the ReflectionClass instance that reflects the
* class-string or object reflected by this Reflection.
*
* @return ReflectionClass<object>
*
* @example
*
* ```
* var_dump($this->reflectionClass());
*
* // example output:
* object(ReflectionClass)#3 (1) {
* ["name"]=>
* string(65) "Darling\PHPUnitTestUtilities\Tests\dev\mock\classes\PublicMethods"
* }
*
* ```
*
* @see https://github.com/sevidmusic/PHPUnitTestUtilities/blob/main/tests/dev/mock/classes/PublicMethods.php
*
*/
protected function reflectionClass(): ReflectionClass
{
/**
* @var class-string $fullyQulifiedNamespaceAndClassname
*/
$fullyQulifiedNamespaceAndClassname = $this->classString->__toString();
return new ReflectionClass($fullyQulifiedNamespaceAndClassname);
}

}

25 changes: 25 additions & 0 deletions src/interfaces/utilities/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Darling\PHPReflectionUtilities\interfaces\utilities;

use Darling\PHPTextTypes\interfaces\strings\ClassString;
use ReflectionClass;
use ReflectionException;
use ReflectionMethod;

Expand Down Expand Up @@ -442,5 +443,29 @@ public function propertyTypes(int $filter = null): array;
*/
public function type(): ClassString;

/**
* Return an instance of a ReflectionClass instance that reflects
* the class-string or object reflected by the Reflection.
*
* @return ReflectionClass<object>
*
* @example
*
* ```
* var_dump($reflection->reflectionClass());
*
* // example output:
* object(ReflectionClass)#3 (1) {
* ["name"]=>
* string(65) "Darling\PHPUnitTestUtilities\Tests\dev\mock\classes\PublicMethods"
* }
*
* ```
*
* @see https://github.com/sevidmusic/PHPUnitTestUtilities/blob/main/tests/dev/mock/classes/PublicMethods.php
*
*/
public function reflectionClass(): ReflectionClass;

}

25 changes: 25 additions & 0 deletions tests/interfaces/utilities/ReflectionTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2722,5 +2722,30 @@ public function test_propertyTypes_returns_the_types_of_the_static_properties_de
)
);
}

/**
* Test that the reflectionClass method returns an instance of a
* ReflectionClass that reflects the class or object instance.
*
* @return void
*
* @covers Darling\PHPReflectionUtilities\classes\utilities\Reflection::reflectionClass()
*
*/
public function test_reflectionClass_returns_an_instance_of_a_ReflectionClass_that_reflects_the_class_or_object_instance_reflected_by_the_Reflection(): void
{
$expectedReflectionClass = $this->reflectionClass($this->reflectedClass);
$this->assertEquals(
$expectedReflectionClass,
$this->reflectionTestInstance()->reflectionClass(),
$this->testFailedMessage(
$this->reflectionTestInstance(),
'reflectionClass',
'return an instance of a ReflectionClass that ' .
'reflects the class or object instance reflected ' .
'by the reflection'
),
);
}
}

0 comments on commit 61fdd93

Please sign in to comment.