Skip to content

Commit 8fa09cd

Browse files
committed
ext/phar: Use RETURN_BOOL() when possible
1 parent d7eef8c commit 8fa09cd

File tree

1 file changed

+12
-32
lines changed

1 file changed

+12
-32
lines changed

ext/phar/phar_object.c

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,23 +1030,11 @@ PHP_METHOD(Phar, canCompress)
10301030
phar_request_initialize();
10311031
switch (method) {
10321032
case PHAR_ENT_COMPRESSED_GZ:
1033-
if (PHAR_G(has_zlib)) {
1034-
RETURN_TRUE;
1035-
} else {
1036-
RETURN_FALSE;
1037-
}
1033+
RETURN_BOOL(PHAR_G(has_zlib));
10381034
case PHAR_ENT_COMPRESSED_BZ2:
1039-
if (PHAR_G(has_bz2)) {
1040-
RETURN_TRUE;
1041-
} else {
1042-
RETURN_FALSE;
1043-
}
1035+
RETURN_BOOL(PHAR_G(has_bz2));
10441036
default:
1045-
if (PHAR_G(has_zlib) || PHAR_G(has_bz2)) {
1046-
RETURN_TRUE;
1047-
} else {
1048-
RETURN_FALSE;
1049-
}
1037+
RETURN_BOOL(PHAR_G(has_zlib) || PHAR_G(has_bz2));
10501038
}
10511039
}
10521040
/* }}} */
@@ -2577,11 +2565,8 @@ PHP_METHOD(Phar, isWritable)
25772565
}
25782566

25792567
if (SUCCESS != php_stream_stat_path(phar_obj->archive->fname, &ssb)) {
2580-
if (phar_obj->archive->is_brandnew) {
2581-
/* assume it works if the file doesn't exist yet */
2582-
RETURN_TRUE;
2583-
}
2584-
RETURN_FALSE;
2568+
/* assume it works if the file doesn't exist yet */
2569+
RETURN_BOOL(phar_obj->archive->is_brandnew);
25852570
}
25862571

25872572
RETURN_BOOL((ssb.sb.st_mode & (S_IWOTH | S_IWGRP | S_IWUSR)) != 0);
@@ -3503,27 +3488,22 @@ PHP_METHOD(Phar, copy)
35033488
PHP_METHOD(Phar, offsetExists)
35043489
{
35053490
zend_string *file_name;
3506-
phar_entry_info *entry;
35073491

35083492
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P", &file_name) == FAILURE) {
35093493
RETURN_THROWS();
35103494
}
35113495

35123496
PHAR_ARCHIVE_OBJECT();
35133497

3514-
if (zend_hash_exists(&phar_obj->archive->manifest, file_name)) {
3515-
if (NULL != (entry = zend_hash_find_ptr(&phar_obj->archive->manifest, file_name))) {
3516-
if (entry->is_deleted) {
3517-
/* entry is deleted, but has not been flushed to disk yet */
3518-
RETURN_FALSE;
3519-
}
3520-
}
3521-
3522-
if (zend_string_starts_with_literal(file_name, ".phar")) {
3523-
/* none of these are real files, so they don't exist */
3498+
const phar_entry_info *entry = zend_hash_find_ptr(&phar_obj->archive->manifest, file_name);
3499+
if (entry != NULL) {
3500+
if (entry->is_deleted) {
3501+
/* entry is deleted, but has not been flushed to disk yet */
35243502
RETURN_FALSE;
35253503
}
3526-
RETURN_TRUE;
3504+
3505+
/* none of these are real files, so they don't exist */
3506+
RETURN_BOOL(!zend_string_starts_with_literal(file_name, ".phar"));
35273507
} else {
35283508
/* If the info class is not based on PharFileInfo, directories are not directly instantiable */
35293509
if (UNEXPECTED(!instanceof_function(phar_obj->spl.info_class, phar_ce_entry))) {

0 commit comments

Comments
 (0)