<commit_before><?php

namespace CirclicalUser\Mapper;

use CirclicalUser\Entity\UserPermission;
use CirclicalUser\Provider\ResourceInterface;
use CirclicalUser\Provider\UserPermissionInterface;
use CirclicalUser\Provider\UserPermissionProviderInterface;
use CirclicalUser\Provider\UserInterface;

/**
 * Class UserPermissionMapper
 * @package CirclicalUser\Mapper
 */
class UserPermissionMapper extends AbstractDoctrineMapper implements UserPermissionProviderInterface
{
    protected $entityName = 'CirclicalUser\Entity\UserPermission';

    /**
     * Get any user-level, string (simple) permissions that are configured in the database.
     *
     * @param               $string
     * @param UserInterface $user
     *
     * @return array
     */
    public function getUserPermission($string, UserInterface $user) : array
    {
        $query = $this->getRepository()->createQueryBuilder('r')
            ->select('r')
            ->where('r.resource_class = "string" AND r.resource_id=:resourceId')
            ->setParameter('resourceId', $string)
            ->getQuery();

        return $query->getResult();
    }

    /**
     * Get resource-type permissions from the database
     *
     * @param ResourceInterface $resource
     * @param UserInterface     $user
     *
     * @return array
     */
    public function getResourceUserPermission(ResourceInterface $resource, UserInterface $user) : array
    {
        $query = $this->getRepository()->createQueryBuilder('r')
            ->select('r')
            ->where('r.resource_class = :resourceClass AND r.resource_id=:resourceId')
            ->setParameter('resourceClass', $resource->getClass())
            ->setParameter('resourceId', $resource->getId())
            ->getQuery();

        return $query->getResult();
    }

    /**
     * Create a user permission, not persisted, and return it.
     *
     * @param UserInterface $user
     * @param               $resourceClass<commit_msg>Using One or Null instead. Fixed user lookup.<commit_after><?php

namespace CirclicalUser\Mapper;

use CirclicalUser\Entity\UserPermission;
use CirclicalUser\Provider\ResourceInterface;
use CirclicalUser\Provider\UserPermissionInterface;
use CirclicalUser\Provider\UserPermissionProviderInterface;
use CirclicalUser\Provider\UserInterface;

/**
 * Class UserPermissionMapper
 * @package CirclicalUser\Mapper
 */
class UserPermissionMapper extends AbstractDoctrineMapper implements UserPermissionProviderInterface
{
    protected $entityName = 'CirclicalUser\Entity\UserPermission';

    /**
     * Get any user-level, string (simple) permissions that are configured in the database.
     *
     * @param               $string
     * @param UserInterface $user
     *
     * @return array
     */
    public function getUserPermission($string, UserInterface $user)
    {
        $query = $this->getRepository()->createQueryBuilder('r')
            ->select('r')
            ->where('r.resource_class = "string" AND r.resource_id=:resourceId AND r.user=:user')
            ->setParameter('resourceId', $string)
            ->setParameter('user', $user)
            ->getQuery();

        return $query->getOneOrNullResult();
    }

    /**
     * Get resource-type permissions from the database
     *
     * @param ResourceInterface $resource
     * @param UserInterface     $user
     *
     * @return array
     */
    public function getResourceUserPermission(ResourceInterface $resource, UserInterface $user)
    {
        $query = $this->getRepository()->createQueryBuilder('r')
            ->select('r')
            ->where('r.resource_class = :resourceClass AND r.resource_id=:resourceId AND r.user=:user')
            ->setParameter('resourceClass', $resource->getClass())
            ->setParameter('resourceId', $resource->getId())
            ->setParameter('user', $user)
            ->getQuery();

        return $query->getOneOrNullResult();
    }

    /**
     * Create a user permission, not persisted, and return it.
     *
     * @param UserInterface $user
     * @param               $resourceClass
{'fraction_non_alphanumeric': 0.11519607843137254, 'fraction_numerical': 0.0, 'mean_word_length': 2.8645833333333335, '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': '5622248', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1052, 'n_words': 236}