Mishkat al-Masabih 258
وَعَنْ أَبِي الدَّرْدَاءِ قَالَ: سُئِلَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: مَا حَدُّ الْعِلْمِ الَّذِي إِذَا بَلَغَهُ الرَّجُلُ كَانَ فَقِيهًا؟ فَقَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: «من حَفِظَ عَلَى أُمَّتِي أَرْبَعِينَ حَدِيثًا فِي أَمْرِ دِينِهَا بَعَثَهُ اللَّهُ فَقِيهًا وَكُنْتُ لَهُ يَوْمَ الْقِيَامَة شافعا وشهيدا»
From Abu ad-Dardaʾ, who said: The Messenger of Allah ﷺ was asked: "What is the extent of knowledge which, when a man reaches it, he is a faqih?" The Messenger of Allah ﷺ said: "Whoever preserves for my Ummah forty hadiths concerning the matter of its religion, Allah will raise him up as a faqih, and I will be for him on the Day of Resurrection an intercessor and a witness."