Completed
Pull Request — master (#884)
by wiese
65:43
created
cli/FundraisingCli.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace WMDE\Fundraising\Frontend\Cli;
6 6
 
@@ -25,12 +25,12 @@  discard block
 block discarded – undo
25 25
 		return $this->app;
26 26
 	}
27 27
 	private function setApplicationInfo() {
28
-		$this->app->setName( 'Fundraising Console' );
29
-		$this->app->setVersion( '2.0' );
28
+		$this->app->setName('Fundraising Console');
29
+		$this->app->setVersion('2.0');
30 30
 	}
31 31
 	private function registerCommands() {
32
-		$this->app->add( new ValidateConfigCommand() );
33
-		$this->app->add( new RenderMailTemplatesCommand() );
32
+		$this->app->add(new ValidateConfigCommand());
33
+		$this->app->add(new RenderMailTemplatesCommand());
34 34
 	}
35 35
 	public function run() {
36 36
 		$this->newApplication()->run();
Please login to merge, or discard this patch.
cli/RenderMailTemplatesCommand.php 1 patch
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace WMDE\Fundraising\Frontend\Cli;
6 6
 
@@ -26,43 +26,43 @@  discard block
 block discarded – undo
26 26
 	const NAME = 'dump-mail-tpl';
27 27
 
28 28
 	protected function configure() {
29
-		$this->setName( self::NAME )
30
-			->setDescription( 'Dump rendered Mail_* Twig templates' )
29
+		$this->setName(self::NAME)
30
+			->setDescription('Dump rendered Mail_* Twig templates')
31 31
 			->setDefinition(
32
-				new InputDefinition( [
32
+				new InputDefinition([
33 33
 					new InputOption(
34 34
 						'output-path',
35 35
 						'o',
36 36
 						InputOption::VALUE_REQUIRED,
37 37
 						'Output path for rendered text'
38 38
 					),
39
-				] )
39
+				])
40 40
 			);
41 41
 	}
42 42
 
43
-	protected function execute( InputInterface $input, OutputInterface $output ) {
43
+	protected function execute(InputInterface $input, OutputInterface $output) {
44 44
 
45 45
 		$config = $this->getDefaultConfig();
46 46
 		$config['twig']['strict-variables'] = true;
47 47
 
48
-		$ffFactory = new FunFunFactory( $config );
48
+		$ffFactory = new FunFunFactory($config);
49 49
 
50 50
 		$app = require __DIR__ . '/../app/bootstrap.php';
51 51
 
52 52
 		$app->flush();
53 53
 
54
-		$ffFactory->setTwigEnvironment( $app['twig'] );
54
+		$ffFactory->setTwigEnvironment($app['twig']);
55 55
 
56 56
 		$testData = require __DIR__ . '/../tests/Data/mail_templates.php';
57 57
 
58
-		$this->validateTemplateFixtures( $testData, $config['twig']['loaders']['filesystem']['template-dir'], $output );
58
+		$this->validateTemplateFixtures($testData, $config['twig']['loaders']['filesystem']['template-dir'], $output);
59 59
 
60
-		$outputPath = $input->getOption( 'output-path' ) ?? '';
61
-		if ( $outputPath && substr( $outputPath, -1 ) !== '/' ) {
60
+		$outputPath = $input->getOption('output-path') ?? '';
61
+		if ($outputPath && substr($outputPath, -1) !== '/') {
62 62
 			$outputPath .= '/';
63 63
 		}
64 64
 
65
-		$this->renderTemplates( $testData, $ffFactory->getTwig(), $outputPath, $output );
65
+		$this->renderTemplates($testData, $ffFactory->getTwig(), $outputPath, $output);
66 66
 	}
67 67
 
68 68
 	private function getDefaultConfig(): array {
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 		$configReader = new ConfigReader(
72 72
 			new SimpleFileFetcher(),
73 73
 			__DIR__ . '/../app/config/config.dist.json',
74
-			is_readable( $prodConfigPath ) ? $prodConfigPath : null
74
+			is_readable($prodConfigPath) ? $prodConfigPath : null
75 75
 		);
76 76
 
77 77
 		return $configReader->getConfig();
@@ -84,29 +84,29 @@  discard block
 block discarded – undo
84 84
 	 * @param array $mailTemplatePaths Directories containing templates
85 85
 	 * @param OutputInterface $output Command output
86 86
 	 */
87
-	private function validateTemplateFixtures( array $testData, array $mailTemplatePaths, OutputInterface $output ): void {
87
+	private function validateTemplateFixtures(array $testData, array $mailTemplatePaths, OutputInterface $output): void {
88 88
 		$mailTemplatesOnDisk = [];
89
-		foreach ( $mailTemplatePaths as $path ) {
90
-			$mailFilesInFolder = glob( $path . '/Mail_*' );
91
-			array_walk( $mailFilesInFolder, function( & $filename ) {
92
-				$filename = basename( $filename ); // this would cause problems w/ mail templates in sub-folders
89
+		foreach ($mailTemplatePaths as $path) {
90
+			$mailFilesInFolder = glob($path . '/Mail_*');
91
+			array_walk($mailFilesInFolder, function(& $filename) {
92
+				$filename = basename($filename); // this would cause problems w/ mail templates in sub-folders
93 93
 			} );
94
-			$mailTemplatesOnDisk = array_merge( $mailTemplatesOnDisk, $mailFilesInFolder );
94
+			$mailTemplatesOnDisk = array_merge($mailTemplatesOnDisk, $mailFilesInFolder);
95 95
 		}
96 96
 
97
-		$testTemplateNames = array_keys( $testData );
97
+		$testTemplateNames = array_keys($testData);
98 98
 
99
-		$untestedTemplates = array_diff( $mailTemplatesOnDisk, $testTemplateNames );
100
-		if ( count( $untestedTemplates ) ) {
99
+		$untestedTemplates = array_diff($mailTemplatesOnDisk, $testTemplateNames);
100
+		if (count($untestedTemplates)) {
101 101
 			$output->writeln(
102
-				'<error>There are untested templates: ' . implode( ', ', $untestedTemplates ) . '</error>'
102
+				'<error>There are untested templates: ' . implode(', ', $untestedTemplates) . '</error>'
103 103
 			);
104 104
 		}
105 105
 
106
-		$strayTemplates = array_diff( $testTemplateNames, $mailTemplatesOnDisk );
107
-		if ( count( $strayTemplates ) ) {
106
+		$strayTemplates = array_diff($testTemplateNames, $mailTemplatesOnDisk);
107
+		if (count($strayTemplates)) {
108 108
 			$output->writeln(
109
-				'<error>There are tests for non-existing templates: ' . implode( ', ', $strayTemplates ) . '</error>'
109
+				'<error>There are tests for non-existing templates: ' . implode(', ', $strayTemplates) . '</error>'
110 110
 			);
111 111
 		}
112 112
 	}
@@ -119,37 +119,37 @@  discard block
 block discarded – undo
119 119
 	 * @param string $outputPath Path where rendered templates will be written to
120 120
 	 * @param OutputInterface $output Command output
121 121
 	 */
122
-	private function renderTemplates( array $testData, Twig_Environment $twig, string $outputPath, OutputInterface $output ): void {
123
-		foreach( $testData as $template => $templateSettings ) {
122
+	private function renderTemplates(array $testData, Twig_Environment $twig, string $outputPath, OutputInterface $output): void {
123
+		foreach ($testData as $template => $templateSettings) {
124 124
 
125
-			if ( empty( $templateSettings['variants'] ) ) {
126
-				$templateSettings['variants'] = [ '' => [] ];
125
+			if (empty($templateSettings['variants'])) {
126
+				$templateSettings['variants'] = ['' => []];
127 127
 			}
128 128
 
129
-			foreach( $templateSettings['variants'] as $variantName => $additionalContext ) {
129
+			foreach ($templateSettings['variants'] as $variantName => $additionalContext) {
130 130
 				$outputName =
131 131
 					$outputPath .
132
-					basename( $template, '.txt.twig' ) .
133
-					( $variantName ? ".$variantName" : '' ) .
132
+					basename($template, '.txt.twig') .
133
+					($variantName ? ".$variantName" : '') .
134 134
 					'.txt';
135 135
 
136
-				$output->write( "$outputName" );
137
-				if ( file_exists( $outputName ) ) {
138
-					$output->writeln( "$outputName already exists, skipping ..." );
136
+				$output->write("$outputName");
137
+				if (file_exists($outputName)) {
138
+					$output->writeln("$outputName already exists, skipping ...");
139 139
 					continue;
140 140
 				}
141 141
 
142 142
 				try {
143
-					file_put_contents( $outputName, $twig->render( $template, array_merge_recursive(
143
+					file_put_contents($outputName, $twig->render($template, array_merge_recursive(
144 144
 						$templateSettings['context'],
145 145
 						$templateSettings['variants'][$variantName]
146
-					) ) );
147
-				} catch( Twig_Error $e ) {
148
-					$output->writeln( '' );
149
-					$output->writeln( '<error>' . $e->getMessage() . '</error>' );
150
-					$output->writeln( var_export( $e->getSourceContext(), true ) );
146
+					)));
147
+				} catch (Twig_Error $e) {
148
+					$output->writeln('');
149
+					$output->writeln('<error>' . $e->getMessage() . '</error>');
150
+					$output->writeln(var_export($e->getSourceContext(), true));
151 151
 				}
152
-				$output->writeln( '' );
152
+				$output->writeln('');
153 153
 			}
154 154
 		}
155 155
 	}
Please login to merge, or discard this patch.
tests/Data/mail_templates.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types = 1);
4 4
 
5 5
 /**
6 6
  * This file contains a list of all Mail templates and the variables rendered in them.
Please login to merge, or discard this patch.