Conditions | 3 |
Paths | 3 |
Total Lines | 20 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
36 | 3 | public function generatePreview(string $url): string |
|
37 | { |
||
38 | 3 | $image = $this->imageBuilder->build(Image::class, ['url' => $url]); |
|
39 | |||
40 | // If the file already exists, return its path |
||
41 | 3 | $cacheId = sprintf('preview_%s.%s', urlencode($url), $image->type); |
|
42 | 3 | $path = $this->location . '/' . $cacheId; |
|
43 | 3 | if ($this->filesystem->exists($path)) { |
|
44 | 1 | return $path; |
|
45 | } |
||
46 | |||
47 | // Save and check if an error occurred |
||
48 | 2 | $image->saveAs($path); |
|
49 | 2 | $error = $image->getError(); |
|
50 | 2 | if (! empty($error)) { |
|
51 | 1 | throw PreviewGenerationException::fromImageError($error); |
|
52 | } |
||
53 | |||
54 | // Cache the path and return it |
||
55 | 1 | return $path; |
|
56 | } |
||
58 |
This interface has been deprecated. The supplier of the interface has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.