Hi,
If the phone was purchased new and hasn’t been opened up or suffered external damage then the first thing you should do is go to the Apple Store and ask for an assessment and based on the results , you could ask if they will provide an out of warranty claim.
You have nothing to lose and everything to gain, they may even offer a discounted replacement.
If you they decline an OOW claim then you can start looking at what other steps to take.
Hope this helps