PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.9
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.9
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / task-list / domain / components / call-to-action-entry.php

call-to-action-entry.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.9, at src/task-list/domain/components/call-to-action-entry.php

110 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
4 namespace Yoast\WP\SEO\Task_List\Domain\Components;
5
6 use InvalidArgumentException;
7
8 /**
9 * This class describes a Call To Action Entry.
10 */
11 class Call_To_Action_Entry {
12
13 /**
14 * Allowed types for the call to action.
15 *
16 * @var string[]
17 */
18 private const ALLOWED_TYPES = [
19 'default',
20 'link',
21 'add',
22 'delete',
23 'edit',
24 ];
25
26 /**
27 * The label of the call to action.
28 *
29 * @var string
30 */
31 private $label;
32
33 /**
34 * The type of the call to action.
35 *
36 * @var string
37 */
38 private $type;
39
40 /**
41 * The href of the call to action.
42 *
43 * @var string
44 */
45 private $href;
46
47 /**
48 * The constructor.
49 *
50 * @param string $label The label of the content type entry.
51 * @param string $type The type of the content type entry.
52 * @param string $href The href of the content type entry.
53 *
54 * @throws InvalidArgumentException If the type is invalid.
55 */
56 public function __construct(
57 string $label,
58 string $type,
59 ?string $href = null
60 ) {
61 if ( ! \in_array( $type, self::ALLOWED_TYPES, true ) ) {
62 throw new InvalidArgumentException( 'Invalid type for call to action' );
63 }
64
65 $this->label = $label;
66 $this->type = $type;
67 $this->href = $href;
68 }
69
70 /**
71 * Returns the task's label.
72 *
73 * @return string|null
74 */
75 public function get_label(): ?string {
76 return $this->label;
77 }
78
79 /**
80 * Returns the task's type.
81 *
82 * @return string|null
83 */
84 public function get_type(): ?string {
85 return $this->type;
86 }
87
88 /**
89 * Returns the task's href.
90 *
91 * @return string|null
92 */
93 public function get_href(): ?string {
94 return $this->href;
95 }
96
97 /**
98 * Returns an array representation of the call to action data.
99 *
100 * @return array<string, string|bool> Returns in an array format.
101 */
102 public function to_array(): array {
103 return [
104 'label' => $this->label,
105 'type' => $this->type,
106 'href' => $this->href,
107 ];
108 }
109 }
110