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

plank / laravel-mediable / 8585433686

07 Apr 2024 02:04AM UTC coverage: 95.282% (-0.5%) from 95.789%
8585433686

push

github

web-flow
Merge pull request #343 from plank/v6

V6

338 of 375 new or added lines in 30 files covered. (90.13%)

1 existing line in 1 file now uncovered.

1434 of 1505 relevant lines covered (95.28%)

117.76 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✔
NEW
26
            throw new \RuntimeException(
×
NEW
27
                'Could not create temporary file. The system temp directory may not be writable.'
×
NEW
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

© 2026 Coveralls, Inc