Skip to content

Commit 43ba7b8

Browse files
authored
Phan: Handle PhanPluginDuplicateIfCondition violations (#45733)
1 parent 3136814 commit 43ba7b8

File tree

6 files changed

+38
-37
lines changed

6 files changed

+38
-37
lines changed

projects/plugins/crm/.phan/baseline.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
// PhanNoopVariable : 1 occurrence
9797
// PhanPluginDuplicateArrayKey : 1 occurrence
9898
// PhanPluginDuplicateCatchStatementBody : 1 occurrence
99-
// PhanPluginDuplicateIfCondition : 1 occurrence
10099
// PhanPluginUseReturnValueInternalKnown : 1 occurrence
101100
// PhanRedefineFunctionInternal : 1 occurrence
102101
// PhanSuspiciousWeakTypeComparisonInLoop : 1 occurrence
@@ -186,7 +185,7 @@
186185
'includes/ZeroBSCRM.DataIOValidation.php' => ['PhanTypeMismatchArgument'],
187186
'includes/ZeroBSCRM.Database.php' => ['PhanRedundantCondition', 'PhanSuspiciousValueComparison'],
188187
'includes/ZeroBSCRM.Delete.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal'],
189-
'includes/ZeroBSCRM.Edit.php' => ['PhanPluginDuplicateIfCondition', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal'],
188+
'includes/ZeroBSCRM.Edit.php' => ['PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal'],
190189
'includes/ZeroBSCRM.Encryption.php' => ['PhanUndeclaredConstant'],
191190
'includes/ZeroBSCRM.ExternalSources.php' => ['PhanPluginMixedKeyNoKey', 'PhanPluginUnreachableCode'],
192191
'includes/ZeroBSCRM.FileUploads.php' => ['PhanTypeComparisonFromArray', 'PhanTypeMismatchDimFetch'],
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Invoices: Ensure object owner is properly set.

projects/plugins/crm/includes/ZeroBSCRM.Edit.php

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -153,45 +153,43 @@ public function catchPost(){
153153
// check ownership, access etc.
154154
public function preChecks(){
155155

156-
global $zbs;
156+
global $zbs;
157157

158-
$is_malformed_obj = false;
158+
$is_malformed_obj = false;
159159

160-
if (is_array($this->obj) && isset($this->obj['owner'])){
161-
$obj_owner = (int) $this->obj['owner'];
160+
if ( is_array( $this->obj ) && isset( $this->obj['owner'] ) ) {
161+
$obj_owner = (int) $this->obj['owner'];
162162

163163
// Transactions can have a contact or company assigned, and quotes just a contact. This covers checking owners for both.
164164
if ( isset( $this->obj['contact'][0]['owner'] ) ) {
165165
$obj_owner = (int) $this->obj['contact'][0]['owner'];
166166

167167
} elseif ( isset( $this->obj['company'][0]['owner'] ) ) {
168-
$obj_owner = (int) $this->obj['company'][0]['owner'];
169-
// phpcs:disable Generic.WhiteSpace.ScopeIndent.IncorrectExact,Generic.WhiteSpace.ScopeIndent.Incorrect -- this sniff is incorrectly reporting spacing issues.
170-
}
171-
172-
// This covers checking owners for assigned contacts or companies in invoices.
173-
if ( $this->objTypeID === ZBS_TYPE_INVOICE ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
174-
$data = zeroBSCRM_invoicing_getInvoiceData( $this->objID ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
175-
if ( ! empty( $data['invoiceObj']['contact'] ) ) {
176-
$obj_owner = (int) $data['invoiceObj']['contact'][0]['owner'];
177-
} elseif ( ! empty( $data['invoiceObj']['contact'] ) ) {
178-
$obj_owner = (int) $data['invoiceObj']['company'][0]['owner'];
179-
}
168+
$obj_owner = (int) $this->obj['company'][0]['owner'];
169+
}
170+
171+
// This covers checking owners for assigned contacts or companies in invoices.
172+
if ( $this->objTypeID === ZBS_TYPE_INVOICE ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
173+
$data = zeroBSCRM_invoicing_getInvoiceData( $this->objID ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
174+
if ( ! empty( $data['invoiceObj']['contact'] ) ) {
175+
$obj_owner = (int) $data['invoiceObj']['contact'][0]['owner'];
176+
} elseif ( ! empty( $data['invoiceObj']['company'] ) ) {
177+
$obj_owner = (int) $data['invoiceObj']['company'][0]['owner'];
180178
}
181-
} else {
182-
// phpcs:enable Generic.WhiteSpace.ScopeIndent.IncorrectExact,Generic.WhiteSpace.ScopeIndent.Incorrect
183-
// if $this->obj is not an array, somehow it's not been loaded properly (probably perms)
184-
// get owner info anyway
185-
$is_malformed_obj = true;
186-
$obj_owner = $zbs->DAL->getObjectOwner( // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
187-
array(
188-
'objID' => $this->objID, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
189-
'objTypeID' => $this->objTypeID, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
190-
)
191-
);
192-
}
193-
// get current user
194-
$current_user_id = get_current_user_id();
179+
}
180+
} else {
181+
// if $this->obj is not an array, somehow it's not been loaded properly (probably perms)
182+
// get owner info anyway
183+
$is_malformed_obj = true;
184+
$obj_owner = $zbs->DAL->getObjectOwner( // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
185+
array(
186+
'objID' => $this->objID, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
187+
'objTypeID' => $this->objTypeID, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
188+
)
189+
);
190+
}
191+
// get current user
192+
$current_user_id = get_current_user_id();
195193

196194
if ( $obj_owner > 0 && $obj_owner != $current_user_id || $obj_owner == -1 ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual,Universal.Operators.StrictComparisons.LooseEqual -- see below.
197195
// not current user

projects/plugins/super-cache/.phan/baseline.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
// PhanTypeMismatchReturn : 2 occurrences
4141
// PhanTypeSuspiciousStringExpression : 2 occurrences
4242
// PhanCommentParamWithoutRealParam : 1 occurrence
43-
// PhanPluginDuplicateIfCondition : 1 occurrence
4443
// PhanTypeConversionFromArray : 1 occurrence
4544
// PhanTypeInvalidLeftOperandOfBitwiseOp : 1 occurrence
4645
// PhanTypeInvalidRightOperandOfAdd : 1 occurrence
@@ -72,7 +71,7 @@
7271
'tests/e2e/tools/mu-test-helpers.php' => ['PhanTypeMismatchArgument'],
7372
'wp-cache-base.php' => ['PhanTypeMismatchArgumentNullableInternal'],
7473
'wp-cache-phase1.php' => ['PhanTypeNonVarPassByRef'],
75-
'wp-cache-phase2.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginDuplicateIfCondition', 'PhanPluginSimplifyExpressionBool', 'PhanPluginUnreachableCode', 'PhanPossiblyUndeclaredVariable', 'PhanSuspiciousValueComparison', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternalProbablyReal', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeNonVarPassByRef', 'PhanTypePossiblyInvalidDimOffset', 'PhanTypeSuspiciousNonTraversableForeach', 'PhanTypeSuspiciousStringExpression', 'PhanUndeclaredVariableDim'],
74+
'wp-cache-phase2.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginSimplifyExpressionBool', 'PhanPluginUnreachableCode', 'PhanPossiblyUndeclaredVariable', 'PhanSuspiciousValueComparison', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternalProbablyReal', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeNonVarPassByRef', 'PhanTypePossiblyInvalidDimOffset', 'PhanTypeSuspiciousNonTraversableForeach', 'PhanTypeSuspiciousStringExpression', 'PhanUndeclaredVariableDim'],
7675
'wp-cache.php' => ['PhanPluginDuplicateAdjacentStatement', 'PhanPluginDuplicateExpressionAssignmentOperation', 'PhanPluginNeverReturnFunction', 'PhanPluginSimplifyExpressionBool', 'PhanPossiblyUndeclaredVariable', 'PhanSuspiciousValueComparison', 'PhanTypeArraySuspiciousNullable', 'PhanTypeInvalidDimOffset', 'PhanTypeInvalidLeftOperandOfBitwiseOp', 'PhanTypeInvalidLeftOperandOfNumericOp', 'PhanTypeInvalidRightOperandOfAdd', 'PhanTypeInvalidRightOperandOfBitwiseOp', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentInternalProbablyReal', 'PhanTypeMismatchArgumentInternalReal', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeNonVarPassByRef', 'PhanTypePossiblyInvalidDimOffset', 'PhanTypeSuspiciousNonTraversableForeach', 'PhanUndeclaredFunction', 'PhanUndeclaredVariable', 'PhanUndeclaredVariableDim'],
7776
],
7877
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Remove redundant code.

projects/plugins/super-cache/wp-cache-phase2.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,9 +2153,6 @@ function wp_cache_ob_callback( $buffer ) {
21532153
} elseif ( wpsc_is_caching_user_disabled() ) {
21542154
wp_cache_debug( 'wp_cache_ob_callback: Caching disabled for known user. User logged in or cookie found.' );
21552155
$cache_this_page = false;
2156-
} elseif ( wp_cache_user_agent_is_rejected() ) {
2157-
wp_cache_debug( 'wp_cache_ob_callback: Caching disabled because user agent was rejected.' );
2158-
$cache_this_page = false;
21592156
}
21602157

21612158
if ( isset( $wpsc_save_headers ) && $wpsc_save_headers ) {

0 commit comments

Comments
 (0)