Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,693 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,40 +1,5 @@ | ||
# Cache and logs (Symfony2) | ||
/app/cache/* | ||
/app/logs/* | ||
!app/cache/.gitkeep | ||
!app/logs/.gitkeep | ||
|
||
# Cache and logs (Symfony3) | ||
/var/cache/* | ||
/var/logs/* | ||
!var/cache/.gitkeep | ||
!var/logs/.gitkeep | ||
|
||
# Parameters | ||
/app/config/parameters.yml | ||
/app/config/parameters.ini | ||
|
||
# Managed by Composer | ||
/app/bootstrap.php.cache | ||
/var/bootstrap.php.cache | ||
/bin/* | ||
!bin/console | ||
!bin/symfony_requirements | ||
composer.phar | ||
/vendor/ | ||
|
||
# Assets and user uploads | ||
/web/bundles/ | ||
/web/uploads/ | ||
|
||
# Assets managed by Bower | ||
/web/assets/vendor/ | ||
|
||
# PHPUnit | ||
/app/phpunit.xml | ||
/phpunit.xml | ||
|
||
# Build data | ||
/build/ | ||
|
||
# Composer PHAR | ||
/composer.phar | ||
composer.lock | ||
/build/logs | ||
/bin |
This file contains 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,23 @@ | ||
<?php | ||
|
||
$finder = Symfony\CS\Finder\DefaultFinder::create() | ||
->in('src') | ||
; | ||
|
||
$header = <<<EOT | ||
This file is part of the CGI-Calc package. | ||
(c) Milos Tomic <tmilos@gmail.com> | ||
This source file is subject to the MIT license that is bundled | ||
with this source code in the file LICENSE. | ||
EOT; | ||
|
||
Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header); | ||
|
||
return Symfony\CS\Config\Config::create() | ||
->setUsingCache(false) | ||
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL) | ||
->fixers(array('-empty_return', '-phpdoc_no_empty_return', 'header_comment')) | ||
->finder($finder) | ||
; |
This file contains 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,2 @@ | ||
tools: | ||
external_code_coverage: false |
This file contains 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,36 @@ | ||
language: php | ||
|
||
sudo: false | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache | ||
|
||
php: | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
- hhvm | ||
|
||
matrix: | ||
fast_finish: true | ||
allow_failures: | ||
- php: hhvm | ||
include: | ||
- php: 5.5 | ||
env: COMPOSER_FLAGS="--prefer-lowest" | ||
|
||
before_install: | ||
- composer self-update | ||
- composer --version | ||
- wget http://get.sensiolabs.org/php-cs-fixer.phar -O php-cs-fixer.phar | ||
|
||
install: | ||
- composer update $COMPOSER_FLAGS | ||
|
||
script: | ||
- php php-cs-fixer.phar fix --dry-run -v | ||
- bin/phpunit --coverage-clover build/logs/clover.xml | ||
|
||
after_script: | ||
- php bin/coveralls -v |
This file contains 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 |
---|---|---|
@@ -1 +1,58 @@ | ||
# cgi-calc | ||
# CGI Calc | ||
|
||
Casual Gaming Infrastructure - Calc PHP library. | ||
|
||
[![License](https://img.shields.io/packagist/l/tmilos/cgi-calc.svg)](https://packagist.org/packages/tmilos/cgi-calc) | ||
[![Build Status](https://travis-ci.org/tmilos/cgi-calc.svg?branch=master)](https://travis-ci.org/tmilos/cgi-calc) | ||
[![Coverage Status](https://coveralls.io/repos/github/tmilos/cgi-calc/badge.svg?branch=master)](https://coveralls.io/github/tmilos/cgi-calc?branch=master) | ||
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/tmilos/cgi-calc/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/tmilos/cgi-calc/?branch=master) | ||
|
||
|
||
## Point | ||
|
||
```php | ||
$point = new Point(10, 10); | ||
print $point->getX(); | ||
print $point->getY(); | ||
$leftPoint = $point->left(); | ||
$otherPoint = $point->move(new Point(2, 3)); | ||
``` | ||
|
||
## PointSet | ||
|
||
```php | ||
$set = new PointSet([new Point(10, 10), new Point(20, 20)]); | ||
$set[new Point(10, 10)] = 'something'; | ||
$set->contains(new Point(10, 10)); // true | ||
print $set[new Point(10, 10)]; // something | ||
|
||
$other = new PointSet([new Point(10, 10), new Point(0, 0)]); | ||
$unionSet = $set->union($other); | ||
$intersectionSet = $set->intersect($other); | ||
$differenceSet = $set->diff($other); | ||
``` | ||
|
||
## Field Producers | ||
|
||
```php | ||
$rectangularProducer = new RectangularFromTwoPoints(new Point(0,0), new Point(3, 2), function (Point $point) { | ||
// value provider for the points of the generated rectangular | ||
return sprintf("%d : %d", $point->getX(), $point->getY()); | ||
}); | ||
$rect = $rectangularProducer->produce(); | ||
``` | ||
|
||
```php | ||
$rectangularProducer = new RectangularFromTwoPoints(new Point(2,3), 10, 8); | ||
$rect = $rectangularProducer->produce(); | ||
``` | ||
|
||
```php | ||
$circleProducer = new CircularCenterRadius(new Point(10,10), 8); | ||
$circle = $circleProducer->produce(); | ||
``` | ||
|
||
|
||
# License | ||
|
||
Copyright [Milos Tomic](https://github.com/tmilos). This package is licensed under MIT, for details check the [LICENSE](LICENSE) file. |
This file contains 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,8 @@ | ||
<?php | ||
|
||
// if library is in dev environement with its own vendor, include its autoload | ||
if(file_exists(__DIR__ . '/vendor')) | ||
require_once __DIR__ . '/vendor/autoload.php'; | ||
// if library is in vendor of another project, include the global autolaod | ||
else | ||
require_once __DIR__ . '/../../autoload.php'; |
This file contains 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,31 @@ | ||
{ | ||
"name": "tmilos/cgi-calc", | ||
"license": "MIT", | ||
"type": "library", | ||
"authors": [ | ||
{ | ||
"name": "Milos Tomic", | ||
"email": "tmilos@gmail.com", | ||
"homepage": "https://github.com/tmilos/", | ||
"role": "Developer" | ||
} | ||
], | ||
"autoload": { | ||
"psr-0": { | ||
"Cgi\\Calc\\Tests\\": "tests/", | ||
"Cgi\\Calc\\": "src/" | ||
} | ||
}, | ||
"require": { | ||
"php": ">=5.5.1" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "~4.8", | ||
"satooshi/php-coveralls": "~0.6" | ||
}, | ||
"config": { | ||
"bin-dir": "bin" | ||
}, | ||
"prefer-stable": true, | ||
"minimum-stability": "dev" | ||
} |
This file contains 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,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html --> | ||
<phpunit | ||
backupGlobals = "false" | ||
backupStaticAttributes = "false" | ||
colors = "false" | ||
convertErrorsToExceptions = "true" | ||
convertNoticesToExceptions = "true" | ||
convertWarningsToExceptions = "true" | ||
processIsolation = "false" | ||
stopOnFailure = "false" | ||
syntaxCheck = "false" | ||
bootstrap = "autoload.php" | ||
> | ||
|
||
<logging> | ||
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/> | ||
</logging> | ||
|
||
<testsuites> | ||
<testsuite name="Project Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<!-- | ||
<php> | ||
<server name="KERNEL_DIR" value="/path/to/your/app/" /> | ||
</php> | ||
--> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>src</directory> | ||
</whitelist> | ||
</filter> | ||
|
||
|
||
</phpunit> |
This file contains 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,56 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the CGI-Calc package. | ||
* | ||
* (c) Milos Tomic <tmilos@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Cgi\Calc\Field; | ||
|
||
use Cgi\Calc\FieldProducer; | ||
use Cgi\Calc\Point; | ||
|
||
abstract class AbstractFieldProducer implements FieldProducer | ||
{ | ||
private $callback; | ||
|
||
public function __construct($valueProvider) | ||
{ | ||
$this->callback = $this->getValueCallable($valueProvider); | ||
} | ||
|
||
/** | ||
* @param Point $point | ||
* | ||
* @return mixed|null | ||
*/ | ||
protected function getValue(Point $point) | ||
{ | ||
return $this->callback ? call_user_func($this->callback, $point) : null; | ||
} | ||
|
||
/** | ||
* @param ValueProvider|callable|null $valueProvider | ||
* | ||
* @return callable|null | ||
*/ | ||
private function getValueCallable($valueProvider) | ||
{ | ||
$callback = null; | ||
if ($valueProvider instanceof ValueProvider) { | ||
$callback = function (Point $p) use ($valueProvider) { | ||
return $valueProvider->get($p); | ||
}; | ||
} elseif (is_callable($valueProvider)) { | ||
$callback = $valueProvider; | ||
} elseif ($valueProvider) { | ||
throw new \InvalidArgumentException('Value provider must be instance of ValueProvider or callable'); | ||
} | ||
|
||
return $callback; | ||
} | ||
} |
Oops, something went wrong.