@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | |
40 | 40 | public function __construct($name = null, array $data = [], $dataName = '') |
41 | 41 | { |
42 | - $this->storage = new Storage($this->dir() . '/Fixtures/'); |
|
42 | + $this->storage = new Storage($this->dir().'/Fixtures/'); |
|
43 | 43 | parent::__construct($name, $data, $dataName); |
44 | 44 | } |
45 | 45 | |
46 | 46 | public function setUp(): void |
47 | 47 | { |
48 | - if (!\class_exists(Kernel::class)) { |
|
48 | + if (!\class_exists(Kernel::class)){ |
|
49 | 49 | $this->markTestSkipped('A "spiral/framework" dependency is required to run these tests'); |
50 | 50 | } |
51 | 51 | |
@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | 'cache' => sys_get_temp_dir() |
57 | 57 | ], null, false); |
58 | 58 | |
59 | - foreach (static::STORE as $name) { |
|
59 | + foreach (static::STORE as $name){ |
|
60 | 60 | $this->storage->store($name); |
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | 64 | public function tearDown(): void |
65 | 65 | { |
66 | - foreach (static::STORE as $name) { |
|
66 | + foreach (static::STORE as $name){ |
|
67 | 67 | $this->storage->restore($name); |
68 | 68 | } |
69 | 69 | } |
@@ -45,7 +45,8 @@ discard block |
||
45 | 45 | |
46 | 46 | public function setUp(): void |
47 | 47 | { |
48 | - if (!\class_exists(Kernel::class)) { |
|
48 | + if (!\class_exists(Kernel::class)) |
|
49 | + { |
|
49 | 50 | $this->markTestSkipped('A "spiral/framework" dependency is required to run these tests'); |
50 | 51 | } |
51 | 52 | |
@@ -56,14 +57,16 @@ discard block |
||
56 | 57 | 'cache' => sys_get_temp_dir() |
57 | 58 | ], null, false); |
58 | 59 | |
59 | - foreach (static::STORE as $name) { |
|
60 | + foreach (static::STORE as $name) |
|
61 | + { |
|
60 | 62 | $this->storage->store($name); |
61 | 63 | } |
62 | 64 | } |
63 | 65 | |
64 | 66 | public function tearDown(): void |
65 | 67 | { |
66 | - foreach (static::STORE as $name) { |
|
68 | + foreach (static::STORE as $name) |
|
69 | + { |
|
67 | 70 | $this->storage->restore($name); |
68 | 71 | } |
69 | 72 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function __construct(Lexer $lexer = null, PrettyPrinterAbstract $printer = null) |
49 | 49 | { |
50 | - if ($lexer === null) { |
|
50 | + if ($lexer === null){ |
|
51 | 51 | $lexer = new Lexer\Emulative([ |
52 | 52 | 'usedAttributes' => [ |
53 | 53 | 'comments', |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function injectDependencies(string $code, ClassNode $node, bool $removeTrait = false): string |
81 | 81 | { |
82 | - if (empty($node->dependencies)) { |
|
83 | - if ($removeTrait) { |
|
82 | + if (empty($node->dependencies)){ |
|
83 | + if ($removeTrait){ |
|
84 | 84 | $tr = new NodeTraverser(); |
85 | 85 | $tr->addVisitor(new RemoveUse()); |
86 | 86 | $tr->addVisitor(new RemoveTrait()); |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | $tr = new NodeTraverser(); |
95 | 95 | $tr->addVisitor(new AddUse($node)); |
96 | 96 | |
97 | - if ($removeTrait) { |
|
97 | + if ($removeTrait){ |
|
98 | 98 | $tr->addVisitor(new RemoveUse()); |
99 | 99 | $tr->addVisitor(new RemoveTrait()); |
100 | 100 | } |
@@ -47,7 +47,8 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function __construct(Lexer $lexer = null, PrettyPrinterAbstract $printer = null) |
49 | 49 | { |
50 | - if ($lexer === null) { |
|
50 | + if ($lexer === null) |
|
51 | + { |
|
51 | 52 | $lexer = new Lexer\Emulative([ |
52 | 53 | 'usedAttributes' => [ |
53 | 54 | 'comments', |
@@ -79,8 +80,10 @@ discard block |
||
79 | 80 | */ |
80 | 81 | public function injectDependencies(string $code, ClassNode $node, bool $removeTrait = false): string |
81 | 82 | { |
82 | - if (empty($node->dependencies)) { |
|
83 | - if ($removeTrait) { |
|
83 | + if (empty($node->dependencies)) |
|
84 | + { |
|
85 | + if ($removeTrait) |
|
86 | + { |
|
84 | 87 | $tr = new NodeTraverser(); |
85 | 88 | $tr->addVisitor(new RemoveUse()); |
86 | 89 | $tr->addVisitor(new RemoveTrait()); |
@@ -94,7 +97,8 @@ discard block |
||
94 | 97 | $tr = new NodeTraverser(); |
95 | 98 | $tr->addVisitor(new AddUse($node)); |
96 | 99 | |
97 | - if ($removeTrait) { |
|
100 | + if ($removeTrait) |
|
101 | + { |
|
98 | 102 | $tr->addVisitor(new RemoveUse()); |
99 | 103 | $tr->addVisitor(new RemoveTrait()); |
100 | 104 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | public function perform(): void |
33 | 33 | { |
34 | 34 | $prototyped = $this->locator->getTargetClasses(); |
35 | - if ($prototyped === []) { |
|
35 | + if ($prototyped === []){ |
|
36 | 36 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
37 | 37 | |
38 | 38 | return; |
@@ -40,18 +40,18 @@ discard block |
||
40 | 40 | |
41 | 41 | $targets = []; |
42 | 42 | |
43 | - foreach ($prototyped as $class) { |
|
43 | + foreach ($prototyped as $class){ |
|
44 | 44 | $proto = $this->getPrototypeProperties($class); |
45 | - if (empty($proto)) { |
|
45 | + if (empty($proto)){ |
|
46 | 46 | $modified = $this->modify($class, $proto); |
47 | - if ($modified !== null) { |
|
47 | + if ($modified !== null){ |
|
48 | 48 | $targets[] = $modified; |
49 | 49 | } |
50 | 50 | continue; |
51 | 51 | } |
52 | 52 | |
53 | - foreach ($proto as $target) { |
|
54 | - if ($target instanceof \Throwable) { |
|
53 | + foreach ($proto as $target){ |
|
54 | + if ($target instanceof \Throwable){ |
|
55 | 55 | $targets[] = [ |
56 | 56 | $class->getName(), |
57 | 57 | $target->getMessage(), |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | continue 2; |
61 | 61 | } |
62 | 62 | |
63 | - if ($target === null) { |
|
63 | + if ($target === null){ |
|
64 | 64 | continue 2; |
65 | 65 | } |
66 | 66 | } |
@@ -68,14 +68,14 @@ discard block |
||
68 | 68 | $targets[] = [$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]; |
69 | 69 | |
70 | 70 | $modified = $this->modify($class, $proto); |
71 | - if ($modified !== null) { |
|
71 | + if ($modified !== null){ |
|
72 | 72 | $targets[] = $modified; |
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
76 | - if (!empty($targets)) { |
|
76 | + if (!empty($targets)){ |
|
77 | 77 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
78 | - foreach ($targets as $target) { |
|
78 | + foreach ($targets as $target){ |
|
79 | 79 | $grid->addRow($target); |
80 | 80 | } |
81 | 81 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | private function modify(\ReflectionClass $class, array $proto): ?array |
87 | 87 | { |
88 | 88 | $classDefinition = $this->extractor->extract($class->getFilename(), $proto); |
89 | - try { |
|
89 | + try{ |
|
90 | 90 | $modified = (new Injector())->injectDependencies( |
91 | 91 | file_get_contents($class->getFileName()), |
92 | 92 | $classDefinition, |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | file_put_contents($class->getFileName(), $modified); |
97 | 97 | return null; |
98 | - } catch (\Throwable $e) { |
|
98 | + }catch (\Throwable $e){ |
|
99 | 99 | return [$class->getName(), $e->getMessage(), "{$e->getFile()}:L{$e->getLine()}"]; |
100 | 100 | } |
101 | 101 | } |
@@ -32,7 +32,8 @@ discard block |
||
32 | 32 | public function perform(): void |
33 | 33 | { |
34 | 34 | $prototyped = $this->locator->getTargetClasses(); |
35 | - if ($prototyped === []) { |
|
35 | + if ($prototyped === []) |
|
36 | + { |
|
36 | 37 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
37 | 38 | |
38 | 39 | return; |
@@ -40,18 +41,23 @@ discard block |
||
40 | 41 | |
41 | 42 | $targets = []; |
42 | 43 | |
43 | - foreach ($prototyped as $class) { |
|
44 | + foreach ($prototyped as $class) |
|
45 | + { |
|
44 | 46 | $proto = $this->getPrototypeProperties($class); |
45 | - if (empty($proto)) { |
|
47 | + if (empty($proto)) |
|
48 | + { |
|
46 | 49 | $modified = $this->modify($class, $proto); |
47 | - if ($modified !== null) { |
|
50 | + if ($modified !== null) |
|
51 | + { |
|
48 | 52 | $targets[] = $modified; |
49 | 53 | } |
50 | 54 | continue; |
51 | 55 | } |
52 | 56 | |
53 | - foreach ($proto as $target) { |
|
54 | - if ($target instanceof \Throwable) { |
|
57 | + foreach ($proto as $target) |
|
58 | + { |
|
59 | + if ($target instanceof \Throwable) |
|
60 | + { |
|
55 | 61 | $targets[] = [ |
56 | 62 | $class->getName(), |
57 | 63 | $target->getMessage(), |
@@ -60,7 +66,8 @@ discard block |
||
60 | 66 | continue 2; |
61 | 67 | } |
62 | 68 | |
63 | - if ($target === null) { |
|
69 | + if ($target === null) |
|
70 | + { |
|
64 | 71 | continue 2; |
65 | 72 | } |
66 | 73 | } |
@@ -68,14 +75,17 @@ discard block |
||
68 | 75 | $targets[] = [$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]; |
69 | 76 | |
70 | 77 | $modified = $this->modify($class, $proto); |
71 | - if ($modified !== null) { |
|
78 | + if ($modified !== null) |
|
79 | + { |
|
72 | 80 | $targets[] = $modified; |
73 | 81 | } |
74 | 82 | } |
75 | 83 | |
76 | - if (!empty($targets)) { |
|
84 | + if (!empty($targets)) |
|
85 | + { |
|
77 | 86 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
78 | - foreach ($targets as $target) { |
|
87 | + foreach ($targets as $target) |
|
88 | + { |
|
79 | 89 | $grid->addRow($target); |
80 | 90 | } |
81 | 91 | |
@@ -86,7 +96,8 @@ discard block |
||
86 | 96 | private function modify(\ReflectionClass $class, array $proto): ?array |
87 | 97 | { |
88 | 98 | $classDefinition = $this->extractor->extract($class->getFilename(), $proto); |
89 | - try { |
|
99 | + try |
|
100 | + { |
|
90 | 101 | $modified = (new Injector())->injectDependencies( |
91 | 102 | file_get_contents($class->getFileName()), |
92 | 103 | $classDefinition, |
@@ -95,7 +106,9 @@ discard block |
||
95 | 106 | |
96 | 107 | file_put_contents($class->getFileName(), $modified); |
97 | 108 | return null; |
98 | - } catch (\Throwable $e) { |
|
109 | + } |
|
110 | + catch (\Throwable $e) |
|
111 | + { |
|
99 | 112 | return [$class->getName(), $e->getMessage(), "{$e->getFile()}:L{$e->getLine()}"]; |
100 | 113 | } |
101 | 114 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | $source = file_get_contents($filename); |
30 | 30 | $this->assertStringContainsString('use PrototypeTrait;', $source); |
31 | 31 | |
32 | - try { |
|
32 | + try{ |
|
33 | 33 | $this->app->bindApp(); |
34 | 34 | |
35 | 35 | $inp = new ArrayInput(['--remove' => true]); |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $this->app->get(Console::class)->run('prototype:inject', $inp, $out); |
38 | 38 | |
39 | 39 | $this->assertStringNotContainsString('use PrototypeTrait;', file_get_contents($filename)); |
40 | - } finally { |
|
40 | + }finally{ |
|
41 | 41 | file_put_contents($filename, $source); |
42 | 42 | } |
43 | 43 | } |
@@ -29,7 +29,8 @@ discard block |
||
29 | 29 | $source = file_get_contents($filename); |
30 | 30 | $this->assertStringContainsString('use PrototypeTrait;', $source); |
31 | 31 | |
32 | - try { |
|
32 | + try |
|
33 | + { |
|
33 | 34 | $this->app->bindApp(); |
34 | 35 | |
35 | 36 | $inp = new ArrayInput(['--remove' => true]); |
@@ -37,7 +38,9 @@ discard block |
||
37 | 38 | $this->app->get(Console::class)->run('prototype:inject', $inp, $out); |
38 | 39 | |
39 | 40 | $this->assertStringNotContainsString('use PrototypeTrait;', file_get_contents($filename)); |
40 | - } finally { |
|
41 | + } |
|
42 | + finally |
|
43 | + { |
|
41 | 44 | file_put_contents($filename, $source); |
42 | 45 | } |
43 | 46 | } |