Skip to content

Commit 68e213d

Browse files
committed
Fixed bug #2802 : Can't specify a report file path using the tilde shortcut
1 parent 30b5457 commit 68e213d

File tree

2 files changed

+10
-33
lines changed

2 files changed

+10
-33
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
5757
- Fixed bug #2773 : PSR2.Methods.FunctionCallSignature false positive when arrow function has array return type
5858
- Fixed bug #2791 : PSR12.Functions.NullableTypeDeclaration false positive when ternary operator used with instanceof
5959
-- Thanks to Juliette Reinders Folmer for the patch
60+
- Fixed bug #2802 : Can't specify a report file path using the tilde shortcut
6061
</notes>
6162
<contents>
6263
<dir name="/">

src/Config.php

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -972,29 +972,14 @@ public function processLongArgument($arg, $pos)
972972
if ($this->reportFile === false) {
973973
$this->reportFile = substr($arg, 12);
974974

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

982-
if ($dir === '.') {
983-
// Passed report file is a file in the current directory.
984-
$this->reportFile = getcwd().'/'.basename($this->reportFile);
985-
} else {
986-
if ($dir[0] === '/') {
987-
// An absolute path.
988-
$dir = Util\Common::realpath($dir);
989-
} else {
990-
$dir = Util\Common::realpath(getcwd().'/'.$dir);
991-
}
992-
993-
if ($dir !== false) {
994-
// Report file path is relative.
995-
$this->reportFile = $dir.'/'.basename($this->reportFile);
996-
}
997-
}
982+
$this->reportFile = $dir.'/'.basename($this->reportFile);
998983
}//end if
999984

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

1060-
if ($dir === '.') {
1061-
// Passed report file is a filename in the current directory.
1062-
$output = getcwd().'/'.basename($output);
1063-
} else {
1064-
if ($dir[0] === '/') {
1065-
// An absolute path.
1066-
$dir = Util\Common::realpath($dir);
1067-
} else {
1068-
$dir = Util\Common::realpath(getcwd().'/'.$dir);
1069-
}
1070-
1071-
if ($dir !== false) {
1072-
// Report file path is relative.
1073-
$output = $dir.'/'.basename($output);
1074-
}
1045+
$output = $dir.'/'.basename($output);
1046+
1047+
if (is_dir($output) === true) {
1048+
$error = 'ERROR: The specified '.$report.' report file path "'.$output.'" is a directory'.PHP_EOL.PHP_EOL;
1049+
$error .= $this->printShortUsage(true);
1050+
throw new DeepExitException($error, 3);
10751051
}
10761052
}//end if
10771053
}//end if

0 commit comments

Comments
 (0)