Completed
Push — master ( 61e1ff...22d949 )
by
unknown
03:51
created

FileProvider::buildProviderEditForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace MediaMonks\SonataMediaBundle\Provider;
4
5
use MediaMonks\SonataMediaBundle\Entity\Media;
6
use Sonata\AdminBundle\Form\FormMapper;
7
use Symfony\Component\Validator\Constraints as Constraint;
8
9
class FileProvider extends AbstractProvider
10
{
11
    /**
12
     * @param FormMapper $formMapper
13
     */
14
    public function buildProviderCreateForm(FormMapper $formMapper)
15
    {
16
        $this->addFileUploadField($formMapper, 'binaryContent', 'File');
17
    }
18
19
    /**
20
     * @param FormMapper $formMapper
21
     */
22
    public function buildProviderEditForm(FormMapper $formMapper)
23
    {
24
        $this->addFileUploadField($formMapper, 'binaryContent', 'File');
25
    }
26
27
    /**
28
     * @param Media $media
29
     */
30
    public function update(Media $media)
31
    {
32
        if (!is_null($media->getBinaryContent())) {
33
            $filename = $this->handleFileUpload($media);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $filename is correct as $this->handleFileUpload($media) (which targets MediaMonks\SonataMediaBu...der::handleFileUpload()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
34
            $media->setProviderReference($filename);
35
        }
36
        if (!is_null($media->getImageContent())) {
37
            $this->handleImageUpload($media);
0 ignored issues
show
Bug introduced by
The method handleImageUpload() does not seem to exist on object<MediaMonks\Sonata...\Provider\FileProvider>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
        }
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function getIcon()
45
    {
46
        return 'file';
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function getTitle()
53
    {
54
        return 'File';
55
    }
56
57
    public function getType()
58
    {
59
        return 'file';
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function getMediaTemplate()
66
    {
67
        return 'MediaMonksSonataMediaBundle:Provider:file_media.html.twig';
68
    }
69
}
70