File tree Expand file tree Collapse file tree 4 files changed +7
-36
lines changed
Expand file tree Collapse file tree 4 files changed +7
-36
lines changed Original file line number Diff line number Diff line change 99use Arkitect \ClassSet ;
1010use Arkitect \ClassSetRules ;
1111use Arkitect \CLI \Printer \Printer ;
12+ use Arkitect \CLI \Printer \PrinterFactory ;
1213use Arkitect \CLI \Progress \VoidProgress ;
1314use Arkitect \CLI \Runner ;
1415use Arkitect \CLI \TargetPhpVersion ;
@@ -40,6 +41,8 @@ class ArchRuleCheckerConstraintAdapter extends Constraint
4041 /** @var ParsingErrors */
4142 private $ parsingErrors ;
4243
44+ private Printer $ printer ;
45+
4346 public function __construct (ClassSet $ classSet )
4447 {
4548 $ targetPhpVersion = TargetPhpVersion::create (null );
@@ -48,6 +51,7 @@ public function __construct(ClassSet $classSet)
4851 $ this ->classSet = $ classSet ;
4952 $ this ->violations = new Violations ();
5053 $ this ->parsingErrors = new ParsingErrors ();
54+ $ this ->printer = PrinterFactory::create (Printer::FORMAT_TEXT );
5155 }
5256
5357 public function toString (): string
@@ -80,6 +84,6 @@ protected function failureDescription($other): string
8084 return "\n parsing error: " .$ this ->parsingErrors ->toString ();
8185 }
8286
83- return "\n" .$ this ->violations ->toString (Printer:: FORMAT_TEXT );
87+ return "\n" .$ this ->printer -> print ( $ this -> violations ->groupedByFqcn () );
8488 }
8589}
Original file line number Diff line number Diff line change 44
55namespace Arkitect \Rules ;
66
7- use Arkitect \CLI \Printer \PrinterFactory ;
87use Arkitect \Exceptions \IndexNotFoundException ;
98
109/**
@@ -75,13 +74,6 @@ public function groupedByFqcn(): array
7574 }, []);
7675 }
7776
78- public function toString (string $ format ): string
79- {
80- $ printer = (new PrinterFactory ())->create ($ format );
81-
82- return $ printer ->print ($ this ->groupedByFqcn ());
83- }
84-
8577 public function toArray (): array
8678 {
8779 return $ this ->violations ;
Original file line number Diff line number Diff line change @@ -15,9 +15,7 @@ class PrinterFactoryTest extends TestCase
1515 */
1616 public function test_create_returns_json_printer_for_json_format (): void
1717 {
18- $ factory = new PrinterFactory ();
19-
20- $ printer = $ factory ->create ('json ' );
18+ $ printer = PrinterFactory::create ('json ' );
2119
2220 self ::assertInstanceOf (JsonPrinter::class, $ printer );
2321 }
@@ -27,9 +25,7 @@ public function test_create_returns_json_printer_for_json_format(): void
2725 */
2826 public function test_create_returns_text_printer_for_non_json_format (): void
2927 {
30- $ factory = new PrinterFactory ();
31-
32- $ printer = $ factory ->create ('text ' );
28+ $ printer = PrinterFactory::create ('text ' );
3329
3430 self ::assertInstanceOf (TextPrinter::class, $ printer );
3531 }
Original file line number Diff line number Diff line change 44
55namespace Arkitect \Tests \Unit \Rules ;
66
7- use Arkitect \CLI \Printer \Printer ;
87use Arkitect \Exceptions \IndexNotFoundException ;
98use Arkitect \Rules \Violation ;
109use Arkitect \Rules \Violations ;
@@ -48,26 +47,6 @@ public function test_count(): void
4847 self ::assertEquals (2 , $ this ->violationStore ->count ());
4948 }
5049
51- public function test_to_string (): void
52- {
53- $ violation = new Violation (
54- 'App\Controller\Foo ' ,
55- 'should have name end with Controller '
56- );
57-
58- $ this ->violationStore ->add ($ violation );
59-
60- $ expected = <<<'ERRORS'
61- App\Controller\ProductController has 1 violations
62- should implement ContainerInterface
63-
64- App\Controller\Foo has 1 violations
65- should have name end with Controller
66- ERRORS;
67-
68- self ::assertStringContainsString ($ expected , $ this ->violationStore ->toString (Printer::FORMAT_TEXT ));
69- }
70-
7150 public function test_get_iterable (): void
7251 {
7352 $ violation = new Violation (
You can’t perform that action at this time.
0 commit comments