Long methods

Methods can be overly complicated in some instances with PHP; for example, in the following class I have intentionally left out some meaningful comments and also made the constructor excessively long:

<?php class TaxiMeter { const MIN_RATE = 2.50; const secondsInDay = 60 * 60 * 24; const MILE_RATE = 0.2; private $timeOfDay; private $baseRate; private $miles; private $dob; /** * TaxiMeter constructor. * @param int $timeOfDay * @param float $baseRate * @param string $driverDateOfBirth * @throws Exception */ public function __construct(int $timeOfDay, float $baseRate, string $driverDateOfBirth) { if ($timeOfDay > self::SECONDS_IN_DAY) { throw new Exception('There can only be ' . self::SECONDS_IN_DAY . ' seconds in a day.'); } else if ...

Get Mastering PHP Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.