Skip to content

Format update #24

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
wants to merge 4 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: php
php:
- 5.6
- 7.0
- hhvm
# - hhvm
# - nightly

before_script:
Expand Down
21 changes: 15 additions & 6 deletions bob.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@
use BestServedCold\PhalueObjects\Format\Byte\Binary;
use BestServedCold\PhalueObjects\Format\Byte\Decimal;

var_dump(Binary::fromString('100 MB')->getValue());
var_dump(Decimal::fromString('100 MB')->getValue());
var_dump(Binary::fromFloat(123456)->toString());
var_dump((string) Binary::fromFloat(1.208925819614629e24));
//var_dump(Binary::fromString('100 MB')->getValue());
//var_dump(Decimal::fromString('100 MB')->getValue());
//var_dump(Binary::fromFloat(123456)->toString());
//var_dump((string) Binary::fromFloat(1.208925819614629e24));

use BestServedCold\PhalueObjects\Format\Csv;
use BestServedCold\PhalueObjects\Format\String\Csv;
use BestServedCold\PhalueObjects\Format\String\Yaml;

var_dump(Csv::fromArray([['some', 'text'], ['in', 'a'],['multi-dimensional', 'array']])->getValue());
var_dump(
Csv::fromArray(
[['some', 'text'], ['in', 'a'], ['multi-dimensional', 'array']]
)->toJson()
);
var_dump(Csv::fromArray(['test', 'a', 'thing'])->getValue());
var_dump(Csv::fromString("this,is,some,CSV\nFor,you,to,see")->toArray());
var_dump(Csv::fromVOYaml(
Yaml::fromString("[['some','yaml'],['with','multiple'],['aspects','jungle']]")
)->toString());
8 changes: 6 additions & 2 deletions src/Colour/Hsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

use BestServedCold\PhalueObjects\ValueObject;

/**
* Class Hsv
*
* @package BestServedCold\PhalueObjects\Colour
*/
class Hsv extends ValueObject
{

}
}
8 changes: 6 additions & 2 deletions src/Colour/Jpg.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

use BestServedCold\PhalueObjects\ValueObject;

/**
* Class Jpg
*
* @package BestServedCold\PhalueObjects\Colour
*/
class Jpg extends ValueObject
{

}
}
8 changes: 6 additions & 2 deletions src/Colour/Rgb.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

use BestServedCold\PhalueObjects\ValueObject;

/**
* Class Rgb
*
* @package BestServedCold\PhalueObjects\Colour
*/
class Rgb extends ValueObject
{

}
}
3 changes: 2 additions & 1 deletion src/Contract/VOFloatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
interface VOFloatable extends Floatable
{
/**
* @return static
* @param VOFloat $voFloat
* @return mixed
*/
public static function fromVOFloat(VOFloat $voFloat);

Expand Down
3 changes: 1 addition & 2 deletions src/DateTime/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public function __construct(Hour $hour, Minute $minute, Second $second)
$this->second = $second;
$this->timestamp = $hour->getSeconds()->add($minute->getSeconds())->add($second);
$this->native = self::getNowDateTime()
->setTime($hour->getValue(), $minute->getValue(), $minute->getValue()
);
->setTime($hour->getValue(), $minute->getValue(), $minute->getValue());

parent::__construct($hour, $minute, $second);
}
Expand Down
4 changes: 3 additions & 1 deletion src/DateTime/TimeZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
* @since 0.0.1-alpha
* @version 0.0.2-alpha
*/
class TimeZone extends ValueObject {}
class TimeZone extends ValueObject
{
}
1 change: 1 addition & 0 deletions src/DateTime/Unit/DayTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function previousDay()
}

/**
* @param integer $days
* @return static
*/
public function addDay($days)
Expand Down
1 change: 0 additions & 1 deletion src/DateTime/Unit/Hour.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,4 @@ public function getMinimum()
{
return 0;
}

}
1 change: 0 additions & 1 deletion src/DateTime/Unit/Month.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,4 @@ public function getMinimum()
{
return 1;
}

}
7 changes: 6 additions & 1 deletion src/DateTime/Unit/Second.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ public function __construct($value)
parent::__construct($value);
}

/**
* @return static
*/
public static function now()
{
return new static(self::getNowDateTimeFormat('s'));
}

/**
* @return string
*/
public function __toString()
{
return str_pad($this->getValue(), 2, '0', STR_PAD_LEFT);
Expand Down Expand Up @@ -76,5 +82,4 @@ public function getMinimum()
{
return 0;
}

}
3 changes: 1 addition & 2 deletions src/Exception/InvalidTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace BestServedCold\PhalueObjects\Exception;

use BestServedCold\PhalueObjects\Format\Csv;
use BestServedCold\PhalueObjects\Mathematical\Integer;
use BestServedCold\PhalueObjects\Format\String\Csv;

/**
* Class InvalidTypeException
Expand Down
6 changes: 3 additions & 3 deletions src/File.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php namespace BestServedCold\PhalueObjects;

use BestServedCold\PhalueObjects\Format\Json;
use BestServedCold\PhalueObjects\Format\Xml;
use BestServedCold\PhalueObjects\Format\Yaml;
use BestServedCold\PhalueObjects\Format\String\Json;
use BestServedCold\PhalueObjects\Format\String\Xml;
use BestServedCold\PhalueObjects\Format\String\Yaml;

/**
* Class File
Expand Down
8 changes: 4 additions & 4 deletions src/Format/Byte.php → src/Format/Float/Byte.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace BestServedCold\PhalueObjects\Format;
namespace BestServedCold\PhalueObjects\Format\Float;

use BestServedCold\PhalueObjects\Contract\VOStringable;
use BestServedCold\PhalueObjects\VOArray\Find;
Expand All @@ -20,7 +20,7 @@ abstract class Byte extends VOFloat implements VOStringable
{
use VOStringTrait;

const UNITS = [
private static $units = [
[ 'Byte' => 'Byte' ],
[ 'KB' => 'Kilobyte' ],
[ 'MB' => 'Megabyte' ],
Expand Down Expand Up @@ -77,7 +77,7 @@ public function toString()
public function getUnit($power = null)
{
$power = $power ?: $this->getPower();
$unit = self::UNITS[ (int) floor($this->base()) ];
$unit = self::$units[ (int) floor($this->base()) ];
return Word::fromString(reset($unit))->getPluralised($power);
}

Expand All @@ -103,6 +103,6 @@ private function base()
*/
private static function getUnitKeyList()
{
return Map::fromVariadic(Value::toArrayWithPlural(true), self::UNITS)->getValue();
return Map::fromVariadic(Value::toArrayWithPlural(true), self::$units)->getValue();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace BestServedCold\PhalueObjects\Format\Byte;
namespace BestServedCold\PhalueObjects\Format\Float\Byte;

use BestServedCold\PhalueObjects\Format\Byte;
use BestServedCold\PhalueObjects\Format\Float\Byte;

/**
* Class Binary
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace BestServedCold\PhalueObjects\Format\Byte;
namespace BestServedCold\PhalueObjects\Format\Float\Byte;

use BestServedCold\PhalueObjects\Format\Byte;
use BestServedCold\PhalueObjects\Format\Float\Byte;

/**
* Class Decimal
Expand Down
52 changes: 51 additions & 1 deletion src/Format/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ BestServedCold\PhalueObjects\Format
![png](diagram.png)


## Classes
## Float classes

### Byte

Expand All @@ -38,11 +38,61 @@ string(16) "120.56 Kilobytes"
string(11) "1 Yottabyte"
```

## String classes

### Csv
```php
BestServedCold\PhalueObjects\Format\Csv
```

Usage:
```php
var_dump(
Csv::fromArray(
[['some', 'text'], ['in', 'a'], ['multi-dimensional', 'array']]
)->toJson()
);
var_dump(Csv::fromArray(['test', 'a', 'thing'])->getValue());
var_dump(Csv::fromString("this,is,some,CSV\nFor,you,to,see")->toArray());
var_dump(Csv::fromVOYaml(
Yaml::fromString("[['some','yaml'],['with','multiple'],['aspects','jungle']]")
)->toString());
```

Outputs:
```shell
string(58) "[["some","text"],["in","a"],["multi-dimensional","array"]]"
string(13) "test,a,thing
"
array(2) {
[0] =>
array(4) {
[0] =>
string(4) "this"
[1] =>
string(2) "is"
[2] =>
string(4) "some"
[3] =>
string(3) "CSV"
}
[1] =>
array(4) {
[0] =>
string(3) "For"
[1] =>
string(3) "you"
[2] =>
string(2) "to"
[3] =>
string(3) "see"
}
}
string(39) "some,yaml
with,multiple
aspects,jungle
"
```
### Json
```php
BestServedcold\PhalueObjects\Format\Json
Expand Down
Loading