$attributes * @return array */ public function replace_in( array $attributes, string $link_url, string $replacement_url ): array { $replaced = array(); foreach ( $attributes as $key => $value ) { $replaced[ $key ] = match ( true ) { is_array( $value ) => $this->replace_in( $value, $link_url, $replacement_url ), $this->points_to( $value, $link_url ) => $replacement_url, default => $value, }; } return $replaced; } /** @param array $attributes */ public function contain( array $attributes, string $link_url ): bool { foreach ( $attributes as $value ) { $is_inside = is_array( $value ) ? $this->contain( $value, $link_url ) : $this->points_to( $value, $link_url ); if ( $is_inside ) { return true; } } return false; } private function points_to( mixed $value, string $link_url ): bool { return is_string( $value ) && 1 === preg_match( self::ADDRESS_START, $value ) && $this->address_match->is_same( $value, $link_url ); } }