Completed
Push — master ( 9e3e67...1dbefb )
by Jeroen
08:30 queued 11s
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
    /**
18
     * @deprecated This property is deprecated since KunstmaanMediaBundle 5.7 and will be removed in KunstmaanMediaBundle 6.0. The aviary service is discontinued.
19
     */
20
    protected $aviaryApiKey;
21
22
    /**
23
     * @param int                                                $priority
24
     * @param MimeTypeGuesserFactoryInterface|MimeTypesInterface $mimeTypeGuesserFactory
25
     * @param ExtensionGuesserFactoryInterface|null              $extensionGuesserFactoryInterface
26
     * @param string                                             $aviaryApiKey
0 ignored issues
show
Should the type for parameter $aviaryApiKey not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
27
     */
28 1
    public function __construct($priority, $mimeTypeGuesser, $extensionGuesser, $aviaryApiKey = null)
29
    {
30 1
        parent::__construct($priority, $mimeTypeGuesser, $extensionGuesser);
31
32 1
        if (null !== $aviaryApiKey) {
33
            @trigger_error(sprintf('Passing a value for the "$aviaryApiKey" constructor parameter of "%s" is deprecated since KunstmaanMediaBundle 5.7 and will be removed in KunstmaanMediaBundle 6.0. The aviary service is discontinued.', __CLASS__), E_USER_DEPRECATED);
34
        }
35 1
        $this->aviaryApiKey = $aviaryApiKey;
36 1
    }
37
38
    /**
39
     * @deprecated This method is deprecated since KunstmaanMediaBundle 5.7 and will be removed in KunstmaanMediaBundle 6.0. The aviary service is discontinued.
40
     *
41
     * @return string
0 ignored issues
show
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
42
     */
43
    public function getAviaryApiKey()
44
    {
45
        @trigger_error(sprintf('The "%s" method is deprecated since KunstmaanMediaBundle 5.7 and will be removed in KunstmaanMediaBundle 6.0. The aviary service is discontinued.', __METHOD__), E_USER_DEPRECATED);
46
47
        return $this->aviaryApiKey;
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getName()
54
    {
55
        return 'Image Handler';
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getType()
62
    {
63
        return 'image';
64
    }
65
66
    /**
67
     * @param mixed $object
68
     *
69
     * @return bool
70
     */
71
    public function canHandle($object)
72
    {
73
        if (parent::canHandle($object) && ($object instanceof File || strncmp($object->getContentType(), 'image', 5) === 0)) {
74
            return true;
75
        }
76
77
        return false;
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function getShowTemplate(Media $media)
84
    {
85
        return '@KunstmaanMedia/Media/Image/show.html.twig';
86
    }
87
88
    /**
89
     * @param Media  $media    The media entity
90
     * @param string $basepath The base path
91
     *
92
     * @return string
93
     */
94
    public function getImageUrl(Media $media, $basepath)
95
    {
96
        return $basepath.$media->getUrl();
97
    }
98
99
    /**
100
     * @param Media $media
101
     */
102 1
    public function prepareMedia(Media $media)
103
    {
104 1
        parent::prepareMedia($media);
105
106 1
        if ($media->getContent()) {
107 1
            $imageInfo = getimagesize($media->getContent());
108
109 1
            $width = $height = null;
110 1
            if (false !== $imageInfo) {
111
                [$width, $height] = $imageInfo;
112
            }
113
114
            $media
115 1
                ->setMetadataValue('original_width', $width)
116 1
                ->setMetadataValue('original_height', $height);
117
        }
118 1
    }
119
}
120