protected function ttlToSeconds($ttl): int
    {
        if (is_null($ttl)) {
            return $this->defaultSeconds;
        }
        if (is_object($ttl)) {
            if ($ttl instanceof \DateInterval) {
                $seconds = $this->dateIntervalToSeconds($ttl);
                if ($seconds < 0) {
                    throw InvalidArgumentException::dateIntervalInPast();
                }
                return $seconds;
            } else {
                throw StrictTypeException::ttlTypeError($ttl);
            }
        }
        if (! $this->strictType) {
            if (is_numeric($ttl)) {
                $ttl = intval($ttl, 10);
            }
        }
        $type = gettype($ttl);
        if (! in_array($type, array('integer', 'string'))) {
            throw StrictTypeException::ttlTypeError($ttl);
        }
        $now = time();
        if (is_int($ttl)) {
            // allow -1 to adjust the cache time +/- up to 15% of default
            if ($ttl === -1) {
                $seconds = $this->defaultSeconds;
                $partial = intval(round(0.15 * $seconds));
                if ($partial >= 900) {
                    $adjust = random_int(0, $partial);
                    $direction = random_int(0, 1);
                    if ($direction === 0) {
                        $seconds = $seconds + $adjust;
                    } else {
                        $seconds = $seconds - $adjust;
                    }
                }
            } else {
                $seconds = $ttl;
            }
            if ($seconds > $now) {
                return ($seconds - $now);
            }
            if ($seconds < 0) {
                throw InvalidArgumentException::negativeTTL($seconds);
            }
            return $seconds;
        }
        // hope it is a date string
        if ($seconds = strtotime($ttl, $now)) {
            if ($seconds > $now) {
                return ($seconds - $now);
            } else {
                throw InvalidArgumentException::dateStringInPast($ttl);
            }
        }
        throw InvalidArgumentException::invalidTTL($ttl);
    }
protected function ttlToSeconds($ttl): int
    {
        if (is_null($ttl)) {
            return $this->defaultSeconds;
        }
        if (is_object($ttl)) {
            if ($ttl instanceof \DateInterval) {
                $seconds = $this->dateIntervalToSeconds($ttl);
                if ($seconds < 0) {
                    throw InvalidArgumentException::dateIntervalInPast();
                }
                return $seconds;
            } else {
                throw StrictTypeException::ttlTypeError($ttl);
            }
        }
        if (! $this->strictType) {
            if (is_numeric($ttl)) {
                $ttl = intval($ttl, 10);
            }
        }
        $type = gettype($ttl);
        if (! in_array($type, array('integer', 'string'))) {
            throw StrictTypeException::ttlTypeError($ttl);
        }
        $now = time();
        if (is_int($ttl)) {
            // allow -1 to adjust the cache time +/- up to 15% of default
            if ($ttl === -1) {
                $seconds = $this->defaultSeconds;
                $partial = intval(round(0.15 * $seconds));
                if ($partial >= 900) {
                    $adjust = random_int(0, $partial);
                    $direction = random_int(0, 1);
                    if ($direction === 0) {
                        $seconds = $seconds + $adjust;
                    } else {
                        $seconds = $seconds - $adjust;
                    }
                }
            } else {
                $seconds = $ttl;
            }
            if ($seconds > $now) {
                return ($seconds - $now);
            }
            if ($seconds < 0) {
                throw InvalidArgumentException::negativeTTL($seconds);
            }
            return $seconds;
        }
        // hope it is a date string
        if ($seconds = strtotime($ttl, $now)) {
            if ($seconds > $now) {
                return ($seconds - $now);
            } else {
                throw InvalidArgumentException::dateStringInPast($ttl);
            }
        }
        throw InvalidArgumentException::invalidTTL($ttl);
    }
protected function ttlToSeconds ( $ ttl ) : int { if ( is_null ( $ ttl ) ) { return $ this -> defaultSeconds ; } if ( is_object ( $ ttl ) ) { if ( $ ttl instanceof \ DateInterval ) { $ seconds = $ this -> dateIntervalToSeconds ( $ ttl ) ; if ( $ seconds < 0 ) { throw InvalidArgumentException :: dateIntervalInPast ( ) ; } return $ seconds ; } else { throw StrictTypeException :: ttlTypeError ( $ ttl ) ; } } if ( ! $ this -> strictType ) { if ( is_numeric ( $ ttl ) ) { $ ttl = intval ( $ ttl , 10 ) ; } } $ type = gettype ( $ ttl ) ; if ( ! in_array ( $ type , array ( 'integer' , 'string' ) ) ) { throw StrictTypeException :: ttlTypeError ( $ ttl ) ; } $ now = time ( ) ; if ( is_int ( $ ttl ) ) { // allow -1 to adjust the cache time +/- up to 15% of default if ( $ ttl === - 1 ) { $ seconds = $ this -> defaultSeconds ; $ partial = intval ( round ( 0.15 * $ seconds ) ) ; if ( $ partial >= 900 ) { $ adjust = random_int ( 0 , $ partial ) ; $ direction = random_int ( 0 , 1 ) ; if ( $ direction === 0 ) { $ seconds = $ seconds + $ adjust ; } else { $ seconds = $ seconds - $ adjust ; } } } else { $ seconds = $ ttl ; } if ( $ seconds > $ now ) { return ( $ seconds - $ now ) ; } if ( $ seconds < 0 ) { throw InvalidArgumentException :: negativeTTL ( $ seconds ) ; } return $ seconds ; } // hope it is a date string if ( $ seconds = strtotime ( $ ttl , $ now ) ) { if ( $ seconds > $ now ) { return ( $ seconds - $ now ) ; } else { throw InvalidArgumentException :: dateStringInPast ( $ ttl ) ; } } throw InvalidArgumentException :: invalidTTL ( $ ttl ) ; }
Generates Time To Live parameter to use with the cache engine.

This function takes either NULL, an integer or a string. When supplied
with an integer, if it is less than the current seconds from UNIX Epoch
it is treated as desired seconds the record should last. If it is larger
it assumed it is an expiration time and then calculates the corresponding
TTL. When fed a string, the `strtotime()` function is used to turn the
string into a UNIX seconds from Epoch expiration, and it then calculates
the corresponding TTL. When fed NULL, it uses the class default TTL.

@param null|int|string|\DateInterval $ttl The length to cache or the expected expiration.

@throws StrictTypeException
@throws InvalidArgumentException

@psalm-suppress RedundantConditionGivenDocblockType
@psalm-suppress RedundantCondition

@return int
Generates Time To Live parameter to use with the cache engine .