From 9cc5c3e35430516e2736745af0451cc019d55ebf Mon Sep 17 00:00:00 2001
From: Tobias Graml <51320851+TobiasGraml11@users.noreply.github.com>
Date: Tue, 19 Nov 2019 09:45:04 +0100
Subject: [PATCH 1/7] Extend usage examples (#112)
---
examples/ExampleBaseItem.php | 87 +++++++++
...ItemContent.php => ExampleContentItem.php} | 49 ++---
examples/ExampleProductItem.php | 178 ++++++++++++++++++
examples/ItemProduct.php | 177 -----------------
examples/XmlExample.php | 50 ++---
5 files changed, 319 insertions(+), 222 deletions(-)
create mode 100644 examples/ExampleBaseItem.php
rename examples/{ItemContent.php => ExampleContentItem.php} (55%)
create mode 100644 examples/ExampleProductItem.php
delete mode 100644 examples/ItemProduct.php
diff --git a/examples/ExampleBaseItem.php b/examples/ExampleBaseItem.php
new file mode 100644
index 0000000..fead79a
--- /dev/null
+++ b/examples/ExampleBaseItem.php
@@ -0,0 +1,87 @@
+ [
+ self::DEFAULT_USER_GROUP => [
'pdf304xyz',
'9424585418519'
],
- self::specificUserGroup => [
+ self::SPECIFIC_USER_GROUP => [
'pdf305xyz'
]
];
public $names = [
- self::defaultUserGroup => 'Aliquam eget vehicula.'
+ self::DEFAULT_USER_GROUP => 'Aliquam eget vehicula.'
];
public $summaries = [
- self::defaultUserGroup => 'Nullam blandit in ipsum ac feugiat. Vivamus varius, velit nec.'
+ self::DEFAULT_USER_GROUP => 'Nullam blandit in ipsum ac feugiat. Vivamus varius, velit nec.'
];
public $descriptions = [
- self::defaultUserGroup =>
+ self::DEFAULT_USER_GROUP =>
'In tempus eleifend orci, eu suscipit dolor pellentesque ac. Morbi.'
];
public $prices = [
- self::defaultUserGroup => 0
+ self::DEFAULT_USER_GROUP => 0
];
public $urls = [
- self::defaultUserGroup => 'https://www.store.com/documents/pdf304xyz.pdf',
- self::specificUserGroup => 'https://www.store.com/documents/pdf305xyz.pdf',
+ self::DEFAULT_USER_GROUP => 'https://www.store.com/documents/pdf304xyz.pdf',
+ self::SPECIFIC_USER_GROUP => 'https://www.store.com/documents/pdf305xyz.pdf',
];
public $keywords = [
- self::defaultUserGroup => [
+ self::DEFAULT_USER_GROUP => [
'pdf304xyz',
'9424585418519'
],
- self::specificUserGroup => [
+ self::SPECIFIC_USER_GROUP => [
'pdf305xyz'
]
];
public $bonuses = [
- self::defaultUserGroup => 7
+ self::DEFAULT_USER_GROUP => 7
];
public $salesFrequencies = [
- self::defaultUserGroup => 23
+ self::DEFAULT_USER_GROUP => 23
];
public $dateAddeds = [
- self::defaultUserGroup => '2019-10-31T10:20:28+02:00'
+ self::DEFAULT_USER_GROUP => '2019-10-31T10:20:28+02:00'
];
public $sorts = [
- self::defaultUserGroup => 1
+ self::DEFAULT_USER_GROUP => 1
];
public $userGroups = [
- self::specificUserGroup,
+ self::SPECIFIC_USER_GROUP,
'cHBw'
];
public $images = [
- self::defaultUserGroup => [
+ self::DEFAULT_USER_GROUP => [
'https://www.store.com/images/pdf304xyz.png' => Image::TYPE_DEFAULT,
'https://www.store.com/images/thumbnails/pdf304xyz.png' => Image::TYPE_THUMBNAIL
],
- self::specificUserGroup => [
+ self::SPECIFIC_USER_GROUP => [
'https://www.store.com/images/pdf305xyz.png' => Image::TYPE_DEFAULT,
'https://www.store.com/images/thumbnails/pdf305xyz.png' => Image::TYPE_THUMBNAIL
]
@@ -91,10 +92,10 @@ class ItemContent
public $properties = [
'file_type' => [
- self::defaultUserGroup => 'pdf',
+ self::DEFAULT_USER_GROUP => 'pdf',
],
'number_of_comments' => [
- self::defaultUserGroup => 9,
+ self::DEFAULT_USER_GROUP => 9,
]
];
-}
\ No newline at end of file
+}
diff --git a/examples/ExampleProductItem.php b/examples/ExampleProductItem.php
new file mode 100644
index 0000000..0950a32
--- /dev/null
+++ b/examples/ExampleProductItem.php
@@ -0,0 +1,178 @@
+ [
+ '277KTL',
+ '4987123846879'
+ ],
+ self::SPECIFIC_USER_GROUP => [
+ '377KTL'
+ ]
+ ];
+
+ public $names = [
+ self::DEFAULT_USER_GROUP => 'Adidas Sneaker',
+ self::SPECIFIC_USER_GROUP => 'Adidas Men\'s Sneaker'
+ ];
+
+ public $summaries = [
+ self::DEFAULT_USER_GROUP => 'A cool and fashionable sneaker',
+ self::SPECIFIC_USER_GROUP => 'A cool and fashionable sneaker for men'
+ ];
+
+ public $descriptions = [
+ self::DEFAULT_USER_GROUP =>
+ 'With this sneaker you will walk in style. It\'s available in green and blue.',
+ self::SPECIFIC_USER_GROUP =>
+ 'With this men\'s sneaker you will walk in style. It\'s comes in various sizes and colors.'
+ ];
+
+ public $prices = [
+ self::DEFAULT_USER_GROUP => 44.8,
+ self::SPECIFIC_USER_GROUP => 45.9
+ ];
+
+ public $urls = [
+ self::DEFAULT_USER_GROUP => 'https://www.store.com/sneakers/adidas.html',
+ self::SPECIFIC_USER_GROUP => 'https://www.store.com/sneakers/adidas.html'
+ ];
+
+ public $keywords = [
+ self::DEFAULT_USER_GROUP => [
+ '277KTL',
+ '4987123846879'
+ ],
+ self::SPECIFIC_USER_GROUP => [
+ '377KTL'
+ ]
+ ];
+
+ public $bonuses = [
+ self::DEFAULT_USER_GROUP => 3,
+ self::SPECIFIC_USER_GROUP => 5
+ ];
+
+ public $salesFrequencies = [
+ self::DEFAULT_USER_GROUP => 5,
+ self::SPECIFIC_USER_GROUP => 10
+ ];
+
+ public $dateAddeds = [
+ self::DEFAULT_USER_GROUP => '2019-10-31T10:20:28+02:00',
+ self::SPECIFIC_USER_GROUP => '2019-10-31T10:20:28+02:00'
+ ];
+
+ public $sorts = [
+ self::DEFAULT_USER_GROUP => 5,
+ self::SPECIFIC_USER_GROUP => 7
+ ];
+
+ public $userGroups = [
+ self::SPECIFIC_USER_GROUP,
+ 'cHBw'
+ ];
+
+ public $images = [
+ self::DEFAULT_USER_GROUP => [
+ 'https://www.store.com/images/277KTL.png' => Image::TYPE_DEFAULT,
+ 'https://www.store.com/images/thumbnails/277KTL.png' => Image::TYPE_THUMBNAIL
+ ],
+ self::SPECIFIC_USER_GROUP => [
+ 'https://www.store.com/images/277KTLmen.png' => Image::TYPE_DEFAULT,
+ 'https://www.store.com/images/thumbnails/277KTLmen.png' => Image::TYPE_THUMBNAIL
+ ]
+ ];
+
+ public $attributes = [
+ 'cat' => [
+ 'Sneakers_Men',
+ 'Specials_Sale'
+ ],
+ 'cat_url' => [
+ '/sneakers',
+ '/sneakers/men',
+ '/specials',
+ '/specials/sale'
+ ],
+ 'brand' => [
+ 'Adidas'
+ ],
+ 'color' => [
+ 'green',
+ 'blue'
+ ],
+ 'type' => [
+ 'product',
+ ]
+ ];
+
+ public $properties = [
+ 'sale' => [
+ self::DEFAULT_USER_GROUP => 1,
+ self::SPECIFIC_USER_GROUP => 0
+ ],
+ 'novelty' => [
+ self::DEFAULT_USER_GROUP => 0,
+ self::SPECIFIC_USER_GROUP => 0
+ ],
+ 'logo' => [
+ self::DEFAULT_USER_GROUP => 'http://www.shop.de/brand.png',
+ self::SPECIFIC_USER_GROUP => 'http://www.shop.de/brand.png'
+ ],
+ 'availability' => [
+ self::DEFAULT_USER_GROUP => '4 days',
+ self::SPECIFIC_USER_GROUP => '3 days'
+ ],
+ 'old_price' => [
+ self::DEFAULT_USER_GROUP => 99.9,
+ self::SPECIFIC_USER_GROUP => 99.9
+ ],
+ 'Basic_rate_price' => [
+ self::DEFAULT_USER_GROUP => 99.9,
+ self::SPECIFIC_USER_GROUP => 89.9
+ ],
+ 'variants' => [
+ self::DEFAULT_USER_GROUP => [
+ 'Blue' => [
+ 'title' => 'Adidas Sneaker blue',
+ 'badge' => 'https://www.store.com/images/badges/new.png',
+ 'price' => '13.99',
+ 'old_price' => '',
+ 'sale' => '',
+ 'image' => 'https://www.store.com/images/277KTL-blue.png',
+ 'thumbnail' => 'https://www.store.com/images/thumbs/277KTL-blue.png',
+ 'productUrl' => 'https://www.store.com/sneakers/adidas-blue.html'
+ ],
+ 'Red' => [
+ 'title' => 'Adidas Sneaker red',
+ 'badge' => 'https://www.store.com/images/badges/sale.png',
+ 'price' => '7.49',
+ 'old_price' => '14.99',
+ 'sale' => '50%',
+ 'image' => 'https://www.store.com/images/277KTL-red.png',
+ 'thumbnail' => 'https://www.store.com/images/thumbs/277KTL-red.png',
+ 'productUrl' => 'https://www.store.com/sneakers/adidas-red.html'
+ ],
+ 'Grey' => [
+ 'title' => 'Adidas Sneaker grey',
+ 'badge' => 'https://www.store.com/images/badges/sale.png',
+ 'price' => '6.49',
+ 'old_price' => '12.99',
+ 'sale' => '50%',
+ 'thumbnail' => 'https://www.store.com/images/thumbs/277KTL-grey.png',
+ 'productUrl' => 'https://www.store.com/sneakers/adidas-grey.html'
+ ]
+ ]
+ ]
+ ];
+}
diff --git a/examples/ItemProduct.php b/examples/ItemProduct.php
deleted file mode 100644
index 6fdc367..0000000
--- a/examples/ItemProduct.php
+++ /dev/null
@@ -1,177 +0,0 @@
- [
- '277KTL',
- '4987123846879'
- ],
- self::specificUserGroup => [
- '377KTL'
- ]
- ];
-
- public $names = [
- self::defaultUserGroup => 'Adidas Sneaker',
- self::specificUserGroup => 'Adidas Men\'s Sneaker'
- ];
-
- public $summaries = [
- self::defaultUserGroup => 'A cool and fashionable sneaker',
- self::specificUserGroup => 'A cool and fashionable sneaker for men'
- ];
-
- public $descriptions = [
- self::defaultUserGroup =>
- 'With this sneaker you will walk in style. It\'s available in green and blue.',
- self::specificUserGroup =>
- 'With this men\'s sneaker you will walk in style. It\'s comes in various sizes and colors.'
- ];
-
- public $prices = [
- self::defaultUserGroup => 44.8,
- self::specificUserGroup => 45.9
- ];
-
- public $urls = [
- self::defaultUserGroup => 'https://www.store.com/sneakers/adidas.html',
- self::specificUserGroup => 'https://www.store.com/sneakers/adidas.html'
- ];
-
- public $keywords = [
- self::defaultUserGroup => [
- '277KTL',
- '4987123846879'
- ],
- self::specificUserGroup => [
- '377KTL'
- ]
- ];
-
- public $bonuses = [
- self::defaultUserGroup => 3,
- self::specificUserGroup => 5
- ];
-
- public $salesFrequencies = [
- self::defaultUserGroup => 5,
- self::specificUserGroup => 10
- ];
-
- public $dateAddeds = [
- self::defaultUserGroup => '2019-10-31T10:20:28+02:00',
- self::specificUserGroup => '2019-10-31T10:20:28+02:00'
- ];
-
- public $sorts = [
- self::defaultUserGroup => 5,
- self::specificUserGroup => 7
- ];
-
- public $userGroups = [
- self::specificUserGroup,
- 'cHBw'
- ];
-
- public $images = [
- self::defaultUserGroup => [
- 'https://www.store.com/images/277KTL.png' => Image::TYPE_DEFAULT,
- 'https://www.store.com/images/thumbnails/277KTL.png' => Image::TYPE_THUMBNAIL
- ],
- self::specificUserGroup => [
- 'https://www.store.com/images/277KTLmen.png' => Image::TYPE_DEFAULT,
- 'https://www.store.com/images/thumbnails/277KTLmen.png' => Image::TYPE_THUMBNAIL
- ]
- ];
-
- public $attributes = [
- 'cat' => [
- 'Sneakers_Men',
- 'Specials_Sale'
- ],
- 'cat_url' => [
- '/sneakers',
- '/sneakers/men',
- '/specials',
- '/specials/sale'
- ],
- 'brand' => [
- 'Adidas'
- ],
- 'color' => [
- 'green',
- 'blue'
- ],
- 'type' => [
- 'product',
- ]
- ];
-
- public $properties = [
- 'sale' => [
- self::defaultUserGroup => 1,
- self::specificUserGroup => 0
- ],
- 'novelty' => [
- self::defaultUserGroup => 0,
- self::specificUserGroup => 0
- ],
- 'logo' => [
- self::defaultUserGroup => 'http://www.shop.de/brand.png',
- self::specificUserGroup => 'http://www.shop.de/brand.png'
- ],
- 'availability' => [
- self::defaultUserGroup => '4 days',
- self::specificUserGroup => '3 days'
- ],
- 'old_price' => [
- self::defaultUserGroup => 99.9,
- self::specificUserGroup => 99.9
- ],
- 'Basic_rate_price' => [
- self::defaultUserGroup => 99.9,
- self::specificUserGroup => 89.9
- ],
- 'variants' => [
- self::defaultUserGroup => '{
- "Blue" : {
- "title": "Adidas Sneaker blue",
- "badge": "https://www.store.com/images/badges/new.png",
- "price": "13.99",
- "old_price": "",
- "sale": "",
- "image": "https://www.store.com/images/277KTL-blue.png",
- "thumbnail": "https://www.store.com/images/thumbs/277KTL-blue.png"
- "productUrl": "https://www.store.com/sneakers/adidas-blue.html"
- },
- "Red" : {
- "title": "Adidas Sneaker red",
- "badge": "https://www.store.com/images/badges/sale.png",
- "price": "7.49",
- "old_price": "14.99",
- "sale": "50%",
- "image": "https://www.store.com/images/277KTL-red.png",
- "thumbnail": "https://www.store.com/images/thumbs/277KTL-red.png"
- "productUrl": "https://www.store.com/sneakers/adidas-red.html"
- },
- "Grey" : {
- "title": "Adidas Sneaker grey",
- "badge": "https://www.store.com/images/badges/sale.png",
- "price": "6.49",
- "old_price": "12.99",
- "sale": "50%",
- "thumbnail": "https://www.store.com/images/thumbs/277KTL-grey.png"
- "productUrl": "https://www.store.com/sneakers/adidas-grey.html"
- }
- }'
- ]
- ];
-}
\ No newline at end of file
diff --git a/examples/XmlExample.php b/examples/XmlExample.php
index 7bfde5a..1a82f10 100644
--- a/examples/XmlExample.php
+++ b/examples/XmlExample.php
@@ -1,8 +1,9 @@
item = $exporter->createItem($product->id);
@@ -57,7 +59,7 @@ public function createExport(): string
return $exporter->serializeItems($items, 0, 2, 2);
}
- private function addOrderNumbers($product): void
+ private function addOrderNumbers(ExampleBaseItem $product): void
{
foreach ($product->orderNumbers as $userGroup => $orderNumbers) {
foreach ($orderNumbers as $orderNumber) {
@@ -66,42 +68,42 @@ private function addOrderNumbers($product): void
}
}
- private function addNames($product): void
+ private function addNames(ExampleBaseItem $product): void
{
foreach ($product->names as $userGroup => $name) {
$this->item->addName($name, $userGroup);
}
}
- private function addSummaries($product): void
+ private function addSummaries(ExampleBaseItem $product): void
{
foreach ($product->summaries as $userGroup => $summary) {
$this->item->addSummary($summary, $userGroup);
}
}
- private function addDescriptions($product): void
+ private function addDescriptions(ExampleBaseItem $product): void
{
foreach ($product->descriptions as $userGroup => $description) {
$this->item->addDescription($description, $userGroup);
}
}
- private function addPrices($product): void
+ private function addPrices(ExampleBaseItem $product): void
{
foreach ($product->prices as $userGroup => $price) {
$this->item->addPrice($price, $userGroup);
}
}
- private function addUrls($product): void
+ private function addUrls(ExampleBaseItem $product): void
{
foreach ($product->urls as $userGroup => $url) {
$this->item->addUrl($url, $userGroup);
}
}
- private function addKeywords($product): void
+ private function addKeywords(ExampleBaseItem $product): void
{
foreach ($product->keywords as $userGroup => $keywords) {
foreach ($keywords as $keyword) {
@@ -110,42 +112,42 @@ private function addKeywords($product): void
}
}
- private function addBonuses($product): void
+ private function addBonuses(ExampleBaseItem $product): void
{
foreach ($product->bonuses as $userGroup => $bonus) {
$this->item->addBonus($bonus, $userGroup);
}
}
- private function addSalesFrequencies($product): void
+ private function addSalesFrequencies(ExampleBaseItem $product): void
{
foreach ($product->salesFrequencies as $userGroup => $salesFrequency) {
$this->item->addSalesFrequency($salesFrequency, $userGroup);
}
}
- private function addDateAddeds($product): void
+ private function addDateAddeds(ExampleBaseItem $product): void
{
foreach ($product->dateAddeds as $userGroup => $dateAdded) {
$this->item->addDateAdded(new DateTime($dateAdded), $userGroup);
}
}
- private function addSorts($product): void
+ private function addSorts(ExampleBaseItem $product): void
{
foreach ($product->sorts as $userGroup => $sort) {
$this->item->addSort($sort, $userGroup);
}
}
- private function addUserGroups($product): void
+ private function addUserGroups(ExampleBaseItem $product): void
{
foreach ($product->userGroups as $userGroup) {
$this->item->addUsergroup(new Usergroup($userGroup));
}
}
- private function addImages($product): void
+ private function addImages(ExampleBaseItem $product): void
{
foreach ($product->images as $userGroup => $images) {
foreach ($images as $image => $type) {
@@ -154,16 +156,22 @@ private function addImages($product): void
}
}
- private function addAttributes($product): void
+ private function addAttributes(ExampleBaseItem $product): void
{
foreach ($product->attributes as $attributeName => $attributeValues) {
$this->item->addAttribute(new Attribute($attributeName, $attributeValues));
}
}
- private function addProperties($product): void
+ private function addProperties(ExampleBaseItem $product): void
{
foreach ($product->properties as $propertyName => $values) {
+ if ($propertyName === 'variants') {
+ foreach ($values as $userGroup => $value) {
+ $values[$userGroup] = json_encode($value);
+ }
+ }
+
$propertyElement = new Property($propertyName, $values);
$this->item->addProperty($propertyElement);
}
From 3666ac0b884bf1cd7788106d5e7963c10802d7e8 Mon Sep 17 00:00:00 2001
From: Markus Machatschek
Date: Mon, 16 Dec 2019 11:47:52 +0100
Subject: [PATCH 2/7] Reduce archive size by ignoring test files and
directories (#109)
---
.gitattributes | 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 .gitattributes
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..fd1bcda
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,12 @@
+* text=auto
+
+/.github export-ignore
+/examples export-ignore
+/tests export-ignore
+.codeclimate.yml export-ignore
+.gitattributes export-ignore
+.gitignore export-ignore
+.travis.yml export-ignore
+CONTRIBUTING.md export-ignore
+phpcs.xml.dist export-ignore
+phpunit.xml.dist export-ignore
From c0a2bc508934c53b05161e280c59748ba0e8f164 Mon Sep 17 00:00:00 2001
From: Chris Ortner
Date: Mon, 16 Dec 2019 11:54:17 +0100
Subject: [PATCH 3/7] Apply PSR-12 rules (#103)
* Also, change role from maintainer to developer for mmachatschek
---
composer.json | 2 +-
phpcs.xml.dist | 3 ++-
tests/FINDOLOGIC/Export/Tests/CSVSerializationTest.php | 2 +-
tests/FINDOLOGIC/Export/Tests/XmlSerializationTest.php | 2 +-
4 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/composer.json b/composer.json
index 9b844c6..0089394 100644
--- a/composer.json
+++ b/composer.json
@@ -27,7 +27,7 @@
{
"name": "Markus Machatschek",
"email": "mmachatschek@yahoo.com",
- "role": "maintainer"
+ "role": "developer"
},
{
"name": "Dominik Brader",
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index f8f07a0..06c869f 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -25,6 +25,7 @@
directory.
-->
+
-
\ No newline at end of file
+
diff --git a/tests/FINDOLOGIC/Export/Tests/CSVSerializationTest.php b/tests/FINDOLOGIC/Export/Tests/CSVSerializationTest.php
index 7ec1740..d19dc0d 100644
--- a/tests/FINDOLOGIC/Export/Tests/CSVSerializationTest.php
+++ b/tests/FINDOLOGIC/Export/Tests/CSVSerializationTest.php
@@ -166,7 +166,7 @@ public function testKitchenSink(): void
$expectedAttributeArray = [];
foreach ($expectedAttributes as $attribute => $values) {
- $expectedAttributeArray []= implode('&', array_map(function (string $value) use ($attribute): string {
+ $expectedAttributeArray [] = implode('&', array_map(function (string $value) use ($attribute): string {
return sprintf('%s=%s', $attribute, urlencode($value));
}, $values));
}
diff --git a/tests/FINDOLOGIC/Export/Tests/XmlSerializationTest.php b/tests/FINDOLOGIC/Export/Tests/XmlSerializationTest.php
index 31be5e1..fe5806f 100644
--- a/tests/FINDOLOGIC/Export/Tests/XmlSerializationTest.php
+++ b/tests/FINDOLOGIC/Export/Tests/XmlSerializationTest.php
@@ -121,7 +121,7 @@ public function testMoreItemsSuppliedThanCountValueCausesException(): void
$price = new Price();
//Generate a random price
- $price->setValue(rand(1, 2000)*1.24);
+ $price->setValue(rand(1, 2000) * 1.24);
$item->setPrice($price);
$items[] = $item;
From 56d23a329ef93212c9ffa84340d3f8269824657a Mon Sep 17 00:00:00 2001
From: Christian Ortner
Date: Mon, 16 Dec 2019 12:19:05 +0100
Subject: [PATCH 4/7] Fix some minor lint issues
---
.../Export/Exceptions/InternalCharacterLimitException.php | 2 +-
src/FINDOLOGIC/Export/Helpers/NameAwareValue.php | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/FINDOLOGIC/Export/Exceptions/InternalCharacterLimitException.php b/src/FINDOLOGIC/Export/Exceptions/InternalCharacterLimitException.php
index fd2b0b0..bccc2c6 100644
--- a/src/FINDOLOGIC/Export/Exceptions/InternalCharacterLimitException.php
+++ b/src/FINDOLOGIC/Export/Exceptions/InternalCharacterLimitException.php
@@ -2,7 +2,7 @@
namespace FINDOLOGIC\Export\Exceptions;
-use \RuntimeException;
+use RuntimeException;
abstract class InternalCharacterLimitException extends RuntimeException
{
diff --git a/src/FINDOLOGIC/Export/Helpers/NameAwareValue.php b/src/FINDOLOGIC/Export/Helpers/NameAwareValue.php
index 6d40a7f..8771511 100644
--- a/src/FINDOLOGIC/Export/Helpers/NameAwareValue.php
+++ b/src/FINDOLOGIC/Export/Helpers/NameAwareValue.php
@@ -1,6 +1,5 @@
Date: Tue, 31 Dec 2019 16:28:31 +0100
Subject: [PATCH 5/7] Split up some methods and extend test coverage (#115)
---
src/FINDOLOGIC/Export/CSV/CSVExporter.php | 38 ++++++---
src/FINDOLOGIC/Export/CSV/CSVItem.php | 4 +-
src/FINDOLOGIC/Export/Data/AllKeywords.php | 4 +-
.../Export/Data/AllOrdernumbers.php | 4 +-
src/FINDOLOGIC/Export/Data/Item.php | 13 ++-
src/FINDOLOGIC/Export/Data/Property.php | 2 +-
src/FINDOLOGIC/Export/Exporter.php | 14 ++--
src/FINDOLOGIC/Export/Helpers/DataHelper.php | 15 ++--
.../Helpers/UsergroupAwareMultiValue.php | 2 +
src/FINDOLOGIC/Export/XML/XMLItem.php | 17 ++--
.../Export/Tests/DataHelperTest.php | 80 +++++++++++++++----
11 files changed, 132 insertions(+), 61 deletions(-)
diff --git a/src/FINDOLOGIC/Export/CSV/CSVExporter.php b/src/FINDOLOGIC/Export/CSV/CSVExporter.php
index 3a81884..00dea79 100644
--- a/src/FINDOLOGIC/Export/CSV/CSVExporter.php
+++ b/src/FINDOLOGIC/Export/CSV/CSVExporter.php
@@ -20,7 +20,7 @@ public function __construct($itemsPerPage, $propertyKeys)
{
parent::__construct($itemsPerPage);
- $this->propertyKeys = $propertyKeys;
+ $this->propertyKeys = DataHelper::checkForInvalidCsvPropertyKeys($propertyKeys);
}
/**
@@ -29,16 +29,10 @@ public function __construct($itemsPerPage, $propertyKeys)
public function serializeItems(array $items, int $start = 0, int $count = 0, int $total = 0): string
{
$export = '';
+
// To enable pagination, don't write the heading if it's anything but the first page.
if ($start === 0) {
- $export = self::HEADING;
-
- foreach ($this->propertyKeys as $propertyKey) {
- DataHelper::checkForIllegalCsvPropertyKeys($propertyKey);
-
- $export .= "\t" . $propertyKey;
- }
- $export .= "\n";
+ $export = $this->getHeadingLine();
}
/** @var CSVItem $item */
@@ -74,4 +68,30 @@ public function createItem($id): Item
{
return new CSVItem($id);
}
+
+ /**
+ * Returns the heading line of a CSV document
+ *
+ * @return string
+ */
+ protected function getHeadingLine(): string
+ {
+ return self::HEADING . $this->getPropertyHeadingPart() . "\n";
+ }
+
+ /**
+ * Returns the property part of the heading line.
+ *
+ * @return string
+ */
+ protected function getPropertyHeadingPart(): string
+ {
+ $propertyHeading = '';
+
+ foreach ($this->propertyKeys as $propertyKey) {
+ $propertyHeading .= "\t" . $propertyKey;
+ }
+
+ return $propertyHeading;
+ }
}
diff --git a/src/FINDOLOGIC/Export/CSV/CSVItem.php b/src/FINDOLOGIC/Export/CSV/CSVItem.php
index 0899fec..2d3321a 100644
--- a/src/FINDOLOGIC/Export/CSV/CSVItem.php
+++ b/src/FINDOLOGIC/Export/CSV/CSVItem.php
@@ -111,6 +111,8 @@ private function buildAttributes(): string
private function buildImages(): string
{
+ $imageUrl = '';
+
// Use the first available image that is not restricted by usergroup. If more than one usergroup-less image
// exists, cause an error because it's no longer certain which one is intended to be used.
if (array_key_exists('', $this->images)) {
@@ -124,8 +126,6 @@ private function buildImages(): string
'Cannot generate CSV if there is not one definitive image set.'
);
}
- } else {
- $imageUrl = '';
}
return $imageUrl;
diff --git a/src/FINDOLOGIC/Export/Data/AllKeywords.php b/src/FINDOLOGIC/Export/Data/AllKeywords.php
index eabc692..57e0056 100644
--- a/src/FINDOLOGIC/Export/Data/AllKeywords.php
+++ b/src/FINDOLOGIC/Export/Data/AllKeywords.php
@@ -22,9 +22,9 @@ public function getCsvFragment(array $availableProperties = []): string
return implode(',', array_map(function (Keyword $keyword): string {
return $keyword->getCsvFragment();
}, $this->values['']));
- } else {
- return '';
}
+
+ return '';
}
/**
diff --git a/src/FINDOLOGIC/Export/Data/AllOrdernumbers.php b/src/FINDOLOGIC/Export/Data/AllOrdernumbers.php
index 0f99457..b8e67a7 100644
--- a/src/FINDOLOGIC/Export/Data/AllOrdernumbers.php
+++ b/src/FINDOLOGIC/Export/Data/AllOrdernumbers.php
@@ -20,9 +20,9 @@ public function getCsvFragment(array $availableProperties = []): string
return implode('|', array_map(function (Ordernumber $ordernumber): string {
return $ordernumber->getCsvFragment();
}, $this->values['']));
- } else {
- return '';
}
+
+ return '';
}
/**
diff --git a/src/FINDOLOGIC/Export/Data/Item.php b/src/FINDOLOGIC/Export/Data/Item.php
index eb6e572..f9ad6a6 100644
--- a/src/FINDOLOGIC/Export/Data/Item.php
+++ b/src/FINDOLOGIC/Export/Data/Item.php
@@ -438,15 +438,14 @@ public function addMergedAttribute(Attribute $attribute): void
throw new EmptyElementsNotAllowedException('Attribute', $attribute->getKey());
}
- if (!isset($this->attributes[$attribute->getKey()])) {
- $this->attributes[$attribute->getKey()] = $attribute;
- return;
+ if (array_key_exists($attribute->getKey(), $this->attributes)) {
+ $attribute = new Attribute(
+ $attribute->getKey(),
+ array_unique(array_merge($this->attributes[$attribute->getKey()]->getValues(), $attribute->getValues()))
+ );
}
- $this->attributes[$attribute->getKey()] = new Attribute(
- $attribute->getKey(),
- array_unique(array_merge($this->attributes[$attribute->getKey()]->getValues(), $attribute->getValues()))
- );
+ $this->attributes[$attribute->getKey()] = $attribute;
}
/**
diff --git a/src/FINDOLOGIC/Export/Data/Property.php b/src/FINDOLOGIC/Export/Data/Property.php
index 99a7dc4..a7f85ec 100644
--- a/src/FINDOLOGIC/Export/Data/Property.php
+++ b/src/FINDOLOGIC/Export/Data/Property.php
@@ -72,7 +72,7 @@ protected function setValues(array $values): void
$this->values = [];
/**
- * As we can not check if the values of the given array is associative,
+ * As we can not check if the values of the given array are associative,
* we trigger a notice if the array keys are not a string.
*/
array_walk($values, function (/** @noinspection PhpUnusedParameterInspection */ $item, $key) {
diff --git a/src/FINDOLOGIC/Export/Exporter.php b/src/FINDOLOGIC/Export/Exporter.php
index 136598e..6ef467e 100644
--- a/src/FINDOLOGIC/Export/Exporter.php
+++ b/src/FINDOLOGIC/Export/Exporter.php
@@ -23,6 +23,13 @@ abstract class Exporter
*/
public const TYPE_CSV = 1;
+ protected $itemsPerPage;
+
+ protected function __construct($itemsPerPage)
+ {
+ $this->itemsPerPage = $itemsPerPage;
+ }
+
/**
* Creates an exporter for the desired output format.
*
@@ -52,13 +59,6 @@ public static function create(int $type, int $itemsPerPage = 20, array $csvPrope
return $exporter;
}
- protected $itemsPerPage;
-
- protected function __construct($itemsPerPage)
- {
- $this->itemsPerPage = $itemsPerPage;
- }
-
/**
* Turns the provided items into their serialized form.
*
diff --git a/src/FINDOLOGIC/Export/Helpers/DataHelper.php b/src/FINDOLOGIC/Export/Helpers/DataHelper.php
index e4a60d0..87aacdc 100644
--- a/src/FINDOLOGIC/Export/Helpers/DataHelper.php
+++ b/src/FINDOLOGIC/Export/Helpers/DataHelper.php
@@ -77,14 +77,19 @@ public static function validateUrl(string $url): string
/**
* Verifies that property keys for use in CSV export don't contain characters that could break the format fatally.
*
- * @param string $propertyKey The property key to check.
- * @throw BadPropertyKeyException In case the property key contains dangerous characters.
+ * @param array $propertyKeys The property keys to check.
+ * @return array The validated property keys.
+ * @throws BadPropertyKeyException In case the property key contains dangerous characters.
*/
- public static function checkForIllegalCsvPropertyKeys(string $propertyKey): void
+ public static function checkForInvalidCsvPropertyKeys(array $propertyKeys): array
{
- if (strpos($propertyKey, "\t") !== false || strpos($propertyKey, "\n") !== false) {
- throw new BadPropertyKeyException($propertyKey);
+ foreach ($propertyKeys as $propertyKey) {
+ if (strpos($propertyKey, "\t") !== false || strpos($propertyKey, "\n") !== false) {
+ throw new BadPropertyKeyException($propertyKey);
+ }
}
+
+ return $propertyKeys;
}
/**
diff --git a/src/FINDOLOGIC/Export/Helpers/UsergroupAwareMultiValue.php b/src/FINDOLOGIC/Export/Helpers/UsergroupAwareMultiValue.php
index 0791a7a..fceec66 100644
--- a/src/FINDOLOGIC/Export/Helpers/UsergroupAwareMultiValue.php
+++ b/src/FINDOLOGIC/Export/Helpers/UsergroupAwareMultiValue.php
@@ -72,9 +72,11 @@ public function getDomSubtree(DOMDocument $document): DOMElement
foreach ($this->getValues() as $usergroup => $usergroupValues) {
$usergroupCollectionElem = XMLHelper::createElement($document, $this->usergroupCollectionName);
+
if ($usergroup) {
$usergroupCollectionElem->setAttribute('usergroup', $usergroup);
}
+
$rootCollectionElem->appendChild($usergroupCollectionElem);
/** @var UsergroupAwareMultiValueItem $value */
diff --git a/src/FINDOLOGIC/Export/XML/XMLItem.php b/src/FINDOLOGIC/Export/XML/XMLItem.php
index 1e6f438..df41ec6 100644
--- a/src/FINDOLOGIC/Export/XML/XMLItem.php
+++ b/src/FINDOLOGIC/Export/XML/XMLItem.php
@@ -64,9 +64,11 @@ private function buildProperties(DOMDocument $document): DOMElement
foreach ($this->properties as $usergroup => $usergroupSpecificProperties) {
$usergroupPropsElem = XMLHelper::createElement($document, 'properties');
+
if ($usergroup) {
$usergroupPropsElem->setAttribute('usergroup', $usergroup);
}
+
$allProps->appendChild($usergroupPropsElem);
foreach ($usergroupSpecificProperties as $key => $value) {
@@ -117,9 +119,10 @@ private function buildImages(DOMDocument $document): DOMElement
$allImagesElem = XMLHelper::createElement($document, 'allImages');
if ($this->images) {
- if (array_key_exists("", $this->images)) {
+ if (array_key_exists('', $this->images)) {
foreach ($this->images as $usergroup => $images) {
$usergroupImagesElem = XMLHelper::createElement($document, 'images');
+
if ($usergroup) {
$usergroupImagesElem->setAttribute('usergroup', $usergroup);
}
@@ -163,23 +166,17 @@ private function buildUsergroups(DOMDocument $document): DOMElement
*
* @param array $images The images to validate.
* @return boolean Whether the images are valid or not.
+ * @throws BaseImageMissingException
*/
private static function validateImages(array $images): bool
{
- $valid = false;
-
foreach ($images as $image) {
if ($image->getType() === Image::TYPE_DEFAULT) {
- $valid = true;
- break;
+ return true;
}
}
- if (!$valid) {
- throw new BaseImageMissingException();
- }
-
- return $valid;
+ throw new BaseImageMissingException();
}
public function getInsteadPrice(): void
diff --git a/tests/FINDOLOGIC/Export/Tests/DataHelperTest.php b/tests/FINDOLOGIC/Export/Tests/DataHelperTest.php
index 62e0a4e..fe825c6 100644
--- a/tests/FINDOLOGIC/Export/Tests/DataHelperTest.php
+++ b/tests/FINDOLOGIC/Export/Tests/DataHelperTest.php
@@ -2,6 +2,7 @@
namespace FINDOLOGIC\Export\Tests;
+use Exception;
use FINDOLOGIC\Export\Data\AllKeywords;
use FINDOLOGIC\Export\Data\AllOrdernumbers;
use FINDOLOGIC\Export\Data\Attribute;
@@ -20,6 +21,7 @@
use FINDOLOGIC\Export\Data\Usergroup;
use FINDOLOGIC\Export\Exceptions\AttributeKeyLengthException;
use FINDOLOGIC\Export\Exceptions\AttributeValueLengthException;
+use FINDOLOGIC\Export\Exceptions\BadPropertyKeyException;
use FINDOLOGIC\Export\Exceptions\EmptyValueNotAllowedException;
use FINDOLOGIC\Export\Exceptions\GroupNameLengthException;
use FINDOLOGIC\Export\Exceptions\ItemIdLengthException;
@@ -32,6 +34,27 @@
class DataHelperTest extends TestCase
{
+ /**
+ * @noinspection PhpMethodMayBeStaticInspection
+ *
+ * Scenarios for empty value validation.
+ *
+ * @return array Cases with the value to check and whether it should cause a validation issue.
+ */
+ public function emptyValueProvider(): array
+ {
+ return [
+ 'empty string' => ['', true],
+ 'non-zero integer' => [123, false],
+ 'zero as integer' => [0, false],
+ 'non-zero float' => [12.3, false],
+ 'zero as float' => [0.0, false],
+ 'zero as string' => ['0', false],
+ 'null' => ['', true],
+ 'false' => [false, true]
+ ];
+ }
+
/**
* @dataProvider emptyValueProvider
*
@@ -67,21 +90,19 @@ public function testEmptyValueDetectsEmptyStringsOnly($value, bool $shouldCauseE
/**
* @noinspection PhpMethodMayBeStaticInspection
*
- * Scenarios for empty value validation.
+ * Scenarios for numeric value validation.
*
* @return array Cases with the value to check and whether it should cause a validation issue.
*/
- public function emptyValueProvider(): array
+ public function numericValueProvider(): array
{
return [
- 'empty string' => ['', true],
+ 'string' => ['blubbergurke', true],
'non-zero integer' => [123, false],
'zero as integer' => [0, false],
'non-zero float' => [12.3, false],
'zero as float' => [0.0, false],
- 'zero as string' => ['0', false],
- 'null' => ['', true],
- 'false' => [false, true]
+ 'zero as string' => ['0', false]
];
}
@@ -114,24 +135,51 @@ public function testNumericValuesAreValidated($value, bool $shouldCauseException
}
/**
- * @noinspection PhpMethodMayBeStaticInspection
- *
- * Scenarios for numeric value validation.
+ * Scenarios for property key validation.
*
* @return array Cases with the value to check and whether it should cause a validation issue.
*/
- public function numericValueProvider(): array
+ public function propertyKeyProvider(): array
{
return [
- 'string' => ['blubbergurke', true],
- 'non-zero integer' => [123, false],
- 'zero as integer' => [0, false],
- 'non-zero float' => [12.3, false],
- 'zero as float' => [0.0, false],
- 'zero as string' => ['0', false]
+ 'Valid property keys' => [
+ ['valid_property_key', 'also-a_valid-propery-key',],
+ false,
+ ],
+ 'Invalid property keys' => [
+ ["invalid\tproperty\nkey", "invalid\tkey", "invalid\nkey",],
+ true,
+ ],
+ 'Mixed valid and invalid property keys' => [
+ ['valid_property_key',"invalid\tproperty\nkey",],
+ true,
+ ],
];
}
+ /**
+ * @dataProvider propertyKeyProvider
+ *
+ * @param array $propertyKeys The keys to check.
+ * @param bool $shouldCauseException Whether the array should cause an exception or not.
+ */
+ public function testAddingInvalidCsvPropertyKeysCausesException(
+ array $propertyKeys,
+ bool $shouldCauseException
+ ): void {
+ try {
+ $validatedPropertyKeys = DataHelper::checkForInvalidCsvPropertyKeys($propertyKeys);
+
+ $this->assertEquals($propertyKeys, $validatedPropertyKeys);
+ } catch (Exception $exception) {
+ if (!$shouldCauseException) {
+ $this->fail('This should not fail.');
+ } else {
+ $this->assertEquals(get_class($exception), BadPropertyKeyException::class);
+ }
+ }
+ }
+
/**
* Test if character limit of data helper causes exception when called outside attribute class.
*/
From e112c282835a4e8490a1a4e7081d5c71ffc3cc5c Mon Sep 17 00:00:00 2001
From: Markus Machatschek
Date: Tue, 31 Dec 2019 16:43:19 +0100
Subject: [PATCH 6/7] Add support for PHP 7.4 (#113)
---
.travis.yml | 4 ++--
README.md | 2 +-
composer.json | 8 ++++----
.../Exceptions/EmptyElementsNotAllowedException.php | 12 +++++-------
4 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 703949d..7a1e53b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,7 +4,7 @@ php:
- 7.1
- 7.2
- 7.3
- - 7.4snapshot
+ - 7.4
install:
- composer install
@@ -13,4 +13,4 @@ script:
- composer lint
after_success:
- - bash <(curl -s https://codecov.io/bash)
\ No newline at end of file
+ - bash <(curl -s https://codecov.io/bash)
diff --git a/README.md b/README.md
index c345018..5e8de6f 100644
--- a/README.md
+++ b/README.md
@@ -126,4 +126,4 @@ releases.
## Contributors
-See [contribution guide](CONTRIBUTING.md).
\ No newline at end of file
+See [contribution guide](CONTRIBUTING.md).
diff --git a/composer.json b/composer.json
index 0089394..479b990 100644
--- a/composer.json
+++ b/composer.json
@@ -6,16 +6,16 @@
"php": "^7.1",
"ext-dom": "*",
"ext-mbstring": "*",
- "findologic/xml-export-schema": "^1.3"
+ "findologic/xml-export-schema": "^1.4"
},
"require-dev": {
- "phpunit/phpunit": ">7.5",
- "squizlabs/php_codesniffer": "^3.4"
+ "phpunit/phpunit": "^7.5",
+ "squizlabs/php_codesniffer": "^3.5"
},
"scripts": {
"lint": "phpcs",
"fix": "phpcbf",
- "test": "phpunit -c phpunit.xml.dist"
+ "test": "phpunit"
},
"license": "MIT",
"authors": [
diff --git a/src/FINDOLOGIC/Export/Exceptions/EmptyElementsNotAllowedException.php b/src/FINDOLOGIC/Export/Exceptions/EmptyElementsNotAllowedException.php
index 7f6e2f2..b6452e7 100644
--- a/src/FINDOLOGIC/Export/Exceptions/EmptyElementsNotAllowedException.php
+++ b/src/FINDOLOGIC/Export/Exceptions/EmptyElementsNotAllowedException.php
@@ -8,12 +8,10 @@ class EmptyElementsNotAllowedException extends RuntimeException
{
public function __construct(string $elementType, string $elementKey)
{
- parent::__construct(
- sprintf(
- 'Elements with empty values are not allowed. "%s" with the name "%s"',
- $elementType,
- $elementKey
- )
- );
+ parent::__construct(sprintf(
+ 'Elements with empty values are not allowed. "%s" with the name "%s"',
+ $elementType,
+ $elementKey
+ ));
}
}
From 395d0ead2ddd21daaf00a5f5687a836f49310295 Mon Sep 17 00:00:00 2001
From: Chris Ortner
Date: Wed, 19 Feb 2020 12:38:54 +0100
Subject: [PATCH 7/7] Add required URL to tests and documentation (#116)
---
README.md | 16 ++++++++++++++++
.../Export/Tests/XmlSerializationTest.php | 2 ++
2 files changed, 18 insertions(+)
diff --git a/README.md b/README.md
index 5e8de6f..f4bd9eb 100644
--- a/README.md
+++ b/README.md
@@ -70,8 +70,16 @@ $exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('123');
+$item->addName('Test');
+$item->addUrl('http://example.org/test.html');
$item->addPrice(13.37);
// Alternative long form:
+// $name = new Name();
+// $name->setValue('Test');
+// $item->setName($name);
+// $url = new Url();
+// $url->setValue('http://example.org/test.html');
+// $item->setUrl($url);
// $price = new Price();
// $price->setValue(13.37);
// $item->setPrice($price);
@@ -91,7 +99,15 @@ $exporter = Exporter::create(Exporter::TYPE_CSV);
$item = $exporter->createItem('123');
$item->addPrice(13.37);
+$item->addName('Test');
+$item->addUrl('http://example.org/test.html');
// Alternative long form:
+// $name = new Name();
+// $name->setValue('Test');
+// $item->setName($name);
+// $url = new Url();
+// $url->setValue('http://example.org/test.html');
+// $item->setUrl($url);
// $price = new Price();
// $price->setValue(13.37);
// $item->setPrice($price);
diff --git a/tests/FINDOLOGIC/Export/Tests/XmlSerializationTest.php b/tests/FINDOLOGIC/Export/Tests/XmlSerializationTest.php
index fe5806f..8a6364d 100644
--- a/tests/FINDOLOGIC/Export/Tests/XmlSerializationTest.php
+++ b/tests/FINDOLOGIC/Export/Tests/XmlSerializationTest.php
@@ -79,6 +79,7 @@ private function getMinimalItem(): Item
$item = $this->exporter->createItem('123');
$item->addName('Alternative name');
+ $item->addUrl('http://example.org/item.html');
$price = new Price();
$price->setValue('13.37');
@@ -591,6 +592,7 @@ public function testAllPricesCanBeSet(): void
$item = $this->exporter->createItem('123');
$item->setAllPrices([$price, $anotherPrice]);
$item->addName('Best item ever');
+ $item->addUrl('http://example.org/item.html');
$page = new Page(0, 1, 1);
$page->addItem($item);