<commit_before><?php

namespace Ilios\AuthenticationBundle\Voter;

use Ilios\CoreBundle\Entity\Manager\PermissionManagerInterface;
use Ilios\CoreBundle\Entity\SchoolInterface;
use Ilios\CoreBundle\Entity\UserInterface;

/**
 * Class SchoolVoter
 * @package Ilios\AuthenticationBundle\Voter
 */
class SchoolVoter extends AbstractVoter
{
    /**
     * @var PermissionManagerInterface
     */
    protected $permissionManager;

    /**
     * @param PermissionManagerInterface $permissionManager
     */
    public function __construct(PermissionManagerInterface $permissionManager)
    {
        $this->permissionManager = $permissionManager;
    }
    /**
     * {@inheritdoc}
     */
    protected function getSupportedClasses()
    {
        return array('Ilios\CoreBundle\Entity\SchoolInterface');
    }

    /**
     * @param string $attribute
     * @param SchoolInterface $school
     * @param UserInterface|null $user
     * @return bool
     */
    protected function isGranted($attribute, $school, $user = null)
    {
        // make sure there is a user object (i.e. that the user is logged in)
        if (!$user instanceof UserInterface) {
            return false;
        }
        
        switch ($attribute) {
            case self::VIEW:
                // Only grant VIEW permissions if the given school is the given user's
                // primary school
                // - or -
                // if the given user has been granted READ right on the given school
                // via the permissions system.
                return ($school->getId() === $user->getPrimarySchool()->getId()
                || $this->permissionManager->userHasReadPermissionToSchool($user, $school));
                break;
            case self::EDIT:
            case self::DELETE:
                // Only grant EDIT and DELETE permissions to users with 'Developer' role.
                // - and -
                // the user must be associated with the given school,
                // either by its primary school attribute
                //     - or - by WRITE rights for the school
                // via the permissions system.
                return ($this->userHasRole($user, ['Developer'])
                    && ($user->getPrimarySchool() === $school->getId()
                        || $this->permissionManager->userHasWritePermissionToSchool($user, $school))
                );
                break;
        }

        return false;
    }
}
<commit_msg>formatting twerks.<commit_after><?php

namespace Ilios\AuthenticationBundle\Voter;

use Ilios\CoreBundle\Entity\Manager\PermissionManagerInterface;
use Ilios\CoreBundle\Entity\SchoolInterface;
use Ilios\CoreBundle\Entity\UserInterface;

/**
 * Class SchoolVoter
 * @package Ilios\AuthenticationBundle\Voter
 */
class SchoolVoter extends AbstractVoter
{
    /**
     * @var PermissionManagerInterface
     */
    protected $permissionManager;

    /**
     * @param PermissionManagerInterface $permissionManager
     */
    public function __construct(PermissionManagerInterface $permissionManager)
    {
        $this->permissionManager = $permissionManager;
    }
    /**
     * {@inheritdoc}
     */
    protected function getSupportedClasses()
    {
        return array('Ilios\CoreBundle\Entity\SchoolInterface');
    }

    /**
     * @param string $attribute
     * @param SchoolInterface $school
     * @param UserInterface|null $user
     * @return bool
     */
    protected function isGranted($attribute, $school, $user = null)
    {
        // make sure there is a user object (i.e. that the user is logged in)
        if (!$user instanceof UserInterface) {
            return false;
        }
        
        switch ($attribute) {
            case self::VIEW:
                // Only grant VIEW permissions if the given school is the given user's
                // primary school
                // - or -
                // if the given user has been granted READ right on the given school
                // via the permissions system.
                return (
                    $school->getId() === $user->getPrimarySchool()->getId()
                    || $this->permissionManager->userHasReadPermissionToSchool($user, $school)
                );
                break;
            case self::EDIT:
            case self::DELETE:
                // Only grant EDIT and DELETE permissions to users with 'Developer' role.
                // - and -
                // the user must be associated with the given school,
                // either by its primary school attribute
                //     - or - by WRITE rights for the school
                // via the permissions system.
                return (
                    $this->userHasRole($user, ['Developer'])
                    && ($user->getPrimarySchool() === $school->getId()
                        || $this->permissionManager->userHasWritePermissionToSchool($user, $school))
                );
                break;
        }

        return false;
    }
}

{'fraction_non_alphanumeric': 0.09940239043824702, 'fraction_numerical': 0.0, 'mean_word_length': 1.8176206509539843, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2363602', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1191, 'n_words': 335}