Skip to content

Commit

Permalink
FollowUp on PR #17: Fixed coding style, cached path
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Opitz committed Jan 6, 2016
1 parent 504d408 commit 3a3de79
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/Netresearch/Composer/Patches/Patch.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,24 @@ public function revert($toPath, $dryRun = FALSE) {
$this->runCommand($toPath, TRUE, $dryRun);
}

/**
* Locate the patch executable
*
* @throws Exception
*/
protected function whichPatchCmd () {
$exit_code = $output = null;
$patch_command = exec('which patch', $output, $exit_code);
if ( 0 !== $exit_code || ! is_executable ($patch_command) ) {
throw new Exception("Cannot find the 'patch' executable command - use your o/s package manager like 'sudo yum install patch'");
}
return $patch_command;
}
/**
* Locate the patch executable
*
* @throws Exception
*
* @return string
*/
protected function whichPatchCmd () {
static $patchCommand = null;
if (!$patchCommand) {
$exitCode = $output = null;
$patchCommand = exec('which patch', $output, $exitCode);
if (0 !== $exitCode || !is_executable($patchCommand)) {
throw new Exception("Cannot find the 'patch' executable command - use your o/s package manager like 'sudo yum install patch'");
}
}
return $patchCommand;
}

/**
* Run the patch command
Expand All @@ -207,11 +212,8 @@ protected function whichPatchCmd () {
* @param boolean $dryRun
* @throws PatchCommandException
*/
protected function runCommand($toPath, $revert = FALSE, $dryRun = FALSE) {

// locate path to patch.. if it exists
$command = $this->whichPatchCmd() .
' -f -p1 --no-backup-if-mismatch -r -';
protected function runCommand($toPath, $revert = FALSE, $dryRun = FALSE) {
$command = $this->whichPatchCmd() . ' -f -p1 --no-backup-if-mismatch -r -';

if ($revert) {
$command .= ' -R';
Expand Down

0 comments on commit 3a3de79

Please # to comment.