<?php

declare(strict_types=1);

namespace CodingTests;

class Prime
{
    public static function isPrime(int $number): bool
    {
        if ($number <= 1) {
            return FALSE;
        }
        $factors = 0;

        for ($i = 1; $i <= floor(sqrt($number)); $i++) {
            if (is_int($number / $i)) {
                $factors++;
            }
        }

        $factors++;
        if ($factors == 2) {
            return TRUE;
        }

        return FALSE;
    }

    /**
     * 
     * Oneliner from https://stackoverflow.com/questions/38008130/php-check-if-number-is-prime
     * @param mixed $num Number to check
     * @return bool
     */
    public static function is_prime(int $num): bool
    {
        if ($num == 1)
        return false;
        for ($i = 2; $i <= $num/2; $i++)
        {
            if ($num % $i == 0)
            {
                return false;
            }
        }
        return true;
    }

    public static function findFactors(int $number): array
    {
        $factors = [];
        if ($number <= 1) {
            return $factors;
        }

        for ($i = 1; $i <= floor(sqrt($number)); $i++) {
            if (is_int($number / $i)) {
                $factors[] = $number / $i;
            }
        }

        $factors[] = $number;

        return $factors;
    }
}
