This is actually incorrect according to the wiki and my personal experience.
If you close the door at night while an animal is outside and then go to bed then there is a chance the animal will be attacked.
The best way to do it IMO is to leave the door open all the time and when the report says its raining the next day, close the door once all the animals are inside to sleep. Then the next time its sunny, open the door up again first thing.
Sure, but avoiding an animal attack is pretty trivial. You can even just go inside the coop after closing the door and any animals that is home for will teleport inside. Or just look and don't leave one out.
The main reason to mess with the coop doors is ensuring they are still in their coop when you get there in the morning. It is a lot less convenient to ensure you pet every animal in the coop if they're outside and spread out somewhere by the time you get there in the AM. Mostly this matters for animals that you are focused on improving friendship with (not mood), such as ducks or anything else you are raising to sell at max hearts for profit and cycle new animals into that building.
For animals that you are just keeping once they reach max friendship it mostly matters that you let them out to eat grass instead of hay whenever possible and not ever letting them be out in the rain. You do lose some animal mood every day if you are staying up later than they are (6-7 PM), and you lose even more if you didn't pet them that day when the next morning comes, which you can usually tell by the drop in purple quality items for that building's animals (assuming you're just skipping petting that building for the day). You can just pet them and let them eat grass to stay near max on mood but it's just a lot less convenient to pet them when they are out unless your fenced area is the same or smaller than the building interior, but that does not leave you enough grass space relative to the size of the building to maintain grass for that long.
I've not had an animal get attacked in 2 years for pretty much the whole second year I've maintained ~40 animals while closing the doors every single night. It's really just so that I can combine the day's petting with product collecting every morning, and to never have to worry about remembering whether it is going to rain the next day or not.