Large cleanup of pinentry code. Add documentation. Fix phpcs errors.