Skip to content

Commit

Permalink
Update code base for php 8.2
Browse files Browse the repository at this point in the history
Applied rules:
 * LongArrayToShortArrayRector
 * TernaryToNullCoalescingRector
 * PublicConstantVisibilityRector (https://wiki.php.net/rfc/class_const_visibility)
 * ListToArrayDestructRector (https://wiki.php.net/rfc/short_list_syntax https://www.php.net/manual/en/migration71.new-features.php#migration71.new-features.symmetric-array-destructuring)
 * MixedTypeRector
 * StrContainsRector (https://externals.io/message/108562 php/php-src#5179)
 * ChangeSwitchToMatchRector (https://wiki.php.net/rfc/match_expression_v2)
 * FinalizePublicClassConstantRector (https://php.watch/versions/8.1/final-class-const)
 * NullToStrictStringFuncCallArgRector
 * TypedPropertyFromAssignsRector
  • Loading branch information
georgfranz committed Dec 11, 2023
1 parent a1f9f22 commit ec73919
Show file tree
Hide file tree
Showing 34 changed files with 347 additions and 520 deletions.
46 changes: 18 additions & 28 deletions src/authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ezcAuthentication
*
* @var array(ezcAuthenticationFilter)
*/
protected $filters = array();
protected $filters = [];

/**
* Options for the Authentication object.
Expand All @@ -101,7 +101,7 @@ class ezcAuthentication
*
* @var array(string=>mixed)
*/
private $properties = array();
private $properties = [];

/**
* Creates a new object of this class.
Expand All @@ -113,7 +113,7 @@ public function __construct( ezcAuthenticationCredentials $credentials, ezcAuthe
{
$this->credentials = $credentials;
$this->status = new ezcAuthenticationStatus();
$this->options = ( $options === null ) ? new ezcAuthenticationOptions() : $options;
$this->options = $options ?? new ezcAuthenticationOptions();
}

/**
Expand All @@ -127,7 +127,7 @@ public function __construct( ezcAuthenticationCredentials $credentials, ezcAuthe
* @param mixed $value The new value of the property
* @ignore
*/
public function __set( $name, $value )
public function __set( $name, mixed $value )
{
switch ( $name )
{
Expand Down Expand Up @@ -180,16 +180,10 @@ public function __set( $name, $value )
*/
public function __get( $name )
{
switch ( $name )
{
case 'session':
case 'status':
case 'credentials':
return $this->properties[$name];

default:
throw new ezcBasePropertyNotFoundException( $name );
}
return match ($name) {
'session', 'status', 'credentials' => $this->properties[$name],
default => throw new ezcBasePropertyNotFoundException( $name ),
};
}

/**
Expand All @@ -201,16 +195,10 @@ public function __get( $name )
*/
public function __isset( $name )
{
switch ( $name )
{
case 'session':
case 'status':
case 'credentials':
return isset( $this->properties[$name] );

default:
return false;
}
return match ($name) {
'session', 'status', 'credentials' => isset( $this->properties[$name] ),
default => false,
};
}

/**
Expand Down Expand Up @@ -247,7 +235,7 @@ public function run()
if ( isset( $this->session ) )
{
$code = $this->session->run( $credentials );
$this->status->append( get_class( $this->session ), $code );
$this->status->append( $this->session::class, $code );
}

if ( !isset( $this->session ) || $code === ezcAuthenticationSession::STATUS_EMPTY )
Expand All @@ -263,13 +251,15 @@ public function run()
// status of the Authentication object
foreach ( $statuses as $status )
{
list( $key, $value ) = each( $status );
$key = key($status);
$value = current($status);
next($status);
$this->status->append( $key, $value );
}
}
else
{
$this->status->append( get_class( $filter[0] ), $code );
$this->status->append( $filter[0]::class, $code );
}

if ( ( $filter[1] === true && $code !== ezcAuthenticationFilter::STATUS_OK ) )
Expand Down Expand Up @@ -313,7 +303,7 @@ public function run()
*/
public function addFilter( ezcAuthenticationFilter $filter, $stop = false )
{
$this->filters[] = array( $filter, $stop );
$this->filters[] = [$filter, $stop];
}

/**
Expand Down
47 changes: 1 addition & 46 deletions src/authentication_autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,5 @@
* @package Authentication
*/

return array(
'ezcAuthenticationException' => 'Authentication/exceptions/authentication_exception.php',
'ezcAuthenticationOpenidException' => 'Authentication/exceptions/openid_exception.php',
'ezcAuthenticationTypekeyException' => 'Authentication/exceptions/typekey_exception.php',
'ezcAuthenticationGroupException' => 'Authentication/exceptions/group_exception.php',
'ezcAuthenticationLdapException' => 'Authentication/exceptions/ldap_exception.php',
'ezcAuthenticationOpenidConnectionException' => 'Authentication/exceptions/openid_connection_exception.php',
'ezcAuthenticationOpenidModeNotSupportedException' => 'Authentication/exceptions/openid_mode_exception.php',
'ezcAuthenticationOpenidRedirectException' => 'Authentication/exceptions/openid_redirect_exception.php',
'ezcAuthenticationTypekeyPublicKeysInvalidException' => 'Authentication/exceptions/typekey_invalid_exception.php',
'ezcAuthenticationTypekeyPublicKeysMissingException' => 'Authentication/exceptions/typekey_missing_exception.php',
'ezcAuthenticationBignumLibrary' => 'Authentication/math/bignum_library.php',
'ezcAuthenticationCredentials' => 'Authentication/credentials/credentials.php',
'ezcAuthenticationDataFetch' => 'Authentication/interfaces/data_fetch.php',
'ezcAuthenticationFilter' => 'Authentication/interfaces/authentication_filter.php',
'ezcAuthenticationFilterOptions' => 'Authentication/options/filter_options.php',
'ezcAuthenticationOpenidStore' => 'Authentication/filters/openid/openid_store.php',
'ezcAuthenticationOpenidStoreOptions' => 'Authentication/options/openid_store_options.php',
'ezcAuthentication' => 'Authentication/authentication.php',
'ezcAuthenticationBcmathLibrary' => 'Authentication/math/bcmath_library.php',
'ezcAuthenticationGmpLibrary' => 'Authentication/math/gmp_library.php',
'ezcAuthenticationGroupFilter' => 'Authentication/filters/group/group_filter.php',
'ezcAuthenticationGroupOptions' => 'Authentication/options/group_options.php',
'ezcAuthenticationHtpasswdFilter' => 'Authentication/filters/htpasswd/htpasswd_filter.php',
'ezcAuthenticationHtpasswdOptions' => 'Authentication/options/htpasswd_options.php',
'ezcAuthenticationIdCredentials' => 'Authentication/credentials/id_credentials.php',
'ezcAuthenticationLdapFilter' => 'Authentication/filters/ldap/ldap_filter.php',
'ezcAuthenticationLdapInfo' => 'Authentication/filters/ldap/ldap_info.php',
'ezcAuthenticationLdapOptions' => 'Authentication/options/ldap_options.php',
'ezcAuthenticationMath' => 'Authentication/math/math.php',
'ezcAuthenticationOpenidAssociation' => 'Authentication/filters/openid/openid_association.php',
'ezcAuthenticationOpenidFileStore' => 'Authentication/filters/openid/openid_file_store.php',
'ezcAuthenticationOpenidFileStoreOptions' => 'Authentication/options/openid_file_store_options.php',
'ezcAuthenticationOpenidFilter' => 'Authentication/filters/openid/openid_filter.php',
'ezcAuthenticationOpenidOptions' => 'Authentication/options/openid_options.php',
'ezcAuthenticationOptions' => 'Authentication/options/authentication_options.php',
'ezcAuthenticationPasswordCredentials' => 'Authentication/credentials/password_credentials.php',
'ezcAuthenticationSession' => 'Authentication/session/authentication_session.php',
'ezcAuthenticationSessionOptions' => 'Authentication/options/session_options.php',
'ezcAuthenticationStatus' => 'Authentication/status/authentication_status.php',
'ezcAuthenticationTokenFilter' => 'Authentication/filters/token/token_filter.php',
'ezcAuthenticationTokenOptions' => 'Authentication/options/token_options.php',
'ezcAuthenticationTypekeyFilter' => 'Authentication/filters/typekey/typekey_filter.php',
'ezcAuthenticationTypekeyOptions' => 'Authentication/options/typekey_options.php',
'ezcAuthenticationUrl' => 'Authentication/url/url.php',
);
return ['ezcAuthenticationException' => 'Authentication/exceptions/authentication_exception.php', 'ezcAuthenticationOpenidException' => 'Authentication/exceptions/openid_exception.php', 'ezcAuthenticationTypekeyException' => 'Authentication/exceptions/typekey_exception.php', 'ezcAuthenticationGroupException' => 'Authentication/exceptions/group_exception.php', 'ezcAuthenticationLdapException' => 'Authentication/exceptions/ldap_exception.php', 'ezcAuthenticationOpenidConnectionException' => 'Authentication/exceptions/openid_connection_exception.php', 'ezcAuthenticationOpenidModeNotSupportedException' => 'Authentication/exceptions/openid_mode_exception.php', 'ezcAuthenticationOpenidRedirectException' => 'Authentication/exceptions/openid_redirect_exception.php', 'ezcAuthenticationTypekeyPublicKeysInvalidException' => 'Authentication/exceptions/typekey_invalid_exception.php', 'ezcAuthenticationTypekeyPublicKeysMissingException' => 'Authentication/exceptions/typekey_missing_exception.php', 'ezcAuthenticationBignumLibrary' => 'Authentication/math/bignum_library.php', 'ezcAuthenticationCredentials' => 'Authentication/credentials/credentials.php', 'ezcAuthenticationDataFetch' => 'Authentication/interfaces/data_fetch.php', 'ezcAuthenticationFilter' => 'Authentication/interfaces/authentication_filter.php', 'ezcAuthenticationFilterOptions' => 'Authentication/options/filter_options.php', 'ezcAuthenticationOpenidStore' => 'Authentication/filters/openid/openid_store.php', 'ezcAuthenticationOpenidStoreOptions' => 'Authentication/options/openid_store_options.php', 'ezcAuthentication' => 'Authentication/authentication.php', 'ezcAuthenticationBcmathLibrary' => 'Authentication/math/bcmath_library.php', 'ezcAuthenticationGmpLibrary' => 'Authentication/math/gmp_library.php', 'ezcAuthenticationGroupFilter' => 'Authentication/filters/group/group_filter.php', 'ezcAuthenticationGroupOptions' => 'Authentication/options/group_options.php', 'ezcAuthenticationHtpasswdFilter' => 'Authentication/filters/htpasswd/htpasswd_filter.php', 'ezcAuthenticationHtpasswdOptions' => 'Authentication/options/htpasswd_options.php', 'ezcAuthenticationIdCredentials' => 'Authentication/credentials/id_credentials.php', 'ezcAuthenticationLdapFilter' => 'Authentication/filters/ldap/ldap_filter.php', 'ezcAuthenticationLdapInfo' => 'Authentication/filters/ldap/ldap_info.php', 'ezcAuthenticationLdapOptions' => 'Authentication/options/ldap_options.php', 'ezcAuthenticationMath' => 'Authentication/math/math.php', 'ezcAuthenticationOpenidAssociation' => 'Authentication/filters/openid/openid_association.php', 'ezcAuthenticationOpenidFileStore' => 'Authentication/filters/openid/openid_file_store.php', 'ezcAuthenticationOpenidFileStoreOptions' => 'Authentication/options/openid_file_store_options.php', 'ezcAuthenticationOpenidFilter' => 'Authentication/filters/openid/openid_filter.php', 'ezcAuthenticationOpenidOptions' => 'Authentication/options/openid_options.php', 'ezcAuthenticationOptions' => 'Authentication/options/authentication_options.php', 'ezcAuthenticationPasswordCredentials' => 'Authentication/credentials/password_credentials.php', 'ezcAuthenticationSession' => 'Authentication/session/authentication_session.php', 'ezcAuthenticationSessionOptions' => 'Authentication/options/session_options.php', 'ezcAuthenticationStatus' => 'Authentication/status/authentication_status.php', 'ezcAuthenticationTokenFilter' => 'Authentication/filters/token/token_filter.php', 'ezcAuthenticationTokenOptions' => 'Authentication/options/token_options.php', 'ezcAuthenticationTypekeyFilter' => 'Authentication/filters/typekey/typekey_filter.php', 'ezcAuthenticationTypekeyOptions' => 'Authentication/options/typekey_options.php', 'ezcAuthenticationUrl' => 'Authentication/url/url.php'];
?>
4 changes: 2 additions & 2 deletions src/credentials/credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @package Authentication
* @version //autogen//
*/
abstract class ezcAuthenticationCredentials extends ezcBaseStruct
abstract class ezcAuthenticationCredentials extends ezcBaseStruct implements \Stringable
{
/**
* Returns string representation of the credentials.
Expand All @@ -40,6 +40,6 @@ abstract class ezcAuthenticationCredentials extends ezcBaseStruct
*
* @return string
*/
abstract public function __toString();
abstract public function __toString(): string;
}
?>
18 changes: 8 additions & 10 deletions src/credentials/id_credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,19 @@
*/
class ezcAuthenticationIdCredentials extends ezcAuthenticationCredentials
{
/**
* Username or userID or url.
*
* @var string
*/
public $id;

/**
* Constructs a new ezcAuthenticationIdCredentials object.
*
* @param string $id
*/
public function __construct( $id )
public function __construct(
/**
* Username or userID or url.
*
*/
public $id
)
{
$this->id = $id;
}

/**
Expand Down Expand Up @@ -76,7 +74,7 @@ public static function __set_state( array $array )
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return $this->id;
}
Expand Down
31 changes: 13 additions & 18 deletions src/credentials/password_credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,25 @@
*/
class ezcAuthenticationPasswordCredentials extends ezcAuthenticationCredentials
{
/**
* Username or userID or url.
*
* @var string
*/
public $id;

/**
* Password for the id.
*
* @var string
*/
public $password;

/**
* Constructs a new ezcAuthenticationPasswordCredentials object.
*
* @param string $id
* @param string $password
*/
public function __construct( $id, $password )
public function __construct(
/**
* Username or userID or url.
*
*/
public $id,
/**
* Password for the id.
*
*/
public $password
)
{
$this->id = $id;
$this->password = $password;
}

/**
Expand Down Expand Up @@ -85,7 +80,7 @@ public static function __set_state( array $array )
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return $this->id;
}
Expand Down
46 changes: 19 additions & 27 deletions src/filters/group/group_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,31 +156,31 @@ class ezcAuthenticationGroupFilter extends ezcAuthenticationFilter
* All or some of the filters in the group failed (depeding on the mode
* option).
*/
const STATUS_GROUP_FAILED = 1;
final public const STATUS_GROUP_FAILED = 1;

/**
* At least one filter needs to succeed in order for the group to succeed.
*/
const MODE_OR = 1;
final public const MODE_OR = 1;

/**
* All the filters need to succeed in order for the group to succeed.
*/
const MODE_AND = 2;
final public const MODE_AND = 2;

/**
* Authentication filters.
*
* @var array(ezcAuthenticationFilter)
*/
protected $filters = array();
protected $filters = [];

/**
* The properties of this class.
*
* @var array(string=>mixed)
*/
private $properties = array();
private array $properties = [];

/**
* Creates a new object of this class.
Expand Down Expand Up @@ -217,7 +217,7 @@ class ezcAuthenticationGroupFilter extends ezcAuthenticationFilter
*/
public function __construct( array $filters, ezcAuthenticationGroupOptions $options = null )
{
$this->options = ( $options === null ) ? new ezcAuthenticationGroupOptions() : $options;
$this->options = $options ?? new ezcAuthenticationGroupOptions();

foreach ( $filters as $filter )
{
Expand Down Expand Up @@ -252,7 +252,7 @@ public function __construct( array $filters, ezcAuthenticationGroupOptions $opti
* @param mixed $value The new value of the property
* @ignore
*/
public function __set( $name, $value )
public function __set( $name, mixed $value )
{
switch ( $name )
{
Expand Down Expand Up @@ -283,14 +283,10 @@ public function __set( $name, $value )
*/
public function __get( $name )
{
switch ( $name )
{
case 'status':
return $this->properties[$name];

default:
throw new ezcBasePropertyNotFoundException( $name );
}
return match ($name) {
'status' => $this->properties[$name],
default => throw new ezcBasePropertyNotFoundException( $name ),
};
}

/**
Expand All @@ -302,14 +298,10 @@ public function __get( $name )
*/
public function __isset( $name )
{
switch ( $name )
{
case 'status':
return isset( $this->properties[$name] );

default:
return false;
}
return match ($name) {
'status' => isset( $this->properties[$name] ),
default => false,
};
}

/**
Expand All @@ -336,7 +328,7 @@ public function run( $credentials )
$credentials;

$code = $filter[0]->run( $credentials );
$this->status->append( get_class( $filter[0] ), $code );
$this->status->append( $filter[0]::class, $code );
if ( $code === self::STATUS_OK )
{
$success = true;
Expand All @@ -353,7 +345,7 @@ public function run( $credentials )
$credentials;

$code = $filter[0]->run( $credentials );
$this->status->append( get_class( $filter[0] ), $code );
$this->status->append( $filter[0]::class, $code );
if ( $code !== self::STATUS_OK )
{
$success = false;
Expand Down Expand Up @@ -408,11 +400,11 @@ public function addFilter( ezcAuthenticationFilter $filter, ezcAuthenticationCre
throw new ezcAuthenticationGroupException( 'A credentials object must be specified for each filter when the multipleCredentials option is enabled.' );
}

$this->filters[] = array( $filter, $credentials );
$this->filters[] = [$filter, $credentials];
}
else
{
$this->filters[] = array( $filter );
$this->filters[] = [$filter];
}
}
}
Expand Down
Loading

0 comments on commit ec73919

Please sign in to comment.