1.2.223. Constant Class

A class or an interface only made up of constants. Constants usually have to be used in conjunction of some behavior (methods, class…) and never alone.

As such, they should be PHP constants (build with define or const), or included in a class with other methods and properties.

<?php

class ConstantClass {
    const KBIT = 1000;
    const MBIT = self::KBIT * 1000;
    const GBIT = self::MBIT * 1000;
    const PBIT = self::GBIT * 1000;
}

?>

See also PHP Classes containing only constants.

1.2.223.1. Suggestions

  • Make the class an interface

  • Make the class an abstract class, to avoid its instantiation

1.2.223.2. Specs

Short name

Classes/ConstantClass

Rulesets

All, CE, Class Review

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Slow (1 hour)

Precision

High

Features

class-constant

Available in

Entreprise Edition, Community Edition, Exakat Cloud