mediamonks /
symfony-sonata-media-bundle
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace MediaMonks\SonataMediaBundle\Helper; |
||
| 4 | |||
| 5 | use League\Glide\Filesystem\FilesystemException; |
||
| 6 | use League\Glide\Server; |
||
| 7 | |||
| 8 | class Thumbnail |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var Server |
||
| 12 | */ |
||
| 13 | protected $server; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Thumbnail constructor. |
||
| 17 | * @param Server $server |
||
| 18 | */ |
||
| 19 | public function __construct(Server $server) |
||
| 20 | { |
||
| 21 | $this->server = $server; |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param string $source |
||
| 26 | * @param string $destination |
||
| 27 | * @param array $parameters |
||
| 28 | * @throws FilesystemException |
||
| 29 | */ |
||
| 30 | public function createIfNotExists($source, $destination, array $parameters) |
||
| 31 | { |
||
| 32 | if (!$this->server->getSource()->has($destination)) { |
||
| 33 | $tmp = tempnam(sys_get_temp_dir(), 'media'); |
||
| 34 | View Code Duplication | if (@file_put_contents($tmp, $this->server->getSource()->read($source)) === false) { |
|
|
0 ignored issues
–
show
|
|||
| 35 | throw new FilesystemException('unable_to_write_temporary_media_file'); |
||
| 36 | } |
||
| 37 | $this->server->getCache()->write($destination, $this->server->getApi()->run($tmp, $parameters)); |
||
| 38 | @unlink($tmp); |
||
| 39 | } |
||
| 40 | } |
||
| 41 | } |
||
| 42 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.