• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

plank / laravel-mediable / 13689748990

06 Mar 2025 02:19AM UTC coverage: 94.72%. Remained the same
13689748990

push

github

web-flow
Fix template type definition in MediableCollection (#378)

1489 of 1572 relevant lines covered (94.72%)

153.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.73
/src/ImageOptimizer.php
1
<?php
2

3
namespace Plank\Mediable;
4

5
use GuzzleHttp\Psr7\Utils;
6
use Psr\Http\Message\StreamInterface;
7
use Spatie\ImageOptimizer\OptimizerChain;
8

9
class ImageOptimizer
10
{
11
    public function optimizeImage(StreamInterface $imageStream, OptimizerChain $optimizerChain): StreamInterface
12
    {
13
        // CLI optimizers require the file to be on disk so write it to /tmp
14
        $tmpPath = $this->getTmpFile();
12✔
15
        $tmpStream = Utils::streamFor(Utils::tryFopen($tmpPath, 'wb'));
12✔
16
        Utils::copyToStream($imageStream, $tmpStream);
12✔
17
        $optimizerChain->optimize($tmpPath);
12✔
18
        // open a separate stream to detect the changes made by the optimizers
19
        return Utils::streamFor(Utils::tryFopen($tmpPath, 'rb'));
12✔
20
    }
21

22
    private function getTmpFile(): string
23
    {
24
        $tmpFile = tempnam(sys_get_temp_dir(), 'mediable-');
12✔
25
        if ($tmpFile === false) {
12✔
26
            throw new \RuntimeException(
×
27
                'Could not create temporary file. The system temp directory may not be writable.'
×
28
            );
×
29
        }
30
        return $tmpFile;
12✔
31
    }
32
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc