Skip to content

Commit 345f6e9

Browse files
committed
Remove dependency from ock/testing to ock/reflection.
1 parent b3d09b1 commit 345f6e9

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"ext-json": "*",
2424
"ock/class-files-iterator": "self.version",
2525
"ock/helpers": "self.version",
26-
"ock/reflection": "self.version",
2726
"symfony/yaml": "^7.1.5"
2827
},
2928
"require-dev": {

src/Exporter/Exporter_ToYamlArray.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace Ock\Testing\Exporter;
66

7-
use Ock\Reflection\ClassReflection;
8-
97
/**
108
* Exports as array suitable for a yaml file.
119
*/
@@ -484,10 +482,13 @@ protected function stabilizePath(string $path): string {
484482
* @return array<string, mixed>
485483
*/
486484
protected function exportObjectProperties(object $object, int $depth, bool $public = false): array {
487-
$reflector = new ClassReflection($object);
488-
$properties = $reflector->getFilteredProperties(static: false, public: $public ?: null);
485+
$reflector = new \ReflectionClass($object);
486+
$properties = $reflector->getProperties($public ? \ReflectionProperty::IS_PUBLIC : null);
489487
$export = [];
490488
foreach ($properties as $property) {
489+
if ($property->isStatic()) {
490+
continue;
491+
}
491492
if ($property->isInitialized($object)) {
492493
$propertyValue = $property->getValue($object);
493494
}
@@ -513,10 +514,17 @@ protected function exportObjectProperties(object $object, int $depth, bool $publ
513514
* @return array<string, mixed>
514515
*/
515516
protected function exportObjectGetterValues(object $object, int $depth): array {
516-
$reflector = new ClassReflection($object);
517+
$reflector = new \ReflectionClass($object);
517518
$result = [];
518-
foreach ($reflector->getFilteredMethods(static: false, public: true, constructor: false) as $method) {
519-
if ($method->hasRequiredParameters()
519+
$methods = $reflector->getMethods(\ReflectionMethod::IS_PUBLIC);
520+
foreach ($methods as $method) {
521+
if ($method->isConstructor() || $method->isStatic()) {
522+
continue;
523+
}
524+
if ($method->isConstructor()
525+
|| $method->isStatic()
526+
// Skip if the method has required parameters.
527+
|| ($method->getParameters()[0] ?? NULL)?->isOptional() === false
520528
|| (string) ($method->getReturnType() ?? '?') === 'void'
521529
|| (string) ($method->getReturnType() ?? '?') === 'never'
522530
|| !\preg_match('#^(get|is|has)[A-Z]#', $method->name)

0 commit comments

Comments
 (0)