Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
ContentGenerationPrompt
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 5
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 validate_input
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
20
 get_refined_site_description
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_meta_response
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 get_prompt
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * Content Generation Prompt Class
4 *
5 * This file contains the ContentGenerationPrompt class which processes
6 * site info entered during onboarding and generates structured prompt
7 * for AI content generation.
8 *
9 * @package NewfoldLabs\WP\Module\Onboarding\Services\Ai\ContentGeneration
10 */
11
12namespace NewfoldLabs\WP\Module\Onboarding\Services\Ai\ContentGeneration;
13
14use NewfoldLabs\WP\Module\AI\SiteGen\SiteGen;
15use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService as LegacySiteGenService;
16
17/**
18 * Content Generation Prompt Class
19 *
20 * This class processes the site info entered during onboarding and generates
21 * structured prompt for AI content generation.
22 */
23class ContentGenerationPrompt {
24
25    /**
26     * The original site description provided by the user.
27     *
28     * @var string
29     */
30    private $site_description;
31
32    /**
33     * The type of site (e.g., 'business', 'blog', 'ecommerce').
34     *
35     * @var string
36     */
37    private $site_type;
38
39    /**
40     * The locale/language code for the site.
41     *
42     * @var string
43     */
44    private $locale;
45
46    /**
47     * The required site meta dependencies.
48     *
49     * @var array
50     */
51    private $prompt_site_meta_dependencies = array(
52        'target_audience',
53        'content_tones',
54        'keywords',
55    );
56
57    /**
58     * Constructor for ContentGenerationPrompt.
59     *
60     * @param string $site_description The user-provided site description.
61     * @param string $site_type       The type of site (e.g., 'business', 'personal', 'ecommerce').
62     * @param string $locale          The locale/language code for the site.
63     */
64    public function __construct( $site_description, $site_type, $locale ) {
65        $this->validate_input( $site_description, $site_type, $locale );
66
67        $this->site_description = trim( $site_description );
68        $this->site_type        = trim( $site_type );
69        $this->locale           = trim( $locale );
70    }
71
72    /**
73     * Validates the input parameters.
74     *
75     * @param string $site_description The site description.
76     * @param string $site_type        The site type.
77     * @param string $locale           The locale.
78     *
79     * @throws \Exception If any parameter is empty.
80     */
81    private function validate_input( $site_description, $site_type, $locale ) {
82        if ( empty( $site_description ) ) {
83            throw new \Exception( 'Site description cannot be empty' );
84        }
85
86        if ( empty( $site_type ) ) {
87            throw new \Exception( 'Site type cannot be empty' );
88        }
89
90        if ( empty( $locale ) ) {
91            throw new \Exception( 'Locale cannot be empty' );
92        }
93    }
94
95    /**
96     * Sets the refined site description using AI processing.
97     *
98     * @return string The refined site description.
99     */
100    private function get_refined_site_description(): string {
101        return SiteGen::get_refined_site_description( $this->site_description );
102    }
103
104    /**
105     * Gets the meta response for the site meta dependency.
106     *
107     * @param string $site_meta_dependency The site meta dependency.
108     *
109     * @return array The meta response.
110     */
111    private function get_meta_response( $site_meta_dependency ): array {
112        $response = LegacySiteGenService::instantiate_site_meta(
113            $this->site_description,
114            $site_meta_dependency,
115            $this->site_type,
116            $this->locale
117        );
118
119        if ( is_wp_error( $response ) ) {
120            return array();
121        }
122
123        return $response;
124    }
125
126    /**
127     * Gets the complete prompt array for content generation.
128     *
129     * @return array {
130     *     The complete prompt array for content generation.
131     *
132     *     @type string $site_description The refined site description.
133     *     @type array  $target_audience  The target audience information.
134     *     @type array  $content_style    The content style/tone information.
135     *     @type array  $keywords         The relevant keywords.
136     * }
137     */
138    public function get_prompt(): array {
139        $prompt = array();
140        $prompt['site_description'] = $this->get_refined_site_description();
141
142        foreach ( $this->prompt_site_meta_dependencies as $site_meta_dependency ) {
143            $prompt[ $site_meta_dependency ] = $this->get_meta_response( $site_meta_dependency );
144        }
145
146        return $prompt;
147    }
148}