-
Notifications
You must be signed in to change notification settings - Fork 3
Temperature #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pradzikowski
wants to merge
4
commits into
purringCatFoundation:master
Choose a base branch
from
pradzikowski:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Temperature #12
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | ||
adeptofvoltron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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) { | ||
adeptofvoltron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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'; | ||
adeptofvoltron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.