Completed
Push — master ( addd79...f4b87d )
by Aimeos
13:42
created
Composer/ScriptHandler.php 1 patch
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -28,18 +28,18 @@  discard block
 block discarded – undo
28 28
 	 * @param CommandEvent $event CommandEvent instance
29 29
 	 * @throws \RuntimeException If an error occured
30 30
 	 */
31
-	public static function setupDatabase( CommandEvent $event )
31
+	public static function setupDatabase(CommandEvent $event)
32 32
 	{
33 33
 		$options = $env = array();
34 34
 
35
-		if( $event->isDevMode() ) {
35
+		if ($event->isDevMode()) {
36 36
 			$options[] = '--option=setup/default/demo:1';
37 37
 		} else {
38 38
 			$env[] = '--env=prod';
39 39
 		}
40 40
 
41
-		self::executeCommand( $event, 'aimeos:setup', $options + $env );
42
-		self::executeCommand( $event, 'aimeos:cache', $env );
41
+		self::executeCommand($event, 'aimeos:setup', $options + $env);
42
+		self::executeCommand($event, 'aimeos:cache', $env);
43 43
 	}
44 44
 
45 45
 
@@ -49,30 +49,30 @@  discard block
 block discarded – undo
49 49
 	 * @param CommandEvent $event CommandEvent instance
50 50
 	 * @throws \RuntimeException If an error occured
51 51
 	 */
52
-	public static function installBundle( CommandEvent $event )
52
+	public static function installBundle(CommandEvent $event)
53 53
 	{
54
-		$event->getIO()->write( 'Installing the Aimeos shop bundle' );
54
+		$event->getIO()->write('Installing the Aimeos shop bundle');
55 55
 
56
-		$options = self::getOptions( $event );
56
+		$options = self::getOptions($event);
57 57
 
58
-		if( !isset( $options['symfony-app-dir'] ) || !is_dir( $options['symfony-app-dir'] ) )
58
+		if (!isset($options['symfony-app-dir']) || !is_dir($options['symfony-app-dir']))
59 59
 		{
60 60
 			$msg = 'An error occurred because the "%1$s" option or the "%2$s" directory isn\'t available';
61
-			throw new \RuntimeException( sprintf( $msg, 'symfony-app-dir', $options['symfony-app-dir'] ) );
61
+			throw new \RuntimeException(sprintf($msg, 'symfony-app-dir', $options['symfony-app-dir']));
62 62
 		}
63 63
 
64
-		if( !isset( $options['symfony-web-dir'] ) || !is_dir( $options['symfony-web-dir'] ) )
64
+		if (!isset($options['symfony-web-dir']) || !is_dir($options['symfony-web-dir']))
65 65
 		{
66 66
 			$msg = 'An error occurred because the "%1$s" option or the "%2$s" directory isn\'t available';
67
-			throw new \RuntimeException( sprintf( $msg, 'symfony-web-dir', $options['symfony-web-dir'] ) );
67
+			throw new \RuntimeException(sprintf($msg, 'symfony-web-dir', $options['symfony-web-dir']));
68 68
 		}
69 69
 
70
-		self::updateConfigFile( $options['symfony-app-dir'] . '/config/config.yml' );
71
-		self::updateRoutingFile( $options['symfony-app-dir'] . '/config/routing.yml' );
72
-		self::createDirectory( $options['symfony-app-dir'] . '/secure' );
73
-		self::createDirectory( $options['symfony-web-dir'] . '/uploads' );
74
-		self::createDirectory( $options['symfony-web-dir'] . '/preview' );
75
-		self::createDirectory( $options['symfony-web-dir'] . '/files' );
70
+		self::updateConfigFile($options['symfony-app-dir'] . '/config/config.yml');
71
+		self::updateRoutingFile($options['symfony-app-dir'] . '/config/routing.yml');
72
+		self::createDirectory($options['symfony-app-dir'] . '/secure');
73
+		self::createDirectory($options['symfony-web-dir'] . '/uploads');
74
+		self::createDirectory($options['symfony-web-dir'] . '/preview');
75
+		self::createDirectory($options['symfony-web-dir'] . '/files');
76 76
 	}
77 77
 
78 78
 
@@ -82,14 +82,14 @@  discard block
 block discarded – undo
82 82
 	 * @param string $dir Absolute path of the new directory
83 83
 	 * @throws \RuntimeException If directory couldn't be created
84 84
 	 */
85
-	protected static function createDirectory( $dir )
85
+	protected static function createDirectory($dir)
86 86
 	{
87 87
 		$perm = 0755;
88 88
 
89
-		if( !is_dir( $dir ) && !mkdir( $dir, $perm, true ) )
89
+		if (!is_dir($dir) && !mkdir($dir, $perm, true))
90 90
 		{
91 91
 			$msg = 'Unable to create directory "%1$s" with permission "%2$s"';
92
-			throw new \RuntimeException( sprintf( $msg, $dir, $perm ) );
92
+			throw new \RuntimeException(sprintf($msg, $dir, $perm));
93 93
 		}
94 94
 	}
95 95
 
@@ -102,28 +102,28 @@  discard block
 block discarded – undo
102 102
 	 * @param array List of configuration options for the given command
103 103
 	 * @throws \RuntimeException If the command couldn't be executed
104 104
 	 */
105
-	protected static function executeCommand( CommandEvent $event, $cmd, array $options = array() )
105
+	protected static function executeCommand(CommandEvent $event, $cmd, array $options = array())
106 106
 	{
107
-		$php = escapeshellarg( self::getPhp() );
108
-		$console = escapeshellarg( self::getConsoleDir( $event ) . '/console' );
109
-		$cmd = escapeshellarg( $cmd );
107
+		$php = escapeshellarg(self::getPhp());
108
+		$console = escapeshellarg(self::getConsoleDir($event) . '/console');
109
+		$cmd = escapeshellarg($cmd);
110 110
 
111
-		foreach( $options as $key => $option ) {
112
-			$options[$key] = escapeshellarg( $option );
111
+		foreach ($options as $key => $option) {
112
+			$options[$key] = escapeshellarg($option);
113 113
 		}
114 114
 
115
-		if( $event->getIO()->isDecorated() ) {
115
+		if ($event->getIO()->isDecorated()) {
116 116
 			$console .= ' --ansi';
117 117
 		}
118 118
 
119
-		$process = new Process( $php . ' ' . $console . ' ' . $cmd . ' ' . implode( ' ', $options ), null, null, null, 3600 );
119
+		$process = new Process($php . ' ' . $console . ' ' . $cmd . ' ' . implode(' ', $options), null, null, null, 3600);
120 120
 
121
-		$process->run( function( $type, $buffer ) use ( $event ) {
122
-			$event->getIO()->write( $buffer, false );
121
+		$process->run(function($type, $buffer) use ($event) {
122
+			$event->getIO()->write($buffer, false);
123 123
 		} );
124 124
 
125
-		if( !$process->isSuccessful() ) {
126
-			throw new \RuntimeException( sprintf( 'An error occurred when executing the "%s" command', escapeshellarg( $cmd ) ) );
125
+		if (!$process->isSuccessful()) {
126
+			throw new \RuntimeException(sprintf('An error occurred when executing the "%s" command', escapeshellarg($cmd)));
127 127
 		}
128 128
 	}
129 129
 
@@ -136,19 +136,19 @@  discard block
 block discarded – undo
136 136
 	 * @return string The path to the console directory
137 137
 	 * @throws \RuntimeException If console directory couldn't be found
138 138
 	 */
139
-	protected static function getConsoleDir( CommandEvent $event )
139
+	protected static function getConsoleDir(CommandEvent $event)
140 140
 	{
141
-		$options = self::getOptions( $event );
141
+		$options = self::getOptions($event);
142 142
 
143
-		if( isset( $options['symfony-bin-dir'] ) && is_dir( $options['symfony-bin-dir'] ) ) {
143
+		if (isset($options['symfony-bin-dir']) && is_dir($options['symfony-bin-dir'])) {
144 144
 			return $options['symfony-bin-dir'];
145 145
 		}
146 146
 
147
-		if( isset( $options['symfony-app-dir'] ) && is_dir( $options['symfony-app-dir'] ) ) {
147
+		if (isset($options['symfony-app-dir']) && is_dir($options['symfony-app-dir'])) {
148 148
 			return $options['symfony-app-dir'];
149 149
 		}
150 150
 
151
-		throw new \RuntimeException( sprintf( 'Console directory not found. Neither %1$s nor %2$s option exist', 'symfony-app-dir', 'symfony-bin-dir' ) );
151
+		throw new \RuntimeException(sprintf('Console directory not found. Neither %1$s nor %2$s option exist', 'symfony-app-dir', 'symfony-bin-dir'));
152 152
 	}
153 153
 
154 154
 
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	 * @param CommandEvent $event Command event object
159 159
 	 * @return array Associative list of option keys and values
160 160
 	 */
161
-	protected static function getOptions( CommandEvent $event )
161
+	protected static function getOptions(CommandEvent $event)
162 162
 	{
163 163
 		return $event->getComposer()->getPackage()->getExtra();
164 164
 	}
@@ -174,8 +174,8 @@  discard block
 block discarded – undo
174 174
 	{
175 175
 		$phpFinder = new PhpExecutableFinder;
176 176
 
177
-		if( !( $phpPath = $phpFinder->find() ) ) {
178
-			throw new \RuntimeException( 'The php executable could not be found, add it to your PATH environment variable and try again' );
177
+		if (!($phpPath = $phpFinder->find())) {
178
+			throw new \RuntimeException('The php executable could not be found, add it to your PATH environment variable and try again');
179 179
 		}
180 180
 
181 181
 		return $phpPath;
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
 	 * @param string $filename Name of the YAML config file
189 189
 	 * @throws \RuntimeException If file is not found
190 190
 	 */
191
-	protected static function updateConfigFile( $filename )
191
+	protected static function updateConfigFile($filename)
192 192
 	{
193
-		if( ( $content = file_get_contents( $filename ) ) === false ) {
194
-			throw new \RuntimeException( sprintf( 'File "%1$s" not found', $filename ) );
193
+		if (($content = file_get_contents($filename)) === false) {
194
+			throw new \RuntimeException(sprintf('File "%1$s" not found', $filename));
195 195
 		}
196 196
 
197
-		if( self::addAsseticBundle( $content ) === true ) {
197
+		if (self::addAsseticBundle($content) === true) {
198 198
 			$fs = new Filesystem();
199
-			$fs->dumpFile( $filename, $content );
199
+			$fs->dumpFile($filename, $content);
200 200
 		}
201 201
 	}
202 202
 
@@ -207,15 +207,15 @@  discard block
 block discarded – undo
207 207
 	 * @param string $filename Name of the YAML config file
208 208
 	 * @throws \RuntimeException If file is not found
209 209
 	 */
210
-	protected static function updateRoutingFile( $filename )
210
+	protected static function updateRoutingFile($filename)
211 211
 	{
212 212
 		$update = false;
213 213
 
214
-		if( ( $content = file_get_contents( $filename ) ) === false ) {
215
-			throw new \RuntimeException( sprintf( 'File "%1$s" not found', $filename ) );
214
+		if (($content = file_get_contents($filename)) === false) {
215
+			throw new \RuntimeException(sprintf('File "%1$s" not found', $filename));
216 216
 		}
217 217
 
218
-		if( strpos( $content, 'aimeos_shop:' ) === false )
218
+		if (strpos($content, 'aimeos_shop:') === false)
219 219
 		{
220 220
 			$content .= "\n" . 'aimeos_shop:
221 221
     resource: "@AimeosShopBundle/Resources/config/routing.yml"
@@ -224,10 +224,10 @@  discard block
 block discarded – undo
224 224
 			$update = true;
225 225
 		}
226 226
 
227
-		if( $update === true )
227
+		if ($update === true)
228 228
 		{
229 229
 			$fs = new Filesystem();
230
-			$fs->dumpFile( $filename, $content );
230
+			$fs->dumpFile($filename, $content);
231 231
 		}
232 232
 	}
233 233
 
@@ -238,14 +238,14 @@  discard block
 block discarded – undo
238 238
 	 * @param string &$content Content of the config.yml file
239 239
 	 * @return boolean True if modified, false if not
240 240
 	 */
241
-	protected static function addAsseticBundle( &$content )
241
+	protected static function addAsseticBundle(&$content)
242 242
 	{
243
-		if( preg_match( "/    bundles:[ ]*\[.*'AimeosShopBundle'.*\]/", $content ) !== 1 )
243
+		if (preg_match("/    bundles:[ ]*\[.*'AimeosShopBundle'.*\]/", $content) !== 1)
244 244
 		{
245
-			$search = array( "/    bundles:[ ]*\[([^\]]+)\]/", "/    bundles:[ ]*\[([ ]*)\]/" );
246
-			$replace = array( "    bundles: [$1,'AimeosShopBundle']", "    bundles: ['AimeosShopBundle']" );
245
+			$search = array("/    bundles:[ ]*\[([^\]]+)\]/", "/    bundles:[ ]*\[([ ]*)\]/");
246
+			$replace = array("    bundles: [$1,'AimeosShopBundle']", "    bundles: ['AimeosShopBundle']");
247 247
 
248
-			if( ( $content = preg_replace( $search, $replace, $content ) ) !== null ) {
248
+			if (($content = preg_replace($search, $replace, $content)) !== null) {
249 249
 				return true;
250 250
 			}
251 251
 		}
Please login to merge, or discard this patch.