<commit_before><?php namespace System\Modules\Filesystem;

/*
 ===========================================================================
 = Application File System
 ===========================================================================
 =
 = Responsible for doing all the file manipulation of the application.
 = 
 */

use \ErrorException;
use \InvalidArgumentException;
use \System\Exceptions\FileNotFoundException;

use \System\Interfaces\FileInterface;

use \FilesystemIterator;
use \Symfony\Component\Finder\Finder;

/**
 * File System
 * @link https://github.com/lleocastro/genniuz-framework/
 * @license (MIT) https://github.com/lleocastro/genniuz-framework/blob/master/LICENSE
 * @author <NAME> <<EMAIL>>
 * @package \System\Modules\Filesystem;
 * @copyright 2016 
 * @version 1.0.0
 */
class FileManipulator implements FileInterface
{
	/**
     * Check a file exists.
     * @param string $path
     * @return bool
     */
    public function exists(string $path):bool
    {
        return is_readable($path);
    }
    
	/**
     * Get the contents of file.
     * @param string $path
     * @return string
     */
    public function read(string $path, bool $planText = false):array
    {
        if(!is_readable($path)):
            throw new FileNotFoundException('File not found!');
        endif;
        
        if($planText):
            $file = fopen($path, 'r');

            $data = [];
            $i = 0;

            while(!feof($file)):
                $data[$i] = fgets($file, 4096);
                $i++;
            endwhile;
            
            return array_filter($data);
        endif;

        return [file_get_contents($path)];
    }

    /**
     * Write the contents of file.
     * @param string $path
     * @param string $contents
     * @return bool
     */
    public function write(string $path, string $contents):bool
    {
        if($this->checkFile($path)):
            return file_put_contents($path, $contents);
        endif;
    }

    /**
     * Append to a file.
     * @param string $path
     * @param string $data
     * @return bool
     */
    public function append(string $path, string $data):bool
    {}
<commit_msg>Implementing method 'read'<commit_after><?php namespace System\Modules\Filesystem;

/*
 ===========================================================================
 = Application File System
 ===========================================================================
 =
 = Responsible for doing all the file manipulation of the application.
 = 
 */

use \ErrorException;
use \InvalidArgumentException;
use \System\Exceptions\FileNotFoundException;

use \System\Interfaces\FileInterface;

use \FilesystemIterator;
use \Symfony\Component\Finder\Finder;

/**
 * File System
 * @link https://github.com/lleocastro/genniuz-framework/
 * @license (MIT) https://github.com/lleocastro/genniuz-framework/blob/master/LICENSE
 * @author <NAME> <<EMAIL>>
 * @package \System\Modules\Filesystem;
 * @copyright 2016 
 * @version 1.0.0
 */
class FileManipulator implements FileInterface
{
	/**
     * Check a file exists.
     * @param string $path
     * @return bool
     */
    public function exists(string $path):bool
    {
        return is_readable($path);
    }
    
	/**
     * Get the contents of file.
     * @param string $path
     * @return string
     */
    public function read(string $path, $look = false):string
    {
        $contents = '';
        
        if($this->exists($path)):
            $handle = fopen($path, 'rb');
            try{
                if(flock($handle, LOCK_SH)):
                    clearstatcache(true, $path);
                    $contents = fread($handle, filesize($path));
                    flock($handle, LOCK_UN);
                endif;
            }finally{
                fclose($handle);
            }
        endif;

        return ($look)?file_get_contents($path):$contents;
    }

    /**
     * Write the contents of file.
     * @param string $path
     * @param string $contents
     * @return bool
     */
    public function write(string $path, string $contents):bool
    {
        if($this->checkFile($path)):
            return file_put_contents($path, $contents);
        endif;
    }

    /**
     * Append to a file.
     * @param string $path
     * @param string $data
     * @return bool
     */
    public function append(string $path, string $data):bool
    {}

{'fraction_non_alphanumeric': 0.1869328493647913, 'fraction_numerical': 0.004310344827586207, 'mean_word_length': 2.3811349693251533, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 4, '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': '6531862', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1196, 'n_words': 291}