src/Chippyash/Type/Number/Complex/ComplexTypeFactory.php
protected static function convertType($original)
    {
        if ($original instanceof AbstractRationalType) {
            return RationalTypeFactory::create(
                $original->numerator()->get(),
                $original->denominator()->get()
            );
        }
        if (is_numeric($original)) {
            if (is_int($original)) {
                return RationalTypeFactory::create($original, 1);
            }
            //default - convert to float
            return RationalTypeFactory::fromFloat(floatval($original));
        }
        if ($original instanceof FloatType) {
            return RationalTypeFactory::fromFloat($original());
        }
        if ($original instanceof IntType) {
            return RationalTypeFactory::create($original, 1);
        }
        if (is_string($original)) {
            try {
                return RationalTypeFactory::fromString($original);
            } catch (\InvalidArgumentException $e) {
                throw new InvalidTypeException("{$original} for Complex type construction");
            }
        }

        $type = gettype($original);
        throw new InvalidTypeException("{$type} for Complex type construction");
    }
protected static function convertType($original)
    {
        if ($original instanceof AbstractRationalType) {
            return RationalTypeFactory::create(
                $original->numerator()->get(),
                $original->denominator()->get()
            );
        }
        if (is_numeric($original)) {
            if (is_int($original)) {
                return RationalTypeFactory::create($original, 1);
            }
            //default - convert to float
            return RationalTypeFactory::fromFloat(floatval($original));
        }
        if ($original instanceof FloatType) {
            return RationalTypeFactory::fromFloat($original());
        }
        if ($original instanceof IntType) {
            return RationalTypeFactory::create($original, 1);
        }
        if (is_string($original)) {
            try {
                return RationalTypeFactory::fromString($original);
            } catch (\InvalidArgumentException $e) {
                throw new InvalidTypeException("{$original} for Complex type construction");
            }
        }

        $type = gettype($original);
        throw new InvalidTypeException("{$type} for Complex type construction");
    }
protected static function convertType ( $ original ) { if ( $ original instanceof AbstractRationalType ) { return RationalTypeFactory :: create ( $ original -> numerator ( ) -> get ( ) , $ original -> denominator ( ) -> get ( ) ) ; } if ( is_numeric ( $ original ) ) { if ( is_int ( $ original ) ) { return RationalTypeFactory :: create ( $ original , 1 ) ; } //default - convert to float return RationalTypeFactory :: fromFloat ( floatval ( $ original ) ) ; } if ( $ original instanceof FloatType ) { return RationalTypeFactory :: fromFloat ( $ original ( ) ) ; } if ( $ original instanceof IntType ) { return RationalTypeFactory :: create ( $ original , 1 ) ; } if ( is_string ( $ original ) ) { try { return RationalTypeFactory :: fromString ( $ original ) ; } catch ( \ InvalidArgumentException $ e ) { throw new InvalidTypeException ( "{$original} for Complex type construction" ) ; } } $ type = gettype ( $ original ) ; throw new InvalidTypeException ( "{$type} for Complex type construction" ) ; }
Convert to RationalType

@param mixed $original

@return \Chippyash\Type\Number\Rational\RationalType|\Chippyash\Type\Number\Rational\GMPRationalType

@throws InvalidTypeException
Convert to RationalType