Code Duplication    Length = 22-22 lines in 2 locations

src/Xtools/UserRepository.php 2 locations

@@ 42-63 (lines=22) @@
39
     * @param string $username The username to find.
40
     * @return int
41
     */
42
    public function getId($databaseName, $username)
43
    {
44
        $cacheKey = $this->getCacheKey(func_get_args(), 'user_id');
45
        if ($this->cache->hasItem($cacheKey)) {
46
            return $this->cache->getItem($cacheKey)->get();
47
        }
48
49
        $userTable = $this->getTableName($databaseName, 'user');
50
        $sql = "SELECT user_id FROM $userTable WHERE user_name = :username LIMIT 1";
51
        $resultQuery = $this->getProjectsConnection()->prepare($sql);
52
        $resultQuery->bindParam('username', $username);
53
        $resultQuery->execute();
54
        $userId = (int)$resultQuery->fetchColumn();
55
56
        // Cache for 10 minutes.
57
        $cacheItem = $this->cache
58
            ->getItem($cacheKey)
59
            ->set($userId)
60
            ->expiresAfter(new DateInterval('PT10M'));
61
        $this->cache->save($cacheItem);
62
        return $userId;
63
    }
64
65
    /**
66
     * Get the user's registration date.
@@ 71-92 (lines=22) @@
68
     * @param string $username The username to find.
69
     * @return string|null As returned by the database.
70
     */
71
    public function getRegistrationDate($databaseName, $username)
72
    {
73
        $cacheKey = $this->getCacheKey(func_get_args(), 'user_registration');
74
        if ($this->cache->hasItem($cacheKey)) {
75
            return $this->cache->getItem($cacheKey)->get();
76
        }
77
78
        $userTable = $this->getTableName($databaseName, 'user');
79
        $sql = "SELECT user_registration FROM $userTable WHERE user_name = :username LIMIT 1";
80
        $resultQuery = $this->getProjectsConnection()->prepare($sql);
81
        $resultQuery->bindParam('username', $username);
82
        $resultQuery->execute();
83
        $registrationDate = $resultQuery->fetchColumn();
84
85
        // Cache for 10 minutes.
86
        $cacheItem = $this->cache
87
            ->getItem($cacheKey)
88
            ->set($registrationDate)
89
            ->expiresAfter(new DateInterval('PT10M'));
90
        $this->cache->save($cacheItem);
91
        return $registrationDate;
92
    }
93
94
    /**
95
     * Get the user's (system) edit count.