File tree Expand file tree Collapse file tree 4 files changed +57
-9
lines changed
tests/Application/ApplicationFileProcessor Expand file tree Collapse file tree 4 files changed +57
-9
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Rector \Core \Tests \Application \ApplicationFileProcessor \Source \Contract ;
6
+
7
+ use Rector \Core \Contract \Rector \RectorInterface ;
8
+
9
+ interface TextRectorInterface extends RectorInterface
10
+ {
11
+ public function refactorContent (string $ content ): string ;
12
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Rector \Core \Tests \Application \ApplicationFileProcessor \Source \Rector ;
6
+
7
+ use Rector \Core \Tests \Application \ApplicationFileProcessor \Source \Contract \TextRectorInterface ;
8
+ use Symplify \RuleDocGenerator \ValueObject \RuleDefinition ;
9
+
10
+ final class ChangeTextRector implements TextRectorInterface
11
+ {
12
+ public function refactorContent (string $ content ): string
13
+ {
14
+ return str_replace ('Foo ' , 'Bar ' , $ content );
15
+ }
16
+
17
+ public function getRuleDefinition (): RuleDefinition
18
+ {
19
+ // just for docs
20
+ }
21
+ }
Original file line number Diff line number Diff line change 5
5
namespace Rector \Core \Tests \Application \ApplicationFileProcessor \Source ;
6
6
7
7
use Rector \Core \Contract \Processor \FileProcessorInterface ;
8
+ use Rector \Core \Tests \Application \ApplicationFileProcessor \Source \Contract \TextRectorInterface ;
8
9
use Rector \Core \ValueObject \Application \File ;
9
10
10
11
final class TextFileProcessor implements FileProcessorInterface
11
12
{
13
+ /**
14
+ * @var TextRectorInterface[]
15
+ */
16
+ private $ textRectors ;
17
+
18
+ /**
19
+ * @param TextRectorInterface[] $textRectors
20
+ */
21
+ public function __construct (array $ textRectors )
22
+ {
23
+ $ this ->textRectors = $ textRectors ;
24
+ }
25
+
12
26
/**
13
27
* @param File[] $files
14
28
*/
15
29
public function process (array $ files ): void
16
30
{
17
31
foreach ($ files as $ file ) {
18
- $ this ->processFile ($ file );
32
+ $ fileContent = $ file ->getFileContent ();
33
+
34
+ foreach ($ this ->textRectors as $ textRector ) {
35
+ $ fileContent = $ textRector ->refactorContent ($ fileContent );
36
+ }
37
+
38
+ $ file ->changeFileContent ($ fileContent );
19
39
}
20
40
}
21
41
@@ -32,12 +52,4 @@ public function getSupportedFileExtensions(): array
32
52
{
33
53
return ['txt ' ];
34
54
}
35
-
36
- private function processFile ($ file ): void
37
- {
38
- $ oldFileContent = $ file ->getFileContent ();
39
- $ changedFileContent = str_replace ('Foo ' , 'Bar ' , $ oldFileContent );
40
-
41
- $ file ->changeFileContent ($ changedFileContent );
42
- }
43
55
}
Original file line number Diff line number Diff line change 2
2
3
3
declare (strict_types=1 );
4
4
5
+ use Rector \Core \Tests \Application \ApplicationFileProcessor \Source \Rector \ChangeTextRector ;
5
6
use Rector \Core \Tests \Application \ApplicationFileProcessor \Source \TextFileProcessor ;
6
7
use Symfony \Component \DependencyInjection \Loader \Configurator \ContainerConfigurator ;
7
8
8
9
return static function (ContainerConfigurator $ containerConfigurator ): void {
9
10
$ services = $ containerConfigurator ->services ();
10
11
$ services ->set (TextFileProcessor::class);
12
+
13
+ $ services ->set (ChangeTextRector::class);
11
14
};
You can’t perform that action at this time.
0 commit comments