<commit_before><?php

namespace Ilios\AuthenticationBundle\Voter;

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

/**
 * Class ReportVoter
 * @package Ilios\AuthenticationBundle\Voter
 */
class ReportVoter extends AbstractVoter
{
    /**
     * {@inheritdoc}
     */
    protected function getSupportedClasses()
    {
        return array('Ilios\CoreBundle\Entity\ReportInterface');
    }

    /**
     * @param string $attribute
     * @param ReportInterface $report
     * @param UserInterface $user
     * @return bool
     */
    protected function isGranted($attribute, $report, $user = null)
    {
        if (!$user instanceof UserInterface) {
            return false;
        }

        switch ($attribute) {
            // Users can perform any CRUD operations on their own reports.
            // Check if the given report's owning user is the given user.
            case self::CREATE:
            case self::VIEW:
            case self::EDIT:
            case self::DELETE:
                return ($user->getId() === $report->getUser()->getId());
                break;
        }

        return false;
    }
}<commit_msg>replaced id-comparison with null-safe user comparison.<commit_after><?php

namespace Ilios\AuthenticationBundle\Voter;

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

/**
 * Class ReportVoter
 * @package Ilios\AuthenticationBundle\Voter
 */
class ReportVoter extends AbstractVoter
{
    /**
     * {@inheritdoc}
     */
    protected function getSupportedClasses()
    {
        return array('Ilios\CoreBundle\Entity\ReportInterface');
    }

    /**
     * @param string $attribute
     * @param ReportInterface $report
     * @param UserInterface $user
     * @return bool
     */
    protected function isGranted($attribute, $report, $user = null)
    {
        if (!$user instanceof UserInterface) {
            return false;
        }

        switch ($attribute) {
            // Users can perform any CRUD operations on their own reports.
            // Check if the given report's owning user is the given user.
            case self::CREATE:
            case self::VIEW:
            case self::EDIT:
            case self::DELETE:
                return $this->usersAreIdentical($user, $report->getUser());
                break;
        }

        return false;
    }
}
{'fraction_non_alphanumeric': 0.10372129849564529, 'fraction_numerical': 0.0, 'mean_word_length': 2.2860858257477243, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '4934784', 'n_tokens_mistral': 679, 'n_tokens_neox': 665, 'n_words': 171}