File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -246,9 +246,18 @@ public function dumpAttribute(FullyQualified | string $fqcn) : string
246246 /**
247247 * Generates a class reference string (e.g., Foo::class)
248248 */
249- public function dumpClassReference (FullyQualified | string $ fqcn , bool $ import = true ) : string
249+ public function dumpClassReference (FullyQualified | string $ fqcn , bool $ import = true , bool $ byParent = false ) : string
250250 {
251- return sprintf ('%s::class ' , $ import ? $ this ->import ($ fqcn ) : '\\' . (string ) $ fqcn );
251+ $ fqcn = FullyQualified::maybeFromString ($ fqcn );
252+
253+ return sprintf (
254+ '%s::class ' ,
255+ match (true ) {
256+ $ import && $ byParent => $ this ->importByParent ($ fqcn ),
257+ $ import => $ this ->import ($ fqcn ),
258+ default => '\\' . $ fqcn ,
259+ },
260+ );
252261 }
253262
254263 /**
Original file line number Diff line number Diff line change @@ -363,12 +363,24 @@ public function testDumpClassReference() : void
363363 );
364364 }
365365
366+ public function testDumpClassReferenceByParent () : void
367+ {
368+ self ::assertSame (
369+ 'Models \\User::class ' ,
370+ $ this ->generator ->dumpClassReference ('App \\Models \\User ' , byParent: true ),
371+ );
372+ }
373+
366374 public function testDumpClassReferenceWithoutImport () : void
367375 {
368376 self ::assertSame (
369377 '\\App \\Models \\User::class ' ,
370378 $ this ->generator ->dumpClassReference ('App \\Models \\User ' , false ),
371379 );
380+ self ::assertSame (
381+ '\\App \\Models \\User::class ' ,
382+ $ this ->generator ->dumpClassReference ('\\App \\Models \\User ' , false ),
383+ );
372384 }
373385
374386 public function testMaybeNowDocWithSingleLine () : void
You can’t perform that action at this time.
0 commit comments