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.180 tracks/php/exercises/triangle/example.php
trackler-2.2.1.179 tracks/php/exercises/triangle/example.php
trackler-2.2.1.178 tracks/php/exercises/triangle/example.php
trackler-2.2.1.177 tracks/php/exercises/triangle/example.php
trackler-2.2.1.176 tracks/php/exercises/triangle/example.php
trackler-2.2.1.175 tracks/php/exercises/triangle/example.php
trackler-2.2.1.174 tracks/php/exercises/triangle/example.php
trackler-2.2.1.173 tracks/php/exercises/triangle/example.php
trackler-2.2.1.172 tracks/php/exercises/triangle/example.php
trackler-2.2.1.171 tracks/php/exercises/triangle/example.php
trackler-2.2.1.170 tracks/php/exercises/triangle/example.php
trackler-2.2.1.169 tracks/php/exercises/triangle/example.php
trackler-2.2.1.167 tracks/php/exercises/triangle/example.php
trackler-2.2.1.166 tracks/php/exercises/triangle/example.php
trackler-2.2.1.165 tracks/php/exercises/triangle/example.php
trackler-2.2.1.164 tracks/php/exercises/triangle/example.php
trackler-2.2.1.163 tracks/php/exercises/triangle/example.php
trackler-2.2.1.162 tracks/php/exercises/triangle/example.php
trackler-2.2.1.161 tracks/php/exercises/triangle/example.php
trackler-2.2.1.160 tracks/php/exercises/triangle/example.php