Damage function for a game
Please see comment above about thinking about broader review. My guess is that you might have a flawed approach to how you are modelling real-world items in your application. For example, a particle/matter/explosive doesn't really "doDamage" right? It "attacks" or "fires" or whatever you might want to call it.

"Damage" as a concept results from what the properties of the attack and the properties of the thing attacked are right?   So why would you model "damage" as a method on the different attacker entities, when it truly is something that needs to be determined based on the properties of both the attack and the target. Putting the actual calculation in the attacker class would not seem to make sense when you think about it.

You might look through another review I gave where the poster was having a similar problem in modelling application entities to match real world behavior. I hope this may give some insight into how you should be thinking about writing your code.



That being said, if you aren't looking to potentially refactor your application, your problem should actually be easy to solve.  Just break that "variable" area of code out into it's own function:

So base class might look like:

function doDamage($fire) {
    // all your code common to every class in hierarchy


    // call method (overridden with specific logic in each inheriting class
    // possibly this method returns your Damage object
    $dmg = $this-&gt;calculateDamage($someParam, $someOtherParam, ...);

    // other code common to all classes in hierarchy
}


And you only override such code in inheriting classes if logic totally varies from that execution path.



Why does this method always return true? Is it really even meaningful to have a return from a method is the value is always the same?