Skip to content

Commit 1008303

Browse files
authored
Merge pull request #184 from softberg/ai-findings-autofix/shared-Transformers-PostTransformer.php
Potential fixes for 2 code quality findings
2 parents bc8a925 + 9fc8925 commit 1008303

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

shared/Transformers/PostTransformer.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class PostTransformer implements TransformerInterface
2626
{
2727
/**
2828
* Transforms the post data
29-
* @param $item
29+
* @param mixed $item
3030
* @return array
3131
*/
3232
public function transform($item): array
@@ -35,9 +35,24 @@ public function transform($item): array
3535
'uuid' => $item->uuid,
3636
'title' => $item->title,
3737
'content' => markdown_to_html($item->content, true),
38-
'image' => $item->image && $item->user_directory ? $item->user_directory . '/' . $item->image : null,
38+
'image' => $this->buildImagePath($item),
3939
'date' => date('Y/m/d H:i', strtotime($item->updated_at)),
4040
'author' => $item->firstname . ' ' . $item->lastname,
4141
];
4242
}
43+
44+
/**
45+
* Builds the image path for the given item.
46+
*
47+
* @param $item
48+
* @return string|null
49+
*/
50+
private function buildImagePath($item): ?string
51+
{
52+
if ($item->image && $item->user_directory) {
53+
return $item->user_directory . '/' . $item->image;
54+
}
55+
56+
return null;
57+
}
4358
}

0 commit comments

Comments
 (0)