Modernize private property declarations in src/timings

This commit is contained in:
Dylan K. Taylor 2022-05-17 21:54:45 +01:00
parent 9de88aa734
commit 1d5430937f
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 20 additions and 39 deletions

View File

@ -34,8 +34,7 @@ use function dechex;
abstract class Timings{ abstract class Timings{
public const INCLUDED_BY_OTHER_TIMINGS_PREFIX = "** "; public const INCLUDED_BY_OTHER_TIMINGS_PREFIX = "** ";
/** @var bool */ private static bool $initialized = false;
private static $initialized = false;
/** @var TimingsHandler */ /** @var TimingsHandler */
public static $fullTick; public static $fullTick;

View File

@ -29,10 +29,8 @@ use function count;
use function hrtime; use function hrtime;
class TimingsHandler{ class TimingsHandler{
/** @var bool */ private static bool $enabled = false;
private static $enabled = false; private static int $timingStart = 0;
/** @var int */
private static $timingStart = 0;
/** @return string[] */ /** @return string[] */
public static function printTimings() : array{ public static function printTimings() : array{
@ -99,21 +97,13 @@ class TimingsHandler{
} }
} }
/** @var string */ private ?TimingsRecord $record = null;
private $name; private int $timingDepth = 0;
/** @var TimingsHandler|null */
private $parent = null;
/** @var TimingsRecord|null */ public function __construct(
private $record = null; private string $name,
private ?TimingsHandler $parent = null
/** @var int */ ){}
private $timingDepth = 0;
public function __construct(string $name, ?TimingsHandler $parent = null){
$this->name = $name;
$this->parent = $parent;
}
public function getName() : string{ return $this->name; } public function getName() : string{ return $this->name; }

View File

@ -36,7 +36,7 @@ final class TimingsRecord{
* @var self[] * @var self[]
* @phpstan-var array<int, self> * @phpstan-var array<int, self>
*/ */
private static $records = []; private static array $records = [];
public static function clearRecords() : void{ public static function clearRecords() : void{
foreach(self::$records as $record){ foreach(self::$records as $record){
@ -71,26 +71,18 @@ final class TimingsRecord{
} }
} }
/** @var TimingsHandler */ private int $count = 0;
private $handler; private int $curCount = 0;
private int $start = 0;
private int $totalTime = 0;
private int $curTickTotal = 0;
private int $violations = 0;
/** @var int */ public function __construct(
private $count = 0;
/** @var int */
private $curCount = 0;
/** @var int */
private $start = 0;
/** @var int */
private $totalTime = 0;
/** @var int */
private $curTickTotal = 0;
/** @var int */
private $violations = 0;
public function __construct(TimingsHandler $handler){
self::$records[spl_object_id($this)] = $this;
//I'm not the biggest fan of this cycle, but it seems to be the most effective way to avoid leaking anything. //I'm not the biggest fan of this cycle, but it seems to be the most effective way to avoid leaking anything.
$this->handler = $handler; private TimingsHandler $handler
){
self::$records[spl_object_id($this)] = $this;
} }
public function getName() : string{ return $this->handler->getName(); } public function getName() : string{ return $this->handler->getName(); }