Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions src/Temperature/AbstractTemperature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Temperature;

use PCF\ValueObject\ValueObjectInterface;

abstract class AbstractTemperature implements ValueObjectInterface
{
public const ABSOLUTE_ZERO = null;

/**
* power of object
*
* @var float
*/
protected $quality;

/**
* unit type of object
*
* @var string
*/
protected $unit;

/**
* AbstractDistance constructor.
* @param float $quality
*/
public function __construct($quality)
{
if (null === (float) static::ABSOLUTE_ZERO) {
throw new \UnexpectedValueException('Constant Absolute Zero not set');
}

$this->validateQuality($quality);

$this->quality = (float) $quality;
}

protected function validateQuality($quality)
{
if (false === is_numeric($quality)) {
throw new \InvalidArgumentException('Quality expect to be a number');
}

if ($quality < static::ABSOLUTE_ZERO) {
throw new \InvalidArgumentException('Quality expect to be grater or equal 0');
}
}

public function isEqualTo(ValueObjectInterface $compare): bool
{
$className = static::class;
if (false === $compare instanceof $className) {
$errorMsg = 'you are able to compare only to same distanceType as ' . $className . 'use Comparator instead';
throw new \InvalidArgumentException($errorMsg);
}

return $compare->getQuality() == $this->getQuality();
}

/**
* {@inheritdoc}
*/
public function __toString(): string
{
return $this->getQuality() .'°'. $this->getUnit();
}

/**
* @return float
*/
public function getQuality(): float
{
return $this->quality;
}

/**
* @return string
*/
public function getUnit(): string
{
return $this->unit;
}
}
22 changes: 22 additions & 0 deletions src/Temperature/Celsius.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Temperature;

class Celsius extends AbstractTemperature
{
public const ABSOLUTE_ZERO = '–273.15';

/**
* Kelvin constructor.
*
* @param float $quality
*/
public function __construct($quality)
{
parent::__construct($quality);

$this->unit = 'C';
}
}
22 changes: 22 additions & 0 deletions src/Temperature/Delisie.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Temperature;

class Delisie extends AbstractTemperature
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add some flag, for reverted scale's Might be usefull during comparison

{
public const ABSOLUTE_ZERO = '559.725';

/**
* Kelvin constructor.
*
* @param float $quality
*/
public function __construct($quality)
{
parent::__construct($quality);

$this->unit = 'D';
}
}
22 changes: 22 additions & 0 deletions src/Temperature/Fahrenheit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Temperature;

class Fahrenheit extends AbstractTemperature
{
public const ABSOLUTE_ZERO = '–459.67';

/**
* Kelvin constructor.
*
* @param float $quality
*/
public function __construct($quality)
{
parent::__construct($quality);

$this->unit = 'F';
}
}
22 changes: 22 additions & 0 deletions src/Temperature/Kelvin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Temperature;

class Kelvin extends AbstractTemperature
{
public const ABSOLUTE_ZERO = 0;

/**
* Kelvin constructor.
*
* @param float $quality
*/
public function __construct($quality)
{
parent::__construct($quality);

$this->unit = 'K';
}
}
22 changes: 22 additions & 0 deletions src/Temperature/NewtonScale.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Temperature;

class Newton extends AbstractTemperature
{
public const ABSOLUTE_ZERO = '-90.14';

/**
* Kelvin constructor.
*
* @param float $quality
*/
public function __construct($quality)
{
parent::__construct($quality);

$this->unit = 'N';
}
}
22 changes: 22 additions & 0 deletions src/Temperature/Rankine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Temperature;

class Rankine extends AbstractTemperature
{
public const ABSOLUTE_ZERO = 0;

/**
* Kelvin constructor.
*
* @param float $quality
*/
public function __construct($quality)
{
parent::__construct($quality);

$this->unit = 'R';
}
}
22 changes: 22 additions & 0 deletions src/Temperature/Reaumur.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Temperature;

class Reaumur extends AbstractTemperature
{
public const ABSOLUTE_ZERO = '–218.52';

/**
* Kelvin constructor.
*
* @param float $quality
*/
public function __construct($quality)
{
parent::__construct($quality);

$this->unit = 'Re';
}
}
22 changes: 22 additions & 0 deletions src/Temperature/Romer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Temperature;

class Romer extends AbstractTemperature
{
public const ABSOLUTE_ZERO = '–135.90';

/**
* Kelvin constructor.
*
* @param float $quality
*/
public function __construct($quality)
{
parent::__construct($quality);

$this->unit = 'C';
}
}