Skip to content

Commit

Permalink
Fixed bug #2802 : Can't specify a report file path using the tilde sh…
Browse files Browse the repository at this point in the history
…ortcut
  • Loading branch information
gsherwood committed Jan 7, 2020
1 parent 30b5457 commit 68e213d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #2773 : PSR2.Methods.FunctionCallSignature false positive when arrow function has array return type
- Fixed bug #2791 : PSR12.Functions.NullableTypeDeclaration false positive when ternary operator used with instanceof
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #2802 : Can't specify a report file path using the tilde shortcut
</notes>
<contents>
<dir name="/">
Expand Down
42 changes: 9 additions & 33 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -972,29 +972,14 @@ public function processLongArgument($arg, $pos)
if ($this->reportFile === false) {
$this->reportFile = substr($arg, 12);

$dir = dirname($this->reportFile);
$dir = Util\Common::realpath(dirname($this->reportFile));
if (is_dir($dir) === false) {
$error = 'ERROR: The specified report file path "'.$this->reportFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
$error .= $this->printShortUsage(true);
throw new DeepExitException($error, 3);
}

if ($dir === '.') {
// Passed report file is a file in the current directory.
$this->reportFile = getcwd().'/'.basename($this->reportFile);
} else {
if ($dir[0] === '/') {
// An absolute path.
$dir = Util\Common::realpath($dir);
} else {
$dir = Util\Common::realpath(getcwd().'/'.$dir);
}

if ($dir !== false) {
// Report file path is relative.
$this->reportFile = $dir.'/'.basename($this->reportFile);
}
}
$this->reportFile = $dir.'/'.basename($this->reportFile);
}//end if

self::$overriddenDefaults['reportFile'] = true;
Expand Down Expand Up @@ -1050,28 +1035,19 @@ public function processLongArgument($arg, $pos)
if ($output === false) {
$output = null;
} else {
$dir = dirname($output);
$dir = Util\Common::realpath(dirname($output));
if (is_dir($dir) === false) {
$error = 'ERROR: The specified '.$report.' report file path "'.$output.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
$error .= $this->printShortUsage(true);
throw new DeepExitException($error, 3);
}

if ($dir === '.') {
// Passed report file is a filename in the current directory.
$output = getcwd().'/'.basename($output);
} else {
if ($dir[0] === '/') {
// An absolute path.
$dir = Util\Common::realpath($dir);
} else {
$dir = Util\Common::realpath(getcwd().'/'.$dir);
}

if ($dir !== false) {
// Report file path is relative.
$output = $dir.'/'.basename($output);
}
$output = $dir.'/'.basename($output);

if (is_dir($output) === true) {
$error = 'ERROR: The specified '.$report.' report file path "'.$output.'" is a directory'.PHP_EOL.PHP_EOL;
$error .= $this->printShortUsage(true);
throw new DeepExitException($error, 3);
}
}//end if
}//end if
Expand Down

0 comments on commit 68e213d

Please sign in to comment.