<commit_before><?php namespace Michaeljennings\Snapshot;

class Snapshot {

	
	
}<commit_msg>Added the functions for the getting the snapshot<commit_after><?php namespace Michaeljennings\Snapshot;

use Michaeljennings\Snapshot\Contracts\Store;

class Snapshot {

    /**
     * An instance of a snapshot store.
     *
     * @var Store
     */
    protected $store;

	public function __construct(Store $store)
    {
        $this->store = $store;
    }

    /**
     * Capture the current state of the application.
     */
    public function capture()
    {
        $data = [];
        $stackTrace = debug_backtrace();

        $data['snapshot'] = [
            'file' => $this->getCalledFile($stackTrace),
            'line' => $this->getCalledLine($stackTrace),
        ];

        $data['items'] = $this->transformStackTrace($stackTrace);

        $this->store->capture($data);
    }

    /**
     * Transform all items in the stack trace.
     *
     * @param array $stackTrace
     * @return array
     */
    protected function transformStackTrace(array $stackTrace)
    {
        $transformedStackTrace = [];

        foreach ($stackTrace as $trace) {
            $transformedStackTrace[] = $this->transformTrace($trace);
        }

        return array_reverse($transformedStackTrace);
    }

    /**
     * Ensure all of the elements in the stack trace can be saved in a store.
     *
     * @param array $trace
     * @return array
     */
    protected function transformTrace(array $trace)
    {
        if ( ! empty($trace['object'])) $trace['object'] = json_encode($trace['object']);

        if ( ! empty($trace['args'])) $trace['args'] = json_encode($trace['args']);

        return $trace;
    }

    /**
     * Get the file where the snapshot was requested.
     *
     * @param array $stackTrace
     * @return mixed
     */
    protected function getCalledFile(array $stackTrace)
    {
        return $stackTrace[0]['file'];
    }

    /**
     * Get the line the snapshot was requested on.
     *
     * @param array $stackTrace
     * @return mixed
     */
    protected function getCalledLine(array $stackTrace)
    {
        return $stackTrace[0]['line'];
    }
	
}
{'fraction_non_alphanumeric': 0.12922374429223743, 'fraction_numerical': 0.0009132420091324201, 'mean_word_length': 2.28978978978979, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '182877', 'n_tokens_mistral': 621, 'n_tokens_neox': 605, 'n_words': 153}