Skip to content

Commit

Permalink
Remove duplicate code.
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-vlasenko authored and Anton Vlasenko committed Apr 8, 2024
1 parent 7a0bd41 commit febac6f
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,8 @@ protected function process_property_token( File $phpcs_file, $stack_pointer ) {

$violation_code = 'MissingPropertySinceTag';

$scope_modifier = Variables::getMemberProperties( $phpcs_file, $stack_pointer )['scope'];
if ( ( $scope_modifier === 'protected'
&& $this->minimumVisibility === 'public' )
|| ( $scope_modifier === 'private'
&& ( $this->minimumVisibility === 'public' || $this->minimumVisibility === 'protected' ) )
) {
$visibility = Variables::getMemberProperties( $phpcs_file, $stack_pointer )['scope'];
if ( $this->check_below_minimum_visibility( $visibility ) ) {
return;
}

Expand Down Expand Up @@ -335,12 +331,8 @@ protected function process_function_token( File $phpcs_file, $stack_pointer ) {
$violation_code = 'MissingFunctionSinceTag';

if ( $is_oo_method ) {
$scope_modifier = FunctionDeclarations::getProperties( $phpcs_file, $stack_pointer )['scope'];
if ( ( $scope_modifier === 'protected'
&& $this->minimumVisibility === 'public' )
|| ( $scope_modifier === 'private'
&& ( $this->minimumVisibility === 'public' || $this->minimumVisibility === 'protected' ) )
) {
$visibility = FunctionDeclarations::getProperties( $phpcs_file, $stack_pointer )['scope'];
if ( $this->check_below_minimum_visibility( $visibility ) ) {
return;
}

Expand Down Expand Up @@ -408,6 +400,24 @@ protected static function validate_version( $version ) {
return version_compare( $version, '0.0.1', '>=' );
}

/**
* Checks if the provided visibility level is below the set minimum visibility level.
*
* @param string $visibility The visibility level to check.
* @return bool Returns true if the provided visibility level is below the minimum visibility level, false otherwise.
*/
protected function check_below_minimum_visibility( $visibility ) {
if ( 'public' === $this->minimumVisibility && in_array( $visibility, array( 'protected', 'private' ), true ) ) {
return true;
}

if ( 'protected' === $this->minimumVisibility && 'private' === $visibility ) {
return true;
}

return false;
}

/**
* Finds the docblock associated with a hook, starting from a specified position in the token stack.
* Since a line containing a hook can include any type of tokens, this method backtracks through the tokens
Expand Down

0 comments on commit febac6f

Please sign in to comment.