<commit_before><?php

declare(strict_types=1);

namespace Becklyn\RouteTreeBundle\Node;

use Becklyn\RouteTreeBundle\Builder\TreeBuilder;
use Becklyn\RouteTreeBundle\Node\Security\SecurityInferHelper;
use Symfony\Component\Routing\Route;


class NodeFactory
{
    /**
     * @var SecurityInferHelper
     */
    private $securityInferHelper;


    /**
     * @param SecurityInferHelper $securityInferHelper
     */
    public function __construct (SecurityInferHelper $securityInferHelper)
    {
        $this->securityInferHelper = $securityInferHelper;
    }


    /**
     * Generates a node from the given route
     *
     * @param string $routeName
     * @param Route  $route
     * @return Node
     */
    public function createNode (string $routeName, Route $route) : Node
    {
        $node = new Node($routeName);
        $routeData = $route->getOption(TreeBuilder::CONFIG_OPTIONS_KEY);

        // if there is no tree data
        if (is_array($routeData))
        {
            // set basic data
            if (isset($routeData["title"]))
            {
                $node->setTitle($routeData["title"]);
                $node->setHidden(false);
            }
            else
            {
                $node->setHidden(true);
            }

            if (isset($routeData["priority"]))
            {
                $node->setPriority($routeData["priority"]);
            }

            if (isset($routeData["parameters"]))
            {
                $node->setParameters($routeData["parameters"]);
            }

            if (isset($routeData["security"]))
            {
                // prefer explicitly set security settings
                $node->setSecurity($routeData["security"]);
            }
            else
            {
                $this->inferSecurity($node, $route);
            }

            if (isset($routeData["extra"]))
            {
                $node->setExtra($routeData["extra"]);
            }

            // set all required parameters at least as "null"
            $node->setParameters(
                array_replace(
                    array_fill_keys($route->compile()->getVariables(), null),
                    $node->getParameters()
                )
            );
        }

        return $node;
    }


    /**
     * Infers the security from the linked controller
     *
     * @param Node  $node
     * @param Route $route
     */
    private function inferSecurity (Node $node, Route $route) : void
    {
        $controller = $route->getDefault("_controller");

        if (null === $controller)
        {
            return;
        }

        $security = $this->securityInferHelper->inferSecurity($controller);
        dump($security);

        if (null !== $security)
        {
            $node->setSecurity($security);
        }
    }
}<commit_msg>Remove debug code<commit_after><?php

declare(strict_types=1);

namespace Becklyn\RouteTreeBundle\Node;

use Becklyn\RouteTreeBundle\Builder\TreeBuilder;
use Becklyn\RouteTreeBundle\Node\Security\SecurityInferHelper;
use Symfony\Component\Routing\Route;


class NodeFactory
{
    /**
     * @var SecurityInferHelper
     */
    private $securityInferHelper;


    /**
     * @param SecurityInferHelper $securityInferHelper
     */
    public function __construct (SecurityInferHelper $securityInferHelper)
    {
        $this->securityInferHelper = $securityInferHelper;
    }


    /**
     * Generates a node from the given route
     *
     * @param string $routeName
     * @param Route  $route
     * @return Node
     */
    public function createNode (string $routeName, Route $route) : Node
    {
        $node = new Node($routeName);
        $routeData = $route->getOption(TreeBuilder::CONFIG_OPTIONS_KEY);

        // if there is no tree data
        if (is_array($routeData))
        {
            // set basic data
            if (isset($routeData["title"]))
            {
                $node->setTitle($routeData["title"]);
                $node->setHidden(false);
            }
            else
            {
                $node->setHidden(true);
            }

            if (isset($routeData["priority"]))
            {
                $node->setPriority($routeData["priority"]);
            }

            if (isset($routeData["parameters"]))
            {
                $node->setParameters($routeData["parameters"]);
            }

            if (isset($routeData["security"]))
            {
                // prefer explicitly set security settings
                $node->setSecurity($routeData["security"]);
            }
            else
            {
                $this->inferSecurity($node, $route);
            }

            if (isset($routeData["extra"]))
            {
                $node->setExtra($routeData["extra"]);
            }

            // set all required parameters at least as "null"
            $node->setParameters(
                array_replace(
                    array_fill_keys($route->compile()->getVariables(), null),
                    $node->getParameters()
                )
            );
        }

        return $node;
    }


    /**
     * Infers the security from the linked controller
     *
     * @param Node  $node
     * @param Route $route
     */
    private function inferSecurity (Node $node, Route $route) : void
    {
        $controller = $route->getDefault("_controller");

        if (null === $controller)
        {
            return;
        }

        $security = $this->securityInferHelper->inferSecurity($controller);

        if (null !== $security)
        {
            $node->setSecurity($security);
        }
    }
}
{'fraction_non_alphanumeric': 0.12095490716180371, 'fraction_numerical': 0.00035366931918656057, 'mean_word_length': 1.633147113594041, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '7445367', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1449, 'n_words': 281}