Skip to content

Commit

Permalink
Merge pull request #35 from fruitl00p/feature/support-php8+fixes
Browse files Browse the repository at this point in the history
Feature/support php8+fixes
  • Loading branch information
JKetelaar authored Nov 17, 2022
2 parents 2494317 + 3df6dac commit 16f37c4
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 50 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"guzzlehttp/guzzle": "^6.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"friendsofphp/php-cs-fixer": "^3.13",
"phpunit/phpunit": "^9.5"
},
"autoload": {
Expand Down
65 changes: 29 additions & 36 deletions src/JKetelaar/Kiyoh/Factory/ReviewFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @author JKetelaar
*/
Expand All @@ -19,28 +22,20 @@ class ReviewFactory
*/
public static function createCompany(SimpleXMLElement $element): Company
{
$averageRating = $element->averageRating;
$numberReviews = $element->numberReviews;
$last12MonthAverageRating = $element->last12MonthAverageRating;
$last12MonthNumberReviews = $element->last12MonthNumberReviews;
$percentageRecommendation = $element->percentageRecommendation;
$locationId = $element->locationId;
$locationName = $element->locationName;

$company = new Company(
(float) $averageRating,
(int) $numberReviews,
(float) $last12MonthAverageRating,
(int) $last12MonthNumberReviews,
(int) $percentageRecommendation,
(int) $locationId,
$locationName
(float) $element->averageRating,
(int) $element->numberReviews,
(float) $element->last12MonthAverageRating,
(int) $element->last12MonthNumberReviews,
(int) $element->percentageRecommendation,
(int) $element->locationId,
(string) $element->locationName
);

$reviews = [];

foreach ($element->reviews->reviews as $review) {
$reviews[] = (self::createReview($review));
$reviews[] = self::createReview($review);
}

$company->setReviews($reviews);
Expand All @@ -55,19 +50,17 @@ public static function createCompany(SimpleXMLElement $element): Company
*/
public static function createReview(SimpleXMLElement $element): Review
{
$id = $element->reviewId;
$author = $element->reviewAuthor;
$city = $element->city;
$rating = $element->rating;
$comment = (isset($element->reviewComments) ? $element->reviewComments : '');
$dateSince = $element->dateSince;
$updatedSince = $element->updatedSince;
$referenceCode = $element->referenceCode;

$content = self::createReviewContent($element->reviewContent->reviewContent);

$review = new Review($id, $author, $city, (float) $rating, $comment, $dateSince, $updatedSince, $referenceCode);
$review->setContent($content);
$review = new Review(
(string) $element->reviewId,
(string) $element->reviewAuthor,
(string) $element->city,
(float) $element->rating,
(isset($element->reviewComments) ? (string) $element->reviewComments : ''),
(string) $element->dateSince,
(string) $element->updatedSince,
(string) $element->referenceCode
);
$review->setContent(self::createReviewContent($element->reviewContent->reviewContent));

return $review;
}
Expand All @@ -82,13 +75,13 @@ public static function createReviewContent(SimpleXMLElement $elements): array
$content = [];

foreach ($elements as $element) {
$group = $element->questionGroup;
$type = $element->questionType;
$rating = $element->rating;
$order = $element->order;
$translation = $element->questionTranslation;

$content[] = new ReviewContent($group, $type, $rating, (int) $order, $translation);
$content[] = new ReviewContent(
(string) $element->questionGroup,
(string) $element->questionType,
(string) $element->rating,
(int) $element->order,
(string) $element->questionTranslation
);
}

return $content;
Expand Down
5 changes: 4 additions & 1 deletion src/JKetelaar/Kiyoh/Kiyoh.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @author JKetelaar
*/
Expand All @@ -11,7 +14,7 @@

class Kiyoh
{
const COMPANY_REVIEWS_URL = 'https://www.kiyoh.com/v1/review/feed.xml?hash=%s&limit=%s';
public const COMPANY_REVIEWS_URL = 'https://www.kiyoh.com/v1/review/feed.xml?hash=%s&limit=%s';

/**
* @var string
Expand Down
3 changes: 3 additions & 0 deletions src/JKetelaar/Kiyoh/Model/Company.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @author JKetelaar
*/
Expand Down
6 changes: 5 additions & 1 deletion src/JKetelaar/Kiyoh/Model/Review.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @author JKetelaar
*/
Expand Down Expand Up @@ -292,7 +295,8 @@ public function setUpdatedSince(DateTime $updatedSince): self
* Retrieves the referenceCode from the review.
* @return string
*/
public function getReferenceCode(): string {
public function getReferenceCode(): string
{
return $this->referenceCode;
}

Expand Down
15 changes: 7 additions & 8 deletions src/JKetelaar/Kiyoh/Model/ReviewContent.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @author JKetelaar
*/
Expand Down Expand Up @@ -78,13 +81,13 @@ public function getRating()
$rating = $this->rating;
switch ($this->getType()) {
case 'INT':
$rating = intval($rating);
$rating = (int) $rating;
break;
case 'BOOLEAN':
$rating = filter_var($rating, FILTER_VALIDATE_BOOLEAN);
break;
default:
$rating = strval($rating);
$rating = (string) $rating;
break;
}

Expand All @@ -103,7 +106,7 @@ public function setRating(string $rating): self
$rating = $this->validateRating($rating);
break;
default:
$rating = strval($rating);
$rating = (string) $rating;
break;
}
$this->rating = $rating;
Expand Down Expand Up @@ -138,11 +141,7 @@ public function setType(string $type): self
*/
private function validateRating(string $rating): string
{
if (is_bool($rating)) {
return $rating ? 'true' : 'false';
} else {
return strval($rating);
}
return $rating;
}

/**
Expand Down
9 changes: 6 additions & 3 deletions tests/Unit/KiyohTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @author JKetelaar
*/
Expand All @@ -10,8 +13,8 @@

final class KiyohTest extends TestCase
{
const KIYOH_KEY_ENV_KEY = 'KIYOH_KEY';
const REVIEW_COUNT = 5;
private const KIYOH_KEY_ENV_KEY = 'KIYOH_KEY';
private const REVIEW_COUNT = 5;

public function testKiyoh()
{
Expand All @@ -29,6 +32,6 @@ public function testKiyoh()

$reviews = $kiyoh->getCompany()->getReviews();
$this->assertNotNull($reviews);
$this->assertEquals(self::REVIEW_COUNT, count($reviews));
$this->assertCount(self::REVIEW_COUNT, $reviews);
}
}

0 comments on commit 16f37c4

Please sign in to comment.