Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
13 / 13
Reputation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
13 / 13
 __construct(\aae\db\FunctionAPI $storageAPI)
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getRep($userEmail)
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 updateAndGetRep($userEmail)
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
8 / 8
 _getRepForEvent($repEvent)
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 registerReputationEvent($userEmail, $eventType, $benefactorId)
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
<?php
/**
 *
 */
namespace aae\app {
    use \aae\db\FunctionAPI as FAPI;
    /**
     * @author Axel Ancona Esselmann
     * @package aae\app
     */
    class Reputation {
        private $_storageAPI;
        public function __construct(\aae\db\FunctionAPI $storageAPI) {
            $this->_storageAPI = $storageAPI;
        }
        public function getRep($userEmail) {
            return (int)$this->_storageAPI->getRep($userEmail);
        }
        /**
         * Calculates reputation for all uncounted reputation events and updates
         * the reputation of the user identified by $userEmail
         * 
         * @param  string $userEmail User Email
         * @return int               The new reputation of that user.
         */
        public function updateAndGetRep($userEmail) {
            $this->_storageAPI->setFetchMode(FAPI::FETCH_NUM_ARRAY);
            $repEvents = $this->_storageAPI->getNewReputationEvents($userEmail);
            $newRepPoints = 0;
            foreach ($repEvents as $repEvent) {
                $newRepPoints += $this->_getRepForEvent($repEvent);
            }
            $this->_storageAPI->setFetchMode(FAPI::RESET);
            return (int)$this->_storageAPI->updateRep($newRepPoints);
        }
        protected function _getRepForEvent($repEvent) {
            //var_dump($repEvent);
            return 5;
        }
    
        public function registerReputationEvent($userEmail, $eventType, $benefactorId) {
            return $this->_storageAPI->registerReputationEvent($userEmail, $eventType, $benefactorId);
        }
    }
}