Skip to content
Open

Mass #14

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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ We are not fear of criticism, our cats will cheer us up.
- [Meter](src/Distance/Meter.php)
- [NavyMile](src/Distance/NavyMile.php)
- [Parsec](src/Distance/Parsec.php)
- [Mass](src/Mass)
- [Gram](src/Mass/Gram.php)
- [Planck](src/Mass/Planck.php)
- [Pound](src/Mass/Pound.php)
- [Slug](src/Mass/Slug.php)
- [Solar](src/Mass/Solar.php)
- [Time](src/Time):
- [Hour](src/Time/Hour.php)
- [Ke](src/Time/Ke.php)
Expand Down
22 changes: 22 additions & 0 deletions script/run.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

require '../vendor/autoload.php';
require 'scriptMethods.php';

$x = include '../vendor/moneyphp/money/resources/currency.php';

foreach ($x as $val) {
$c = getClass($val['currency'], $val['alphabeticCode'], $val['numericCode']);
$ret = $c->generate();
$ret = preg_replace('/^/','<?php'.PHP_EOL.PHP_EOL.'declare(strict_types = 1);'.PHP_EOL.PHP_EOL,$ret);
$ret = preg_replace('#[^t]Currency {#','Currency;', $ret);
$ret = preg_replace('#tCurrency {#','Currency'.PHP_EOL.'{', $ret);
$ret = preg_replace('/}$/','', $ret);
$ret = preg_replace('/\n /', PHP_EOL, $ret);
$ret = preg_replace('#ity\) {#','ity)'.PHP_EOL.' {', $ret);
$path = getPath($val['currency']);
if (!file_exists($path)) {
file_put_contents($path, $ret);
}

}
72 changes: 72 additions & 0 deletions src/Mass/AbstractMass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Mass;

use PCF\ValueObject\ValueObjectInterface;

abstract class AbstractMass implements ValueObjectInterface
{
/**
* power of object
*
* @var float
*/
protected $quality;

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

/**
* AbstractMass constructor.
* @param float $quality
*/
public function __construct($quality)
{
if (false === is_numeric($quality)) {
throw new \InvalidArgumentException('quality expect to be a number');
}

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

public function isEqualTo(ValueObjectInterface $compare): bool
{
$className = static::class;
if (false === ($compare instanceof AbstractMass) || false === ($compare instanceof $className)) {
$errorMsg = 'you are able to compare only to same massUnit as ' . $className;
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;
}
}
14 changes: 14 additions & 0 deletions src/Mass/Gram.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types = 1);

namespace PCF\ValueObject\Mass;

class Gram extends AbstractMass
{
public function __construct($quality)
{
parent::__construct($quality);
$this->unit = 'g';
}
}
14 changes: 14 additions & 0 deletions src/Mass/Planck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types = 1);

namespace PCF\ValueObject\Mass;

class Planck extends AbstractMass
{
public function __construct($quality)
{
parent::__construct($quality);
$this->unit = 'mP';
}
}
14 changes: 14 additions & 0 deletions src/Mass/Pound.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types = 1);

namespace PCF\ValueObject\Mass;

class Pound extends AbstractMass
{
public function __construct($quality)
{
parent::__construct($quality);
$this->unit = 'lb';
}
}
14 changes: 14 additions & 0 deletions src/Mass/Slug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types = 1);

namespace PCF\ValueObject\Mass;

class Slug extends AbstractMass
{
public function __construct($quality)
{
parent::__construct($quality);
$this->unit = 'sl';
}
}
14 changes: 14 additions & 0 deletions src/Mass/Solar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types = 1);

namespace PCF\ValueObject\Mass;

class Solar extends AbstractMass
{
public function __construct($quality)
{
parent::__construct($quality);
$this->unit = 'M☉';
}
}