Skip to content

Commit

Permalink
version for php 7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MartkCz committed Jun 1, 2017
1 parent c084730 commit dbeda81
Show file tree
Hide file tree
Showing 23 changed files with 174 additions and 170 deletions.
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
anguage: php

os:
- linux

php:
- 7.0
- 7.1

matrix:
include:
- php: 7.0
env: PHPSTAN=1
- php: 7.1
env: PHPSTAN=1

install:
- composer self-update
- composer install

script:
- if ["$PHPSTAN" = "1"]; then vendor/bin/phpstan analyse src --level=7 --ansi --no-progress; fi
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
[![Build Status](https://travis-ci.org/WebChemistry/invoice.svg?branch=master)](https://travis-ci.org/WebChemistry/invoice)

# PHP Invoice

## Installation

php 7.0

```
composer require webchemistry/invoice
```

php 5.5

```
composer require webchemistry/invoice:^1.0
```

## Usage

### Company
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
"invoice"
],
"require": {
"php": ">=5.5",
"php": ">=7.0",
"intervention/image": "^2.3",
"nette/utils": "^2.3"
},
"require-dev": {
"nette/di": "^2.3"
"nette/di": "^2.3",
"phpstan/phpstan": "^0.7.0"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 7 additions & 5 deletions src/Components/IPaginator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace WebChemistry\Invoice\Components;

use WebChemistry\Invoice\Data\Item;
Expand All @@ -9,26 +11,26 @@ interface IPaginator {
/**
* @return int
*/
public function getTotalPages();
public function getTotalPages(): int;

/**
* @return Item[]
*/
public function getItems();
public function getItems(): array;

/**
* @return bool
*/
public function isLastPage();
public function isLastPage(): bool;

/**
* @return int
*/
public function getCurrentPage();
public function getCurrentPage(): int;

/**
* @return bool
*/
public function hasNextPage();
public function hasNextPage(): bool;

}
4 changes: 3 additions & 1 deletion src/Components/IPaginatorFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace WebChemistry\Invoice\Components;

use WebChemistry\Invoice\Data\Item;
Expand All @@ -10,6 +12,6 @@ interface IPaginatorFactory {
* @param Item[] $items
* @return IPaginator
*/
public function createPaginator(array $items);
public function createPaginator(array $items): IPaginator;

}
12 changes: 7 additions & 5 deletions src/Components/Paginator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace WebChemistry\Invoice\Components;

use WebChemistry\Invoice\Data\Item;
Expand Down Expand Up @@ -28,14 +30,14 @@ public function __construct(array $items) {
/**
* @return int
*/
public function getTotalPages() {
public function getTotalPages(): int {
return $this->totalPages;
}

/**
* @return Item[]
*/
public function getItems() {
public function getItems(): array {
$page = $this->currentPage - 1;

return array_slice($this->items, $page * self::ITEMS_PER_PAGE, $page * self::ITEMS_PER_PAGE + self::ITEMS_PER_PAGE);
Expand All @@ -44,21 +46,21 @@ public function getItems() {
/**
* @return bool
*/
public function isLastPage() {
public function isLastPage(): bool {
return $this->currentPage >= $this->getTotalPages();
}

/**
* @return int
*/
public function getCurrentPage() {
public function getCurrentPage(): int {
return $this->currentPage;
}

/**
* @return bool
*/
public function hasNextPage() {
public function hasNextPage(): bool {
if ($this->isLastPage()) {
return FALSE;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Components/PaginatorFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace WebChemistry\Invoice\Components;

use WebChemistry\Invoice\Data\Item;
Expand All @@ -8,9 +10,9 @@ class PaginatorFactory implements IPaginatorFactory {

/**
* @param Item[] $items
* @return Paginator
* @return IPaginator
*/
public function createPaginator(array $items) {
public function createPaginator(array $items): IPaginator {
return new Paginator($items);
}

Expand Down
2 changes: 2 additions & 0 deletions src/DI/InvoiceExtension.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace WebChemistry\Invoice\DI;

use Nette\DI\CompilerExtension;
Expand Down
31 changes: 6 additions & 25 deletions src/Data/Account.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace WebChemistry\Invoice\Data;
declare(strict_types=1);

use WebChemistry\Invoice\InvoiceException;
namespace WebChemistry\Invoice\Data;

class Account {

Expand All @@ -20,51 +20,32 @@ class Account {
* @param string|null $iBan
* @param string|null $swift
*/
public function __construct($accountNumber, $iBan = NULL, $swift = NULL) {
public function __construct(string $accountNumber, ?string $iBan = NULL, ?string $swift = NULL) {
$this->accountNumber = $accountNumber;
$this->iBan = $iBan;
$this->swift = $swift;

$this->validate();
}

/**
* Validates properties
*
* @throws InvoiceException
*/
private function validate() {
if (!$this->accountNumber || !is_string($this->accountNumber)) {
throw InvoiceException::wrongType('non-empty string', $this->accountNumber);
}
if ($this->iBan !== NULL && !$this->iBan || !is_string($this->iBan)) {
throw InvoiceException::wrongType('non-empty string or null', $this->iBan);
}
if ($this->swift !== NULL && !$this->swift || !is_string($this->swift)) {
throw InvoiceException::wrongType('non-empty string or null', $this->iBan);
}
}

/////////////////////////////////////////////////////////////////

/**
* @return string
*/
public function getAccountNumber() {
public function getAccountNumber(): string {
return $this->accountNumber;
}

/**
* @return null|string
*/
public function getIBan() {
public function getIBan(): ?string {
return $this->iBan;
}

/**
* @return null|string
*/
public function getSwift() {
public function getSwift(): ?string {
return $this->swift;
}

Expand Down
10 changes: 6 additions & 4 deletions src/Data/Company.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace WebChemistry\Invoice\Data;

class Company extends Subject {
Expand All @@ -17,16 +19,16 @@ class Company extends Subject {
* @param string|null $vaTin
* @param bool $hasTax
*/
public function __construct($name, $town, $address, $zip, $country, $tin = NULL, $vaTin = NULL,
$hasTax = FALSE) {
public function __construct(string $name, string $town, string $address, string $zip, string $country, ?string $tin = NULL, ?string $vaTin = NULL,
bool $hasTax = FALSE) {
parent::__construct($name, $town, $address, $zip, $country, $tin, $vaTin);
$this->hasTax = (bool) $hasTax;
$this->hasTax = $hasTax;
}

/**
* @return bool
*/
public function hasTax() {
public function hasTax(): bool {
return $this->hasTax;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Data/Customer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace WebChemistry\Invoice\Data;

class Customer extends Subject {
Expand Down
21 changes: 10 additions & 11 deletions src/Data/Item.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace WebChemistry\Invoice\Data;

use WebChemistry\Invoice\InvoiceException;
Expand All @@ -9,19 +11,19 @@ class Item {
/** @var string */
protected $name;

/** @var int */
/** @var int|float */
protected $count;

/** @var int */
/** @var int|float */
protected $price;

/**
* @param string $name
* @param int $count
* @param int $price
* @param int|float $count
* @param int|float $price
* @throws InvoiceException
*/
public function __construct($name, $count, $price) {
public function __construct(string $name, $count, $price) {
$this->name = $name;
$this->count = $count;
$this->price = $price;
Expand All @@ -35,9 +37,6 @@ public function __construct($name, $count, $price) {
* @throws InvoiceException
*/
private function validate() {
if (!$this->name || !is_string($this->name)) {
throw InvoiceException::wrongType('non-empty string', $this->name);
}
if (!is_numeric($this->count)) {
throw InvoiceException::wrongType('numeric', $this->count);
}
Expand All @@ -51,19 +50,19 @@ private function validate() {
/**
* @return string
*/
public function getName() {
public function getName(): string {
return $this->name;
}

/**
* @return int
* @return int|float
*/
public function getCount() {
return $this->count;
}

/**
* @return int
* @return int|float
*/
public function getPrice() {
return $this->price;
Expand Down
Loading

0 comments on commit dbeda81

Please # to comment.