<commit_before><?php

namespace Padawan\Framework\Domain\Project;


use Padawan\Domain\Project;
use __PHP_Incomplete_Class;
use React\EventLoop\LoopInterface;
use React\Filesystem\Filesystem;
use Padawan\Framework\Utils\PathResolver;

/**
 * Class Persister
 */
class Persister
{
    const PADAWAN_DIR = ".padawan";
    const INDEX_FILE = "project";

    public function __construct(PathResolver $path, LoopInterface $loop)
    {
        $this->path = $path;
        $this->fs = Filesystem::create($loop);
    }

    public function save(Project $project)
    {
        $this->checkForPadawanDir($project->getRootFolder());
        return $this->fs->file(
            $this->getProjectIndexFilePath($project->getRootFolder())
        )->putContents($this->serialize($project));
    }

    public function load($rootDir)
    {
        try {
            $project = $this->unserialize(
                $this->readFromFile($this->getProjectIndexFilePath($rootDir))
            );<commit_msg>Use a more straight forward way to save index file<commit_after><?php

namespace Padawan\Framework\Domain\Project;


use Padawan\Domain\Project;
use __PHP_Incomplete_Class;
use React\EventLoop\LoopInterface;
use React\Filesystem\Filesystem;
use Padawan\Framework\Utils\PathResolver;

/**
 * Class Persister
 */
class Persister
{
    const PADAWAN_DIR = ".padawan";
    const INDEX_FILE = "project";

    public function __construct(PathResolver $path, LoopInterface $loop)
    {
        $this->path = $path;
        $this->fs = Filesystem::create($loop);
    }

    public function save(Project $project)
    {
        $this->checkForPadawanDir($project->getRootFolder());
        return file_put_contents(
            $this->getProjectIndexFilePath($project->getRootFolder()),
            $this->serialize($project)
        );
    }

    public function load($rootDir)
    {
        try {
            $project = $this->unserialize(
                $this->readFromFile($this->getProjectIndexFilePath($rootDir))
            );
{'fraction_non_alphanumeric': 0.12524850894632206, 'fraction_numerical': 0.0, 'mean_word_length': 3.00996015936255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '1685964', 'n_tokens_mistral': 594, 'n_tokens_neox': 582, 'n_words': 107}