<commit_before><?php

namespace KekRozsak\SecurityBundle\Service;

use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
use Symfony\Bridge\Doctrine\RegistryInterface;

class RoleHierarchy implements RoleHierarchyInterface
{
    private $hierarchy;
    private $roleRepo;
    private $map;

    public function __construct(RegistryInterface $doctrine)
    {
        $this->hierarchy = array();
        $this->roleRepo = $doctrine->getRepository('KekRozsakSecurityBundle:Role');

        $this->buildRoleMap();
    }

    public function getReachableRoles(array $roles)
    {
        $reachableRoles = array();
        foreach ($roles as $role) {
            if (!isset($this->map[$role->getRole()])) {
                continue;
            }

            foreach ($this->map[$role->getRole()] as $r) {
                if (($childRole = $this->roleRepo->findOneByName($r)) !== null) {
                    $reachableRoles[] = $childRole;
                }
            }
        }

        return $reachableRoles;
    }

    private function buildRoleMap()
    {
        $this->map = array();
        $roles = $this->roleRepo->findAll();
        foreach ($roles as $mainRole) {
            $main = $mainRole->getRole();
            $this->map[$main] = array($main);<commit_msg>Fixed RoleHierarchy class to return an array of strings instead of array of objects<commit_after><?php

namespace KekRozsak\SecurityBundle\Service;

use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
use Symfony\Bridge\Doctrine\RegistryInterface;
use Symfony\Component\Security\Core\Role\RoleInterface;

class RoleHierarchy implements RoleHierarchyInterface
{
    private $hierarchy;
    private $roleRepo;
    private $map;

    public function __construct(RegistryInterface $doctrine)
    {
        $this->hierarchy = array();
        $this->roleRepo = $doctrine->getRepository('KekRozsakSecurityBundle:Role');

        $this->buildRoleMap();
    }

    public function getReachableRoles(array $roles)
    {
        $reachableRoles = array();
        foreach ($roles as $role) {
            if ($role instanceof RoleInterface) {
                $thisRole = $role->getRole();
            } else {
                $thisRole = $role;
            }
            if (!isset($this->map[$thisRole])) {
                continue;
            }
            $reachableRoles[] = $thisRole;

            foreach ($this->map[$thisRole] as $r) {
                if (($childRole = $this->roleRepo->findOneByName($r)) !== null) {
                    $reachableRoles[] = $childRole->getRole();
                }
            }
        }

        return $reachableRoles;
    }

    private function buildRoleMap()
    {
        $this->map = array();
        $roles = $this->roleRepo->findAll();
        foreach ($roles as $mainRole) {
            $main = $mainRole->getRole();
            $this->map[$main] = array($main);
{'fraction_non_alphanumeric': 0.13059958649207443, 'fraction_numerical': 0.0, 'mean_word_length': 2.2435754189944133, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '3867546', 'n_tokens_mistral': 849, 'n_tokens_neox': 837, 'n_words': 157}