<commit_before><?php

namespace Looptribe\Paytoshi\Controller;

use Looptribe\Paytoshi\Setup\Configurator;
use Looptribe\Paytoshi\Setup\Diagnostics;
use Looptribe\Paytoshi\Templating\TemplatingEngineInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Yaml\Yaml;

class SetupController
{
    /** @var TemplatingEngineInterface */
    private $templating;

    /** @var UrlGeneratorInterface */
    private $urlGenerator;

    /** @var Diagnostics */
    private $diagnostics;

    /** @var Configurator */
    private $configurator;

    /** @var array */
    private $dbConfig;

    public function __construct(
        TemplatingEngineInterface $templating,
        UrlGeneratorInterface $urlGenerator,
        Diagnostics $diagnostics,
        Configurator $configurator,
        $dbConfig
    ) {
        $this->templating = $templating;
        $this->urlGenerator = $urlGenerator;
        $this->diagnostics = $diagnostics;
        $this->configurator = $configurator;
        $this->dbConfig = $dbConfig;
    }

    public function startAction()
    {
        return $this->templating->render('admin/setup.html.twig', array(
            'isConfigWritable' => $this->diagnostics->isConfigWritable(),
            'config' => array(
                'database' => $this->dbConfig,
            ),
        ));
    }

    public function saveAction(Request $request)
    {
        $config = array(
            'database' => array(
                'name' => $request->request->get('dbName'),
                'host' => $request->request->get('dbHost'),
                'username' => $request->request->get('dbUser'),
                'password' => $request->request->get('dbPass'),
            )
        );

        $this->configurator->saveConfig($config);

        return new RedirectResponse($this->urlGenerator->generate('setup_complete'));
    }

    public function completeAction()
    {
        $results = $this->configurator->setup();

        return $this->templating->render('admin/setup_completed.html.twig', array(<commit_msg>Don't save config file during setup if not writable<commit_after><?php

namespace Looptribe\Paytoshi\Controller;

use Looptribe\Paytoshi\Setup\Configurator;
use Looptribe\Paytoshi\Setup\Diagnostics;
use Looptribe\Paytoshi\Templating\TemplatingEngineInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Yaml\Yaml;

class SetupController
{
    /** @var TemplatingEngineInterface */
    private $templating;

    /** @var UrlGeneratorInterface */
    private $urlGenerator;

    /** @var Diagnostics */
    private $diagnostics;

    /** @var Configurator */
    private $configurator;

    /** @var array */
    private $dbConfig;

    public function __construct(
        TemplatingEngineInterface $templating,
        UrlGeneratorInterface $urlGenerator,
        Diagnostics $diagnostics,
        Configurator $configurator,
        $dbConfig
    ) {
        $this->templating = $templating;
        $this->urlGenerator = $urlGenerator;
        $this->diagnostics = $diagnostics;
        $this->configurator = $configurator;
        $this->dbConfig = $dbConfig;
    }

    public function startAction()
    {
        return $this->templating->render('admin/setup.html.twig', array(
            'isConfigWritable' => $this->diagnostics->isConfigWritable(),
            'config' => array(
                'database' => $this->dbConfig,
            ),
        ));
    }

    public function saveAction(Request $request)
    {
        if ($this->diagnostics->isConfigWritable() === true) {
            $config = array(
                'database' => array(
                    'name' => $request->request->get('dbName'),
                    'host' => $request->request->get('dbHost'),
                    'username' => $request->request->get('dbUser'),
                    'password' => $request->request->get('dbPass'),
                )
            );

            $this->configurator->saveConfig($config);
        }

        return new RedirectResponse($this->urlGenerator->generate('setup_complete'));
    }

    public function completeAction()
    {
        $results = $this->configurator->setup();

        return $this->templating->render('admin/setup_completed.html.twig', array(
{'fraction_non_alphanumeric': 0.12952918203514863, 'fraction_numerical': 0.0, 'mean_word_length': 2.6850519584332533, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 73, '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': '1082178', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1272, 'n_words': 216}