From b7ba3da1e2e8c3e2dca89d75b5e27e6eddef1c10 Mon Sep 17 00:00:00 2001 From: Thijs van der heijden Date: Fri, 15 Nov 2024 14:52:42 +0100 Subject: [PATCH 1/4] Add dashboard configuration object. --- packages/js/src/general/initialize.js | 4 +- .../configuration/dashboard-configuration.php | 85 +++++++++++++++++++ .../enabled-analysis-features-repository.php | 38 ++++++--- .../analysis-features-list.php | 15 ++++ src/editors/framework/cornerstone-content.php | 4 +- .../framework/inclusive-language-analysis.php | 4 +- src/editors/framework/keyphrase-analysis.php | 4 +- .../framework/previously-used-keyphrase.php | 4 +- .../framework/readability-analysis.php | 3 +- .../framework/word-form-recognition.php | 4 +- .../general-page-integration.php | 52 ++++++------ src/helpers/user-helper.php | 14 +++ .../Analysis_Features_List_Test.php | 40 ++++++--- .../General_Page_Integration_Test.php | 32 +++---- tests/Unit/Helpers/User_Helper_Test.php | 39 +++++++++ 15 files changed, 269 insertions(+), 73 deletions(-) create mode 100644 src/dashboard/application/configuration/dashboard-configuration.php diff --git a/packages/js/src/general/initialize.js b/packages/js/src/general/initialize.js index 2e574cf45b8..510e44426e5 100644 --- a/packages/js/src/general/initialize.js +++ b/packages/js/src/general/initialize.js @@ -32,8 +32,8 @@ domReady( () => { } ); const isRtl = select( STORE_NAME ).selectPreference( "isRtl", false ); - const contentTypes = get( window, "wpseoScriptData.contentTypes", [] ); - const userName = get( window, "wpseoScriptData.dash.userName", "User" ); + const contentTypes = get( window, "wpseoScriptData.dashboard.contentTypes", [] ); + const userName = get( window, "wpseoScriptData.dashboard.displayName", "User" ); const router = createHashRouter( createRoutesFromElements( diff --git a/src/dashboard/application/configuration/dashboard-configuration.php b/src/dashboard/application/configuration/dashboard-configuration.php new file mode 100644 index 00000000000..2a578848775 --- /dev/null +++ b/src/dashboard/application/configuration/dashboard-configuration.php @@ -0,0 +1,85 @@ +content_types_repository = $content_types_repository; + $this->indexable_helper = $indexable_helper; + $this->user_helper = $user_helper; + $this->analysis_features_repository = $analysis_features_repository; + } + + /** + * Returns a configuration + * + * @return array> + */ + public function get_configuration(): array { + return [ + 'contentTypes' => $this->content_types_repository->get_content_types(), + 'indexablesEnabled' => $this->indexable_helper->should_index_indexables(), + 'displayName' => $this->user_helper->get_current_user_display_name(), + 'enabledAnalysisFeatures' => $this->analysis_features_repository->get_enabled_features_by_keys( + [ + Readability_Analysis::NAME, + Keyphrase_Analysis::NAME, + ] + )->to_array(), + ]; + } +} diff --git a/src/editors/application/analysis-features/enabled-analysis-features-repository.php b/src/editors/application/analysis-features/enabled-analysis-features-repository.php index 2cec11db2ac..9261d22aba3 100644 --- a/src/editors/application/analysis-features/enabled-analysis-features-repository.php +++ b/src/editors/application/analysis-features/enabled-analysis-features-repository.php @@ -21,21 +21,13 @@ class Enabled_Analysis_Features_Repository { */ private $plugin_features; - /** - * The list of analysis features. - * - * @var Analysis_Features_List - */ - private $enabled_analysis_features; - /** * The constructor. * * @param Analysis_Feature_Interface ...$plugin_features All analysis objects. */ public function __construct( Analysis_Feature_Interface ...$plugin_features ) { - $this->enabled_analysis_features = new Analysis_Features_List(); - $this->plugin_features = $plugin_features; + $this->plugin_features = $plugin_features; } /** @@ -44,12 +36,32 @@ public function __construct( Analysis_Feature_Interface ...$plugin_features ) { * @return Analysis_Features_List The analysis list. */ public function get_enabled_features(): Analysis_Features_List { - if ( \count( $this->enabled_analysis_features->parse_to_legacy_array() ) === 0 ) { - foreach ( $this->plugin_features as $plugin_feature ) { + $enabled_analysis_features = new Analysis_Features_List(); + foreach ( $this->plugin_features as $plugin_feature ) { + $analysis_feature = new Analysis_Feature( $plugin_feature->is_enabled(), $plugin_feature->get_name(), $plugin_feature->get_legacy_key() ); + $enabled_analysis_features->add_feature( $analysis_feature ); + } + + return $enabled_analysis_features; + } + + /** + * Returns the analysis list for the given names. + * + * @param array $feature_names The feature names to include. + * + * @return Analysis_Features_List The analysis list. + */ + public function get_enabled_features_by_keys( array $feature_names ): Analysis_Features_List { + $enabled_analysis_features = new Analysis_Features_List(); + + foreach ( $this->plugin_features as $plugin_feature ) { + if ( \in_array( $plugin_feature->get_name(), $feature_names, true ) ) { $analysis_feature = new Analysis_Feature( $plugin_feature->is_enabled(), $plugin_feature->get_name(), $plugin_feature->get_legacy_key() ); - $this->enabled_analysis_features->add_feature( $analysis_feature ); + $enabled_analysis_features->add_feature( $analysis_feature ); } } - return $this->enabled_analysis_features; + + return $enabled_analysis_features; } } diff --git a/src/editors/domain/analysis-features/analysis-features-list.php b/src/editors/domain/analysis-features/analysis-features-list.php index 3fb19d04fec..bc918d25d03 100644 --- a/src/editors/domain/analysis-features/analysis-features-list.php +++ b/src/editors/domain/analysis-features/analysis-features-list.php @@ -35,6 +35,21 @@ public function parse_to_legacy_array(): array { foreach ( $this->features as $feature ) { $array = \array_merge( $array, $feature->to_legacy_array() ); } + + return $array; + } + + /** + * Parses the feature list to an array representation. + * + * @return array The list presented as a key value representation. + */ + public function to_array(): array { + $array = []; + foreach ( $this->features as $feature ) { + $array = \array_merge( $array, $feature->to_array() ); + } + return $array; } } diff --git a/src/editors/framework/cornerstone-content.php b/src/editors/framework/cornerstone-content.php index 8dff716c8c9..e75f3bdbf50 100644 --- a/src/editors/framework/cornerstone-content.php +++ b/src/editors/framework/cornerstone-content.php @@ -10,6 +10,8 @@ */ class Cornerstone_Content implements Analysis_Feature_Interface { + public const NAME = 'cornerstoneContent'; + /** * The options helper. * @@ -41,7 +43,7 @@ public function is_enabled(): bool { * @return string The name. */ public function get_name(): string { - return 'cornerstoneContent'; + return self::NAME; } /** diff --git a/src/editors/framework/inclusive-language-analysis.php b/src/editors/framework/inclusive-language-analysis.php index 4cfbe0254dc..8a8328b58e1 100644 --- a/src/editors/framework/inclusive-language-analysis.php +++ b/src/editors/framework/inclusive-language-analysis.php @@ -12,6 +12,8 @@ */ class Inclusive_Language_Analysis implements Analysis_Feature_Interface { + public const NAME = 'inclusiveLanguageAnalysis'; + /** * The options helper. * @@ -102,7 +104,7 @@ private function is_current_version_supported(): bool { * @return string The name. */ public function get_name(): string { - return 'inclusiveLanguageAnalysis'; + return self::NAME; } /** diff --git a/src/editors/framework/keyphrase-analysis.php b/src/editors/framework/keyphrase-analysis.php index 648639b2e55..287477ec38a 100644 --- a/src/editors/framework/keyphrase-analysis.php +++ b/src/editors/framework/keyphrase-analysis.php @@ -10,6 +10,8 @@ */ class Keyphrase_Analysis implements Analysis_Feature_Interface { + public const NAME = 'keyphraseAnalysis'; + /** * The options helper. * @@ -59,7 +61,7 @@ public function is_globally_enabled(): bool { * @return string The name. */ public function get_name(): string { - return 'keyphraseAnalysis'; + return self::NAME; } /** diff --git a/src/editors/framework/previously-used-keyphrase.php b/src/editors/framework/previously-used-keyphrase.php index 3400f561c6d..e4f3da7288f 100644 --- a/src/editors/framework/previously-used-keyphrase.php +++ b/src/editors/framework/previously-used-keyphrase.php @@ -9,6 +9,8 @@ */ class Previously_Used_Keyphrase implements Analysis_Feature_Interface { + public const NAME = 'previouslyUsedKeyphrase'; + /** * If this analysis is enabled. * @@ -29,7 +31,7 @@ public function is_enabled(): bool { * @return string */ public function get_name(): string { - return 'previouslyUsedKeyphrase'; + return self::NAME; } /** diff --git a/src/editors/framework/readability-analysis.php b/src/editors/framework/readability-analysis.php index 03accffe776..9e3b4b9cf9a 100644 --- a/src/editors/framework/readability-analysis.php +++ b/src/editors/framework/readability-analysis.php @@ -9,6 +9,7 @@ * This class describes the Readability analysis feature. */ class Readability_Analysis implements Analysis_Feature_Interface { + public const NAME = 'readabilityAnalysis'; /** * The options helper. @@ -59,7 +60,7 @@ private function is_globally_enabled(): bool { * @return string The name. */ public function get_name(): string { - return 'readabilityAnalysis'; + return self::NAME; } /** diff --git a/src/editors/framework/word-form-recognition.php b/src/editors/framework/word-form-recognition.php index da63caf798e..e54dbf828ee 100644 --- a/src/editors/framework/word-form-recognition.php +++ b/src/editors/framework/word-form-recognition.php @@ -10,6 +10,8 @@ */ class Word_Form_Recognition implements Analysis_Feature_Interface { + public const NAME = 'wordFormRecognition'; + /** * The language helper. * @@ -41,7 +43,7 @@ public function is_enabled(): bool { * @return string */ public function get_name(): string { - return 'wordFormRecognition'; + return self::NAME; } /** diff --git a/src/general/user-interface/general-page-integration.php b/src/general/user-interface/general-page-integration.php index 3346da75324..0a119835477 100644 --- a/src/general/user-interface/general-page-integration.php +++ b/src/general/user-interface/general-page-integration.php @@ -6,7 +6,7 @@ use Yoast\WP\SEO\Actions\Alert_Dismissal_Action; use Yoast\WP\SEO\Conditionals\Admin\Non_Network_Admin_Conditional; use Yoast\WP\SEO\Conditionals\Admin_Conditional; -use Yoast\WP\SEO\Dashboard\Application\Content_Types\Content_Types_Repository; +use Yoast\WP\SEO\Dashboard\Application\Configuration\Dashboard_Configuration; use Yoast\WP\SEO\Helpers\Current_Page_Helper; use Yoast\WP\SEO\Helpers\Notification_Helper; use Yoast\WP\SEO\Helpers\Product_Helper; @@ -31,6 +31,13 @@ class General_Page_Integration implements Integration_Interface { */ protected $notification_helper; + /** + * The dashboard configuration. + * + * @var Dashboard_Configuration + */ + private $dashboard_configuration; + /** * Holds the WPSEO_Admin_Asset_Manager. * @@ -73,24 +80,17 @@ class General_Page_Integration implements Integration_Interface { */ private $alert_dismissal_action; - /** - * The content types repository. - * - * @var Content_Types_Repository $content_types_repository - */ - private $content_types_repository; - /** * Constructs Academy_Integration. * - * @param WPSEO_Admin_Asset_Manager $asset_manager The WPSEO_Admin_Asset_Manager. - * @param Current_Page_Helper $current_page_helper The Current_Page_Helper. - * @param Product_Helper $product_helper The Product_Helper. - * @param Short_Link_Helper $shortlink_helper The Short_Link_Helper. - * @param Notification_Helper $notification_helper The Notification_Helper. - * @param Alert_Dismissal_Action $alert_dismissal_action The alert dismissal action. - * @param Promotion_Manager $promotion_manager The promotion manager. - * @param Content_Types_Repository $content_types_repository The content types repository. + * @param WPSEO_Admin_Asset_Manager $asset_manager The WPSEO_Admin_Asset_Manager. + * @param Current_Page_Helper $current_page_helper The Current_Page_Helper. + * @param Product_Helper $product_helper The Product_Helper. + * @param Short_Link_Helper $shortlink_helper The Short_Link_Helper. + * @param Notification_Helper $notification_helper The Notification_Helper. + * @param Alert_Dismissal_Action $alert_dismissal_action The alert dismissal action. + * @param Promotion_Manager $promotion_manager The promotion manager. + * @param Dashboard_Configuration $dashboard_configuration The dashboard configuration. */ public function __construct( WPSEO_Admin_Asset_Manager $asset_manager, @@ -100,16 +100,16 @@ public function __construct( Notification_Helper $notification_helper, Alert_Dismissal_Action $alert_dismissal_action, Promotion_Manager $promotion_manager, - Content_Types_Repository $content_types_repository + Dashboard_Configuration $dashboard_configuration ) { - $this->asset_manager = $asset_manager; - $this->current_page_helper = $current_page_helper; - $this->product_helper = $product_helper; - $this->shortlink_helper = $shortlink_helper; - $this->notification_helper = $notification_helper; - $this->alert_dismissal_action = $alert_dismissal_action; - $this->promotion_manager = $promotion_manager; - $this->content_types_repository = $content_types_repository; + $this->asset_manager = $asset_manager; + $this->current_page_helper = $current_page_helper; + $this->product_helper = $product_helper; + $this->shortlink_helper = $shortlink_helper; + $this->notification_helper = $notification_helper; + $this->alert_dismissal_action = $alert_dismissal_action; + $this->promotion_manager = $promotion_manager; + $this->dashboard_configuration = $dashboard_configuration; } /** @@ -213,7 +213,7 @@ private function get_script_data() { 'alerts' => $this->notification_helper->get_alerts(), 'currentPromotions' => $this->promotion_manager->get_current_promotions(), 'dismissedAlerts' => $this->alert_dismissal_action->all_dismissed(), - 'contentTypes' => $this->content_types_repository->get_content_types(), + 'dashboard' => $this->dashboard_configuration->get_configuration(), ]; } } diff --git a/src/helpers/user-helper.php b/src/helpers/user-helper.php index d319a8c2ad9..a34dbf0d529 100644 --- a/src/helpers/user-helper.php +++ b/src/helpers/user-helper.php @@ -65,6 +65,20 @@ public function get_current_user_id() { return \get_current_user_id(); } + /** + * Returns the current users display_name. + * + * @return string + */ + public function get_current_user_display_name(): string { + $user = \wp_get_current_user(); + if ( $user && $user->display_name ) { + return $user->display_name; + } + + return ''; + } + /** * Updates user meta field for a user. * diff --git a/tests/Unit/Editors/Domain/Analysis_Features/Analysis_Features_List_Test.php b/tests/Unit/Editors/Domain/Analysis_Features/Analysis_Features_List_Test.php index 3792992aba0..435076d252e 100644 --- a/tests/Unit/Editors/Domain/Analysis_Features/Analysis_Features_List_Test.php +++ b/tests/Unit/Editors/Domain/Analysis_Features/Analysis_Features_List_Test.php @@ -22,16 +22,6 @@ final class Analysis_Features_List_Test extends TestCase { */ private $instance; - /** - * Set up the test. - * - * @return void - */ - protected function set_up(): void { - parent::set_up(); - $this->instance = new Analysis_Features_List(); - } - /** * Tests the getters. * @@ -51,4 +41,34 @@ public function test_parse_to_legacy_array(): void { $this->instance->parse_to_legacy_array() ); } + + /** + * Tests the to array. + * + * @covers ::add_feature + * @covers ::parse_to_array + * + * @return void + */ + public function test_parse_to_array(): void { + $this->instance->add_feature( new Analysis_Feature( false, 'name-false', 'legacy-key-false' ) ); + $this->instance->add_feature( new Analysis_Feature( true, 'name-true', 'legacy-key-true' ) ); + $this->assertSame( + [ + 'name-false' => false, + 'name-true' => true, + ], + $this->instance->to_array() + ); + } + + /** + * Set up the test. + * + * @return void + */ + protected function set_up(): void { + parent::set_up(); + $this->instance = new Analysis_Features_List(); + } } diff --git a/tests/Unit/General/User_Interface/General_Page_Integration_Test.php b/tests/Unit/General/User_Interface/General_Page_Integration_Test.php index 1c21f9435d8..e40003f3148 100644 --- a/tests/Unit/General/User_Interface/General_Page_Integration_Test.php +++ b/tests/Unit/General/User_Interface/General_Page_Integration_Test.php @@ -8,7 +8,7 @@ use Yoast\WP\SEO\Actions\Alert_Dismissal_Action; use Yoast\WP\SEO\Conditionals\Admin\Non_Network_Admin_Conditional; use Yoast\WP\SEO\Conditionals\Admin_Conditional; -use Yoast\WP\SEO\Dashboard\Application\Content_Types\Content_Types_Repository; +use Yoast\WP\SEO\Dashboard\Application\Configuration\Dashboard_Configuration; use Yoast\WP\SEO\General\User_Interface\General_Page_Integration; use Yoast\WP\SEO\Helpers\Current_Page_Helper; use Yoast\WP\SEO\Helpers\Notification_Helper; @@ -76,11 +76,11 @@ final class General_Page_Integration_Test extends TestCase { private $promotion_manager; /** - * Holds the content types repository. + * Holds the dashboard configuration. * - * @var Mockery\MockInterface|Content_Types_Repository + * @var Mockery\MockInterface|Dashboard_Configuration */ - private $content_types_repository; + private $dashboard_configuration; /** * The class under test. @@ -97,14 +97,14 @@ final class General_Page_Integration_Test extends TestCase { public function set_up() { $this->stubTranslationFunctions(); - $this->asset_manager = Mockery::mock( WPSEO_Admin_Asset_Manager::class ); - $this->current_page_helper = Mockery::mock( Current_Page_Helper::class ); - $this->product_helper = Mockery::mock( Product_Helper::class ); - $this->shortlink_helper = Mockery::mock( Short_Link_Helper::class ); - $this->notifications_helper = Mockery::mock( Notification_Helper::class ); - $this->alert_dismissal_action = Mockery::mock( Alert_Dismissal_Action::class ); - $this->promotion_manager = Mockery::mock( Promotion_Manager::class ); - $this->content_types_repository = Mockery::mock( Content_Types_Repository::class ); + $this->asset_manager = Mockery::mock( WPSEO_Admin_Asset_Manager::class ); + $this->current_page_helper = Mockery::mock( Current_Page_Helper::class ); + $this->product_helper = Mockery::mock( Product_Helper::class ); + $this->shortlink_helper = Mockery::mock( Short_Link_Helper::class ); + $this->notifications_helper = Mockery::mock( Notification_Helper::class ); + $this->alert_dismissal_action = Mockery::mock( Alert_Dismissal_Action::class ); + $this->promotion_manager = Mockery::mock( Promotion_Manager::class ); + $this->dashboard_configuration = Mockery::mock( Dashboard_Configuration::class ); $this->instance = new General_Page_Integration( $this->asset_manager, @@ -114,7 +114,7 @@ public function set_up() { $this->notifications_helper, $this->alert_dismissal_action, $this->promotion_manager, - $this->content_types_repository + $this->dashboard_configuration ); } @@ -136,7 +136,7 @@ public function test_construct() { $this->notifications_helper, $this->alert_dismissal_action, $this->promotion_manager, - $this->content_types_repository + $this->dashboard_configuration ) ); } @@ -342,8 +342,8 @@ public function expect_get_script_data() { ->once() ->andReturn( [] ); - $this->content_types_repository - ->expects( 'get_content_types' ) + $this->dashboard_configuration + ->expects( 'get_configuration' ) ->once() ->andReturn( [] ); diff --git a/tests/Unit/Helpers/User_Helper_Test.php b/tests/Unit/Helpers/User_Helper_Test.php index f461ad81c52..48632ec35b5 100644 --- a/tests/Unit/Helpers/User_Helper_Test.php +++ b/tests/Unit/Helpers/User_Helper_Test.php @@ -3,6 +3,7 @@ namespace Yoast\WP\SEO\Tests\Unit\Helpers; use Brain\Monkey\Functions; +use WP_User; use Yoast\WP\SEO\Helpers\User_Helper; use Yoast\WP\SEO\Tests\Unit\TestCase; @@ -139,4 +140,42 @@ public function test_delete_meta() { $this->assertTrue( $this->instance->delete_meta( 1, 'key', 'value' ) ); } + + /** + * Tests that get_current_user_display_name return the display_name if its there or an empty string. + * + * @covers ::get_current_user_display_name + * + * @dataProvider current_user_display_name_provider + * + * @param WP_User|null $user The user. + * @param string $expected_display_name The expected display name. + * + * @return void + */ + public function test_get_current_user_display_name( $user, $expected_display_name ) { + Functions\expect( 'wp_get_current_user' ) + ->once() + ->andReturn( $user ); + + $this->assertSame( $expected_display_name, $this->instance->get_current_user_display_name() ); + } + + /** + * Data provider for current_user_display_name_provider test. + * + * @return array> + */ + public static function current_user_display_name_provider() { + $user1 = new WP_User(); + $user1->display_name = 'admin'; + $user2 = new WP_User(); + $user2->display_name = 'First_name'; + + return [ + [ $user1, 'admin' ], + [ $user2, 'First_name' ], + [ null, '' ], + ]; + } } From 042d654d925876f63ca2112c8a5d8108bb0b971e Mon Sep 17 00:00:00 2001 From: Thijs van der heijden Date: Mon, 18 Nov 2024 13:40:31 +0100 Subject: [PATCH 2/4] Small refactor + feedback. --- admin/formatter/class-metabox-formatter.php | 21 +++++++++--------- .../configuration/dashboard-configuration.php | 22 +++++++++---------- ...y.php => analysis-features-repository.php} | 18 +++++++-------- 3 files changed, 31 insertions(+), 30 deletions(-) rename src/editors/application/analysis-features/{enabled-analysis-features-repository.php => analysis-features-repository.php} (74%) diff --git a/admin/formatter/class-metabox-formatter.php b/admin/formatter/class-metabox-formatter.php index 02deb3c8eb4..aeabaacf4c4 100644 --- a/admin/formatter/class-metabox-formatter.php +++ b/admin/formatter/class-metabox-formatter.php @@ -6,7 +6,7 @@ */ use Yoast\WP\SEO\Config\Schema_Types; -use Yoast\WP\SEO\Editors\Application\Analysis_Features\Enabled_Analysis_Features_Repository; +use Yoast\WP\SEO\Editors\Application\Analysis_Features\Analysis_Features_Repository; use Yoast\WP\SEO\Editors\Application\Integrations\Integration_Information_Repository; /** @@ -51,31 +51,32 @@ private function get_defaults() { $schema_types = new Schema_Types(); $defaults = [ - 'author_name' => get_the_author_meta( 'display_name' ), - 'keyword_usage' => [], - 'title_template' => '', - 'metadesc_template' => '', - 'schema' => [ + 'author_name' => get_the_author_meta( 'display_name' ), + 'keyword_usage' => [], + 'title_template' => '', + 'metadesc_template' => '', + 'schema' => [ 'displayFooter' => WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ), 'pageTypeOptions' => $schema_types->get_page_type_options(), 'articleTypeOptions' => $schema_types->get_article_type_options(), ], - 'twitterCardType' => 'summary_large_image', + 'twitterCardType' => 'summary_large_image', /** * Filter to determine if the markers should be enabled or not. * * @param bool $showMarkers Should the markers being enabled. Default = true. */ - 'show_markers' => apply_filters( 'wpseo_enable_assessment_markers', true ), + 'show_markers' => apply_filters( 'wpseo_enable_assessment_markers', true ), ]; $integration_information_repo = YoastSEO()->classes->get( Integration_Information_Repository::class ); $enabled_integrations = $integration_information_repo->get_integration_information(); $defaults = array_merge( $defaults, $enabled_integrations ); - $enabled_features_repo = YoastSEO()->classes->get( Enabled_Analysis_Features_Repository::class ); + $enabled_features_repo = YoastSEO()->classes->get( Analysis_Features_Repository::class ); + + $enabled_features = $enabled_features_repo->get_analysis_features()->parse_to_legacy_array(); - $enabled_features = $enabled_features_repo->get_enabled_features()->parse_to_legacy_array(); return array_merge( $defaults, $enabled_features ); } } diff --git a/src/dashboard/application/configuration/dashboard-configuration.php b/src/dashboard/application/configuration/dashboard-configuration.php index 2a578848775..f55073169b9 100644 --- a/src/dashboard/application/configuration/dashboard-configuration.php +++ b/src/dashboard/application/configuration/dashboard-configuration.php @@ -5,7 +5,7 @@ namespace Yoast\WP\SEO\Dashboard\Application\Configuration; use Yoast\WP\SEO\Dashboard\Application\Content_Types\Content_Types_Repository; -use Yoast\WP\SEO\Editors\Application\Analysis_Features\Enabled_Analysis_Features_Repository; +use Yoast\WP\SEO\Editors\Application\Analysis_Features\Analysis_Features_Repository; use Yoast\WP\SEO\Editors\Framework\Keyphrase_Analysis; use Yoast\WP\SEO\Editors\Framework\Readability_Analysis; use Yoast\WP\SEO\Helpers\Indexable_Helper; @@ -40,23 +40,23 @@ class Dashboard_Configuration { /** * The repository. * - * @var Enabled_Analysis_Features_Repository + * @var Analysis_Features_Repository */ private $analysis_features_repository; /** * The constructor. * - * @param Content_Types_Repository $content_types_repository The content types repository. - * @param Indexable_Helper $indexable_helper The indexable helper repository. - * @param User_Helper $user_helper The user helper. - * @param Enabled_Analysis_Features_Repository $analysis_features_repository The analysis feature repository. + * @param Content_Types_Repository $content_types_repository The content types repository. + * @param Indexable_Helper $indexable_helper The indexable helper repository. + * @param User_Helper $user_helper The user helper. + * @param Analysis_Features_Repository $analysis_features_repository The analysis feature repository. */ public function __construct( Content_Types_Repository $content_types_repository, Indexable_Helper $indexable_helper, User_Helper $user_helper, - Enabled_Analysis_Features_Repository $analysis_features_repository + Analysis_Features_Repository $analysis_features_repository ) { $this->content_types_repository = $content_types_repository; $this->indexable_helper = $indexable_helper; @@ -71,10 +71,10 @@ public function __construct( */ public function get_configuration(): array { return [ - 'contentTypes' => $this->content_types_repository->get_content_types(), - 'indexablesEnabled' => $this->indexable_helper->should_index_indexables(), - 'displayName' => $this->user_helper->get_current_user_display_name(), - 'enabledAnalysisFeatures' => $this->analysis_features_repository->get_enabled_features_by_keys( + 'contentTypes' => $this->content_types_repository->get_content_types(), + 'indexablesEnabled' => $this->indexable_helper->should_index_indexables(), + 'displayName' => $this->user_helper->get_current_user_display_name(), + 'analysisFeatures' => $this->analysis_features_repository->get_analysis_features_by_keys( [ Readability_Analysis::NAME, Keyphrase_Analysis::NAME, diff --git a/src/editors/application/analysis-features/enabled-analysis-features-repository.php b/src/editors/application/analysis-features/analysis-features-repository.php similarity index 74% rename from src/editors/application/analysis-features/enabled-analysis-features-repository.php rename to src/editors/application/analysis-features/analysis-features-repository.php index 9261d22aba3..d70aa57e4c9 100644 --- a/src/editors/application/analysis-features/enabled-analysis-features-repository.php +++ b/src/editors/application/analysis-features/analysis-features-repository.php @@ -12,7 +12,7 @@ * * @makePublic */ -class Enabled_Analysis_Features_Repository { +class Analysis_Features_Repository { /** * All plugin features. @@ -35,14 +35,14 @@ public function __construct( Analysis_Feature_Interface ...$plugin_features ) { * * @return Analysis_Features_List The analysis list. */ - public function get_enabled_features(): Analysis_Features_List { - $enabled_analysis_features = new Analysis_Features_List(); + public function get_analysis_features(): Analysis_Features_List { + $analysis_features_list = new Analysis_Features_List(); foreach ( $this->plugin_features as $plugin_feature ) { $analysis_feature = new Analysis_Feature( $plugin_feature->is_enabled(), $plugin_feature->get_name(), $plugin_feature->get_legacy_key() ); - $enabled_analysis_features->add_feature( $analysis_feature ); + $analysis_features_list->add_feature( $analysis_feature ); } - return $enabled_analysis_features; + return $analysis_features_list; } /** @@ -52,16 +52,16 @@ public function get_enabled_features(): Analysis_Features_List { * * @return Analysis_Features_List The analysis list. */ - public function get_enabled_features_by_keys( array $feature_names ): Analysis_Features_List { - $enabled_analysis_features = new Analysis_Features_List(); + public function get_analysis_features_by_keys( array $feature_names ): Analysis_Features_List { + $analysis_features_list = new Analysis_Features_List(); foreach ( $this->plugin_features as $plugin_feature ) { if ( \in_array( $plugin_feature->get_name(), $feature_names, true ) ) { $analysis_feature = new Analysis_Feature( $plugin_feature->is_enabled(), $plugin_feature->get_name(), $plugin_feature->get_legacy_key() ); - $enabled_analysis_features->add_feature( $analysis_feature ); + $analysis_features_list->add_feature( $analysis_feature ); } } - return $enabled_analysis_features; + return $analysis_features_list; } } From ae7b25649da6cd722ef6d7fd40022beb3441b92a Mon Sep 17 00:00:00 2001 From: Thijs van der heijden Date: Mon, 18 Nov 2024 16:19:22 +0100 Subject: [PATCH 3/4] Revert "Small refactor + feedback." This reverts commit 042d654d925876f63ca2112c8a5d8108bb0b971e. --- admin/formatter/class-metabox-formatter.php | 21 +++++++++--------- .../configuration/dashboard-configuration.php | 22 +++++++++---------- ... enabled-analysis-features-repository.php} | 18 +++++++-------- 3 files changed, 30 insertions(+), 31 deletions(-) rename src/editors/application/analysis-features/{analysis-features-repository.php => enabled-analysis-features-repository.php} (74%) diff --git a/admin/formatter/class-metabox-formatter.php b/admin/formatter/class-metabox-formatter.php index aeabaacf4c4..02deb3c8eb4 100644 --- a/admin/formatter/class-metabox-formatter.php +++ b/admin/formatter/class-metabox-formatter.php @@ -6,7 +6,7 @@ */ use Yoast\WP\SEO\Config\Schema_Types; -use Yoast\WP\SEO\Editors\Application\Analysis_Features\Analysis_Features_Repository; +use Yoast\WP\SEO\Editors\Application\Analysis_Features\Enabled_Analysis_Features_Repository; use Yoast\WP\SEO\Editors\Application\Integrations\Integration_Information_Repository; /** @@ -51,32 +51,31 @@ private function get_defaults() { $schema_types = new Schema_Types(); $defaults = [ - 'author_name' => get_the_author_meta( 'display_name' ), - 'keyword_usage' => [], - 'title_template' => '', - 'metadesc_template' => '', - 'schema' => [ + 'author_name' => get_the_author_meta( 'display_name' ), + 'keyword_usage' => [], + 'title_template' => '', + 'metadesc_template' => '', + 'schema' => [ 'displayFooter' => WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ), 'pageTypeOptions' => $schema_types->get_page_type_options(), 'articleTypeOptions' => $schema_types->get_article_type_options(), ], - 'twitterCardType' => 'summary_large_image', + 'twitterCardType' => 'summary_large_image', /** * Filter to determine if the markers should be enabled or not. * * @param bool $showMarkers Should the markers being enabled. Default = true. */ - 'show_markers' => apply_filters( 'wpseo_enable_assessment_markers', true ), + 'show_markers' => apply_filters( 'wpseo_enable_assessment_markers', true ), ]; $integration_information_repo = YoastSEO()->classes->get( Integration_Information_Repository::class ); $enabled_integrations = $integration_information_repo->get_integration_information(); $defaults = array_merge( $defaults, $enabled_integrations ); - $enabled_features_repo = YoastSEO()->classes->get( Analysis_Features_Repository::class ); - - $enabled_features = $enabled_features_repo->get_analysis_features()->parse_to_legacy_array(); + $enabled_features_repo = YoastSEO()->classes->get( Enabled_Analysis_Features_Repository::class ); + $enabled_features = $enabled_features_repo->get_enabled_features()->parse_to_legacy_array(); return array_merge( $defaults, $enabled_features ); } } diff --git a/src/dashboard/application/configuration/dashboard-configuration.php b/src/dashboard/application/configuration/dashboard-configuration.php index f55073169b9..2a578848775 100644 --- a/src/dashboard/application/configuration/dashboard-configuration.php +++ b/src/dashboard/application/configuration/dashboard-configuration.php @@ -5,7 +5,7 @@ namespace Yoast\WP\SEO\Dashboard\Application\Configuration; use Yoast\WP\SEO\Dashboard\Application\Content_Types\Content_Types_Repository; -use Yoast\WP\SEO\Editors\Application\Analysis_Features\Analysis_Features_Repository; +use Yoast\WP\SEO\Editors\Application\Analysis_Features\Enabled_Analysis_Features_Repository; use Yoast\WP\SEO\Editors\Framework\Keyphrase_Analysis; use Yoast\WP\SEO\Editors\Framework\Readability_Analysis; use Yoast\WP\SEO\Helpers\Indexable_Helper; @@ -40,23 +40,23 @@ class Dashboard_Configuration { /** * The repository. * - * @var Analysis_Features_Repository + * @var Enabled_Analysis_Features_Repository */ private $analysis_features_repository; /** * The constructor. * - * @param Content_Types_Repository $content_types_repository The content types repository. - * @param Indexable_Helper $indexable_helper The indexable helper repository. - * @param User_Helper $user_helper The user helper. - * @param Analysis_Features_Repository $analysis_features_repository The analysis feature repository. + * @param Content_Types_Repository $content_types_repository The content types repository. + * @param Indexable_Helper $indexable_helper The indexable helper repository. + * @param User_Helper $user_helper The user helper. + * @param Enabled_Analysis_Features_Repository $analysis_features_repository The analysis feature repository. */ public function __construct( Content_Types_Repository $content_types_repository, Indexable_Helper $indexable_helper, User_Helper $user_helper, - Analysis_Features_Repository $analysis_features_repository + Enabled_Analysis_Features_Repository $analysis_features_repository ) { $this->content_types_repository = $content_types_repository; $this->indexable_helper = $indexable_helper; @@ -71,10 +71,10 @@ public function __construct( */ public function get_configuration(): array { return [ - 'contentTypes' => $this->content_types_repository->get_content_types(), - 'indexablesEnabled' => $this->indexable_helper->should_index_indexables(), - 'displayName' => $this->user_helper->get_current_user_display_name(), - 'analysisFeatures' => $this->analysis_features_repository->get_analysis_features_by_keys( + 'contentTypes' => $this->content_types_repository->get_content_types(), + 'indexablesEnabled' => $this->indexable_helper->should_index_indexables(), + 'displayName' => $this->user_helper->get_current_user_display_name(), + 'enabledAnalysisFeatures' => $this->analysis_features_repository->get_enabled_features_by_keys( [ Readability_Analysis::NAME, Keyphrase_Analysis::NAME, diff --git a/src/editors/application/analysis-features/analysis-features-repository.php b/src/editors/application/analysis-features/enabled-analysis-features-repository.php similarity index 74% rename from src/editors/application/analysis-features/analysis-features-repository.php rename to src/editors/application/analysis-features/enabled-analysis-features-repository.php index d70aa57e4c9..9261d22aba3 100644 --- a/src/editors/application/analysis-features/analysis-features-repository.php +++ b/src/editors/application/analysis-features/enabled-analysis-features-repository.php @@ -12,7 +12,7 @@ * * @makePublic */ -class Analysis_Features_Repository { +class Enabled_Analysis_Features_Repository { /** * All plugin features. @@ -35,14 +35,14 @@ public function __construct( Analysis_Feature_Interface ...$plugin_features ) { * * @return Analysis_Features_List The analysis list. */ - public function get_analysis_features(): Analysis_Features_List { - $analysis_features_list = new Analysis_Features_List(); + public function get_enabled_features(): Analysis_Features_List { + $enabled_analysis_features = new Analysis_Features_List(); foreach ( $this->plugin_features as $plugin_feature ) { $analysis_feature = new Analysis_Feature( $plugin_feature->is_enabled(), $plugin_feature->get_name(), $plugin_feature->get_legacy_key() ); - $analysis_features_list->add_feature( $analysis_feature ); + $enabled_analysis_features->add_feature( $analysis_feature ); } - return $analysis_features_list; + return $enabled_analysis_features; } /** @@ -52,16 +52,16 @@ public function get_analysis_features(): Analysis_Features_List { * * @return Analysis_Features_List The analysis list. */ - public function get_analysis_features_by_keys( array $feature_names ): Analysis_Features_List { - $analysis_features_list = new Analysis_Features_List(); + public function get_enabled_features_by_keys( array $feature_names ): Analysis_Features_List { + $enabled_analysis_features = new Analysis_Features_List(); foreach ( $this->plugin_features as $plugin_feature ) { if ( \in_array( $plugin_feature->get_name(), $feature_names, true ) ) { $analysis_feature = new Analysis_Feature( $plugin_feature->is_enabled(), $plugin_feature->get_name(), $plugin_feature->get_legacy_key() ); - $analysis_features_list->add_feature( $analysis_feature ); + $enabled_analysis_features->add_feature( $analysis_feature ); } } - return $analysis_features_list; + return $enabled_analysis_features; } } From c154ab86dd3374fb9a18a021059ff59984e1777f Mon Sep 17 00:00:00 2001 From: Thijs van der heijden Date: Mon, 18 Nov 2024 16:21:54 +0100 Subject: [PATCH 4/4] Revert refactors. --- .../configuration/dashboard-configuration.php | 24 ++++++++++--------- .../enabled-analysis-features-repository.php | 23 ++++++++++++------ 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/dashboard/application/configuration/dashboard-configuration.php b/src/dashboard/application/configuration/dashboard-configuration.php index 2a578848775..c9eb9fef674 100644 --- a/src/dashboard/application/configuration/dashboard-configuration.php +++ b/src/dashboard/application/configuration/dashboard-configuration.php @@ -42,26 +42,28 @@ class Dashboard_Configuration { * * @var Enabled_Analysis_Features_Repository */ - private $analysis_features_repository; + private $enabled_analysis_features_repository; /** * The constructor. * - * @param Content_Types_Repository $content_types_repository The content types repository. - * @param Indexable_Helper $indexable_helper The indexable helper repository. - * @param User_Helper $user_helper The user helper. - * @param Enabled_Analysis_Features_Repository $analysis_features_repository The analysis feature repository. + * @param Content_Types_Repository $content_types_repository The content types repository. + * @param Indexable_Helper $indexable_helper The indexable helper + * repository. + * @param User_Helper $user_helper The user helper. + * @param Enabled_Analysis_Features_Repository $enabled_analysis_features_repository The analysis feature + * repository. */ public function __construct( Content_Types_Repository $content_types_repository, Indexable_Helper $indexable_helper, User_Helper $user_helper, - Enabled_Analysis_Features_Repository $analysis_features_repository + Enabled_Analysis_Features_Repository $enabled_analysis_features_repository ) { - $this->content_types_repository = $content_types_repository; - $this->indexable_helper = $indexable_helper; - $this->user_helper = $user_helper; - $this->analysis_features_repository = $analysis_features_repository; + $this->content_types_repository = $content_types_repository; + $this->indexable_helper = $indexable_helper; + $this->user_helper = $user_helper; + $this->enabled_analysis_features_repository = $enabled_analysis_features_repository; } /** @@ -74,7 +76,7 @@ public function get_configuration(): array { 'contentTypes' => $this->content_types_repository->get_content_types(), 'indexablesEnabled' => $this->indexable_helper->should_index_indexables(), 'displayName' => $this->user_helper->get_current_user_display_name(), - 'enabledAnalysisFeatures' => $this->analysis_features_repository->get_enabled_features_by_keys( + 'enabledAnalysisFeatures' => $this->enabled_analysis_features_repository->get_features_by_keys( [ Readability_Analysis::NAME, Keyphrase_Analysis::NAME, diff --git a/src/editors/application/analysis-features/enabled-analysis-features-repository.php b/src/editors/application/analysis-features/enabled-analysis-features-repository.php index 9261d22aba3..66312a610a7 100644 --- a/src/editors/application/analysis-features/enabled-analysis-features-repository.php +++ b/src/editors/application/analysis-features/enabled-analysis-features-repository.php @@ -21,13 +21,21 @@ class Enabled_Analysis_Features_Repository { */ private $plugin_features; + /** + * The list of analysis features. + * + * @var Analysis_Features_List + */ + private $enabled_analysis_features; + /** * The constructor. * * @param Analysis_Feature_Interface ...$plugin_features All analysis objects. */ public function __construct( Analysis_Feature_Interface ...$plugin_features ) { - $this->plugin_features = $plugin_features; + $this->enabled_analysis_features = new Analysis_Features_List(); + $this->plugin_features = $plugin_features; } /** @@ -36,13 +44,14 @@ public function __construct( Analysis_Feature_Interface ...$plugin_features ) { * @return Analysis_Features_List The analysis list. */ public function get_enabled_features(): Analysis_Features_List { - $enabled_analysis_features = new Analysis_Features_List(); - foreach ( $this->plugin_features as $plugin_feature ) { - $analysis_feature = new Analysis_Feature( $plugin_feature->is_enabled(), $plugin_feature->get_name(), $plugin_feature->get_legacy_key() ); - $enabled_analysis_features->add_feature( $analysis_feature ); + if ( \count( $this->enabled_analysis_features->parse_to_legacy_array() ) === 0 ) { + foreach ( $this->plugin_features as $plugin_feature ) { + $analysis_feature = new Analysis_Feature( $plugin_feature->is_enabled(), $plugin_feature->get_name(), $plugin_feature->get_legacy_key() ); + $this->enabled_analysis_features->add_feature( $analysis_feature ); + } } - return $enabled_analysis_features; + return $this->enabled_analysis_features; } /** @@ -52,7 +61,7 @@ public function get_enabled_features(): Analysis_Features_List { * * @return Analysis_Features_List The analysis list. */ - public function get_enabled_features_by_keys( array $feature_names ): Analysis_Features_List { + public function get_features_by_keys( array $feature_names ): Analysis_Features_List { $enabled_analysis_features = new Analysis_Features_List(); foreach ( $this->plugin_features as $plugin_feature ) {