- Added a cleanup method to the migration process
This commit is contained in:
		
							parent
							
								
									564a05a1d4
								
							
						
					
					
						commit
						e3e922e3bf
					
				| @ -3,7 +3,7 @@ | |||||||
| 
 | 
 | ||||||
| array_shift($argv); | array_shift($argv); | ||||||
| 
 | 
 | ||||||
| $opt = getopt('c::f:v', [ 'folder:', 'confirm', 'verbose' ]); | $opt = getopt('c::f:v', [ 'folder:', 'confirm', 'verbose', 'clean' ]); | ||||||
| 
 | 
 | ||||||
| if ( ! $opt ) { | if ( ! $opt ) { | ||||||
|     exit("Bad arguments provided, you must specify a fullpath using the -f or --folder option\n"); |     exit("Bad arguments provided, you must specify a fullpath using the -f or --folder option\n"); | ||||||
| @ -30,16 +30,30 @@ foreach ($iterator as $info) { | |||||||
| 
 | 
 | ||||||
|     $content = file_get_contents($info->getPathname()); |     $content = file_get_contents($info->getPathname()); | ||||||
| 
 | 
 | ||||||
|  |     if ( isset($opt['clean']) ) { | ||||||
|  |         foreach (explode(PHP_EOL, $content) as $lineIdx => $line) { | ||||||
|  |             if ( $pos = strpos($line, '# migrated from: ') ) { | ||||||
|  |                 $attr = true; | ||||||
|  | 
 | ||||||
|  |                 $newContent[] = $newLine = substr($line, 0, $pos); | ||||||
|  | 
 | ||||||
|  |                 echo sprintf("Changed line '%s' \n", trim($newLine)); | ||||||
|  |             } | ||||||
|  |             else { | ||||||
|  |                 $newContent[] = $line; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|         foreach (explode(PHP_EOL, $content) as $lineIdx => $line) { |         foreach (explode(PHP_EOL, $content) as $lineIdx => $line) { | ||||||
|             $tline = trim($line); |             $tline = trim($line); | ||||||
| 
 | 
 | ||||||
|             if ($tline === "/**") { |             if ($tline === "/**") { | ||||||
|                 $opened = true; |                 $opened = true; | ||||||
|         } |             } elseif ($tline === '*/') { | ||||||
|         elseif ($tline === '*/') { |  | ||||||
|                 $opened = false; |                 $opened = false; | ||||||
|         } |             } elseif (substr($tline, 0, 1) === '*') { | ||||||
|         elseif (substr($tline, 0, 1) === '*') { |  | ||||||
|                 $annotation = trim(substr($tline, 1)); |                 $annotation = trim(substr($tline, 1)); | ||||||
| 
 | 
 | ||||||
|                 if (strpos($annotation, '@') === 0) { |                 if (strpos($annotation, '@') === 0) { | ||||||
| @ -58,31 +72,26 @@ foreach ($iterator as $info) { | |||||||
| 
 | 
 | ||||||
|                                 if (is_array($argument)) { |                                 if (is_array($argument)) { | ||||||
|                                     $argument = var_export($argument, true); |                                     $argument = var_export($argument, true); | ||||||
|                             } |                                 } elseif (is_bool($argument)) { | ||||||
|                             elseif ( is_bool($argument) ) { |  | ||||||
|                                     $argument = $argument ? 'true' : 'false'; |                                     $argument = $argument ? 'true' : 'false'; | ||||||
|                             } |                                 } elseif (!is_numeric($argument)) { | ||||||
|                             elseif (! is_numeric($argument) ) { |  | ||||||
|                                     $argument = "\"$argument\"";
 |                                     $argument = "\"$argument\"";
 | ||||||
|                                 } |                                 } | ||||||
| 
 | 
 | ||||||
|                                 if (is_numeric($key)) { |                                 if (is_numeric($key)) { | ||||||
|                                     $renderedArgs[] = $argument; |                                     $renderedArgs[] = $argument; | ||||||
|                             } |                                 } else { | ||||||
|                             else { |  | ||||||
|                                     $renderedArgs[] = "$key: $argument"; |                                     $renderedArgs[] = "$key: $argument"; | ||||||
|                                 } |                                 } | ||||||
|                             } |                             } | ||||||
| 
 | 
 | ||||||
|                             $renderedArgs = implode(', ', $renderedArgs); |                             $renderedArgs = implode(', ', $renderedArgs); | ||||||
|                     } |                         } catch (\Throwable $e) { | ||||||
|                     catch(\Throwable $e) { |  | ||||||
|                             echo sprintf("!!! WARNING : %s in file (%s) line %d ; using previous notation.\n", $e->getMessage(), $info->getPathname(), $lineIdx + 1); |                             echo sprintf("!!! WARNING : %s in file (%s) line %d ; using previous notation.\n", $e->getMessage(), $info->getPathname(), $lineIdx + 1); | ||||||
| 
 | 
 | ||||||
|                             $renderedArgs = str_replace(' => ', ': ', $args); |                             $renderedArgs = str_replace(' => ', ': ', $args); | ||||||
|                         } |                         } | ||||||
|                 } |                     } else { | ||||||
|                 else { |  | ||||||
|                         $name = substr($annotation, 1); |                         $name = substr($annotation, 1); | ||||||
|                         $renderedArgs = ""; |                         $renderedArgs = ""; | ||||||
|                     } |                     } | ||||||
| @ -91,11 +100,11 @@ foreach ($iterator as $info) { | |||||||
| 
 | 
 | ||||||
|                     $newContent[] = $attribute; |                     $newContent[] = $attribute; | ||||||
|                 } |                 } | ||||||
|         } |             } else { | ||||||
|         else { |  | ||||||
|                 $newContent[] = $line; |                 $newContent[] = $line; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     $newContent = implode(PHP_EOL, $newContent); |     $newContent = implode(PHP_EOL, $newContent); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user