<commit_before><?php
/**
 * Created by PhpStorm.
 * User: christof
 * Date: 11.11.15
 * Time: 14:21.
 */

namespace MandarinMedien\MMMediaBundle\MediaType;

use MandarinMedien\MMMediaBundle\Model\MediaInterface;

class ImageMediaType extends BaseMediaType
{
    const NAME = 'mm.media.type.image';

    /**
     * @TODO: implement extra file object check
     *
     * @param $data
     *
     * @return ImageMediaType|null
     */
    public static function check($data)
    {
        $allowedExtensions = array(
            'png',
            'jpeg',
            'jpg',
            'gif',
            'tiff',
        );

        if (in_array(strtolower(pathinfo($data, PATHINFO_EXTENSION)), $allowedExtensions)) {
            return new self($data);
        } else {
            return;
        }
    }

    /**
     * @param MediaInterface $media
     * @param array|null $options
     *
     * @return string
     */
    public function getPreview(MediaInterface $media, array $options = null)
    {
        $self_options = array(
            'html' => array(
                'class' => array(self::NAME),
                'alt' => ''
            ));

        if (is_array($options)) {
            $options = array_merge($self_options, $options);
        } else {
            $options = $self_options;
        }


        $html = '<img src="/media/' . $media->getMediaTypeReference() . '" class="' . implode(' ', $options['html']['class']) . '" alt="' . ($options['html']['alt'] ?: "") . '"  />';
<commit_msg>ImageMediaType: better alt-attribute check<commit_after><?php
/**
 * Created by PhpStorm.
 * User: christof
 * Date: 11.11.15
 * Time: 14:21.
 */

namespace MandarinMedien\MMMediaBundle\MediaType;

use MandarinMedien\MMMediaBundle\Model\MediaInterface;

class ImageMediaType extends BaseMediaType
{
    const NAME = 'mm.media.type.image';

    /**
     * @TODO: implement extra file object check
     *
     * @param $data
     *
     * @return ImageMediaType|null
     */
    public static function check($data)
    {
        $allowedExtensions = array(
            'png',
            'jpeg',
            'jpg',
            'gif',
            'tiff',
        );

        if (in_array(strtolower(pathinfo($data, PATHINFO_EXTENSION)), $allowedExtensions)) {
            return new self($data);
        } else {
            return;
        }
    }

    /**
     * @param MediaInterface $media
     * @param array|null $options
     *
     * @return string
     */
    public function getPreview(MediaInterface $media, array $options = null)
    {
        $self_options = array(
            'html' => array(
                'class' => array(self::NAME),
                'alt' => ''
            ));

        if (is_array($options)) {
            $options = array_merge($self_options, $options);
        } else {
            $options = $self_options;
        }


        $html = '<img src="/media/' . $media->getMediaTypeReference() . '" class="' . implode(' ', $options['html']['class']) . '" alt="' . (isset($options['html']['alt']) ? $options['html']['alt'] : "") . '"  />';

{'fraction_non_alphanumeric': 0.1552674230145867, 'fraction_numerical': 0.006482982171799027, 'mean_word_length': 1.9418493803622499, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '747069', 'n_tokens_mistral': 940, 'n_tokens_neox': 899, 'n_words': 184}