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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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)
- [Currency](src/Currency) - to many to list them all
- [Time](src/Time):
- [Hour](src/Time/Hour.php)
- [Ke](src/Time/Ke.php)
Expand All @@ -22,7 +23,7 @@ We are not fear of criticism, our cats will cheer us up.
- [Svedberg](src/Time/Svedberg.php)
- [Speed](src/Speed/Speed.php)
- possible every combination of [Distance](src/Distance) and [Time](src/Time) units




Expand Down
107 changes: 107 additions & 0 deletions src/Currency/AbstractCurrency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

use PCF\ValueObject\ValueObjectInterface;

abstract class AbstractCurrency implements ValueObjectInterface
{

public const FULL_NAME = '';
public const SUBUNIT = '';
public const ISO_CODE = '';
public const SYMBOL = '';

protected const SUBUNIT_TO_UNIT = 1;
protected const SYMBOL_FIRST = false;

/**
* @var integer
*/
protected $subUnitQuality;

/**
* AbstractCurrency constructor.
* @param float $quality
* @param int $subUnitQuality
*/
public function __construct($quality = null, $subUnitQuality = null)
{
if (false === empty($subUnitQuality)) {
$this->subUnitQuality = $subUnitQuality;
} elseif (false === empty($quality)) {
Copy link
Member

Choose a reason for hiding this comment

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

Strange if-else code block. What if both was not empty ?

Copy link
Member Author

Choose a reason for hiding this comment

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

than I throw an exception

$this->subUnitQuality = intval($quality * static::SUBUNIT_TO_UNIT);
} else {
throw new \InvalidArgumentException('quality or subunit quality required');
}
}

/**
* @inheritdoc
*/
public function isEqualTo(ValueObjectInterface $compare): bool
{
if (!$compare instanceof AbstractCurrency || !$compare instanceof static::class) {
throw new \InvalidArgumentException('You may compare only same currency');
}
return $compare->getQuality() == $this->getQuality();
}

/**
* @inheritdoc
*/
public function __toString(): string
{
return ($this->subUnitQuality / static::SUBUNIT_TO_UNIT) . ' ' . static::SYMBOL;
}

/**
* @return string
*/
public function getSubUnitQuality()
{
return $this->subUnitQuality . ' ' . static::SUBUNIT;
}

/**
* @return string
*/
public function getSymbol()
{
return static::SYMBOL;
}

/**
* @return string
*/
public function getName()
{
return static::FULL_NAME;
}

/**
* @return string
*/
public function getSubUnit()
{
return static::SUBUNIT;
}

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

/**
* @return int
*/
public function getSubQuality()
{
return $this->subUnitQuality;
}
}
16 changes: 16 additions & 0 deletions src/Currency/AfghanAfghani.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

class AfghanAfghani extends AbstractCurrency
{
public const FULL_NAME = 'Afghan Afghani';
public const SUBUNIT = 'Pul';
public const ISO_CODE = 'AFN';
public const SYMBOL = 'Ø‹';

protected const SUBUNIT_TO_UNIT = 100;
protected const SYMBOL_FIRST = false;
}
16 changes: 16 additions & 0 deletions src/Currency/AlbanianLek.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

class AlbanianLek extends AbstractCurrency
{
public const FULL_NAME = 'Albanian Lek';
public const SUBUNIT = 'Qintar';
public const ISO_CODE = 'ALL';
public const SYMBOL = 'L';

protected const SUBUNIT_TO_UNIT = 100;
protected const SYMBOL_FIRST = false;
}
16 changes: 16 additions & 0 deletions src/Currency/AlgerianDinar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

class AlgerianDinar extends AbstractCurrency
{
public const FULL_NAME = 'Algerian Dinar';
public const SUBUNIT = 'Centime';
public const ISO_CODE = 'DZD';
public const SYMBOL = 'د.ج';

protected const SUBUNIT_TO_UNIT = 100;
protected const SYMBOL_FIRST = false;
}
16 changes: 16 additions & 0 deletions src/Currency/AngolanKwanza.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

class AngolanKwanza extends AbstractCurrency
{
public const FULL_NAME = 'Angolan Kwanza';
public const SUBUNIT = 'Cêntimo';
public const ISO_CODE = 'AOA';
public const SYMBOL = 'Kz';

protected const SUBUNIT_TO_UNIT = 100;
protected const SYMBOL_FIRST = false;
}
16 changes: 16 additions & 0 deletions src/Currency/ArgentinePeso.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

class ArgentinePeso extends AbstractCurrency
{
public const FULL_NAME = 'Argentine Peso';
public const SUBUNIT = 'Centavo';
public const ISO_CODE = 'ARS';
public const SYMBOL = '$';

protected const SUBUNIT_TO_UNIT = 100;
protected const SYMBOL_FIRST = true;
}
16 changes: 16 additions & 0 deletions src/Currency/ArmenianDram.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

class ArmenianDram extends AbstractCurrency
{
public const FULL_NAME = 'Armenian Dram';
public const SUBUNIT = 'Luma';
public const ISO_CODE = 'AMD';
public const SYMBOL = 'Õ¤Ö€.';

protected const SUBUNIT_TO_UNIT = 100;
protected const SYMBOL_FIRST = false;
}
16 changes: 16 additions & 0 deletions src/Currency/ArubanFlorin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

class ArubanFlorin extends AbstractCurrency
{
public const FULL_NAME = 'Aruban Florin';
public const SUBUNIT = 'Cent';
public const ISO_CODE = 'AWG';
public const SYMBOL = 'Æ’';

protected const SUBUNIT_TO_UNIT = 100;
protected const SYMBOL_FIRST = false;
}
16 changes: 16 additions & 0 deletions src/Currency/AustralianDollar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

class AustralianDollar extends AbstractCurrency
{
public const FULL_NAME = 'Australian Dollar';
public const SUBUNIT = 'Cent';
public const ISO_CODE = 'AUD';
public const SYMBOL = '$';

protected const SUBUNIT_TO_UNIT = 100;
protected const SYMBOL_FIRST = true;
}
16 changes: 16 additions & 0 deletions src/Currency/AzerbaijaniManat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

class AzerbaijaniManat extends AbstractCurrency
{
public const FULL_NAME = 'Azerbaijani Manat';
public const SUBUNIT = 'Qəpik';
public const ISO_CODE = 'AZN';
public const SYMBOL = '';

protected const SUBUNIT_TO_UNIT = 100;
protected const SYMBOL_FIRST = true;
}
16 changes: 16 additions & 0 deletions src/Currency/BahamianDollar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

class BahamianDollar extends AbstractCurrency
{
public const FULL_NAME = 'Bahamian Dollar';
public const SUBUNIT = 'Cent';
public const ISO_CODE = 'BSD';
public const SYMBOL = '$';

protected const SUBUNIT_TO_UNIT = 100;
protected const SYMBOL_FIRST = true;
}
16 changes: 16 additions & 0 deletions src/Currency/BahrainiDinar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

class BahrainiDinar extends AbstractCurrency
{
public const FULL_NAME = 'Bahraini Dinar';
public const SUBUNIT = 'Fils';
public const ISO_CODE = 'BHD';
public const SYMBOL = 'ب.د';

protected const SUBUNIT_TO_UNIT = 1000;
protected const SYMBOL_FIRST = true;
}
16 changes: 16 additions & 0 deletions src/Currency/BangladeshiTaka.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

class BangladeshiTaka extends AbstractCurrency
{
public const FULL_NAME = 'Bangladeshi Taka';
public const SUBUNIT = 'Paisa';
public const ISO_CODE = 'BDT';
public const SYMBOL = 'à§³';

protected const SUBUNIT_TO_UNIT = 100;
protected const SYMBOL_FIRST = true;
}
16 changes: 16 additions & 0 deletions src/Currency/BarbadianDollar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

class BarbadianDollar extends AbstractCurrency
{
public const FULL_NAME = 'Barbadian Dollar';
public const SUBUNIT = 'Cent';
public const ISO_CODE = 'BBD';
public const SYMBOL = '$';

protected const SUBUNIT_TO_UNIT = 100;
protected const SYMBOL_FIRST = false;
}
16 changes: 16 additions & 0 deletions src/Currency/BelarusianRuble.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

class BelarusianRuble extends AbstractCurrency
{
public const FULL_NAME = 'Belarusian Ruble';
public const SUBUNIT = 'Kapyeyka';
public const ISO_CODE = 'BYR';
public const SYMBOL = 'Br';

protected const SUBUNIT_TO_UNIT = 100;
protected const SYMBOL_FIRST = false;
}
16 changes: 16 additions & 0 deletions src/Currency/BelizeDollar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

class BelizeDollar extends AbstractCurrency
{
public const FULL_NAME = 'Belize Dollar';
public const SUBUNIT = 'Cent';
public const ISO_CODE = 'BZD';
public const SYMBOL = '$';

protected const SUBUNIT_TO_UNIT = 100;
protected const SYMBOL_FIRST = true;
}
16 changes: 16 additions & 0 deletions src/Currency/BermudianDollar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PCF\ValueObject\Currency;

class BermudianDollar extends AbstractCurrency
{
public const FULL_NAME = 'Bermudian Dollar';
public const SUBUNIT = 'Cent';
public const ISO_CODE = 'BMD';
public const SYMBOL = '$';

protected const SUBUNIT_TO_UNIT = 100;
protected const SYMBOL_FIRST = true;
}
Loading