14 private readonly LoggerInterface $logger
22 public function isValid( mixed $condition ): bool {
24 if ( $condition === [] ) {
27 return $this->isValidInternal( $condition );
30 private function isValidInternal( mixed $condition ): bool {
31 if ( !is_array( $condition ) ) {
32 $condition = [ $condition ];
34 if ( $condition === [] ) {
35 $this->logger->warning(
'Empty array is invalid descriptor of a user requirements condition' );
39 $condType = $condition[0];
40 $args = array_slice( $condition, 1 );
44 if ( $condType ===
'^' && count( $args ) !== 2 ) {
45 $this->logger->warning(
'XOR (^) in user requirements conditions must have exactly two arguments' );
48 if ( count( $args ) === 0 ) {
49 $this->logger->warning(
'Compound conditions must have at least one argument' );
53 foreach ( $args as $arg ) {
54 if ( !$this->isValidInternal( $arg ) ) {
62 if ( !is_string( $condType ) && !is_int( $condType ) ) {
63 $this->logger->warning(
'User requirements conditions must be designated as string or int' );