asrock-memory-qvl-scraper/src/Domain/Model/MemoryConfiguration.php

57 lines
1.7 KiB
PHP

<?php
namespace Domain\Model;
class MemoryConfiguration
{
private const MAX_MOTHERBOARD_SLOTS = 8;
private const OVERCLOCKING_VERIFIED = ['v', '2'];
public int $moduleSize;
public int $totalSize;
public string $totalSizeHr;
public int $numberOfModules;
public bool $overclockingVerified;
public bool $dualChannelOverclockingVerified;
public function __construct(
public string $type,
public string $vendor,
public int $speed,
public int $supportedSpeed,
public string $moduleSizeHr,
public string $module,
public string $chip,
public bool $isDualSided,
public string $dimmSocketSupport,
public string $overclockingSupport,
public string $note
)
{
$this->moduleSize = filter_var($this->moduleSizeHr, FILTER_SANITIZE_NUMBER_INT);
$this->overclockingVerified = in_array($this->overclockingSupport, self::OVERCLOCKING_VERIFIED, true);
$this->dualChannelOverclockingVerified = $this->overclockingSupport === '2';
$this->deriveAdditionalFields();
}
private function deriveAdditionalFields(): void
{
$this->findTotalSize();
$this->numberOfModules = $this->totalSize / $this->moduleSize;
}
private function findTotalSize(): void
{
// Initially 8 times the module size
$this->totalSize = self::MAX_MOTHERBOARD_SLOTS * $this->moduleSize;
// Work our way down to the module size...
while (!str_contains($this->module, $this->totalSize) && $this->totalSize > $this->moduleSize) {
$this->totalSize /= 2;
}
$this->totalSizeHr = sprintf('%dGB', $this->totalSize);
}
}