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
|
|||
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); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
|
|||
34 | } |
||
35 | 1 | $this->aviaryApiKey = $aviaryApiKey; |
|
0 ignored issues
–
show
The property
Kunstmaan\MediaBundle\He...eHandler::$aviaryApiKey has been deprecated with message: This property is deprecated since KunstmaanMediaBundle 5.7 and will be removed in KunstmaanMediaBundle 6.0. The aviary service is discontinued.
This property has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.
Loading history...
|
|||
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
|
|||
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); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
|
|||
46 | |||
47 | return $this->aviaryApiKey; |
||
0 ignored issues
–
show
The property
Kunstmaan\MediaBundle\He...eHandler::$aviaryApiKey has been deprecated with message: This property is deprecated since KunstmaanMediaBundle 5.7 and will be removed in KunstmaanMediaBundle 6.0. The aviary service is discontinued.
This property has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.
Loading history...
|
|||
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 |
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.