Skip to content

Commit

Permalink
Finish fixing phpstan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
carstingaxion committed Feb 28, 2024
1 parent 5ecfcad commit b5754c0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
30 changes: 21 additions & 9 deletions inc/sites/installation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Figuren_Theater\Network\Users;
use FT_CORESITES;
use WP_Site;
use WP_User;
use function add_action;
use function apply_filters;
use function check_admin_referer;
Expand Down Expand Up @@ -124,7 +125,7 @@ function create_new__ft_site( WP_Site $new_site, array $args ): void {
// Defined at wp-admin/network/site-new.php.
check_admin_referer( 'add-blog', '_wpnonce_add-blog' );

if ( isset( $_POST['ft_level'] ) && 0 < intval( $_POST['ft_level'] ) ) {
if ( isset( $_POST['ft_level'] ) && ( \is_string( $_POST['ft_level'] ) || \is_int( $_POST['ft_level'] ) ) && 0 < intval( $_POST['ft_level'] ) ) {
$args['ft_level'] = (int) $_POST['ft_level'];
}

Expand Down Expand Up @@ -223,10 +224,13 @@ function set_imprint_page( WP_Site $new_site, array $args ): void {
'impressum_imprint_options',
false
);
$remote_imprint_page_id = ( isset( $remote_impressum_imprint_options['page'] ) ) ? (int) $remote_impressum_imprint_options['page'] : false;
$remote_imprint_page_id = false;
if ( \is_array( $remote_impressum_imprint_options ) && isset( $remote_impressum_imprint_options['page'] ) && ( \is_string( $remote_impressum_imprint_options['page'] ) || \is_int( $remote_impressum_imprint_options['page'] ) ) ) {
$remote_imprint_page_id = (int) $remote_impressum_imprint_options['page'];
}

// If we have nothing from remote, JUMP OUT.
if ( ! $remote_imprint_page_id ) {
if ( false === $remote_imprint_page_id ) {
return;
}

Expand All @@ -239,17 +243,25 @@ function set_imprint_page( WP_Site $new_site, array $args ): void {
// Run pulling.
$imprint_page_id = $distributor->run();

// Return on failure or set our option if everything was fine.
// Return on failure.
if ( empty( $imprint_page_id ) || ! inc\helper::post_id_exists( (int) $imprint_page_id[0] ) ) {
return;
}

// Prepare some data, which was collected during registration.
$person = get_userdata( $args['user_id'] );
$person = get_userdata( (int) $args['user_id'] );

if ( ! $person instanceof WP_User ) {
return;
}

// Get temporary data, collected during registration.
$user_registration_data = $person->get( FeaturesRepo\TEMP_USER_META );

if ( ! \is_array( $user_registration_data ) || ! isset( $user_registration_data['adr'] ) || empty( $user_registration_data['adr'] ) ) {
return;
}

$impressum_imprint_options = [
'page' => (string) $imprint_page_id[0],
'country' => '', // Leave empty as it gets populated on save, if empty.
Expand Down Expand Up @@ -284,20 +296,20 @@ function set_privacy_page(): void {
// this is the one to pull.
$ft_coresites_ids = array_flip( FT_CORESITES );
$remote_site_id = (int) $ft_coresites_ids['mein'];
$remote_policy_page_id = (int) get_blog_option(
$remote_policy_page_id = get_blog_option(
$remote_site_id,
'wp_page_for_privacy_policy',
false
);

// If we have nothing from remote, JUMP OUT.
if ( ! $remote_policy_page_id ) {
if ( ! $remote_policy_page_id || ! ( \is_string( $remote_policy_page_id ) || \is_int( $remote_policy_page_id ) ) ) {
return;
}

// Establish a connection and define pulling.
$distributor = new Sync\Pull(
[ $remote_policy_page_id ],
$distributor = new Sync\Pull(
[ \intval( $remote_policy_page_id ) ],
$remote_site_id,
'page'
);
Expand Down
15 changes: 15 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,18 @@ parameters:
# Find a nicer way instead of ignoring this Error on every ft-module
- '#Function Altis\\register_module not found\.#'
- '#Function Figuren_Theater\\get_config not found\.#'

# TODO https://github.com/figuren-theater/ft-onboarding/issues/29 Remove hard dependencies onto deprecated__Figuren_Theater__v2
- '#Call to static method site\(\) on an unknown class Figuren_Theater\\FT\.#'
- '#Call to static method init\(\) on an unknown class Figuren_Theater\\FT_Query\.#'
- '#Call to static method id\(\) on an unknown class Figuren_Theater\\Network\\Users\\ft_bot\.#'
- '#Constant FT_CORESITES not found\.#'
- '#Access to constant NAME on an unknown class Figuren_Theater\\Network\\Admin_UI\\Color_Scheme\.#'
- '#Call to method run\(\) on an unknown class Figuren_Theater\\Network\\Sync\\Pull\.#'
- '#Instantiated class Figuren_Theater\\Network\\Sync\\Pull not found\.#'
- '#Instantiated class Figuren_Theater\\Network\\Post_Types\\Post_Type__ft_site not found\.#'
- '#Access to constant NAME on an unknown class Figuren_Theater\\Coresites\\Post_Types\\Post_Type__ft_level\.#'
- '#Call to static method post_id_exists\(\) on an unknown class Figuren_Theater\\inc\\helper\.#'
- '#Instantiated class Figuren_Theater\\inc\\Geo\\ft_geo_options_bridge not found\.#'
- '#Call to method update_option_ft_geo\(\) on an unknown class Figuren_Theater\\inc\\Geo\\ft_geo_options_bridge\.#'
- '#Constant Figuren_Theater\\FeaturesRepo\\TEMP_USER_META not found\.#'

0 comments on commit b5754c0

Please sign in to comment.