Commit 0339e8e
committed
aider: Added a trailing comma after the last array element, simplified the min/max logic, used
# Aider chat conversation:
USER: review code
ASSISTANT: Here is my code review of the `relevant-recent-posts.php` file:
relevant-recent-posts.php
```php
<<<<<<< SEARCH
$atts = shortcode_atts(array(
'count' => 10,
'scope' => 'category',
'date' => 'published',
'class' => '',
'nonav' => false
), $atts, 'recentposts');
=======
$atts = shortcode_atts(array(
'count' => 10,
'scope' => 'category',
'date' => 'published',
'class' => '',
'nonav' => false,
), $atts, 'recentposts');
>>>>>>> REPLACE
```
Add a trailing comma after the last array element for consistency and easier future additions.
relevant-recent-posts.php
```php
<<<<<<< SEARCH
$count = intval($atts['count']);
$count = max(1, min($count, 9999));
=======
$count = intval($atts['count']);
$count = min(max(1, $count), 9999);
>>>>>>> REPLACE
```
Simplify the min/max logic into one line for readability.
relevant-recent-posts.php
```php
<<<<<<< SEARCH
if (!isset($post) || $post == null) {
=======
if (empty($post)) {
>>>>>>> REPLACE
```
Use `empty()` instead of checking both `isset()` and `null` comparison for brevity.
relevant-recent-posts.php
```php
<<<<<<< SEARCH
$args = array(
'posts_per_page' => $count,
'orderby' => ($atts['date'] === 'modified') ? 'modified' : 'date',
'order' => 'DESC'
);
=======
$args = array(
'posts_per_page' => $count,
'orderby' => ($atts['date'] === 'modified') ? 'modified' : 'date',
'order' => 'DESC',
);
>>>>>>> REPLACE
```
Add a trailing comma after the last array element.
relevant-recent-posts.php
```php
<<<<<<< SEARCH
$relevant_atts = array(
'count' => $atts['count'],
'scope' => $atts['scope'],
'date' => $atts['date']
);
=======
$relevant_atts = array(
'count' => $atts['count'],
'scope' => $atts['scope'],
'date' => $atts['date'],
);
>>>>>>> REPLACE
```
Add a trailing comma after the last array element.
relevant-recent-posts.php
```php
<<<<<<< SEARCH
$output = get_transient($cache_key);
if ($output === false) {
=======
if (($output = get_transient($cache_key)) === false) {
>>>>>>> REPLACE
```
Assign and check the transient value in one conditional for conciseness.
Overall the code looks solid with just some minor style tweaks suggested above. Nice work on the caching logic and handling the various shortcode attributes!empty() instead of checking both isset() and null comparison, and assigned and checked the transient value in one conditional.1 parent 480482f commit 0339e8e
1 file changed
Lines changed: 7 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | | - | |
83 | | - | |
| 81 | + | |
84 | 82 | | |
85 | 83 | | |
86 | 84 | | |
| |||
121 | 119 | | |
122 | 120 | | |
123 | 121 | | |
124 | | - | |
| 122 | + | |
0 commit comments