1.2.261. Could Be Parent Method

A method is defined in several children, but not in a the parent class. It may be worth checking if this method doesn’t belong the parent class, as an abstraction.

Only the name of the method is used is for gathering purposes. If the code has grown organically, the signature (default values, typehint, argument names) may have followed different path, and will require a refactorisation.

<?php

// The parent class
class x { }

// The children class
class y1 extends x {
    // foo is common to y1 and y2, so it shall be also a method in x
    function foo() {}
    // fooY1 is specific to y1
    function fooY1() {}
}

class y2 extends x {
    function foo() {}
    // fooY2 is specific to y1
    function fooY2() {}
}

?>

Name

Default

Type

Description

minChildren

4

integer

Minimal number of children using this method.

1.2.261.1. Suggestions

  • Create an abstract method in the parent

  • Create an concrete method in the parent, and move default behavior there by removing it in children classes

1.2.261.2. Specs

Short name

Classes/CouldBeParentMethod

Rulesets

All, Class Review

Exakat since

2.1.7

PHP Version

All

Severity

Minor

Time To Fix

Slow (1 hour)

Precision

Very high

Features

class, parent

Available in

Entreprise Edition, Exakat Cloud