<commit_before><?php
/**
 * The main minifying class
 *
 * PHP version 5.5
 *
 * @category   Minifine
 * @author     <NAME> <<EMAIL>>
 * @copyright  Copyright (c) 2015 <NAME> <https://pieterhordijk.com>
 * @license    See the LICENSE file
 * @version    1.0.0
 */
namespace Minifine;

use Minifine\Minifier\Minifier;

/**
 * The main minifying class
 *
 * @category   Minifine
 * @author     <NAME> <<EMAIL>>
 */
class Minifine
{
    private $basePath;

    private $production = false;

    private $jsMinifiers = [];

    private $cssMinifiers = [];

    public function __construct($basePath, $production = false)
    {
        $this->basePath   = $basePath;
        $this->production = $production;
    }

    public function appendJsMinifier(Minifier $minifier)
    {
        $this->append('js', $minifier);
    }

    public function prependJsMinifier(Minifier $minifier)
    {
        $this->prepend('js', $minifier);
    }

    public function appendCssMinifier(Minifier $minifier)
    {
        $this->append('css', $minifier);
    }

    public function prependCssMinifier(Minifier $minifier)
    {
        $this->prepend('css', $minifier);
    }

    private function append($type, Minifier $minifier)
    {
        switch ($type) {
            case 'js':
                $this->jsMinifiers[] = $minifier;
                break;

            case 'css':
                $this->cssMinifiers[] = $minifier;
                break;

            default:
                throw new InvalidTypeException('Can not append minifier of type `' . $type . '`.');
        }
    }

    private function prepend($type, Minifier $minifier)
    {
        switch ($type) {
            case 'js':
                array_unshift($this->jsMinifiers, $minifier);
                break;

            case 'css':
                array_unshift($this->cssMinifiers, $minifier);
                break;


            default:
                throw new InvalidTypeException('Can not prepend minifier of type `' . $type . '`.');
        }
    }

    public function css(array $files, $directory, $name)
    {
        if ($this->production) {
            return '<link rel="stylesheet" href="' . $directory . '/' . $name . '">';
        }

        $this->minify($files, $directory, $name, $this->cssMinifiers);

        $stylesheets = [];

        foreach ($files as $file) {
            $stylesheets[] = '<link rel="stylesheet" href="' . $file . '">';
        }

        return implode("\n", $stylesheets);
    }

    public function js(array $files, $directory, $name)
    {
        if ($this->production) {
            return '<script src="' . $directory . '/' . $name . '"></script>';
        }

        $this->minify($files, $directory, $name, $this->jsMinifiers);

        $scripts = [];

        foreach ($files as $file) {
            $scripts[] = '<script src="' . $file . '"></script>';
        }

        return implode("\n", $scripts);
    }

    private function minify($files, $directory, $name, array $minifiers)
    {
        $content = $this->merge($files, $minifiers);

        foreach ($minifiers as $minifier) {
            $content = $minifier->minify($content);
        }

        file_put_contents($this->basePath . $directory . '/' . $name, $content);
    }

    private function merge(array $files)
    {
        $content = '';

        foreach ($files as $file) {
            $content .= file_get_contents($this->basePath . $file);
        }

        return $content;
    }
}<commit_msg>Added missing docblocks<commit_after><?php
/**
 * The main minifying class
 *
 * PHP version 5.5
 *
 * @category   Minifine
 * @author     <NAME> <<EMAIL>>
 * @copyright  Copyright (c) 2015 <NAME> <https://pieterhordijk.com>
 * @license    See the LICENSE file
 * @version    1.0.0
 */
namespace Minifine;

use Minifine\Minifier\Minifier;

/**
 * The main minifying class
 *
 * @category   Minifine
 * @author     <NAME> <<EMAIL>>
 */
class Minifine
{
    /**
     * @var string The base path of the resources
     */
    private $basePath;

    /**
     * @var bool Whether we are running in production
     */
    private $production = false;

    /**
     * @var array List of JS minifiers
     */
    private $jsMinifiers = [];

    /**
     * @var array List of CSS minifiers
     */
    private $cssMinifiers = [];

    /**
     * Creates instance
     *
     * @param string $basePath   The base path of the resources
     * @param bool   $production Whether we are running in production
     */
    public function __construct($basePath, $production = false)
    {
        $this->basePath   = $basePath;
        $this->production = $production;
    }

    /**
     * Appends a JS minifier to the chain
     *
     * @param \Minifine\Minifier\Minifier $minifier Instance of a minifier
     */
    public function appendJsMinifier(Minifier $minifier)
    {
        $this->append('js', $minifier);
    }

    /**
     * Prepends a JS minifier to the chain
     *
     * @param \Minifine\Minifier\Minifier $minifier Instance of a minifier
     */
    public function prependJsMinifier(Minifier $minifier)
    {
        $this->prepend('js', $minifier);
    }

    /**
     * Appends a CSS minifier to the chain
     *
     * @param \Minifine\Minifier\Minifier $minifier Instance of a minifier
     */
    public function appendCssMinifier(Minifier $minifier)
    {
        $this->append('css', $minifier);
    }

    /**
     * Prepends a CSS minifier to the chain
     *
     * @param \Minifine\Minifier\Minifier $minifier Instance of a minifier
     */
    public function prependCssMinifier(Minifier $minifier)
    {
        $this->prepend('css', $minifier);
    }

    /**
     * Appends a minifier to the chain
     *
     * @param string                      $type     The type of minifier to append
     * @param \Minifine\Minifier\Minifier $minifier Instance of a minifier
     *
     * @throws \Minifine\InvalidTypeException When trying to append an invalid type
     */
    private function append($type, Minifier $minifier)
    {
        switch ($type) {
            case 'js':
                $this->jsMinifiers[] = $minifier;
                break;

            case 'css':
                $this->cssMinifiers[] = $minifier;
                break;

            default:
                throw new InvalidTypeException('Can not append minifier of type `' . $type . '`.');
        }
    }

    /**
     * Prepends a minifier to the chain
     *
     * @param string                      $type     The type of minifier to append
     * @param \Minifine\Minifier\Minifier $minifier Instance of a minifier
     *
     * @throws \Minifine\InvalidTypeException When trying to prepend an invalid type
     */
    private function prepend($type, Minifier $minifier)
    {
        switch ($type) {
            case 'js':
                array_unshift($this->jsMinifiers, $minifier);
                break;

            case 'css':
                array_unshift($this->cssMinifiers, $minifier);
                break;


            default:
                throw new InvalidTypeException('Can not prepend minifier of type `' . $type . '`.');
        }
    }

    /**
     * Combines and minifies CSS files
     *
     * @param array  $files     List of files to combine and minify
     * @param string $directory The output directory of the generated file
     * @param string $name      The name of the generated file
     *
     * @return string The HTML of the generated stylesheet tag(s)
     */
    public function css(array $files, $directory, $name)
    {
        if ($this->production) {
            return '<link rel="stylesheet" href="' . $directory . '/' . $name . '">';
        }

        $this->minify($files, $directory, $name, $this->cssMinifiers);

        $stylesheets = [];

        foreach ($files as $file) {
            $stylesheets[] = '<link rel="stylesheet" href="' . $file . '">';
        }

        return implode("\n", $stylesheets);
    }

    /**
     * Combines and minifies JS files
     *
     * @param array  $files     List of files to combine and minify
     * @param string $directory The output directory of the generated file
     * @param string $name      The name of the generated file
     *
     * @return string The HTML of the generated stylesheet tag(s)
     */
    public function js(array $files, $directory, $name)
    {
        if ($this->production) {
            return '<script src="' . $directory . '/' . $name . '"></script>';
        }

        $this->minify($files, $directory, $name, $this->jsMinifiers);

        $scripts = [];

        foreach ($files as $file) {
            $scripts[] = '<script src="' . $file . '"></script>';
        }

        return implode("\n", $scripts);
    }

    /**
     * Combines and minifies files
     *
     *
     * @param array  $files     List of files to combine and minify
     * @param string $directory The output directory of the generated file
     * @param string $name      The name of the generated file
     * @param array  $minifiers The list of minifiers to run
     */
    private function minify($files, $directory, $name, array $minifiers)
    {
        $content = $this->merge($files, $minifiers);

        foreach ($minifiers as $minifier) {
            $content = $minifier->minify($content);
        }

        file_put_contents($this->basePath . $directory . '/' . $name, $content);
    }

    /**
     * Merges files
     *
     * @param array $files List of files to merge
     *
     * @return string The merged content
     */
    private function merge(array $files)
    {
        $content = '';

        foreach ($files as $file) {
            $content .= file_get_contents($this->basePath . $file);
        }

        return $content;
    }
}
{'fraction_non_alphanumeric': 0.12948166359352592, 'fraction_numerical': 0.0018438844499078057, 'mean_word_length': 1.9424352019288729, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 71, 'https://': 2, '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': '6369957', 'n_tokens_mistral': 2899, 'n_tokens_neox': 2797, 'n_words': 777}