OOP (course 4): Static methods, Namespaces, Exceptions & Traits! Woh!
The Wonder of Class Constants
  Unlock this challenge
Login Register

Challenge 3 / 3

The intern has gone crazy with constants, by even making the hex strings into constants:

class GasPlanet implements PlanetInterface
{
    // ...

    const COLOR_BROWN_ISH = '663300';
    const COLOR_BLUE_BRIGHT = '0066FF';
    const COLOR_GRAY_DARK = '464646';
    // ...

    public function getHexColor()
    {
        // a "fake" map of elements to colors
        switch ($this->mainElement) {
            case GasPlanet::MATERIAL_AMMONIA:
                return GasPlanet::COLOR_BROWN_ISH;
            case GasPlanet::MATERIAL_METHANE:
                return GasPlanet::COLOR_BLUE_BRIGHT;
            default:
                return GasPlanet::COLOR_GRAY_DARK;
        }
    }
}

Is this a good step forward?

Skip challenges and go to theNext Chapter

Turn Challenges Off?

All further challenges will be skipped automatically.
You can re-enable challenges at any time on this page or from your account page.