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

liip / LiipImagineBundle / 10701363663

04 Sep 2024 12:11PM UTC coverage: 81.688% (-0.06%) from 81.746%
10701363663

push

github

web-flow
Merge pull request #1610 from liip/cs-fix

apply latest cs fixer

67 of 84 new or added lines in 42 files covered. (79.76%)

2 existing lines in 1 file now uncovered.

2275 of 2785 relevant lines covered (81.69%)

103.1 hits per line

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

80.0
/Binary/Loader/StreamLoader.php
1
<?php
2

3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11

12
namespace Liip\ImagineBundle\Binary\Loader;
13

14
use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException;
15

16
class StreamLoader implements LoaderInterface
17
{
18
    /**
19
     * The wrapper prefix to append to the path to be loaded.
20
     *
21
     * @var string
22
     */
23
    protected $wrapperPrefix;
24

25
    /**
26
     * A stream context resource to use.
27
     *
28
     * @var resource|null
29
     */
30
    protected $context;
31

32
    /**
33
     * @param string        $wrapperPrefix
34
     * @param resource|null $context
35
     *
36
     * @throws \InvalidArgumentException
37
     */
38
    public function __construct($wrapperPrefix, $context = null)
39
    {
40
        $this->wrapperPrefix = $wrapperPrefix;
52✔
41

42
        if ($context && !\is_resource($context)) {
52✔
43
            throw new \InvalidArgumentException('The given context is no valid resource.');
13✔
44
        }
45

46
        $this->context = empty($context) ? null : $context;
39✔
47
    }
21✔
48

49
    public function find($path)
50
    {
51
        $name = $this->wrapperPrefix.$path;
39✔
52

53
        /*
54
         * This looks strange, but at least in PHP 5.3.8 it will raise an E_WARNING if the 4th parameter is null.
55
         * fopen() will be called only once with the correct arguments.
56
         *
57
         * The error suppression is solely to determine whether the file exists.
58
         * file_exists() is not used as not all wrappers support stat() to actually check for existing resources.
59
         */
60
        if (($this->context && !$resource = @fopen($name, 'rb', false, $this->context)) || !$resource = @fopen($name, 'rb')) {
39✔
61
            throw new NotLoadableException(\sprintf('Source image %s not found.', $name));
13✔
62
        }
63

64
        // Closing the opened stream to avoid locking of the resource to find.
65
        fclose($resource);
26✔
66

67
        try {
68
            $content = file_get_contents($name, false, $this->context);
26✔
69
        } catch (\Exception $e) {
×
NEW
70
            throw new NotLoadableException(\sprintf('Source image %s could not be loaded.', $name), $e->getCode(), $e);
×
71
        }
72

73
        if (false === $content) {
26✔
NEW
74
            throw new NotLoadableException(\sprintf('Source image %s could not be loaded.', $name));
×
75
        }
76

77
        return $content;
26✔
78
    }
79
}
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