<commit_before><?php

use Symfony\Component\Process\Process;

/**
 * Class OptimisedGDBackend
 */
class OptimisedGDBackend extends GDBackend implements ImageOptimiserInterface
{
    /**
     * @var Config_ForClass
     */
    protected $config;
    /**
     * @var Raven_Client
     */
    public $logger;
    /**
     * @var array
     */
    public static $dependencies = array(
        'logger' => '%$Raven'
    );
    /**
     * @param null $filename
     */
    public function __construct($filename = null)
    {
        $this->config = $this->config();
        parent::__construct($filename);
    }
    /**
     * @param string $filename
     */
    public function writeTo($filename)
    {
        parent::writeTo($filename);

        $this->optimiseImage($filename);
    }
    /**
     * @param $filename
     * @return mixed|void
     */
    public function optimiseImage($filename)
    {
        if (file_exists($filename)) {
            list($width, $height, $type, $attr) = getimagesize($filename);

            $command = $this->getCommand(
                $filename,
                $this->getImageType($type)
            );

            if ($command) {
                $process = $this->execCommand($command);

                $debug = $this->config->get('debug');

                if (null !== $this->logger && (!$process->isSuccessful() || $debug)) {
                    $requestMethod = $_SERVER['REQUEST_METHOD'];
                    unset($_SERVER['REQUEST_METHOD']);
                    $this->logger->capture(
                        array(
                            'message' => 'SilverStripe Optimised Image',
                            'extra'   => array(
                                'command'     => $command,
                                'exitCode'    => $process->getExitCode(),
                                'output'      => $process->getOutput(),
                                'errorOutput' => $process->getErrorOutput()
                            ),
                            'level'   => !$process->isSuccessful() ? Raven_Client::ERROR : Raven_Client::INFO
                        ),
                        false
                    );
                    $_SERVER['REQUEST_METHOD'] = $requestMethod;
                }
            }
        }
    }
    protected function getImageType($type)
    {
        switch ($type) {
            case IMAGETYPE_JPEG:
                return 'jpg';
            case IMAGETYPE_PNG:
                return 'png';
            default:<commit_msg>UPDATE: Use more informative title in logging<commit_after><?php

use Symfony\Component\Process\Process;

/**
 * Class OptimisedGDBackend
 */
class OptimisedGDBackend extends GDBackend implements ImageOptimiserInterface
{
    /**
     * @var Config_ForClass
     */
    protected $config;
    /**
     * @var Raven_Client
     */
    public $logger;
    /**
     * @var array
     */
    public static $dependencies = array(
        'logger' => '%$Raven'
    );
    /**
     * @param null $filename
     */
    public function __construct($filename = null)
    {
        $this->config = $this->config();
        parent::__construct($filename);
    }
    /**
     * @param string $filename
     */
    public function writeTo($filename)
    {
        parent::writeTo($filename);

        $this->optimiseImage($filename);
    }
    /**
     * @param $filename
     * @return mixed|void
     */
    public function optimiseImage($filename)
    {
        if (file_exists($filename)) {
            list($width, $height, $type, $attr) = getimagesize($filename);

            $command = $this->getCommand(
                $filename,
                $this->getImageType($type)
            );

            if ($command) {
                $process = $this->execCommand($command);

                if (null !== $this->logger && (!$process->isSuccessful() || $this->config->get('debug'))) {
                    $requestMethod = $_SERVER['REQUEST_METHOD'];
                    unset($_SERVER['REQUEST_METHOD']);
                    $this->logger->capture(
                        array(
                            'message' => 'SilverStripe Optimised Image' . ($process->isSuccessful() ? '' : ' Failure'),
                            'extra'   => array(
                                'command'     => $command,
                                'exitCode'    => $process->getExitCode(),
                                'output'      => $process->getOutput(),
                                'errorOutput' => $process->getErrorOutput()
                            ),
                            'level'   => !$process->isSuccessful() ? Raven_Client::ERROR : Raven_Client::INFO
                        ),
                        false
                    );
                    $_SERVER['REQUEST_METHOD'] = $requestMethod;
                }
            }
        }
    }
    protected function getImageType($type)
    {
        switch ($type) {
            case IMAGETYPE_JPEG:
                return 'jpg';
            case IMAGETYPE_PNG:
                return 'png';
            default:
{'fraction_non_alphanumeric': 0.13099667123555903, 'fraction_numerical': 0.0, 'mean_word_length': 1.3604436229205175, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, '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': '3682608', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1274, 'n_words': 233}