Completed
Push — feature-20rc1 ( 008ae2 )
by Rob
16:55
created

FileBlob::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
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\File;
13
14
use Liip\ImagineBundle\File\Attributes\ContentTypeAttribute;
15
use Liip\ImagineBundle\File\Attributes\ExtensionAttribute;
16
17
/**
18
 * @author Rob Frawley 2nd <[email protected]>
19
 */
20
class FileBlob extends AbstractFileBlob implements FileBlobInterface
21
{
22
    /**
23
     * @var string|null
24
     */
25
    private $contents;
26
27
    /**
28
     * @param string|null               $contents
29
     * @param ContentTypeAttribute|null $contentType
30
     * @param ExtensionAttribute|null   $extension
31
     */
32
    public function __construct(string $contents = null, ContentTypeAttribute $contentType = null, ExtensionAttribute $extension = null)
33
    {
34
        parent::__construct($contentType, $extension);
35
36
        $this->contents = $contents;
37
    }
38
39
    /**
40
     * @param string|null $contents
41
     * @param string|null $contentType
42
     * @param string|null $extension
43
     *
44
     * @return self
45
     */
46
    public static function create(string $contents = null, string $contentType = null, string $extension = null)
47
    {
48
        return new self($contents, ContentTypeAttribute::create($contentType), ExtensionAttribute::create($extension));
49
    }
50
51
    /**
52
     * @return string|null
53
     */
54
    protected function doGetContents(): ?string
55
    {
56
        return $this->contents;
57
    }
58
59
    /**
60
     * @param string $contents
61
     * @param bool   $append
62
     */
63
    protected function doSetContents(string $contents, bool $append): void
64
    {
65
        $this->contents = true === $append ? $this->contents.$contents : $contents;
66
    }
67
}
68