*/ public static function all(): array { static $tools = null; if ( null === $tools ) { $tools = array(); foreach ( array( new SalesSummary(), new TopProducts(), new StockRunway(), new OrdersByChannel(), new LapsedCustomers(), new CouponPerformance(), new TodaysOrders(), new Profit(), new SalesBreakdown(), new CustomerRetention(), new DeadStock(), new CustomQuery(), ) as $tool ) { $tools[ $tool->name() ] = $tool; } } return $tools; } /** * A tool by name. * * @param string $name Tool name. */ public static function get( string $name ): ?Tool { return self::all()[ $name ] ?? null; } /** * Whether all of a tool's scopes are on. * * @param Tool $tool Tool. */ public static function is_enabled( Tool $tool ): bool { $scopes = Settings::scopes(); foreach ( $tool->scopes() as $scope ) { if ( empty( $scopes[ $scope ] ) ) { return false; } } return true; } /** * Names of tools the current settings allow. * * @return list */ public static function enabled_names(): array { return array_values( array_map( static fn( Tool $t ): string => $t->name(), array_filter( self::all(), array( self::class, 'is_enabled' ) ) ) ); } }