| Total Complexity | 10 |
| Total Lines | 83 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | class Volume |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Calculate the volume of a cuboid |
||
| 14 | * |
||
| 15 | * Formula: |
||
| 16 | * ``` |
||
| 17 | * V = w * h * l |
||
| 18 | * ``` |
||
| 19 | * |
||
| 20 | * @param float $height |
||
| 21 | * @param float $width |
||
| 22 | * @param float $depth |
||
| 23 | * @return float |
||
| 24 | * @author Ronan Chilvers <[email protected]> |
||
| 25 | */ |
||
| 26 | static public function cuboid($height, $width, $depth): ?float |
||
| 27 | { |
||
| 28 | if (0 == (float) $height || 0 == (float) $width || 0 == (float) $depth) |
||
| 29 | { |
||
| 30 | return null; |
||
| 31 | } |
||
| 32 | |||
| 33 | return $height * $width * $depth; |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Calculate the volume of a cylinder |
||
| 38 | * |
||
| 39 | * Formula: |
||
| 40 | * ``` |
||
| 41 | * V = π * r2 * h |
||
| 42 | * ``` |
||
| 43 | * |
||
| 44 | * @param float $height |
||
| 45 | * @param float $radius |
||
| 46 | * @return float |
||
| 47 | * @author Ronan Chilvers <[email protected]> |
||
| 48 | */ |
||
| 49 | static public function cylinder($height, $radius): ?float |
||
| 50 | { |
||
| 51 | if (0 == (float) $height || 0 == (float) $radius) { |
||
| 52 | return null; |
||
| 53 | } |
||
| 54 | |||
| 55 | return pi() * pow((float) $radius, 2) * $height; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Calculate the volume of a sphere |
||
| 60 | * |
||
| 61 | * Formula: |
||
| 62 | * ``` |
||
| 63 | * V = 4/3 * π * r3 |
||
| 64 | * ``` |
||
| 65 | * @param float $radius |
||
| 66 | * @param float |
||
| 67 | * @author Ronan Chilvers <[email protected]> |
||
| 68 | */ |
||
| 69 | static public function sphere($radius): ?float |
||
| 70 | { |
||
| 71 | if (0 == (float) $radius) { |
||
| 72 | return null; |
||
| 73 | } |
||
| 74 | |||
| 75 | return (4/3) * pi() * pow($radius, 3); |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Calculate the volume of a hexagonal prism |
||
| 80 | * |
||
| 81 | * Formula: |
||
| 82 | * ``` |
||
| 83 | * V = 3/2 * √3 * a2 *h |
||
| 84 | * ``` |
||
| 85 | * @param float $height |
||
| 86 | * @param float $edgeLength |
||
| 87 | * @return float |
||
| 88 | * @author Ronan Chilvers <[email protected]> |
||
| 89 | */ |
||
| 90 | public function hexagonalPrism($height, $edgeLength): ?float |
||
| 93 | } |
||
| 94 | } |
||
| 95 |