2323
2424namespace KonradMichalik \PhpDocBlockHeaderFixer \Rules ;
2525
26+ use KonradMichalik \PhpDocBlockHeaderFixer \Model \Separate ;
2627use PhpCsFixer \AbstractFixer ;
2728use PhpCsFixer \Fixer \ConfigurableFixerInterface ;
2829use PhpCsFixer \FixerConfiguration \FixerConfigurationResolver ;
4344final class DocBlockHeaderFixer extends AbstractFixer implements ConfigurableFixerInterface
4445{
4546 /**
46- * @var array<string, mixed>|null
47+ * @var array<string, mixed>
4748 */
48- protected ? array $ configuration = null ;
49+ private array $ resolvedConfiguration = [] ;
4950
5051 public function getDefinition (): FixerDefinitionInterface
5152 {
@@ -77,20 +78,20 @@ public function getConfigurationDefinition(): FixerConfigurationResolverInterfac
7778 ->setDefault (true )
7879 ->getOption (),
7980 (new FixerOptionBuilder ('separate ' , 'Separate the comment ' ))
80- ->setAllowedValues ([ ' top ' , ' bottom ' , ' both ' , ' none ' ] )
81- ->setDefault (' both ' )
81+ ->setAllowedValues (Separate:: getList () )
82+ ->setDefault (Separate::Both-> value )
8283 ->getOption (),
8384 ]);
8485 }
8586
8687 public function configure (?array $ configuration = null ): void
8788 {
88- $ this ->configuration = $ this ->getConfigurationDefinition ()->resolve ($ configuration ?? []);
89+ $ this ->resolvedConfiguration = $ this ->getConfigurationDefinition ()->resolve ($ configuration ?? []);
8990 }
9091
9192 protected function applyFix (SplFileInfo $ file , Tokens $ tokens ): void
9293 {
93- $ annotations = $ this ->configuration ['annotations ' ] ?? [];
94+ $ annotations = $ this ->resolvedConfiguration ['annotations ' ] ?? [];
9495 if (empty ($ annotations )) {
9596 return ;
9697 }
@@ -112,7 +113,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void
112113 private function processClassDocBlock (Tokens $ tokens , int $ classIndex , array $ annotations ): void
113114 {
114115 $ existingDocBlockIndex = $ this ->findExistingDocBlock ($ tokens , $ classIndex );
115- $ preserveExisting = $ this ->configuration ['preserve_existing ' ] ?? true ;
116+ $ preserveExisting = $ this ->resolvedConfiguration ['preserve_existing ' ] ?? true ;
116117
117118 if (null !== $ existingDocBlockIndex ) {
118119 if ($ preserveExisting ) {
@@ -174,7 +175,7 @@ private function replaceDocBlock(Tokens $tokens, int $docBlockIndex, array $anno
174175 */
175176 private function insertNewDocBlock (Tokens $ tokens , int $ classIndex , array $ annotations ): void
176177 {
177- $ separate = $ this ->configuration ['separate ' ] ?? 'both ' ;
178+ $ separate = $ this ->resolvedConfiguration ['separate ' ] ?? 'both ' ;
178179 $ insertIndex = $ this ->findInsertPosition ($ tokens , $ classIndex );
179180
180181 $ tokensToInsert = [];
0 commit comments