1.2.247. Could Be Abstract Class

An abstract class is never instantiated, and has children class that are. As such, a ‘parent’ class that is never instantiated by itself, but has its own children instantiated could be marked as abstract.

That will prevent new code to try to instantiate it.

<?php

// Example code would actually be split over multiple files.


// That class could be abstract
class motherClass {}

// Those classes shouldn't be abstract
class firstChildren extends motherClass {}
class secondChildren extends motherClass {}
class thirdChildren extends motherClass {}

new firstChildren();
new secondChildren();
new thirdChildren();

//Not a single : new motherClass()

?>

See also Class Abstraction and Abstract classes and methods.

1.2.247.1. Suggestions

  • Make this class an abstract class

1.2.247.2. Specs

Short name

Classes/CouldBeAbstractClass

Rulesets

All, Analyze, Class Review

Exakat since

1.3.9

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

abstract

Examples

Edusoho, shopware

Available in

Entreprise Edition, Exakat Cloud