ApiMediaFile   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 1
dl 0
loc 61
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A getExtension() 0 4 2
A setExtension() 0 4 1
A getMimetype() 0 4 2
A setMimetype() 0 4 1
A guessExtension() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\MediaBundle\Extra;
15
16
use Symfony\Component\HttpFoundation\File\File;
17
18
/**
19
 * @final since sonata-project/media-bundle 3.21.0
20
 */
21
class ApiMediaFile extends File
22
{
23
    /**
24
     * @var string
25
     */
26
    protected $extension;
27
28
    /**
29
     * @var string
30
     */
31
    protected $mimetype;
32
33
    /**
34
     * @var resource
35
     */
36
    protected $resource;
37
38
    public function __construct($handle)
39
    {
40
        if (!\is_resource($handle)) {
41
            throw new \RuntimeException('handle is not a resource');
42
        }
43
44
        $this->resource = $handle;
45
46
        $meta = stream_get_meta_data($handle);
47
48
        parent::__construct($meta['uri']);
49
    }
50
51
    public function getExtension()
52
    {
53
        return $this->extension ?: parent::getExtension();
54
    }
55
56
    /**
57
     * @param string $extension
58
     */
59
    public function setExtension($extension): void
60
    {
61
        $this->extension = $extension;
62
    }
63
64
    public function getMimetype()
65
    {
66
        return $this->mimetype ?: parent::getMimeType();
67
    }
68
69
    /**
70
     * @param string $mimetype
71
     */
72
    public function setMimetype($mimetype): void
73
    {
74
        $this->mimetype = $mimetype;
75
    }
76
77
    public function guessExtension()
78
    {
79
        return $this->extension ?: parent::guessExtension();
80
    }
81
}
82