Imagine a class is a person at a party. The Response For a Class (RFC) is the number of distinct things this person can talk about if you ask them a question.
If you ask them one question, and to answer you, they have to call 5 different friends, look up 3 different books, and shout across the room to the DJ… they are too loud!
RFC counts the “blast radius” of your class. We calculate it by adding two things:
If your class has 5 methods, and those methods call $this->db->save(), Logger::info(), and strlen(), your RFC score is 8 (5 own methods + 3 called methods). If the score is too high (default > 50), the class has its hands in too many external operations.
This class calls way too many different external methods.
class GodProcessor {
// RFC counts this method (+1)
public function process(): void {
// And counts all these unique external calls (+5)
Validator::check();
$repo = new Repository();
$repo->persist();
$repo->flush();
Logger::info('done');
EventBus::dispatch();
}
// Total RFC = 6. If this class had 10 methods doing this, it would fail!
}
Keep the number of external calls low by grouping related behavior.
class FocusedProcessor {
public function process(): void {
// RFC = 1 (own method) + 2 (external calls) = 3. Much better!
$this->repository->saveAll();
$this->notifier->notifySuccess();
}
}
rules:
E0019:
max_rfc: 50
If Phanalist flags your class for RFC, it means your class is trying to micromanage the whole system. Stop calling 20 different methods on 10 different objects, and delegate that work!