Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. HRTime.php

class HRTime

@psalm-immutable

@no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit

Hierarchy

  • class \PHPUnit\Event\Telemetry\HRTime

Expanded class hierarchy of HRTime

4 files declare their use of HRTime
Facade.php in vendor/phpunit/phpunit/src/Event/Facade.php
JunitXmlLogger.php in vendor/phpunit/phpunit/src/Logging/JUnit/JunitXmlLogger.php
ResultCacheHandler.php in vendor/phpunit/phpunit/src/Runner/ResultCache/ResultCacheHandler.php
TeamCityLogger.php in vendor/phpunit/phpunit/src/Logging/TeamCity/TeamCityLogger.php
1 string reference to 'HRTime'
Utils::currentTime in vendor/guzzlehttp/guzzle/src/Utils.php
Wrapper for the hrtime() or microtime() functions (depending on the PHP version, one of the two is used)

File

vendor/phpunit/phpunit/src/Event/Value/Telemetry/HRTime.php, line 20

Namespace

PHPUnit\Event\Telemetry
View source
final class HRTime {
    private readonly int $seconds;
    private readonly int $nanoseconds;
    
    /**
     * @throws InvalidArgumentException
     */
    public static function fromSecondsAndNanoseconds(int $seconds, int $nanoseconds) : self {
        return new self($seconds, $nanoseconds);
    }
    
    /**
     * @throws InvalidArgumentException
     */
    private function __construct(int $seconds, int $nanoseconds) {
        $this->ensureNotNegative($seconds, 'seconds');
        $this->ensureNotNegative($nanoseconds, 'nanoseconds');
        $this->ensureNanoSecondsInRange($nanoseconds);
        $this->seconds = $seconds;
        $this->nanoseconds = $nanoseconds;
    }
    public function seconds() : int {
        return $this->seconds;
    }
    public function nanoseconds() : int {
        return $this->nanoseconds;
    }
    public function duration(self $start) : Duration {
        $seconds = $this->seconds - $start->seconds();
        $nanoseconds = $this->nanoseconds - $start->nanoseconds();
        if ($nanoseconds < 0) {
            $seconds--;
            $nanoseconds += 1000000000;
        }
        if ($seconds < 0) {
            return Duration::fromSecondsAndNanoseconds(0, 0);
        }
        return Duration::fromSecondsAndNanoseconds($seconds, $nanoseconds);
    }
    
    /**
     * @throws InvalidArgumentException
     */
    private function ensureNotNegative(int $value, string $type) : void {
        if ($value < 0) {
            throw new InvalidArgumentException(sprintf('Value for %s must not be negative.', $type));
        }
    }
    
    /**
     * @throws InvalidArgumentException
     */
    private function ensureNanoSecondsInRange(int $nanoseconds) : void {
        if ($nanoseconds > 999999999) {
            throw new InvalidArgumentException('Value for nanoseconds must not be greater than 999999999.');
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
HRTime::$nanoseconds private property
HRTime::$seconds private property
HRTime::duration public function
HRTime::ensureNanoSecondsInRange private function
HRTime::ensureNotNegative private function
HRTime::fromSecondsAndNanoseconds public static function
HRTime::nanoseconds public function
HRTime::seconds public function
HRTime::__construct private function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal