Barcelona defender Gerard Pique has agreed to extend his contract until June 2022, the club have confirmed.