<NME> UsersRepository.php
<BEF> <?php

namespace Bolt\Storage\Repository;

use Bolt\Storage\Entity;
use Bolt\Storage\Repository;
use Doctrine\DBAL\Query\QueryBuilder;

/**
 * A Repository class that handles storage operations for the users table.
 */
class UsersRepository extends Repository
{
    private $userEntities = [];

    /**
     * Delete a user.
     *
     * @param string|int $userId either the user's ID, username, or email
     *                           address
     *
     * @return int
     */
    public function deleteUser($userId)
    {
        // Forget remembered users.
        $this->userEntities = [];

        $query = $this->deleteUserQuery($userId);

        return $query->execute();
    }

    /**
     * Get the user deletion query.
     *
     * @param string|int $userId
     *
     * @return QueryBuilder
     */
    public function deleteUserQuery($userId)
    {
        $qb = $this->createQueryBuilder();
        $qb->delete($this->getTableName());

        if (is_numeric($userId)) {
            $qb->where('id = :userId');
        } else {
            $qb->where('username = :userId')->orWhere('email = :userId');
        }
        $qb->setParameter('userId', $userId);

        return $qb;
    }

    /**
     * Get a user.
     *
     * @param string|int $userId either the user's ID, username, or email
     *                           address
     *
     * @return Entity\Users|false
     */
    public function getUser($userId)
    {
        // Check if we've already retrieved this user.
        if (isset($this->userEntities[$userId])) {
            return $this->userEntities[$userId];
        }

        $query = $this->getUserQuery($userId);
        /** @var Entity\Users $userEntity */
        if ($userEntity = $this->findOneWith($query)) {
            $this->unsetSensitiveFields($userEntity);
        }

        // Remember the user
        $this->userEntities[$userId] = $userEntity;

        return $userEntity;
    }

    /**
     * Get the user fetch query.
     *
     * @param string|int $userId
     *
     * @return QueryBuilder
     */
    public function getUserQuery($userId)
    {
        $qb = $this->createQueryBuilder();
        $qb->select('*');

        if (is_numeric($userId)) {
            $qb->where('id = :userId');
        } else {
            $qb
                ->where($qb->expr()->like('username', ':userId'))
                ->orWhere('email = :userId')
            ;
        }
        $qb->setParameter('userId', $userId);

        return $qb;
    }

    /**
     * Get a user's authentication data.
     *
     * @param string|int $userId
     *
     * @return Entity\Users|false
     */
    public function getUserAuthData($userId)
    {
        $query = $this->getUserAuthDataQuery($userId);

        return $this->findOneWith($query);
    }

    /**
     * Get the user fetch query.
     *
     * @param string|int $userId
     *
     * @return QueryBuilder
     */
    public function getUserAuthDataQuery($userId)
    {
        $qb = $this->createQueryBuilder();
        $qb->select('id')
            ->addSelect('password')
            ->addSelect('shadowpassword')
            ->where('id = :userId')
            ->setParameter('userId', $userId);

        return $qb;
    }

    /**
     * Get all the system users.
     *
     * @return Entity\Users[]|false
     */
    public function getUsers()
    {
        $userEntities = $this->findAll();
        if ($userEntities) {
            foreach ($userEntities as $userEntity) {
                $this->unsetSensitiveFields($userEntity);
            }
        }

        return $userEntities;
    }

    /**
     * Check to see if there are users in the user table.
     *
     * @deprecated Deprecated since 3.3. To be removed in v4.0.
     *
     * @return int
     */
    public function hasUsers()
    {
        $query = $this->hasUsersQuery();

        return $query->execute()->fetch();
    }

    /**
     * @deprecated Deprecated since 3.3. To be removed in v4.0.
     *
     * @return QueryBuilder
     */
    public function hasUsersQuery()
    {
        $qb = $this->createQueryBuilder();
        $qb->select('COUNT(id) as count');

        return $qb;
    }

    /**
     * Get user based on password reset notification.
     *
     * @param string $shadowToken
     *
     * @return Entity\Users|false
     */
    public function getUserShadowAuth($shadowToken)
    {
        $query = $this->getUserShadowAuthQuery($shadowToken);

        return $this->findOneWith($query);
    }

    /**
     * @param string $shadowToken
     *
     * @return QueryBuilder
     */
    /**
     * Null sensitive data that doesn't need to be passed around.
     *
     * @param Entity\Users $userEntity
     */
    protected function unsetSensitiveFields(Entity\Users $userEntity)
    {
        $userEntity->setPassword(null);
        $userEntity->setShadowpassword(null);
        $userEntity->setShadowtoken(null);
        $userEntity->setShadowvalidity(null);
    }
}
     * {@inheritdoc}
     */
    public function save($entity, $silent = null)
    {
        $this->userEntities = [];

        return parent::save($entity, $silent);
    }

    /**
     * {@inheritdoc}
     */
    public function update($entity, $exclusions = [])
    {
        // Forget remembered users.
        $this->userEntities = [];

        if ($entity->getPassword() === null) {
            $result = parent::update($entity, ['password']);
        } else {
            $result = parent::update($entity);
        }

        return $result;
    }

    /**
     * Null sensitive data that doesn't need to be passed around.
     *
     * @param Entity\Users $entity
     */
    protected function unsetSensitiveFields(Entity\Users $entity)
    {
        $entity->setPassword(null);
        $entity->setShadowpassword(null);
        $entity->setShadowtoken(null);
        $entity->setShadowvalidity(null);
    }
}

<MSG> Rename parameter
<DFF> @@ -204,13 +204,13 @@ class UsersRepository extends Repository
     /**
      * Null sensitive data that doesn't need to be passed around.
      *
-     * @param Entity\Users $userEntity
+     * @param Entity\Users $entity
      */
-    protected function unsetSensitiveFields(Entity\Users $userEntity)
+    protected function unsetSensitiveFields(Entity\Users $entity)
     {
-        $userEntity->setPassword(null);
-        $userEntity->setShadowpassword(null);
-        $userEntity->setShadowtoken(null);
-        $userEntity->setShadowvalidity(null);
+        $entity->setPassword(null);
+        $entity->setShadowpassword(null);
+        $entity->setShadowtoken(null);
+        $entity->setShadowvalidity(null);
     }
 }

{'commit': "diff --git a/src/Storage/Repository/UsersRepository.php b/src/Storage/Repository/UsersRepository.php\nindex 774a90d2a..3be687ca6 100644\n--- a/src/Storage/Repository/UsersRepository.php\n+++ b/src/Storage/Repository/UsersRepository.php\n@@ -204,13 +204,13 @@ class UsersRepository extends Repository\n     /**\n      * Null sensitive data that doesn't need to be passed around.\n      *\n-     * @param Entity\\Users $userEntity\n+     * @param Entity\\Users $entity\n      */\n-    protected function unsetSensitiveFields(Entity\\Users $userEntity)\n+    protected function unsetSensitiveFields(Entity\\Users $entity)\n     {\n-        $userEntity->setPassword(null);\n-        $userEntity->setShadowpassword(null);\n-        $userEntity->setShadowtoken(null);\n-        $userEntity->setShadowvalidity(null);\n+        $entity->setPassword(null);\n+        $entity->setShadowpassword(null);\n+        $entity->setShadowtoken(null);\n+        $entity->setShadowvalidity(null);\n     }\n }\n", 'commit_subject': 'Rename parameter', 'repo_name': 'bolt/bolt', 'committer': {'name': 'Gawain Lynch', 'email': 'f745ec5336bcd096400627fc09f6ec7139408726@gmail.com', 'time_sec': '1447567139', 'tz_offset': '660', 'date': {'seconds': '1447567139'}}, 'commit_tree': '90b8af4089430aef01ebea7e092dd30e95e301f3', 'commit_message': 'Rename parameter', 'language_name': 'PHP', 'license': 'mit', 'hunks': "@@ -204,13 +204,13 @@ class UsersRepository extends Repository\n     /**\n      * Null sensitive data that doesn't need to be passed around.\n      *\n-     * @param Entity\\Users $userEntity\n+     * @param Entity\\Users $entity\n      */\n-    protected function unsetSensitiveFields(Entity\\Users $userEntity)\n+    protected function unsetSensitiveFields(Entity\\Users $entity)\n     {\n-        $userEntity->setPassword(null);\n-        $userEntity->setShadowpassword(null);\n-        $userEntity->setShadowtoken(null);\n-        $userEntity->setShadowvalidity(null);\n+        $entity->setPassword(null);\n+        $entity->setShadowpassword(null);\n+        $entity->setShadowtoken(null);\n+        $entity->setShadowvalidity(null);\n     }\n }\n", 'addition_count': 6, 'deletion_count': 6, 'src_file': 'a/src/Storage/Repository/UsersRepository.php', 'tgt_file': 'b/src/Storage/Repository/UsersRepository.php', 'file_extension': '.php', 'before_file': "<?php\n\nnamespace Bolt\\Storage\\Repository;\n\nuse Bolt\\Storage\\Entity;\nuse Bolt\\Storage\\Repository;\nuse Doctrine\\DBAL\\Query\\QueryBuilder;\n\n/**\n * A Repository class that handles storage operations for the users table.\n */\nclass UsersRepository extends Repository\n{\n    private $userEntities = [];\n\n    /**\n     * Delete a user.\n     *\n     * @param string|int $userId either the user's ID, username, or email\n     *                           address\n     *\n     * @return int\n     */\n    public function deleteUser($userId)\n    {\n        // Forget remembered users.\n        $this->userEntities = [];\n\n        $query = $this->deleteUserQuery($userId);\n\n        return $query->execute();\n    }\n\n    /**\n     * Get the user deletion query.\n     *\n     * @param string|int $userId\n     *\n     * @return QueryBuilder\n     */\n    public function deleteUserQuery($userId)\n    {\n        $qb = $this->createQueryBuilder();\n        $qb->delete($this->getTableName());\n\n        if (is_numeric($userId)) {\n            $qb->where('id = :userId');\n        } else {\n            $qb->where('username = :userId')->orWhere('email = :userId');\n        }\n        $qb->setParameter('userId', $userId);\n\n        return $qb;\n    }\n\n    /**\n     * Get a user.\n     *\n     * @param string|int $userId either the user's ID, username, or email\n     *                           address\n     *\n     * @return Entity\\Users|false\n     */\n    public function getUser($userId)\n    {\n        // Check if we've already retrieved this user.\n        if (isset($this->userEntities[$userId])) {\n            return $this->userEntities[$userId];\n        }\n\n        $query = $this->getUserQuery($userId);\n        /** @var Entity\\Users $userEntity */\n        if ($userEntity = $this->findOneWith($query)) {\n            $this->unsetSensitiveFields($userEntity);\n        }\n\n        // Remember the user\n        $this->userEntities[$userId] = $userEntity;\n\n        return $userEntity;\n    }\n\n    /**\n     * Get the user fetch query.\n     *\n     * @param string|int $userId\n     *\n     * @return QueryBuilder\n     */\n    public function getUserQuery($userId)\n    {\n        $qb = $this->createQueryBuilder();\n        $qb->select('*');\n\n        if (is_numeric($userId)) {\n            $qb->where('id = :userId');\n        } else {\n            $qb\n                ->where($qb->expr()->like('username', ':userId'))\n                ->orWhere('email = :userId')\n            ;\n        }\n        $qb->setParameter('userId', $userId);\n\n        return $qb;\n    }\n\n    /**\n     * Get a user's authentication data.\n     *\n     * @param string|int $userId\n     *\n     * @return Entity\\Users|false\n     */\n    public function getUserAuthData($userId)\n    {\n        $query = $this->getUserAuthDataQuery($userId);\n\n        return $this->findOneWith($query);\n    }\n\n    /**\n     * Get the user fetch query.\n     *\n     * @param string|int $userId\n     *\n     * @return QueryBuilder\n     */\n    public function getUserAuthDataQuery($userId)\n    {\n        $qb = $this->createQueryBuilder();\n        $qb->select('id')\n            ->addSelect('password')\n            ->addSelect('shadowpassword')\n            ->where('id = :userId')\n            ->setParameter('userId', $userId);\n\n        return $qb;\n    }\n\n    /**\n     * Get all the system users.\n     *\n     * @return Entity\\Users[]|false\n     */\n    public function getUsers()\n    {\n        $userEntities = $this->findAll();\n        if ($userEntities) {\n            foreach ($userEntities as $userEntity) {\n                $this->unsetSensitiveFields($userEntity);\n            }\n        }\n\n        return $userEntities;\n    }\n\n    /**\n     * Check to see if there are users in the user table.\n     *\n     * @deprecated Deprecated since 3.3. To be removed in v4.0.\n     *\n     * @return int\n     */\n    public function hasUsers()\n    {\n        $query = $this->hasUsersQuery();\n\n        return $query->execute()->fetch();\n    }\n\n    /**\n     * @deprecated Deprecated since 3.3. To be removed in v4.0.\n     *\n     * @return QueryBuilder\n     */\n    public function hasUsersQuery()\n    {\n        $qb = $this->createQueryBuilder();\n        $qb->select('COUNT(id) as count');\n\n        return $qb;\n    }\n\n    /**\n     * Get user based on password reset notification.\n     *\n     * @param string $shadowToken\n     *\n     * @return Entity\\Users|false\n     */\n    public function getUserShadowAuth($shadowToken)\n    {\n        $query = $this->getUserShadowAuthQuery($shadowToken);\n\n        return $this->findOneWith($query);\n    }\n\n    /**\n     * @param string $shadowToken\n     *\n     * @return QueryBuilder\n     */\n    /**\n     * Null sensitive data that doesn't need to be passed around.\n     *\n     * @param Entity\\Users $userEntity\n     */\n    protected function unsetSensitiveFields(Entity\\Users $userEntity)\n    {\n        $userEntity->setPassword(null);\n        $userEntity->setShadowpassword(null);\n        $userEntity->setShadowtoken(null);\n        $userEntity->setShadowvalidity(null);\n    }\n}\n     * {@inheritdoc}\n     */\n    public function save($entity, $silent = null)\n    {\n        $this->userEntities = [];\n\n        return parent::save($entity, $silent);\n    }\n\n    /**\n     * {@inheritdoc}\n     */\n    public function update($entity, $exclusions = [])\n    {\n        // Forget remembered users.\n        $this->userEntities = [];\n\n        if ($entity->getPassword() === null) {\n            $result = parent::update($entity, ['password']);\n        } else {\n            $result = parent::update($entity);\n        }\n\n        return $result;\n    }\n\n    /**\n     * Null sensitive data that doesn't need to be passed around.\n     *\n     * @param Entity\\Users $entity\n     */\n    protected function unsetSensitiveFields(Entity\\Users $entity)\n    {\n        $entity->setPassword(null);\n        $entity->setShadowpassword(null);\n        $entity->setShadowtoken(null);\n        $entity->setShadowvalidity(null);\n    }\n}\n", 'message': 'Rename parameter', 'author_name': 'Gawain Lynch', 'lang': 'php'}