Skip to content

Commit 24b8900

Browse files
committed
ext/phar: reclassify various exception
Main purpose is to use ValueError/TypeError in cases that are about value/type validation. This fixes the wording to match the more usual wording. Secondly use Error when an object is not initialized or one attemps to call the constructor twice, similar to other extensions
1 parent ce3a240 commit 24b8900

File tree

81 files changed

+476
-477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+476
-477
lines changed

ext/phar/phar_object.c

Lines changed: 68 additions & 75 deletions
Large diffs are not rendered by default.

ext/phar/phar_object.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function delete(string $localName): true {}
123123
public function delMetadata(): true {}
124124

125125
/** @tentative-return-type */
126-
public function extractTo(string $directory, array|string|null $files = null, bool $overwrite = false): bool {}
126+
public function extractTo(string $directory, array|string|null $files = null, bool $overwrite = false): true {}
127127

128128
/** @tentative-return-type */
129129
public function getAlias(): ?string {}
@@ -345,7 +345,7 @@ public function delMetadata(): true {}
345345
* @tentative-return-type
346346
* @implementation-alias Phar::extractTo
347347
*/
348-
public function extractTo(string $directory, array|string|null $files = null, bool $overwrite = false): bool {}
348+
public function extractTo(string $directory, array|string|null $files = null, bool $overwrite = false): true {}
349349

350350
/**
351351
* @tentative-return-type

ext/phar/phar_object_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/phar/tests/030.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ require $pname . '/a.php';
2727
$p = new Phar($fname);
2828
var_dump(isset($p['.phar/test']));
2929
try {
30-
$p['.phar/test'];
31-
} catch (Exception $e) {
32-
echo $e->getMessage(),"\n";
30+
$p['.phar/test'];
31+
} catch (Throwable $e) {
32+
echo $e::class, ': ', $e->getMessage() . "\n";
3333
}
3434
?>
3535
--CLEAN--
@@ -43,4 +43,4 @@ This is b/c
4343
This is b/d
4444
This is e
4545
bool(false)
46-
Cannot directly get any files or directories in magic ".phar" directory
46+
ValueError: Phar::offsetGet(): Argument #1 ($localName) must not start with ".phar"

ext/phar/tests/bug54289.phpt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ var_dump(is_dir($outDir.DIRECTORY_SEPARATOR.'dirAB'));
2626
try {
2727
$pharB->extractTo($outDir, 'dirX/', true);
2828
echo 'failed to throw expected exception';
29-
} catch (PharException $ex) {
29+
} catch (Throwable $e) {
30+
echo $e::class, ': ', $e->getMessage() . "\n";
3031
}
3132

3233
// should also not be able to pull out /, because paths are not "rooted" that way
3334
try {
3435
$pharB->extractTo($outDir, '/', true);
3536
echo 'failed to throw expected exception';
36-
} catch (PharException $ex) {
37+
} catch (Throwable $e) {
38+
echo $e::class, ': ', $e->getMessage() . "\n";
3739
}
3840

3941
// should be able to do by array, too
@@ -45,7 +47,8 @@ try {
4547
$pharB = new Phar($phar);
4648
$pharB->extractTo($outDir, [ 'dirA/', 'dirX/' ], true);
4749
echo 'failed to throw expected exception';
48-
} catch (PharException $ex) {
50+
} catch (Throwable $e) {
51+
echo $e::class, ': ', $e->getMessage() . "\n";
4952
}
5053

5154
echo 'done';
@@ -63,8 +66,11 @@ foreach ($iter as $value) {
6366
$value->isFile() ? unlink($value) : rmdir($value);
6467
}
6568
?>
66-
--EXPECT--
69+
--EXPECTF--
6770
bool(true)
6871
bool(true)
6972
bool(false)
73+
PharException: phar error: attempted to extract non-existent file or directory "dirX/" from phar "%sbug54289/test.phar"
74+
PharException: phar error: attempted to extract non-existent file or directory "/" from phar "%sbug54289/test.phar"
75+
PharException: phar error: attempted to extract non-existent file or directory "dirX/" from phar "%sbug54289/test.phar"
7076
done

ext/phar/tests/buildFromIterator_user_overrides/getPathname_exception.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ $workdir = __DIR__.'/getPathname_exception';
5959
[ Found: %shello.txt ]
6060
[getPathname]
6161
string(%d) "%shello.txt"
62-
getPathname() must return a string
62+
MyGlobIterator::getPathname(): Return value must be of type string, null returned
6363
Previous: exception in getPathname()

ext/phar/tests/buildFromIterator_user_overrides/getPathname_wrong_type.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ $workdir = __DIR__.'/getPathname_wrong_type';
5555
--EXPECTF--
5656
[ Found: %scontent%chello.txt ]
5757
[getPathname]
58-
getPathname() must return a string
58+
MyGlobIterator::getPathname(): Return value must be of type string, int returned

ext/phar/tests/cache_list/frontcontroller12.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ files/frontcontroller6.phar
1414
--EXPECTHEADERS--
1515
Content-type: text/html; charset=UTF-8
1616
--EXPECTF--
17-
Fatal error: Uncaught PharException: Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller12.php:2
17+
Fatal error: Uncaught ValueError: Phar::webPhar(): Argument #4 ($mimeTypes) mime type specifier must be one of Phar::PHP or Phar::PHPS in %sfrontcontroller12.php:2
1818
Stack trace:
1919
#0 %sfrontcontroller12.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array)
2020
#1 {main}

ext/phar/tests/cache_list/frontcontroller13.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ files/frontcontroller7.phar
1414
--EXPECTHEADERS--
1515
Content-type: text/html; charset=UTF-8
1616
--EXPECTF--
17-
Fatal error: Uncaught PharException: Unknown mime type specifier used (not a string or int), only Phar::PHP, Phar::PHPS and a mime type string are allowed in %sfrontcontroller13.php:2
17+
Fatal error: Uncaught TypeError: Phar::webPhar(): Argument #4 ($mimeTypes) mime type specifier must be of type string|int, null given in %sfrontcontroller13.php:2
1818
Stack trace:
1919
#0 %sfrontcontroller13.php(2): Phar::webPhar('whatever', 'index.php', NULL, Array)
2020
#1 {main}

ext/phar/tests/cache_list/frontcontroller18.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PATH_INFO=/fronk.gronk
1111
--FILE_EXTERNAL--
1212
files/frontcontroller9.phar
1313
--EXPECTF--
14-
Fatal error: Uncaught PharException: No values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME in %sfrontcontroller18.php:2
14+
Fatal error: Uncaught ValueError: Phar::mungServer(): Argument #1 ($variables) must not be empty in %sfrontcontroller18.php:2
1515
Stack trace:
1616
#0 %sfrontcontroller18.php(2): Phar::mungServer(Array)
1717
#1 {main}

0 commit comments

Comments
 (0)