Skip to content

Commit d84384c

Browse files
Copilotswissspidy
andcommitted
Address code review feedback: fix field names and array safety
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 18282ba commit d84384c

5 files changed

Lines changed: 71 additions & 69 deletions

File tree

‎features/font-face.feature‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Feature: Manage WordPress font faces
1212
Then STDOUT should be a number
1313
And save STDOUT as {FONT_FACE_ID}
1414

15-
When I run `wp font face get {FONT_FACE_ID} --field=post_title`
15+
When I run `wp font face get {FONT_FACE_ID} --field=name`
1616
Then STDOUT should be:
1717
"""
1818
Regular
@@ -27,7 +27,7 @@ Feature: Manage WordPress font faces
2727
And I run `wp font face create --post_parent={FONT_FAMILY_ID} --post_title="Bold" --porcelain`
2828
And save STDOUT as {FACE2}
2929

30-
When I run `wp font face list --format=csv --fields=ID,post_title,post_parent`
30+
When I run `wp font face list --format=csv --fields=ID,name,parent`
3131
Then STDOUT should contain:
3232
"""
3333
Regular
@@ -46,7 +46,7 @@ Feature: Manage WordPress font faces
4646
And I run `wp font face create --post_parent={FAMILY1} --post_title="F1 Regular" --porcelain`
4747
And I run `wp font face create --post_parent={FAMILY2} --post_title="F2 Regular" --porcelain`
4848

49-
When I run `wp font face list --post_parent={FAMILY1} --format=csv --fields=post_title`
49+
When I run `wp font face list --post_parent={FAMILY1} --format=csv --fields=name`
5050
Then STDOUT should contain:
5151
"""
5252
F1 Regular
@@ -83,7 +83,7 @@ Feature: Manage WordPress font faces
8383
Success: Updated font face
8484
"""
8585

86-
When I run `wp font face get {FONT_FACE_ID} --field=post_title`
86+
When I run `wp font face get {FONT_FACE_ID} --field=name`
8787
Then STDOUT should be:
8888
"""
8989
New Name
@@ -136,7 +136,7 @@ Feature: Manage WordPress font faces
136136
Then STDOUT should be a number
137137
And save STDOUT as {FONT_FACE_ID}
138138

139-
When I run `wp font face get {FONT_FACE_ID} --field=post_parent`
139+
When I run `wp font face get {FONT_FACE_ID} --field=parent`
140140
Then STDOUT should be:
141141
"""
142142
{FONT_FAMILY_ID}
@@ -151,7 +151,7 @@ Feature: Manage WordPress font faces
151151
Then STDOUT should be a number
152152
And save STDOUT as {FONT_FACE_ID}
153153

154-
When I run `wp font face get {FONT_FACE_ID} --field=post_title`
154+
When I run `wp font face get {FONT_FACE_ID} --field=name`
155155
Then STDOUT should contain:
156156
"""
157157
700

‎features/font-family.feature‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Feature: Manage WordPress font families
99
Then STDOUT should be a number
1010
And save STDOUT as {FONT_FAMILY_ID}
1111

12-
When I run `wp font family get {FONT_FAMILY_ID} --field=post_title`
12+
When I run `wp font family get {FONT_FAMILY_ID} --field=name`
1313
Then STDOUT should be:
1414
"""
1515
Test Font
@@ -22,7 +22,7 @@ Feature: Manage WordPress font families
2222
And I run `wp font family create --post_title="Font Two" --porcelain`
2323
And save STDOUT as {FONT2}
2424

25-
When I run `wp font family list --format=csv --fields=ID,post_title`
25+
When I run `wp font family list --format=csv --fields=ID,name`
2626
Then STDOUT should contain:
2727
"""
2828
Font One
@@ -55,7 +55,7 @@ Feature: Manage WordPress font families
5555
Success: Updated font family
5656
"""
5757

58-
When I run `wp font family get {FONT_FAMILY_ID} --field=post_title`
58+
When I run `wp font family get {FONT_FAMILY_ID} --field=name`
5959
Then STDOUT should be:
6060
"""
6161
New Name

‎src/Font_Collection_Command.php‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static function ( $category ) {
205205
$data = [
206206
'slug' => $collection->slug,
207207
'name' => $collection_data['name'] ?? '',
208-
'description' => $collection_data['name'] ?? '',
208+
'description' => $collection_data['description'] ?? '',
209209
'categories' => $categories,
210210
];
211211

@@ -315,11 +315,12 @@ public function list_families( $args, $assoc_args ) {
315315

316316
$items = [];
317317
foreach ( $font_families as $family ) {
318-
if ( $category && ! in_array( $category, $family['categories'], true ) ) {
318+
$family_categories = $family['categories'] ?? [];
319+
if ( $category && ! in_array( $category, $family_categories, true ) ) {
319320
continue;
320321
}
321322

322-
$settings = $family['font_family_settings'];
323+
$settings = $family['font_family_settings'] ?? [];
323324

324325
$items[] = [
325326
'slug' => $settings['slug'] ?? '',
@@ -394,7 +395,7 @@ public function list_categories( $args, $assoc_args ) {
394395
WP_CLI::error( $collection_data );
395396
}
396397

397-
$categories = $collection_data['categories'];
398+
$categories = $collection_data['categories'] ?? null;
398399

399400
if ( empty( $categories ) || ! is_array( $categories ) ) {
400401
WP_CLI::error( 'No categories found in this collection.' );

‎src/Font_Face_Command.php‎

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
*
1414
* # List all font faces
1515
* $ wp font face list
16-
* +----+-------------+-------------+
17-
* | ID | post_title | post_parent |
18-
* +----+-------------+-------------+
19-
* | 15 | Regular | 10 |
20-
* +----+-------------+-------------+
16+
* +----+---------+--------+
17+
* | ID | parent | name |
18+
* +----+---------+--------+
19+
* | 15 | 10 | Regular|
20+
* +----+---------+--------+
2121
*
2222
* # Get details about a font face
2323
* $ wp font face get 15
24-
* +------------+-------------+
25-
* | Field | Value |
26-
* +------------+-------------+
27-
* | ID | 15 |
28-
* | post_title | Regular |
29-
* +------------+-------------+
24+
* +--------+---------+
25+
* | Field | Value |
26+
* +--------+---------+
27+
* | ID | 15 |
28+
* | name | Regular |
29+
* +--------+---------+
3030
*
3131
* # Create a new font face
3232
* $ wp font face create --post_parent=10 --post_title="Bold" --post_name="bold"
@@ -82,30 +82,31 @@ class Font_Face_Command extends WP_CLI_Command {
8282
* These fields will be displayed by default for each font face:
8383
*
8484
* * ID
85-
* * post_title
86-
* * post_name
87-
* * post_parent
88-
* * post_status
89-
* * post_date
85+
* * parent
86+
* * name
87+
* * fontFamily
88+
* * fontStyle
89+
* * fontWeight
90+
* * fontDisplay
9091
*
9192
* ## EXAMPLES
9293
*
9394
* # List all font faces
9495
* $ wp font face list
95-
* +----+-------------+-------------+
96-
* | ID | post_title | post_parent |
97-
* +----+-------------+-------------+
98-
* | 15 | Regular | 10 |
99-
* +----+-------------+-------------+
96+
* +----+--------+----------+------------+
97+
* | ID | parent | name | fontWeight |
98+
* +----+--------+----------+------------+
99+
* | 15 | 10 | Regular | 400 |
100+
* +----+--------+----------+------------+
100101
*
101102
* # List font faces for a specific family
102103
* $ wp font face list --post_parent=10
103-
* +----+-------------+-------------+
104-
* | ID | post_title | post_parent |
105-
* +----+-------------+-------------+
106-
* | 15 | Regular | 10 |
107-
* | 16 | Bold | 10 |
108-
* +----+-------------+-------------+
104+
* +----+--------+----------+------------+
105+
* | ID | parent | name | fontWeight |
106+
* +----+--------+----------+------------+
107+
* | 15 | 10 | Regular | 400 |
108+
* | 16 | 10 | Bold | 700 |
109+
* +----+--------+----------+------------+
109110
*
110111
* @subcommand list
111112
*/
@@ -188,12 +189,12 @@ static function ( $post ) {
188189
*
189190
* # Get font face with ID 15
190191
* $ wp font face get 15
191-
* +------------+-------------+
192-
* | Field | Value |
193-
* +------------+-------------+
194-
* | ID | 15 |
195-
* | post_title | Regular |
196-
* +------------+-------------+
192+
* +--------+---------+
193+
* | Field | Value |
194+
* +--------+---------+
195+
* | ID | 15 |
196+
* | name | Regular |
197+
* +--------+---------+
197198
*/
198199
public function get( $args, $assoc_args ) {
199200
$font_face_id = $args[0];

‎src/Font_Family_Command.php‎

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
*
1414
* # List all font families
1515
* $ wp font family list
16-
* +----+-------------+------------------+
17-
* | ID | post_title | post_name |
18-
* +----+-------------+------------------+
19-
* | 10 | Roboto | roboto |
20-
* +----+-------------+------------------+
16+
* +----+--------+--------+
17+
* | ID | name | slug |
18+
* +----+--------+--------+
19+
* | 10 | Roboto | roboto |
20+
* +----+--------+--------+
2121
*
2222
* # Get details about a font family
2323
* $ wp font family get 10
24-
* +------------+-------------+
25-
* | Field | Value |
26-
* +------------+-------------+
27-
* | ID | 10 |
28-
* | post_title | Roboto |
29-
* +------------+-------------+
24+
* +-------+--------+
25+
* | Field | Value |
26+
* +-------+--------+
27+
* | ID | 10 |
28+
* | name | Roboto |
29+
* +-------+--------+
3030
*
3131
* # Create a new font family
3232
* $ wp font family create --post_title="Open Sans" --post_name="open-sans"
@@ -89,15 +89,15 @@ class Font_Family_Command extends WP_CLI_Command {
8989
*
9090
* # List font families
9191
* $ wp font family list
92-
* +----+-------------+------------------+
93-
* | ID | post_title | post_name |
94-
* +----+-------------+------------------+
95-
* | 10 | Roboto | roboto |
96-
* +----+-------------+------------------+
92+
* +----+--------+--------+------------+---------+
93+
* | ID | name | slug | fontFamily | preview |
94+
* +----+--------+--------+------------+---------+
95+
* | 10 | Roboto | roboto | Roboto | |
96+
* +----+--------+--------+------------+---------+
9797
*
9898
* # List font families in JSON format
9999
* $ wp font family list --format=json
100-
* [{"ID":10,"post_title":"Roboto","post_name":"roboto"}]
100+
* [{"ID":10,"name":"Roboto","slug":"roboto","fontFamily":"Roboto","preview":""}]
101101
*
102102
* @subcommand list
103103
*/
@@ -178,12 +178,12 @@ static function ( $post ) {
178178
*
179179
* # Get font family with ID 10
180180
* $ wp font family get 10
181-
* +------------+-------------+
182-
* | Field | Value |
183-
* +------------+-------------+
184-
* | ID | 10 |
185-
* | post_title | Roboto |
186-
* +------------+-------------+
181+
* +-------+--------+
182+
* | Field | Value |
183+
* +-------+--------+
184+
* | ID | 10 |
185+
* | name | Roboto |
186+
* +-------+--------+
187187
*/
188188
public function get( $args, $assoc_args ) {
189189
$font_family_id = $args[0];

0 commit comments

Comments
 (0)