Skip to content

Commit

Permalink
Rename the --remove-existing option to --replace-existing
Browse files Browse the repository at this point in the history
  • Loading branch information
unfunco committed Jan 16, 2016
1 parent f8c2bfa commit 4328fb2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ values are used:

## Replacing an existing license ##

You can tell the Licenser to replace an existing license header with a new one by just using the `--remove-existing` option
You can tell the Licenser to replace an existing license header with a new one by using the `--replace-existing` option
when running the command. This will tell Licenser to remove any existing licenses and replace them with the new one generated.

### Caution ###
Expand Down
6 changes: 3 additions & 3 deletions src/JamesHalsall/Licenser/Command/LicenserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ protected function configure()
'separated list of email addresses or a single email address'
)
->addOption(
'remove-existing',
'replace-existing',
'r',
InputOption::VALUE_NONE,
'Remove existing license headers'
'Replace existing license headers'
)
->addOption(
'dry-run',
Expand Down Expand Up @@ -117,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->licenser->process(
$sources,
(bool) $input->getOption('remove-existing'),
(bool) $input->getOption('replace-existing'),
(bool) $input->getOption('dry-run')
);
}
Expand Down
23 changes: 11 additions & 12 deletions src/JamesHalsall/Licenser/Licenser.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,29 +87,28 @@ public function getLicenseHeader()
/**
* Processes a path and adds licenses
*
* @param string $path The path to the files/directory
* @param bool $removeExisting True to remove existing license headers in files before adding
* new license (defaults to false)
* @param bool $dryRun True to report modified files and to not make any modifications
* @param string $path The path to the files/directory
* @param bool $replaceExisting True to replace existing license headers
* @param bool $dryRun True to report modified files and to not make any modifications
*/
public function process($path, $removeExisting = false, $dryRun = false)
public function process($path, $replaceExisting = false, $dryRun = false)
{
$iterator = $this->finder->name('*.php')
->in(realpath($path));

foreach ($iterator as $file) {
$this->processFile($file, $removeExisting, $dryRun);
$this->processFile($file, $replaceExisting, $dryRun);
}
}

/**
* Processes a single file
*
* @param SplFileInfo $file The path to the file
* @param bool $removeExisting True to remove existing license header before adding new one
* @param bool $dryRun True to report a modified file and to not make modifications
* @param SplFileInfo $file The path to the file
* @param bool $replaceExisting True to replace existing license header
* @param bool $dryRun True to report a modified file and to not make modifications
*/
private function processFile(SplFileInfo $file, $removeExisting, $dryRun)
private function processFile(SplFileInfo $file, $replaceExisting, $dryRun)
{
if ($file->isDir()) {
return;
Expand All @@ -129,11 +128,11 @@ private function processFile(SplFileInfo $file, $removeExisting, $dryRun)
}
}

if (null !== $licenseTokenIndex && true === $removeExisting) {
if (null !== $licenseTokenIndex && true === $replaceExisting) {
$this->removeExistingLicense($file, $tokens, $licenseTokenIndex, $dryRun);
}

if (null === $licenseTokenIndex || true === $removeExisting) {
if (null === $licenseTokenIndex || true === $replaceExisting) {
$this->log(sprintf('<fg=green>[+]</> Adding license header for <options=bold>%s</>', $file->getRealPath()));

if (true === $dryRun) {
Expand Down

0 comments on commit 4328fb2

Please sign in to comment.