ColorProfile   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 66
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getStream() 0 4 1
A getData() 0 13 2
A fromFilename() 0 8 4
1
<?php
2
/**
3
 * This file is part of the Magickly project.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Magickly\Image;
9
10
use GravityMedia\Magickly\Exception\RuntimeException;
11
use GuzzleHttp\Stream\StreamInterface;
12
use GuzzleHttp\Stream\Utils as StreamUtils;
13
14
/**
15
 * Color profile class.
16
 *
17
 * @package GravityMedia\Magickly\Image
18
 */
19
class ColorProfile
20
{
21
    /**
22
     * @var StreamInterface
23
     */
24
    private $stream;
25
26
    /**
27
     * Create color profile object.
28
     *
29
     * @param StreamInterface $stream
30
     */
31
    public function __construct(StreamInterface $stream)
32
    {
33
        $this->stream = $stream;
34
    }
35
36
    /**
37
     * Get stream.
38
     *
39
     * @return StreamInterface
40
     */
41
    public function getStream()
42
    {
43
        return $this->stream;
44
    }
45
46
    /**
47
     * Get data.
48
     *
49
     * @throws RuntimeException
50
     *
51
     * @return string
52
     */
53
    public function getData()
54
    {
55
        $offset = $this->stream->tell();
56
        if (!is_int($offset)) {
57
            throw new RuntimeException('Unable to get profile data');
58
        }
59
60
        $this->stream->seek(0);
61
        $data = $this->stream->getContents();
62
        $this->stream->seek($offset);
63
64
        return $data;
65
    }
66
67
    /**
68
     * Create color profile object from filename.
69
     *
70
     * @param string $filename
71
     *
72
     * @throws RuntimeException
73
     *
74
     * @return $this
75
     */
76
    public static function fromFilename($filename)
77
    {
78
        if (!file_exists($filename) || !is_file($filename) || !is_readable($filename)) {
79
            throw new RuntimeException(sprintf('Filename %s is an invalid profile file or is not readable', $filename));
80
        }
81
82
        return new static(StreamUtils::create(StreamUtils::open($filename, 'r')));
83
    }
84
}
85