Completed
Push — master ( 8fe45b...3e4cf7 )
by Jeroen
08:37
created

MediaBundle/Helper/Image/ImageHandler.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\MediaBundle\Helper\Image;
4
5
use Kunstmaan\MediaBundle\Entity\Media;
6
use Kunstmaan\MediaBundle\Helper\ExtensionGuesserFactoryInterface;
7
use Kunstmaan\MediaBundle\Helper\File\FileHandler;
8
use Kunstmaan\MediaBundle\Helper\MimeTypeGuesserFactoryInterface;
9
use Symfony\Component\HttpFoundation\File\File;
10
use Symfony\Component\Mime\MimeTypesInterface;
11
12
/**
13
 * FileHandler
14
 */
15
class ImageHandler extends FileHandler
16
{
17
    protected $aviaryApiKey;
18
19
    /**
20
     * @param int                                                $priority
21
     * @param MimeTypeGuesserFactoryInterface|MimeTypesInterface $mimeTypeGuesserFactory
0 ignored issues
show
There is no parameter named $mimeTypeGuesserFactory. Did you maybe mean $mimeTypeGuesser?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
22
     * @param ExtensionGuesserFactoryInterface|null              $extensionGuesserFactoryInterface
0 ignored issues
show
There is no parameter named $extensionGuesserFactoryInterface. Did you maybe mean $extensionGuesser?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
23
     * @param string                                             $aviaryApiKey
24
     */
25 1
    public function __construct($priority, $mimeTypeGuesser, $extensionGuesser, $aviaryApiKey)
26
    {
27 1
        parent::__construct($priority, $mimeTypeGuesser, $extensionGuesser);
28 1
        $this->aviaryApiKey = $aviaryApiKey;
29 1
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getAviaryApiKey()
35
    {
36
        return $this->aviaryApiKey;
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function getName()
43
    {
44
        return 'Image Handler';
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getType()
51
    {
52
        return 'image';
53
    }
54
55
    /**
56
     * @param mixed $object
57
     *
58
     * @return bool
59
     */
60
    public function canHandle($object)
61
    {
62
        if (parent::canHandle($object) && ($object instanceof File || strncmp($object->getContentType(), 'image', 5) === 0)) {
63
            return true;
64
        }
65
66
        return false;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function getShowTemplate(Media $media)
73
    {
74
        return '@KunstmaanMedia/Media/Image/show.html.twig';
75
    }
76
77
    /**
78
     * @param Media  $media    The media entity
79
     * @param string $basepath The base path
80
     *
81
     * @return string
82
     */
83
    public function getImageUrl(Media $media, $basepath)
84
    {
85
        return $basepath.$media->getUrl();
86
    }
87
88
    /**
89
     * @param Media $media
90
     */
91 1
    public function prepareMedia(Media $media)
92
    {
93 1
        parent::prepareMedia($media);
94
95 1
        if ($media->getContent()) {
96 1
            $imageInfo = getimagesize($media->getContent());
97
98 1
            $width = $height = null;
99 1
            if (false !== $imageInfo) {
100
                [$width, $height] = $imageInfo;
101
            }
102
103
            $media
104 1
                ->setMetadataValue('original_width', $width)
105 1
                ->setMetadataValue('original_height', $height);
106
        }
107 1
    }
108
}
109