Skip to content

Commit

Permalink
contributte
Browse files Browse the repository at this point in the history
  • Loading branch information
MartkCz committed Feb 27, 2019
1 parent 6670823 commit 030c9ef
Show file tree
Hide file tree
Showing 42 changed files with 584 additions and 422 deletions.
40 changes: 28 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
language: php
php:
- 7.2
- 7.3

os:
- linux
before_install:
# Turn off XDebug
- phpenv config-rm xdebug.ini || return 0

php:
- 7.1
install:
# Composer
- travis_retry composer install --no-progress --prefer-dist
script:
# Tests
- composer run-script tests

matrix:
jobs:
include:
- php: 7.1
env: PHPSTAN=1
- env: title="Lowest Dependencies 7.2"
php: 7.2
install:
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest
script:
- composer run-script tests

install:
- composer self-update
- composer install
- stage: Quality Assurance
php: 7.2
script:
- composer run-script qa

script:
- if [ "$PHPSTAN" = "1" ]; then vendor/bin/phpstan analyse src --level=6 --ansi --no-progress; fi
sudo: false

cache:
directories:
- $HOME/.composer/cache
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/WebChemistry/invoice.svg?branch=master)](https://travis-ci.org/WebChemistry/invoice)
[![Build Status](https://travis-ci.org/Contributte/invoice.svg?branch=master)](https://travis-ci.org/Contributte/invoice)

# PHP Invoice

Expand All @@ -9,39 +9,39 @@ Average output ~20ms
php 7.1

```
composer require webchemistry/invoice
composer require contributte/invoice
```

## Usage

### Company

```php
$company = new WebChemistry\Invoice\Data\Company('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA', '0123456789', 'CZ0123456789');
$company = new Contributte\Invoice\Data\Company('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA', '0123456789', 'CZ0123456789');
```

### Customer

```php
$customer = new WebChemistry\Invoice\Data\Customer('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA');
$customer = new Contributte\Invoice\Data\Customer('John Doe', 'Los Angeles', 'Cavetown', '720 55', 'USA');
```

### Account

```php
$account = new WebChemistry\Invoice\Data\Account('1111', 'CZ4808000000002353462015', 'GIGACZPX');
$account = new Contributte\Invoice\Data\Account('1111', 'CZ4808000000002353462015', 'GIGACZPX');
```

### Payment info

```php
$payment = new WebChemistry\Invoice\Data\PaymentInformation('Kč', '0123456789', '1234', 0.21);
$payment = new Contributte\Invoice\Data\PaymentInformation('Kč', '0123456789', '1234', 0.21);
```

### Order

```php
$order = new WebChemistry\Invoice\Data\Order('20160001', new \DateTime('+ 14 days'), $account, $payment);
$order = new Contributte\Invoice\Data\Order('20160001', new \DateTime('+ 14 days'), $account, $payment);
```

Adding items
Expand All @@ -61,30 +61,30 @@ class CustomFormatter implements IFormatter {
## Generating invoices

```php
$invoice = new WebChemistry\Invoice\Invoice($company);
$invoice = new Contributte\Invoice\Invoice($company);

header('Content-Type: application/pdf; charset=utf-8');
echo $invoice->create($customer, $order);
```

shorter
```php
$invoice = new WebChemistry\Invoice\Invoice($company);
$invoice = new Contributte\Invoice\Invoice($company);

$invoice->send($customer, $order);
```

nette framework way
```php
$invoice = new WebChemistry\Invoice\Invoice($company);
$invoice = new Contributte\Invoice\Invoice($company);

$this->sendResponse($invoice->createResponse($customer, $order));
```

## Generating preview

```php
$invoice->send(WebChemistry\Invoice\Preview\PreviewFactory::createCustomer(), WebChemistry\Invoice\Preview\PreviewFactory::createOrder());
$invoice->send(Contributte\Invoice\Preview\PreviewFactory::createCustomer(), Contributte\Invoice\Preview\PreviewFactory::createOrder());
```

```php
Expand All @@ -95,7 +95,7 @@ $invoice->send(WebChemistry\Invoice\Preview\PreviewFactory::createCustomer(), We

```yaml
extensions:
invoice: WebChemistry\Invoice\DI\InvoiceExtension
invoice: Contributte\Invoice\DI\InvoiceExtension

invoice:
lang: en
Expand All @@ -115,7 +115,7 @@ invoice:

class Component {

public function __construct(WebChemistry\Invoice\Invoice $invoice) {
public function __construct(Contributte\Invoice\Invoice $invoice) {
// ...
}
}
Expand Down
27 changes: 24 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "webchemistry/invoice",
"name": "contributte/invoice",
"type": "library",
"description": "Library for easily and quickly creating invoices for customers.",
"tags": [
"webchemistry",
"contributte",
"invoice"
],
"require": {
Expand All @@ -12,15 +12,36 @@
"setasign/fpdf": "^1.8"
},
"require-dev": {
"ninjify/qa": "^0.8.0",
"ninjify/nunjuck": "^0.2.0",
"nette/di": "^3.0",
"nette/application": "^3.0",
"codeception/codeception": "^2.4"
},
"autoload": {
"psr-4": {
"WebChemistry\\Invoice\\": "src/"
"Contributte\\Invoice\\": "src/"
}
},
"scripts": {
"qa": [
"linter src tests",
"codesniffer src tests"
],
"tests": [
"vendor/bin/codecept run"
],
"phpstan-install": [
"mkdir -p temp/phpstan",
"composer require -d temp/phpstan phpstan/phpstan:^0.10",
"composer require -d temp/phpstan phpstan/phpstan-deprecation-rules:^0.10",
"composer require -d temp/phpstan phpstan/phpstan-nette:^0.10",
"composer require -d temp/phpstan phpstan/phpstan-strict-rules:^0.10"
],
"phpstan": [
"temp/phpstan/vendor/bin/phpstan analyse -l max src"
]
},
"minimum-stability": "RC",
"prefer-stable": true
}
19 changes: 19 additions & 0 deletions ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Contributte">
<!-- Contributte Coding Standard -->
<rule ref="./vendor/ninjify/coding-standard/contributte.xml"/>

<!-- Specific rules -->
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array" value="
src=>Contributte\Invoice
"/>
</properties>
</rule>

<!-- Exclude folders -->
<exclude-pattern>/tests/</exclude-pattern>
<exclude-pattern>/src/Data/Account.php</exclude-pattern>
<exclude-pattern>/src/Renderers/PDF.php</exclude-pattern>
</ruleset>
32 changes: 18 additions & 14 deletions src/Calculators/BcCalculator.php
Original file line number Diff line number Diff line change
@@ -1,61 +1,65 @@
<?php declare(strict_types = 1);

namespace WebChemistry\Invoice\Calculators;
namespace Contributte\Invoice\Calculators;

class BcCalculator implements ICalculator {
use RuntimeException;

class BcCalculator implements ICalculator
{

/** @var int */
private $scale;

public function __construct(int $scale = 0) {
public function __construct(int $scale = 0)
{
if (!function_exists('bcadd')) {
throw new \RuntimeException('BC math is not installed.');
throw new RuntimeException('BC math is not installed.');
}
$this->scale = $scale;
}

/**
* @param string|int|float $op1
* @param string|int|float $op2
* @return string
*/
public function add($op1, $op2): string {
public function add($op1, $op2): string
{
return bcadd((string) $op1, (string) $op2, $this->scale);
}

/**
* @param string|int|float $op1
* @param string|int|float $op2
* @return string
*/
public function mul($op1, $op2): string {
public function mul($op1, $op2): string
{
return bcmul((string) $op1, (string) $op2, $this->scale);
}

/**
* @param string|int|float $op1
* @param string|int|float $op2
* @return string|null
*/
public function div($op1, $op2): ?string {
public function div($op1, $op2): ?string
{
return bcdiv((string) $op1, (string) $op2, $this->scale);
}

/**
* @param string|int|float $op1
* @param string|int|float $op2
* @return string
*/
public function sub($op1, $op2) {
public function sub($op1, $op2): string
{
return bcsub((string) $op1, (string) $op2, $this->scale);
}

/**
* @param string|int|float $op1
* @param string|int|float $op2
* @return int
*/
public function comp($op1, $op2): int {
public function comp($op1, $op2): int
{
return bccomp((string) $op1, (string) $op2, $this->scale);
}

Expand Down
21 changes: 13 additions & 8 deletions src/Calculators/FloatCalculator.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?php declare(strict_types = 1);

namespace WebChemistry\Invoice\Calculators;
namespace Contributte\Invoice\Calculators;

class FloatCalculator implements ICalculator {
class FloatCalculator implements ICalculator
{

/**
* @param string|int|float $op1
* @param string|int|float $op2
* @return float|int
*/
public function add($op1, $op2) {
public function add($op1, $op2)
{
return $op1 + $op2;
}

Expand All @@ -18,7 +20,8 @@ public function add($op1, $op2) {
* @param string|int|float $op2
* @return float|int
*/
public function mul($op1, $op2) {
public function mul($op1, $op2)
{
return $op1 * $op2;
}

Expand All @@ -27,7 +30,8 @@ public function mul($op1, $op2) {
* @param string|int|float $op2
* @return float|int
*/
public function div($op1, $op2) {
public function div($op1, $op2)
{
return $op1 / $op2;
}

Expand All @@ -36,16 +40,17 @@ public function div($op1, $op2) {
* @param string|int|float $op2
* @return float|int
*/
public function sub($op1, $op2) {
public function sub($op1, $op2)
{
return $op1 - $op2;
}

/**
* @param string|int|float $op1
* @param string|int|float $op2
* @return int
*/
public function comp($op1, $op2): int {
public function comp($op1, $op2): int
{
return $op1 <=> $op2;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Calculators/ICalculator.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php declare(strict_types = 1);

namespace WebChemistry\Invoice\Calculators;
namespace Contributte\Invoice\Calculators;

interface ICalculator {
interface ICalculator
{

/**
* @param string|int|float $op1
Expand Down Expand Up @@ -35,7 +36,6 @@ public function sub($op1, $op2);
/**
* @param string|int|float $op1
* @param string|int|float $op2
* @return int
*/
public function comp($op1, $op2): int;

Expand Down
Loading

0 comments on commit 030c9ef

Please sign in to comment.