1515/**
1616 * @implements SourceFetcherInterface<GitlabSource>
1717 */
18+ #[LoggerPrefix(prefix: 'gitlab-source ' )]
1819final readonly class GitlabSourceFetcher implements SourceFetcherInterface
1920{
2021 public function __construct (
2122 private GitlabFinder $ finder ,
23+ private LoggerInterface $ logger ,
2224 private ContentBuilderFactory $ builderFactory = new ContentBuilderFactory (),
23- #[LoggerPrefix(prefix: 'gitlab-source ' )]
24- private ?LoggerInterface $ logger = null ,
2525 ) {}
2626
2727 public function supports (SourceInterface $ source ): bool
2828 {
2929 $ isSupported = $ source instanceof GitlabSource;
30- $ this ->logger ? ->debug('Checking if source is supported ' , [
30+ $ this ->logger ->debug ('Checking if source is supported ' , [
3131 'sourceType ' => $ source ::class,
3232 'isSupported ' => $ isSupported ,
3333 ]);
@@ -38,28 +38,28 @@ public function fetch(SourceInterface $source, ModifiersApplierInterface $modifi
3838 {
3939 if (!$ source instanceof GitlabSource) {
4040 $ errorMessage = 'Source must be an instance of GitlabSource ' ;
41- $ this ->logger ? ->error($ errorMessage , [
41+ $ this ->logger ->error ($ errorMessage , [
4242 'sourceType ' => $ source ::class,
4343 ]);
4444 throw new \InvalidArgumentException ($ errorMessage );
4545 }
4646
47- $ this ->logger ? ->info('Fetching GitLab source content ' , [
47+ $ this ->logger ->info ('Fetching GitLab source content ' , [
4848 'repository ' => $ source ->repository ,
4949 'branch ' => $ source ->branch ,
5050 'hasModifiers ' => !empty ($ source ->modifiers ),
5151 'showTreeView ' => $ source ->showTreeView ,
5252 ]);
5353
5454 // Parse repository from string
55- $ this ->logger ? ->debug('Parsing repository from string ' , [
55+ $ this ->logger ->debug ('Parsing repository from string ' , [
5656 'repository ' => $ source ->repository ,
5757 'branch ' => $ source ->branch ,
5858 ]);
5959 $ repository = new GitlabRepository ($ source ->repository , $ source ->branch );
6060
6161 // Create builder
62- $ this ->logger ? ->debug('Creating content builder ' );
62+ $ this ->logger ->debug ('Creating content builder ' );
6363 $ builder = $ this ->builderFactory
6464 ->create ()
6565 ->addTitle ($ source ->getDescription (), 2 );
@@ -76,27 +76,27 @@ public function fetch(SourceInterface $source, ModifiersApplierInterface $modifi
7676 );
7777
7878 // Find files using the finder and get the FinderResult
79- $ this ->logger ? ->debug('Finding files in repository ' , [
79+ $ this ->logger ->debug ('Finding files in repository ' , [
8080 'repository ' => $ repository ->getPath (),
8181 'branch ' => $ repository ->branch ,
8282 ]);
8383 $ finderResult = $ this ->finder ->find ($ source );
8484 $ fileCount = $ finderResult ->count ();
85- $ this ->logger ? ->debug('Files found in repository ' , [
85+ $ this ->logger ->debug ('Files found in repository ' , [
8686 'fileCount ' => $ fileCount ,
8787 ]);
8888
8989 // Add tree view if requested
9090 if ($ source ->showTreeView ) {
91- $ this ->logger ? ->debug('Adding tree view to output ' );
91+ $ this ->logger ->debug ('Adding tree view to output ' );
9292 $ builder ->addTreeView ($ finderResult ->treeView );
9393 }
9494
9595 // Fetch and add the content of each file
96- $ this ->logger ? ->debug('Processing repository files ' );
96+ $ this ->logger ->debug ('Processing repository files ' );
9797 foreach ($ finderResult ->files as $ index => $ file ) {
9898 $ path = $ file ->getRelativePathname ();
99- $ this ->logger ? ->debug('Processing file ' , [
99+ $ this ->logger ->debug ('Processing file ' , [
100100 'file ' => $ path ,
101101 'index ' => $ index + 1 ,
102102 'total ' => $ fileCount ,
@@ -105,7 +105,7 @@ public function fetch(SourceInterface $source, ModifiersApplierInterface $modifi
105105 $ fileContent = $ modifiersApplier ->apply ($ file ->getContents (), $ path );
106106
107107 $ language = $ this ->detectLanguage ($ path );
108- $ this ->logger ? ->debug('Adding file to content ' , [
108+ $ this ->logger ->debug ('Adding file to content ' , [
109109 'file ' => $ path ,
110110 'language ' => $ language ,
111111 'contentLength ' => \strlen ($ fileContent ),
@@ -120,7 +120,7 @@ public function fetch(SourceInterface $source, ModifiersApplierInterface $modifi
120120 }
121121
122122 $ content = $ builder ->build ();
123- $ this ->logger ? ->info('GitLab source content fetched successfully ' , [
123+ $ this ->logger ->info ('GitLab source content fetched successfully ' , [
124124 'repository ' => $ repository ->getPath (),
125125 'branch ' => $ repository ->branch ,
126126 'fileCount ' => $ fileCount ,
@@ -138,7 +138,7 @@ private function detectLanguage(string $filePath): ?string
138138 {
139139 $ extension = \pathinfo ($ filePath , PATHINFO_EXTENSION );
140140
141- $ this ->logger ? ->debug('Detecting language for file ' , [
141+ $ this ->logger ->debug ('Detecting language for file ' , [
142142 'file ' => $ filePath ,
143143 'extension ' => $ extension ,
144144 ]);
0 commit comments