Sha256: 429794639ce4a338a751f566f61a3fe0c6242bb2e7cb811f0b4ad875d9986aee

Contents?: true

Size: 1010 Bytes

Versions: 384

Compression:

Stored size: 1010 Bytes

Contents

<?php

class Triangle
{
    protected $sideA;
    protected $sideB;
    protected $sideC;

    public function __construct($sideA, $sideB, $sideC)
    {
        $this->sideA = $sideA;
        $this->sideB = $sideB;
        $this->sideC = $sideC;
    }
    
    public function kind()
    {
        if (0 == ($this->sideA + $this->sideB + $this->sideC)) {
            throw new \Exception("These sides have no values.");
        }

        $sides = [$this->sideA, $this->sideB, $this->sideC];
        sort($sides);
        if ($sides[2] >= $sides[0] + $sides[1]) {
            throw new \Exception("This violates the triangle inequality");
        }

        if ($this->sideA == $this->sideB &&
            $this->sideA == $this->sideC
        ) {
            return 'equilateral';
        }

        if ($this->sideB == $this->sideC ||
            $this->sideA == $this->sideC ||
            $this->sideA == $this->sideB
        ) {
            return 'isosceles';
        }

        return 'scalene';
    }
}

Version data entries

384 entries across 384 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/php/exercises/triangle/example.php
trackler-2.2.1.97 tracks/php/exercises/triangle/example.php
trackler-2.2.1.96 tracks/php/exercises/triangle/example.php
trackler-2.2.1.95 tracks/php/exercises/triangle/example.php
trackler-2.2.1.94 tracks/php/exercises/triangle/example.php
trackler-2.2.1.93 tracks/php/exercises/triangle/example.php
trackler-2.2.1.92 tracks/php/exercises/triangle/example.php
trackler-2.2.1.91 tracks/php/exercises/triangle/example.php
trackler-2.2.1.90 tracks/php/exercises/triangle/example.php
trackler-2.2.1.89 tracks/php/exercises/triangle/example.php
trackler-2.2.1.88 tracks/php/exercises/triangle/example.php
trackler-2.2.1.87 tracks/php/exercises/triangle/example.php
trackler-2.2.1.86 tracks/php/exercises/triangle/example.php
trackler-2.2.1.85 tracks/php/exercises/triangle/example.php
trackler-2.2.1.84 tracks/php/exercises/triangle/example.php
trackler-2.2.1.83 tracks/php/exercises/triangle/example.php
trackler-2.2.1.82 tracks/php/exercises/triangle/example.php
trackler-2.2.1.81 tracks/php/exercises/triangle/example.php
trackler-2.2.1.80 tracks/php/exercises/triangle/example.php
trackler-2.2.1.79 tracks/php/exercises/triangle/example.php