Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
ytake committed Apr 19, 2017
1 parent 18dd2b8 commit 7b7b497
Show file tree
Hide file tree
Showing 134 changed files with 7,678 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/bin/
/composer.lock
/phpunit.xml
/vendor/
12 changes: 12 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tools:
external_code_coverage:
timeout: 600
php_code_sniffer: true
php_cpd: true
php_loc: true
php_mess_detector: true
php_pdepend: true
php_analyzer: true
sensiolabs_security_checker: true
filter:
paths: [src/*]
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: php

sudo: false

php:
- 5.4
- 5.5
- 5.6
- hhvm
- nightly

before_script:
- composer self-update
- composer install --prefer-dist --no-interaction

script:
- bin/phpunit --coverage-clover=coverage.clover --coverage-text

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
30 changes: 30 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Contributing
============

If you are reading this, **thank you**! You are about to make things better and this makes you **a hero**!

Here are a few rules to follow in order to ease code reviews, and discussions before
maintainers accept and merge your work.

You MUST follow the [PSR-1](http://www.php-fig.org/psr/1/) and
[PSR-2](http://www.php-fig.org/psr/2/). If you don't know about any of them, you
should really read the recommendations. Can't wait? Use the [PHP-CS-Fixer
tool](http://cs.sensiolabs.org/).

You MUST run the test suite.

You MUST write (or update) unit tests.

You SHOULD write documentation.

Please, write [commit messages that make
sense](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html),
and [rebase your branch](http://git-scm.com/book/en/Git-Branching-Rebasing)
before submitting your Pull Request.

One may ask you to [squash your
commits](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html)
too. This is used to "clean" your Pull Request before merging it (we don't want
commits such as `fix tests`, `fix 2`, `fix 3`, etc.).

Thank you very much!
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2013 Nicolò Pignatelli

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# valueobjects
ValueObjects
============

*nicolopignatelli/valueobjects*

Temporary substitute library
7 changes: 7 additions & 0 deletions UPGRADE-3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
UPGRADE FROM 2.x to 3.0
=======================

### StringLiteral

* The `String` and `Null` classed and namespaces have been respectively renamed to
`StringLiteral` and `NullValue` in order to be compatible with PHP 7.
43 changes: 43 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "ytake/valueobjects",
"description": "A PHP library/collection of classes aimed to help developers using and undestanding immutable objects.(temporary package)",
"license": "MIT",
"authors": [
{
"name": "Nicolò Pignatelli",
"email": "pignatelli.nicolo@gmail.com"
}
],
"require": {
"php": ">=5.4",
"ramsey/uuid": "~3.0",
"mathiasverraes/money": "~1.2",
"marc-mabe/php-enum": "~1.0",
"zendframework/zend-validator": "~2.2",
"league/geotools": "~0.7"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"config": {
"bin-dir": "bin"
},
"autoload": {
"psr-4": {
"ValueObjects\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"ValueObjects\\Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "4.2.x-dev"
}
},
"replace": {
"nicolopignatelli/valueobjects": "^4.0"
}
}
23 changes: 23 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="valueobjects Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
30 changes: 30 additions & 0 deletions src/Climate/Celsius.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace ValueObjects\Climate;

class Celsius extends Temperature
{
/**
* @return Celsius
*/
public function toCelsius()
{
return new static($this->value);
}

/**
* @return Kelvin
*/
public function toKelvin()
{
return new Kelvin($this->value + 273.15);
}

/**
* @return Fahrenheit
*/
public function toFahrenheit()
{
return new Fahrenheit($this->value * 1.8 + 32);
}
}
30 changes: 30 additions & 0 deletions src/Climate/Fahrenheit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace ValueObjects\Climate;

class Fahrenheit extends Temperature
{
/**
* @return Celsius
*/
public function toCelsius()
{
return new Celsius(($this->value - 32) / 1.8);
}

/**
* @return Kelvin
*/
public function toKelvin()
{
return new Kelvin($this->toCelsius()->toNative() + 273.15);
}

/**
* @return Fahrenheit
*/
public function toFahrenheit()
{
return new static($this->value);
}
}
30 changes: 30 additions & 0 deletions src/Climate/Kelvin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace ValueObjects\Climate;

class Kelvin extends Temperature
{
/**
* @return Celsius
*/
public function toCelsius()
{
return new Celsius($this->value - 273.15);
}

/**
* @return Kelvin
*/
public function toKelvin()
{
return new static($this->value);
}

/**
* @return Fahrenheit
*/
public function toFahrenheit()
{
return new Fahrenheit($this->toCelsius()->toNative() * 1.8 + 32);
}
}
46 changes: 46 additions & 0 deletions src/Climate/RelativeHumidity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace ValueObjects\Climate;

use ValueObjects\Number\Natural;
use ValueObjects\Exception\InvalidNativeArgumentException;

class RelativeHumidity extends Natural
{
const MIN = 0;

const MAX = 100;

/**
* Returns a new RelativeHumidity from native int value
*
* @param int $value
* @return RelativeHumidity
*/
public static function fromNative()
{
$value = func_get_arg(0);

return new static($value);
}

/**
* Returns a new RelativeHumidity object
*
* @param int $value
*/
public function __construct($value)
{
$options = array(
'options' => array('min_range' => self::MIN, 'max_range' => self::MAX)
);

$value = filter_var($value, FILTER_VALIDATE_INT, $options);

if (false === $value) {
throw new InvalidNativeArgumentException($value, array('int (>=' . self::MIN . ', <=' . self::MAX . ')'));
}

parent::__construct($value);
}
}
23 changes: 23 additions & 0 deletions src/Climate/Temperature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace ValueObjects\Climate;

use ValueObjects\Number\Real;

abstract class Temperature extends Real
{
/**
* @return Celsius
*/
abstract public function toCelsius();

/**
* @return Kelvin
*/
abstract public function toKelvin();

/**
* @return Fahrenheit
*/
abstract public function toFahrenheit();
}
Loading

0 comments on commit 7b7b497

Please sign in to comment.