Skip to content

Commit

Permalink
fixed phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
MartkCz committed Oct 4, 2017
1 parent c606e8f commit 3fb4fd5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ install:
- composer install

script:
- if [ "$PHPSTAN" = "1" ]; then vendor/bin/phpstan analyse src --level=7 --ansi --no-progress; fi
- if [ "$PHPSTAN" = "1" ]; then vendor/bin/phpstan analyse src --level=6 --ansi --no-progress; fi
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"require-dev": {
"nette/di": "^2.3",
"phpstan/phpstan": "^0.7.0"
"phpstan/phpstan": "dev-master"
},
"autoload": {
"psr-4": {
Expand Down
34 changes: 17 additions & 17 deletions src/Data/Subject.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ abstract class Subject {
/** @var string */
protected $name;

/** @var string */
/** @var string|null */
protected $town;

/** @var string */
/** @var string|null */
protected $address;

/** @var string */
/** @var string|null */
protected $zip;

/** @var string */
/** @var string|null */
protected $country;

/** @var string|null */
Expand All @@ -29,14 +29,14 @@ abstract class Subject {

/**
* @param string $name
* @param string $town
* @param string $address
* @param string $zip
* @param string $country
* @param string|null $town
* @param string|null $address
* @param string|null $zip
* @param string|null $country
* @param string|null $tin
* @param string|null $vaTin
*/
public function __construct(string $name, string $town, string $address, string $zip, string $country, ?string $tin = NULL, ?string $vaTin = NULL) {
public function __construct(string $name, ?string $town, ?string $address, ?string $zip, ?string $country, ?string $tin = NULL, ?string $vaTin = NULL) {
$this->name = $name;
$this->town = $town;
$this->address = $address;
Expand All @@ -54,30 +54,30 @@ public function getName(): string {
}

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

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

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

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

Expand Down
43 changes: 28 additions & 15 deletions src/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ class Invoice {

/** @var Template */
private $template;

/** @var Order */
private $order;

/** @var Customer */
private $customer;

/** @var Image */
private $image;

/** @var ITranslator */
private $translator;

Expand Down Expand Up @@ -354,11 +354,11 @@ protected function initialize() {

$this->image->text($this->company->hasTax() ? $this->translate('taxPay') : $this->translate('notTax'),
520, $y + ($multiplier * 50), function (Font $font) {
$font->file($this->template->getFont());
$font->color($this->template->getColorOdd());
$font->align('left');
$font->size(27);
});
$font->file($this->template->getFont());
$font->color($this->template->getColorOdd());
$font->align('left');
$font->size(27);
});

// Company name or full name
$this->image->text($this->company->getName(), 1775, 100, function (Font $font) {
Expand Down Expand Up @@ -392,7 +392,7 @@ protected function initialize() {
$shape->background($this->template->getFontColor());
});

$this->image->text($this->template->getFooter(), $this->image->getWidth() / 2, $this->image->getHeight() - 40, function (Font $font) {
$this->image->text($this->template->getFooter(), (int) ($this->image->getWidth() / 2), $this->image->getHeight() - 40, function (Font $font) {
$font->file($this->template->getFont());
$font->color($this->template->getColorOdd());
$font->align('center');
Expand Down Expand Up @@ -458,9 +458,15 @@ private function getTotalPrice($useTax = FALSE) {
} else {
$tax = 1;
}

foreach ($this->order->getItems() as $item) {
$total += $item->getPrice() * $item->getCount();
if ($useTax === FALSE && $this->order->hasPriceWithTax()) {
foreach ($this->order->getItems() as $item) {
$price = $item->getPrice() - ($item->getPrice() / ($this->order->getPayment()->getTax() + 1.0)) * $this->order->getPayment()->getTax();
$total += $price * $item->getCount();
}
} else {
foreach ($this->order->getItems() as $item) {
$total += $item->getPrice() * $item->getCount();
}
}

return $total * $tax;
Expand Down Expand Up @@ -537,6 +543,13 @@ protected function item($multiplier, Item $item) {
}
}

if ($this->order->hasPriceWithTax() && $this->order->getPayment()->getTax()) {
$price = $item->getPrice() - ($item->getPrice() / ($this->order->getPayment()->getTax() + 1.0)) * $this->order->getPayment()->getTax();
} else {
$price = $item->getPrice();
}


$this->image->text($text, 115, 1350 + $plus, function (Font $font) {
$font->size(27);
$font->file($this->template->getFont());
Expand All @@ -552,15 +565,15 @@ protected function item($multiplier, Item $item) {
$font->color($this->template->getFontColor());
});

$this->image->text($this->formatter->formatMoney($item->getPrice(), $this->order->getPayment()->getCurrency()), 1650, 1350 + $plus, function (Font $font) {
$this->image->text($this->formatter->formatMoney($price, $this->order->getPayment()->getCurrency()), 1650, 1350 + $plus, function (Font $font) {
$font->size(27);
$font->file($this->template->getFont());
$font->valign('center');
$font->align('center');
$font->color($this->template->getFontColor());
});

$this->image->text($this->formatter->formatMoney($item->getCount() * $item->getPrice(), $this->order->getPayment()->getCurrency()), 2322, 1350 + $plus, function (Font $font) {
$this->image->text($this->formatter->formatMoney($item->getCount() * $price, $this->order->getPayment()->getCurrency()), 2322, 1350 + $plus, function (Font $font) {
$font->size(27);
$font->file($this->template->getFontBold());
$font->valign('center');
Expand Down

0 comments on commit 3fb4fd5

Please sign in to comment.