Introduction

Welcome back to another exciting session where we learn about enhancing existing functionality without causing regressions. Today, our scenario involves designing a voting system. We'll start with the basic implementation of the voting system and gradually introduce additional elements of complexity using PHP.

Starter Task Review

In our initial task, we created a simple voting system in PHP with a set of basic functionalities:

  • function registerCandidate(string $candidateId): bool: This function is used to add new candidates to our system.
  • function vote(int $timestamp, string $voterId, string $candidateId): bool: This function facilitates users casting their votes. Each vote is given a timestamp.
  • function getVotes(string $candidateId): ?int: This function retrieves the total number of votes for a given candidate.
  • function topNCandidates(int $n): array: We also want to add a leaderboard functionality to our system. This function returns the top n candidates sorted by the number of votes.
Initial Solution Development
Introduce New Methods
Implementing New Methods: `getVotingHistory` and `blockVoterRegistration`
Updating the `vote` Method
Implementing `changeVote` Method
Lesson Summary

Congratulations! You've successfully enhanced the voting system by adding functionalities to view voting history, block new candidate registrations, and, most importantly, enable vote changes under specific conditions. Each of these features was developed with careful consideration to maintain the integrity and backward compatibility of the system in a PHP context. Continue exploring with practice sessions and further experimentation to refine your skills in developing complex, functionality-rich applications in PHP. Happy coding!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal