Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
Logo
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 8
240
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 validate_parameters
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
30
 set_properties
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 get_reference_id
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_style
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_url
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 to_array
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 from_array
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace NewfoldLabs\WP\Module\Onboarding\Types;
4
5/**
6 * Logo data type class.
7 *
8 * Represents a logo with reference ID, style, and URL.
9 *
10 * @package NewfoldLabs\WP\Module\Onboarding\Types
11 *
12 * @example
13 * reference_id: "3FNjUdY"
14 * style: "Text-only"
15 * url: "https://url.com/to/logogen/3FNjUdY-text-only.png"
16 */
17class Logo {
18
19    /**
20     * Logo reference ID.
21     *
22     * @var string
23     */
24    private $reference_id;
25
26    /**
27     * Logo style.
28     *
29     * @var string
30     */
31    private $style;
32
33    /**
34     * Logo URL.
35     *
36     * @var string
37     */
38    private $url;
39
40    /**
41     * Logo constructor.
42     *
43     * @param string $reference_id Logo reference ID - e.g. "3FNjUdY".
44     * @param string $style Logo style - e.g. "Text-only".
45     * @param string $url Logo URL - e.g. "https://cloud-patterns.test/storage/logogen/3FNjUdY-text-only.png".
46     * @throws \InvalidArgumentException When parameters are invalid.
47     */
48    public function __construct( string $reference_id, string $style, string $url ) {
49        $this->validate_parameters( $reference_id, $style, $url );
50        $this->set_properties( $reference_id, $style, $url );
51    }
52
53    /**
54     * Validate constructor parameters.
55     *
56     * @param string $reference_id Logo reference ID.
57     * @param string $style Logo style.
58     * @param string $url Logo URL.
59     * @throws \InvalidArgumentException When parameters are invalid.
60     */
61    private function validate_parameters( string $reference_id, string $style, string $url ): void {
62        if ( empty( trim( $reference_id ) ) ) {
63            throw new \InvalidArgumentException( 'Reference ID cannot be empty' );
64        }
65
66        if ( empty( trim( $style ) ) ) {
67            throw new \InvalidArgumentException( 'Style cannot be empty' );
68        }
69
70        if ( empty( trim( $url ) ) ) {
71            throw new \InvalidArgumentException( 'URL cannot be empty' );
72        }
73
74        if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) {
75            throw new \InvalidArgumentException( 'URL must be a valid URL' );
76        }
77    }
78
79    /**
80     * Set properties from parameters.
81     *
82     * @param string $reference_id Logo reference ID.
83     * @param string $style Logo style.
84     * @param string $url Logo URL.
85     */
86    private function set_properties( string $reference_id, string $style, string $url ): void {
87        $this->reference_id = trim( $reference_id );
88        $this->style        = trim( $style );
89        $this->url          = trim( $url );
90    }
91
92    /**
93     * Get reference ID.
94     *
95     * @return string
96     */
97    public function get_reference_id(): string {
98        return $this->reference_id;
99    }
100
101    /**
102     * Get style.
103     *
104     * @return string
105     */
106    public function get_style(): string {
107        return $this->style;
108    }
109
110    /**
111     * Get URL.
112     *
113     * @return string
114     */
115    public function get_url(): string {
116        return $this->url;
117    }
118
119    /**
120     * Convert to array.
121     *
122     * @return array
123     */
124    public function to_array(): array {
125        return array(
126            'reference_id' => $this->reference_id,
127            'style'        => $this->style,
128            'url'          => $this->url,
129        );
130    }
131
132    /**
133     * Create from array (static factory method).
134     *
135     * @param array $data Logo data array.
136     * @return Logo
137     * @throws \InvalidArgumentException When required keys are missing.
138     */
139    public static function from_array( array $data ): Logo {
140        if ( ! isset( $data['reference_id'] ) || ! isset( $data['style'] ) || ! isset( $data['url'] ) ) {
141            throw new \InvalidArgumentException( 'Array must contain reference_id, style, and url keys' );
142        }
143
144        return new self( $data['reference_id'], $data['style'], $data['url'] );
145    }
146}