Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit 6de8c7c

Browse files
committed
Created Shop model
1 parent c89ed28 commit 6de8c7c

File tree

4 files changed

+65
-19
lines changed

4 files changed

+65
-19
lines changed

index.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Receipt.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,14 @@ public function getShopNr(): int
4848
}
4949

5050
/**
51-
* @return array
51+
* @return Shop
5252
*/
53-
public function getShop(): array
53+
public function getShop(): Shop
5454
{
5555
$rawPos = explode("\n", $this->raw_receipt);
5656
$address_part = array_slice($rawPos, 0, 5);
5757
preg_match('/(\d{5}) (.*)/', implode("\n", $address_part), $zip_city);
58-
return [
59-
'name' => trim($address_part[0]),
60-
'address' => trim($address_part[1]),
61-
'zip' => trim($zip_city[1]),
62-
'city' => trim($zip_city[2])
63-
];
58+
return new Shop(trim($address_part[0]), trim($address_part[1]), trim($zip_city[1]), trim($zip_city[2]));
6459
}
6560

6661
/**

src/Shop.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace REWEParser;
4+
5+
class Shop
6+
{
7+
8+
private $name;
9+
private $address;
10+
private $postalCode;
11+
private $city;
12+
13+
public function __construct(string $name = NULL, string $address = NULL, string $postalCode = NULL, string $city = NULL)
14+
{
15+
$this->name = $name;
16+
$this->address = $address;
17+
$this->postalCode = $postalCode;
18+
$this->city = $city;
19+
}
20+
21+
public function getName(): string
22+
{
23+
return $this->name;
24+
}
25+
26+
public function getAddress(): string
27+
{
28+
return $this->address;
29+
}
30+
31+
public function getPostalCode(): string
32+
{
33+
return $this->postalCode;
34+
}
35+
36+
public function getCity(): string
37+
{
38+
return $this->city;
39+
}
40+
}

tests/ReceiptParsingTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public function testCanBeCreatedFromValidEmailAddress(): void
1111

1212
/**
1313
* @return void
14+
* @throws \REWEParser\Exception\ReceiptParseException
15+
* @throws \Spatie\PdfToText\Exceptions\PdfNotFound
1416
*/
1517
public function testNegativeTotalAmount(): void
1618
{
@@ -20,6 +22,8 @@ public function testNegativeTotalAmount(): void
2022

2123
/**
2224
* @return void
25+
* @throws \REWEParser\Exception\ReceiptParseException
26+
* @throws \Spatie\PdfToText\Exceptions\PdfNotFound
2327
*/
2428
public function testBonParsingWeight(): void
2529
{
@@ -56,6 +60,8 @@ public function testBonParsingWeight(): void
5660

5761
/**
5862
* @return void
63+
* @throws \REWEParser\Exception\ReceiptParseException
64+
* @throws \Spatie\PdfToText\Exceptions\PdfNotFound
5965
*/
6066
public function testBonParsingPaymentMethods(): void
6167
{
@@ -84,4 +90,20 @@ public function testBonParsingPaymentMethods(): void
8490
$this->assertEquals(1.38, $positions['SCHOKOLADE']['price_total']);
8591
$this->assertEquals(0.53, $positions['SCHMAND 24%']['price_single']);
8692
}
93+
94+
/**
95+
* @throws \Spatie\PdfToText\Exceptions\PdfNotFound
96+
*/
97+
public function testShopParsing(): void
98+
{
99+
$receipt = REWEParser\Parser::parseFromPDF(dirname(__FILE__) . '/receipts/negative_amount.pdf', '/usr/local/bin/pdftotext');
100+
$shop = $receipt->getShop();
101+
102+
$this->assertInstanceOf(\REWEParser\Shop::class, $shop);
103+
104+
$this->assertEquals("REWE Mustermann oHG", $shop->getName());
105+
$this->assertEquals("Muster-Str. 1", $shop->getAddress());
106+
$this->assertEquals("12345", $shop->getPostalCode());
107+
$this->assertEquals("Musterstadt", $shop->getCity());
108+
}
87109
}

0 commit comments

Comments
 (0)